332 lines
18 KiB
PHP
332 lines
18 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/header.php';
|
|
require_once __DIR__ . '/includes/exchange.php';
|
|
|
|
if (!$user) {
|
|
header('Location: /auth/login.php');
|
|
exit;
|
|
}
|
|
|
|
$rates = get_exchange_rates();
|
|
|
|
$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>
|
|
|
|
<div class="mb-4">
|
|
<label class="form-label text-white-50 small fw-bold mb-2"><?= __('select_network') ?></label>
|
|
<div class="d-flex gap-2" id="withdrawNetworkSelectors">
|
|
<button type="button" class="btn btn-outline-warning active flex-fill py-2 rounded-3" onclick="selectWithdrawNetwork('TRC20')">TRC20</button>
|
|
<button type="button" class="btn btn-outline-secondary flex-fill py-2 rounded-3" onclick="selectWithdrawNetwork('ERC20')">ERC20</button>
|
|
<button type="button" class="btn btn-outline-secondary flex-fill py-2 rounded-3" 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" id="withdrawAddress" class="form-control bg-dark border-secondary text-white py-3 px-4 rounded-4" placeholder="<?= __('enter_address') ?>">
|
|
</div>
|
|
|
|
<div class="mb-4">
|
|
<div class="d-flex justify-content-between mb-2">
|
|
<label class="form-label text-white-50 small fw-bold mb-0"><?= __('withdraw_amount') ?></label>
|
|
<span class="small text-white-50"><?= __('available_balance') ?>: <span class="text-warning"><?= number_format($available, 2) ?> USDT</span></span>
|
|
</div>
|
|
<div class="input-group">
|
|
<input type="number" id="withdrawAmount" class="form-control bg-dark border-secondary text-white py-3 rounded-start-4" placeholder="<?= __('min_withdraw_hint') ?>" oninput="calculateCryptoWithdraw()">
|
|
<button class="btn btn-outline-warning px-3 rounded-end-4" type="button" onclick="setMax('withdrawAmount')"><?= __('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" id="withdrawPassword" class="form-control bg-dark border-secondary text-white py-3 px-4 rounded-4" 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') ?></span>
|
|
<span class="text-white fw-bold 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 text-dark" onclick="confirmCryptoWithdraw()">
|
|
<?= __('confirm') ?>
|
|
</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()">
|
|
<?php
|
|
$currencies = get_global_currencies();
|
|
foreach ($currencies as $code => $info) {
|
|
$rate = $rates[$code] ?? 1.0;
|
|
echo "<option value=\"$code\" data-rate=\"$rate\">{$info['flag']} $code - {$info['name']}</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 mb-0"><?= __('withdraw_amount') ?> (USDT)</label>
|
|
<span class="small text-white-50"><?= __('available_balance') ?>: <span class="text-warning"><?= number_format($available, 2) ?> USDT</span></span>
|
|
</div>
|
|
<div class="input-group">
|
|
<input type="number" id="fiatWithdrawAmount" class="form-control bg-dark border-secondary text-white py-3 rounded-start-4" placeholder="<?= __('min_withdraw_hint') ?>" oninput="calculateFiatWithdraw()">
|
|
<button class="btn btn-outline-warning px-3 rounded-end-4" type="button" onclick="setMax('fiatWithdrawAmount')"><?= __('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" id="fiatWithdrawPassword" class="form-control bg-dark border-secondary text-white py-3 px-4 rounded-4" 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"><?= __('rate') ?></span>
|
|
<span class="text-white fw-bold small">1 USDT ≈ <span id="fiatWithdrawRateText">1.00 USD</span></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="fiatReceiveAmount">0.00 USD</span>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="button" class="btn btn-warning w-100 py-3 rounded-pill fw-bold shadow-lg text-dark" onclick="confirmFiatWithdraw()">
|
|
<?= __('confirm') ?>
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mt-5 p-4 bg-black bg-opacity-20 rounded-4 border border-secondary border-opacity-50">
|
|
<h6 class="text-white fw-bold mb-3 d-flex align-items-center gap-2">
|
|
<i class="bi bi-info-circle text-info"></i> <?= __('withdraw_steps') ?>
|
|
</h6>
|
|
<ul class="text-white-50 small mb-0 ps-3">
|
|
<li class="mb-2"><?= __('withdraw_step1') ?></li>
|
|
<li class="mb-2"><?= __('withdraw_step2') ?></li>
|
|
<li class="mb-2"><?= __('withdraw_step3') ?></li>
|
|
<li><?= __('withdraw_step4') ?></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</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) {
|
|
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);
|
|
formData.append('symbol', 'USDT');
|
|
formData.append('fiat_amount', estFiat);
|
|
formData.append('fiat_currency', currency);
|
|
formData.append('address', '<?= __('fiat_withdraw') ?> (' + 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) {
|
|
const csBox = document.getElementById('cs-box');
|
|
if (csBox && csBox.classList.contains('d-none')) {
|
|
const toggle = document.getElementById('cs-toggle');
|
|
if (toggle) toggle.click();
|
|
}
|
|
|
|
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'; ?>
|