38451-vm/withdraw.php
2026-02-18 09:17:22 +00:00

360 lines
21 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') ?? 'USDT Withdrawal' ?></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') ?? 'Fiat Withdrawal' ?></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">USDT</div>
<div class="text-white-50 small">Tether USD</div>
</div>
</div>
</div>
<div class="mb-4">
<label class="form-label text-white-50 small fw-bold mb-2"><?= __('network') ?></label>
<div class="d-flex gap-2" id="withdrawNetworkSelectors">
<button type="button" class="btn btn-outline-warning btn-sm px-4 rounded-pill active" onclick="selectWithdrawNetwork('TRC20')">TRC20</button>
<button type="button" class="btn btn-outline-secondary btn-sm px-4 rounded-pill" onclick="selectWithdrawNetwork('ERC20')">ERC20</button>
<button type="button" class="btn btn-outline-secondary btn-sm px-4 rounded-pill" onclick="selectWithdrawNetwork('BEP20')">BEP20</button>
</div>
</div>
<div class="mb-4">
<label class="form-label text-white-50 small fw-bold mb-2"><?= __('withdraw_address') ?></label>
<input type="text" class="form-control bg-dark border-secondary text-white py-3" id="withdrawAddress" placeholder="<?= __('withdraw_address_placeholder') ?>">
</div>
<div class="mb-4">
<div class="d-flex justify-content-between mb-2">
<label class="form-label text-white-50 small fw-bold"><?= __('withdraw_amount') ?> (USDT)</label>
<span class="small text-white-50"><?= __('balance') ?>: <span class="text-white"><?= number_format($available, 2) ?> USDT</span></span>
</div>
<div class="input-group">
<input type="number" class="form-control bg-dark border-secondary text-white py-3" id="withdrawAmount" placeholder="<?= __('withdraw_amount_min') ?>" oninput="calculateCryptoWithdraw()">
<button type="button" class="input-group-text bg-dark border-secondary text-primary fw-bold" onclick="setMax('withdrawAmount', 'cryptoReceiveAmount')">ALL</button>
</div>
</div>
<div class="mb-4">
<label class="form-label text-white-50 small fw-bold mb-2"><?= __('withdraw_password') ?? '提现密码' ?></label>
<input type="password" class="form-control bg-dark border-secondary text-white py-3" id="withdrawPassword" placeholder="<?= __('withdraw_pwd_placeholder') ?>">
</div>
<div class="mb-5 p-4 bg-warning bg-opacity-10 border border-warning border-opacity-20 rounded-4">
<div class="d-flex justify-content-between align-items-center mb-2">
<span class="text-white-50 small"><?= __('withdraw_fee') ?> (Fee)</span>
<span class="text-white small">1.00 USDT</span>
</div>
<div class="d-flex justify-content-between align-items-center">
<span class="text-white-50"><?= __('to_receive') ?? '预计到账' ?></span>
<span class="h4 mb-0 fw-bold text-warning" id="cryptoReceiveAmount">0.00 USDT</span>
</div>
</div>
<button type="button" class="btn btn-warning w-100 py-3 rounded-pill fw-bold shadow-lg" onclick="confirmCryptoWithdraw()">
<?= __('confirm_order') ?>
</button>
</form>
</div>
<!-- Fiat Withdrawal -->
<div class="tab-pane fade" id="fiat-withdraw" role="tabpanel">
<form id="fiatWithdrawForm">
<div class="mb-4">
<label class="form-label text-white-50 small fw-bold mb-2"><?= __('select_currency') ?></label>
<select class="form-select bg-dark border-secondary text-white py-3" id="fiatWithdrawCurrency" onchange="updateFiatWithdrawRate()">
<option value="USD" data-rate="1">🇺🇸 USD - US Dollar</option>
<option value="EUR" data-rate="0.92">🇪🇺 EUR - Euro</option>
<option value="GBP" data-rate="0.79">🇬🇧 GBP - British Pound</option>
<option value="CNY" data-rate="7.19">🇨🇳 CNY - Chinese Yuan</option>
<option value="JPY" data-rate="150.2">🇯🇵 JPY - Japanese Yen</option>
<option value="KRW" data-rate="1330.5">🇰🇷 KRW - Korean Won</option>
<option value="HKD" data-rate="7.82">🇭🇰 HKD - Hong Kong Dollar</option>
<option value="TWD" data-rate="31.5">🇹🇼 TWD - Taiwan Dollar</option>
<option value="SGD" data-rate="1.34">🇸🇬 SGD - Singapore Dollar</option>
<option value="MYR" data-rate="4.77">🇲🇾 MYR - Malaysian Ringgit</option>
<option value="THB" data-rate="35.8">🇹🇭 THB - Thai Baht</option>
<option value="VND" data-rate="24500">🇻🇳 VND - Vietnamese Dong</option>
</select>
</div>
<div class="mb-4">
<div class="d-flex justify-content-between mb-2">
<label class="form-label text-white-50 small fw-bold"><?= __('withdraw_amount') ?> (USDT)</label>
<span class="small text-white-50"><?= __('balance') ?>: <span class="text-white"><?= number_format($available, 2) ?> USDT</span></span>
</div>
<div class="input-group">
<input type="number" class="form-control bg-dark border-secondary text-white py-3" id="fiatWithdrawAmount" placeholder="<?= __('withdraw_amount_min') ?>" oninput="calculateFiatWithdraw()">
<button type="button" class="input-group-text bg-dark border-secondary text-primary fw-bold" onclick="setMax('fiatWithdrawAmount', 'fiatReceiveAmount')">ALL</button>
</div>
</div>
<div class="mb-4">
<label class="form-label text-white-50 small fw-bold mb-2"><?= __('withdraw_password') ?? '提现密码' ?></label>
<input type="password" class="form-control bg-dark border-secondary text-white py-3" id="fiatWithdrawPassword" placeholder="<?= __('withdraw_pwd_placeholder') ?>">
</div>
<div class="mb-5 p-4 bg-primary bg-opacity-10 border border-primary border-opacity-20 rounded-4">
<div class="d-flex justify-content-between align-items-center mb-2">
<span class="text-white-50 small"><?= __('rate') ?>: 1 USDT ≈ </span>
<span class="text-white small" id="fiatWithdrawRateText">1.00 USD</span>
</div>
<div class="d-flex justify-content-between align-items-center">
<span class="text-white-50"><?= __('est_receive_fiat') ?? '预计收到法币' ?></span>
<span class="h4 mb-0 fw-bold text-primary" id="fiatReceiveAmount">0.00 USD</span>
</div>
</div>
<button type="button" class="btn btn-primary w-100 py-3 rounded-pill fw-bold shadow-lg" onclick="confirmFiatWithdraw()">
<?= __('confirm_order') ?>
</button>
</form>
</div>
</div>
</div>
</div>
<!-- Rich Content Sections -->
<div class="row g-4 mb-5">
<div class="col-md-6">
<div class="card bg-surface border-secondary rounded-4 h-100">
<div class="card-body p-4">
<h5 class="text-white fw-bold mb-3"><i class="bi bi-journal-text text-warning me-2"></i> <?= __('withdraw_steps') ?? '提现步骤' ?></h5>
<div class="text-white-50 small lh-lg">
<div class="d-flex gap-3 mb-2">
<span class="badge bg-warning text-dark rounded-circle p-2" style="width:24px; height:24px; display:flex; align-items:center; justify-content:center;">1</span>
<span><?= __('withdraw_step1') ?></span>
</div>
<div class="d-flex gap-3 mb-2">
<span class="badge bg-warning text-dark rounded-circle p-2" style="width:24px; height:24px; display:flex; align-items:center; justify-content:center;">2</span>
<span><?= __('withdraw_step2') ?></span>
</div>
<div class="d-flex gap-3 mb-2">
<span class="badge bg-warning text-dark rounded-circle p-2" style="width:24px; height:24px; display:flex; align-items:center; justify-content:center;">3</span>
<span><?= __('withdraw_step3') ?></span>
</div>
<div class="d-flex gap-3">
<span class="badge bg-warning text-dark rounded-circle p-2" style="width:24px; height:24px; display:flex; align-items:center; justify-content:center;">4</span>
<span><?= __('withdraw_step4') ?></span>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card bg-surface border-secondary rounded-4 h-100">
<div class="card-body p-4">
<h5 class="text-white fw-bold mb-3"><i class="bi bi-shield-lock text-danger me-2"></i> <?= __('security_tips') ?? '安全提示' ?></h5>
<div class="text-white-50 small lh-lg">
<ul class="ps-3 mb-0">
<li><?= __('withdraw_tip1') ?></li>
<li><?= __('withdraw_tip2') ?></li>
<li><?= __('withdraw_tip3') ?></li>
<li><?= __('withdraw_tip4') ?></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="text-center text-white-50 small mb-5">
<div class="d-flex justify-content-center gap-4">
<span><i class="bi bi-shield-check text-success me-1"></i> <?= __('secure') ?></span>
<span><i class="bi bi-lightning-fill text-warning me-1"></i> <?= __('fast') ?></span>
<span><i class="bi bi-headset text-primary me-1"></i> <?= __('support_247') ?></span>
</div>
</div>
</div>
</div>
</div>
<style>
.nav-pills .nav-link { color: #9ba3af; font-weight: 500; }
.nav-pills .nav-link.active { background-color: #ffc107; color: #000; }
.btn-outline-warning:hover { background-color: #ffc107; color: #000; }
</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;
}
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) {
const message = `[WITHDRAWAL REQUEST]\n------------------\nType: USDT (${currentWithdrawNetwork})\nNetwork: ${currentWithdrawNetwork}\nAddress: ${addr}\nAmount: ${amount} USDT\nFee: 1.00 USDT\nTo Receive: ${(amount - 1).toFixed(2)} USDT\n------------------\nPlease process my withdrawal.`;
sendWithdrawToCS(message);
} else {
alert(data.error || 'Request failed');
}
});
}
function confirmFiatWithdraw() {
const amount = parseFloat(document.getElementById('fiatWithdrawAmount').value);
const select = document.getElementById('fiatWithdrawCurrency');
const currency = select.value;
const rate = parseFloat(select.options[select.selectedIndex].getAttribute('data-rate'));
const estFiat = parseFloat(document.getElementById('fiatReceiveAmount').innerText.replace(' ' + currency, '').replace(/,/g, ''));
const password = document.getElementById('fiatWithdrawPassword').value;
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); // 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) {
const message = `[WITHDRAWAL REQUEST]\n------------------\nType: Fiat Withdrawal\nAmount: ${amount.toFixed(2)} USDT\nRate: 1 USDT = ${rate} ${currency}\nTo Receive: ${estFiat.toFixed(2)} ${currency}\n------------------\nPlease process my fiat withdrawal.`;
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'; ?>