217 lines
9.2 KiB
PHP
217 lines
9.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/header.php';
|
|
|
|
if (!$user) {
|
|
header('Location: /auth/login.php');
|
|
exit;
|
|
}
|
|
|
|
$stmt = db()->prepare("SELECT available FROM user_balances WHERE user_id = ? AND symbol = 'USDT'");
|
|
$stmt->execute([$user['id']]);
|
|
$bal = $stmt->fetch();
|
|
$available = $bal['available'] ?? 0;
|
|
?>
|
|
|
|
<div class="container py-4">
|
|
<div class="row justify-content-center">
|
|
<div class="col-lg-8">
|
|
<!-- Back Button -->
|
|
<div class="mb-4">
|
|
<a href="javascript:history.back()" class="text-white-50 text-decoration-none d-inline-flex align-items-center gap-2">
|
|
<i class="bi bi-arrow-left fs-4"></i>
|
|
<span><?= __('back') ?></span>
|
|
</a>
|
|
</div>
|
|
|
|
<div class="card bg-surface border-secondary rounded-4 shadow-lg overflow-hidden mb-4">
|
|
<div class="card-header border-secondary bg-black bg-opacity-30 p-4">
|
|
<h4 class="mb-0 fw-bold d-flex align-items-center gap-3 text-white">
|
|
<i class="bi bi-cash-stack text-warning"></i>
|
|
<?= __('withdraw') ?>
|
|
</h4>
|
|
</div>
|
|
|
|
<div class="card-body p-4">
|
|
<!-- Tabs -->
|
|
<ul class="nav nav-pills nav-fill mb-4 bg-black p-1 rounded-pill" id="withdrawTabs" role="tablist">
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link active rounded-pill px-4" id="crypto-withdraw-tab" data-bs-toggle="pill" data-bs-target="#crypto-withdraw" type="button" role="tab"><?= __('crypto_withdraw') ?></button>
|
|
</li>
|
|
<li class="nav-item" role="presentation">
|
|
<button class="nav-link rounded-pill px-4" id="fiat-withdraw-tab" data-bs-toggle="pill" data-bs-target="#fiat-withdraw" type="button" role="tab"><?= __('fiat_withdraw') ?></button>
|
|
</li>
|
|
</ul>
|
|
|
|
<div class="tab-content" id="withdrawTabsContent">
|
|
<!-- USDT Withdrawal -->
|
|
<div class="tab-pane fade show active" id="crypto-withdraw" role="tabpanel">
|
|
<form id="cryptoWithdrawForm">
|
|
<div class="mb-4">
|
|
<label class="form-label text-white-50 small fw-bold mb-2"><?= __('coin') ?></label>
|
|
<div class="d-flex align-items-center gap-3 p-3 bg-dark border border-secondary rounded-4">
|
|
<img src="<?= getCoinIcon('USDT') ?>" width="32" height="32" alt="USDT">
|
|
<div>
|
|
<div class="fw-bold text-white"><?= $lang === 'zh' ? __('USDT') : 'USDT' ?></div>
|
|
<div class="text-white-50 small"><?= $lang === 'zh' ? __('tether') : 'Tether' ?></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
...
|
|
<style>
|
|
@media (max-width: 768px) {
|
|
.container { padding-left: 10px !important; padding-right: 10px !important; }
|
|
.card-body { padding: 1.25rem !important; }
|
|
.nav-pills .nav-link { padding: 10px 15px !important; font-size: 13px; }
|
|
.h4 { font-size: 1.25rem !important; }
|
|
}
|
|
</style>
|
|
|
|
<script>
|
|
let currentWithdrawNetwork = 'TRC20';
|
|
|
|
function setMax(inputId, displayId) {
|
|
document.getElementById(inputId).value = <?= $available ?>;
|
|
if (inputId === 'withdrawAmount') calculateCryptoWithdraw();
|
|
else calculateFiatWithdraw();
|
|
}
|
|
|
|
function selectWithdrawNetwork(net) {
|
|
currentWithdrawNetwork = net;
|
|
const btns = document.querySelectorAll('#withdrawNetworkSelectors button');
|
|
btns.forEach(btn => {
|
|
if (btn.innerText === net) {
|
|
btn.classList.add('active', 'btn-outline-warning');
|
|
btn.classList.remove('btn-outline-secondary');
|
|
} else {
|
|
btn.classList.remove('active', 'btn-outline-warning');
|
|
btn.classList.add('btn-outline-secondary');
|
|
}
|
|
});
|
|
}
|
|
|
|
function calculateCryptoWithdraw() {
|
|
const amount = parseFloat(document.getElementById('withdrawAmount').value) || 0;
|
|
const fee = amount > 0 ? 1 : 0;
|
|
const receive = Math.max(0, amount - fee);
|
|
document.getElementById('cryptoReceiveAmount').innerText = receive.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}) + ' USDT';
|
|
}
|
|
|
|
function updateFiatWithdrawRate() {
|
|
const select = document.getElementById('fiatWithdrawCurrency');
|
|
const symbol = select.value;
|
|
const rate = select.options[select.selectedIndex].getAttribute('data-rate');
|
|
document.getElementById('fiatWithdrawRateText').innerText = `${rate} ${symbol}`;
|
|
calculateFiatWithdraw();
|
|
}
|
|
|
|
function calculateFiatWithdraw() {
|
|
const amount = parseFloat(document.getElementById('fiatWithdrawAmount').value) || 0;
|
|
const select = document.getElementById('fiatWithdrawCurrency');
|
|
const rate = parseFloat(select.options[select.selectedIndex].getAttribute('data-rate'));
|
|
const est = amount * rate;
|
|
document.getElementById('fiatReceiveAmount').innerText = est.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2}) + ' ' + select.value;
|
|
}
|
|
|
|
const userId = '<?= $user['uid'] ?? $user['id'] ?>';
|
|
|
|
function confirmCryptoWithdraw() {
|
|
const addr = document.getElementById('withdrawAddress').value.trim();
|
|
const amount = parseFloat(document.getElementById('withdrawAmount').value);
|
|
const password = document.getElementById('withdrawPassword').value;
|
|
|
|
if (!addr) { alert('<?= __("enter_address") ?>'); return; }
|
|
if (!amount || amount < 10) { alert('<?= __("min_withdraw_hint") ?>'); return; }
|
|
if (amount > <?= $available ?>) { alert('<?= __("insufficient_balance") ?>'); return; }
|
|
if (!password) { alert('<?= __("enter_password") ?>'); return; }
|
|
|
|
const formData = new FormData();
|
|
formData.append('action', 'withdraw');
|
|
formData.append('amount', amount);
|
|
formData.append('symbol', 'USDT');
|
|
formData.append('address', addr);
|
|
formData.append('password', password);
|
|
|
|
fetch('/api/finance.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
let message = `<?= __('withdraw_msg_crypto') ?>`;
|
|
message = message.replace('%uid%', userId)
|
|
.replace('%network%', currentWithdrawNetwork)
|
|
.replace('%amount%', amount.toFixed(2));
|
|
sendWithdrawToCS(message);
|
|
} else {
|
|
alert(data.error || 'Request failed');
|
|
}
|
|
});
|
|
}
|
|
|
|
function confirmFiatWithdraw() {
|
|
const amountInput = document.getElementById('fiatWithdrawAmount');
|
|
const amount = parseFloat(amountInput.value);
|
|
const select = document.getElementById('fiatWithdrawCurrency');
|
|
const currency = select.value;
|
|
const rate = parseFloat(select.options[select.selectedIndex].getAttribute('data-rate'));
|
|
const password = document.getElementById('fiatWithdrawPassword').value;
|
|
|
|
if (isNaN(amount) || amount < 10) { alert('<?= __("min_withdraw_hint") ?>'); return; }
|
|
if (amount > <?= $available ?>) { alert('<?= __("insufficient_balance") ?>'); return; }
|
|
if (!password) { alert('<?= __("enter_password") ?>'); return; }
|
|
|
|
const estFiat = amount * rate;
|
|
|
|
const formData = new FormData();
|
|
formData.append('action', 'withdraw');
|
|
formData.append('amount', amount); // USDT amount
|
|
formData.append('symbol', 'USDT');
|
|
formData.append('fiat_amount', estFiat);
|
|
formData.append('fiat_currency', currency);
|
|
formData.append('address', 'Fiat (' + currency + ')');
|
|
formData.append('password', password);
|
|
|
|
fetch('/api/finance.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
let message = `<?= __('withdraw_msg_fiat') ?>`;
|
|
const preciseRes = (amount * rate).toFixed(2);
|
|
message = message.replace('%uid%', userId)
|
|
.replace('%amount%', amount.toFixed(2))
|
|
.replace('%rate%', rate)
|
|
.replace('%currency%', currency)
|
|
.replace('%res%', preciseRes);
|
|
sendWithdrawToCS(message);
|
|
} else {
|
|
alert(data.error || 'Request failed');
|
|
}
|
|
});
|
|
}
|
|
|
|
function sendWithdrawToCS(message) {
|
|
// Open chat box
|
|
const csBox = document.getElementById('cs-box');
|
|
if (csBox.classList.contains('d-none')) {
|
|
const toggle = document.getElementById('cs-toggle');
|
|
if (toggle) toggle.click();
|
|
}
|
|
|
|
// Auto-fill and send message
|
|
const csInput = document.getElementById('cs-input');
|
|
if (csInput) {
|
|
csInput.value = message;
|
|
document.getElementById('cs-form').dispatchEvent(new Event('submit'));
|
|
alert('<?= __("request_sent") ?>');
|
|
} else {
|
|
alert('<?= __("cs_connect_fail") ?>');
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|