303 lines
16 KiB
PHP
303 lines
16 KiB
PHP
<?php
|
|
include __DIR__ . '/includes/header.php';
|
|
|
|
if (!$user) {
|
|
header('Location: /auth/login.php');
|
|
exit;
|
|
}
|
|
|
|
// Get user data again to ensure we have latest fields
|
|
$stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
|
|
$stmt->execute([$user['id']]);
|
|
$userData = $stmt->fetch();
|
|
|
|
// Get balances
|
|
$stmt = db()->prepare("SELECT * FROM user_balances WHERE user_id = ?");
|
|
$stmt->execute([$user['id']]);
|
|
$userBalances = $stmt->fetchAll();
|
|
$balancesBySymbol = [];
|
|
foreach ($userBalances as $ub) {
|
|
$balancesBySymbol[$ub['symbol']] = $ub;
|
|
}
|
|
|
|
// Calculate total balance in USDT
|
|
$totalBalanceUsdt = 0;
|
|
foreach ($userBalances as $ub) {
|
|
$totalBalanceUsdt += ($ub['available'] + $ub['frozen']) * getCoinPrice($ub['symbol']);
|
|
}
|
|
|
|
$displayCoins = ['BTC', 'ETH', 'USDT', 'LTC', 'BNB', 'SOL', 'TRX', 'XRP'];
|
|
$balances = [];
|
|
foreach ($displayCoins as $symbol) {
|
|
$balances[] = [
|
|
'symbol' => $symbol,
|
|
'available' => $balancesBySymbol[$symbol]['available'] ?? 0,
|
|
'frozen' => $balancesBySymbol[$symbol]['frozen'] ?? 0,
|
|
];
|
|
}
|
|
// Add any other coins user might have that are not in displayCoins
|
|
foreach ($userBalances as $ub) {
|
|
if (!in_array($ub['symbol'], $displayCoins)) {
|
|
$balances[] = $ub;
|
|
}
|
|
}
|
|
|
|
function getCoinPrice($symbol) {
|
|
$prices = [
|
|
'BTC' => 65432.10,
|
|
'ETH' => 3542.50,
|
|
'USDT' => 1.00,
|
|
'BNB' => 612.30,
|
|
'SOL' => 145.20,
|
|
'LTC' => 85.40,
|
|
'TRX' => 0.12,
|
|
'XRP' => 0.62,
|
|
'ADA' => 0.45,
|
|
'DOGE' => 0.16,
|
|
'DOT' => 7.20,
|
|
'MATIC' => 0.72,
|
|
];
|
|
return $prices[strtoupper($symbol)] ?? 1.00;
|
|
}
|
|
|
|
function getVipLevel($totalRecharge) {
|
|
if ($totalRecharge >= 10000000) return 7;
|
|
if ($totalRecharge >= 5000000) return 6;
|
|
if ($totalRecharge >= 1000000) return 5;
|
|
if ($totalRecharge >= 500000) return 4;
|
|
if ($totalRecharge >= 100000) return 3;
|
|
if ($totalRecharge >= 50000) return 2;
|
|
if ($totalRecharge >= 10001) return 1;
|
|
return 0;
|
|
}
|
|
|
|
$vipLevel = getVipLevel($userData['total_recharge'] ?? 0);
|
|
|
|
// Fetch transactions
|
|
$stmt = db()->prepare("SELECT * FROM transactions WHERE user_id = ? ORDER BY created_at DESC LIMIT 50");
|
|
$stmt->execute([$user['id']]);
|
|
$transactions = $stmt->fetchAll();
|
|
|
|
// Fetch orders to sync if needed, or just show transactions which should cover most balance changes
|
|
// For a complete "order history", we might want a separate tab, but user asked for "recharge, withdrawal, and order records" to be synced here.
|
|
|
|
$kycStatusText = [
|
|
0 => __('unverified'),
|
|
1 => __('pending'),
|
|
2 => __('verified'),
|
|
3 => __('rejected')
|
|
];
|
|
$kycStatusColor = [
|
|
0 => 'text-white-50',
|
|
1 => 'text-warning',
|
|
2 => 'text-success',
|
|
3 => 'text-danger'
|
|
];
|
|
?>
|
|
|
|
<div class="container py-4">
|
|
<div class="row g-4">
|
|
<!-- Sidebar -->
|
|
<div class="col-lg-3">
|
|
<div class="card bg-surface border-secondary rounded-4 overflow-hidden h-100 shadow-lg">
|
|
<div class="card-body p-0">
|
|
<!-- User Header -->
|
|
<div class="p-4 text-center border-bottom border-secondary bg-black bg-opacity-30">
|
|
<div class="avatar-wrapper mb-3 mx-auto">
|
|
<div class="rounded-circle bg-primary bg-gradient d-flex align-items-center justify-content-center text-white shadow" style="width: 80px; height: 80px; font-size: 32px;">
|
|
<?= strtoupper(substr($userData['username'], 0, 1)) ?>
|
|
</div>
|
|
</div>
|
|
<h5 class="fw-bold text-white mb-0"><?= htmlspecialchars($userData['username']) ?></h5>
|
|
</div>
|
|
|
|
<!-- Menu List -->
|
|
<div class="list-group list-group-flush">
|
|
<div class="list-group-item py-3 d-flex justify-content-between align-items-center">
|
|
<span class="text-white-50 small"><i class="bi bi-person-badge me-2 text-primary"></i>UID</span>
|
|
<span class="text-white fw-bold small"><?= $userData['uid'] ?></span>
|
|
</div>
|
|
<div class="list-group-item py-3 d-flex justify-content-between align-items-center">
|
|
<span class="text-white-50 small"><i class="bi bi-shield-check me-2 text-info"></i><?= __('credit_score') ?></span>
|
|
<span class="text-info fw-bold small"><?= $userData['credit_score'] ?></span>
|
|
</div>
|
|
<div class="list-group-item py-3 d-flex justify-content-between align-items-center">
|
|
<span class="text-white-50 small"><i class="bi bi-gem me-2 text-warning"></i><?= __('vip_level') ?></span>
|
|
<span class="badge bg-warning text-dark fw-bold">VIP <?= $vipLevel ?></span>
|
|
</div>
|
|
|
|
<a href="/kyc.php" class="list-group-item list-group-item-action py-3 d-flex justify-content-between align-items-center">
|
|
<span class="text-white-50 small"><i class="bi bi-person-vcard me-2 text-success"></i><?= __('kyc') ?></span>
|
|
<span class="small <?= $kycStatusColor[$userData['kyc_status'] ?? 0] ?>">
|
|
<?= $kycStatusText[$userData['kyc_status'] ?? 0] ?> <i class="bi bi-chevron-right ms-1"></i>
|
|
</span>
|
|
</a>
|
|
|
|
<a href="/security.php" class="list-group-item list-group-item-action py-3 d-flex justify-content-between align-items-center">
|
|
<span class="text-white-50 small"><i class="bi bi-lock me-2 text-danger"></i><?= __('security') ?></span>
|
|
<span class="text-white-50 small"><i class="bi bi-chevron-right"></i></span>
|
|
</a>
|
|
|
|
<a href="/auth/logout.php" class="list-group-item list-group-item-action py-3 d-flex justify-content-between align-items-center text-danger border-0">
|
|
<span class="small"><i class="bi bi-box-arrow-right me-2"></i><?= __('logout') ?></span>
|
|
<span class="small"><i class="bi bi-chevron-right"></i></span>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Main Content -->
|
|
<div class="col-lg-9">
|
|
<!-- Asset Summary -->
|
|
<div class="card bg-surface border-secondary rounded-4 mb-4 shadow-lg overflow-hidden">
|
|
<div class="card-body p-0">
|
|
<div class="p-4 border-bottom border-secondary bg-black bg-opacity-20">
|
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
|
<span class="text-white-50 small"><?= __('balance') ?>:</span>
|
|
<span class="text-white-50 small">(USDT)</span>
|
|
</div>
|
|
<h2 class="text-white fw-bold mb-0">≈ <?= number_format($totalBalanceUsdt, 2) ?></h2>
|
|
</div>
|
|
<div class="p-3 d-flex gap-2">
|
|
<a href="/recharge.php" class="btn btn-primary flex-fill rounded-3 py-2 shadow-primary">
|
|
<i class="bi bi-plus-circle me-2"></i><?= __('deposit') ?>
|
|
</a>
|
|
<a href="/withdraw.php" class="btn btn-outline-light flex-fill rounded-3 py-2">
|
|
<i class="bi bi-arrow-up-circle me-2"></i><?= __('withdraw') ?>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Asset Table -->
|
|
<div class="card bg-surface border-secondary rounded-4 overflow-hidden shadow-lg">
|
|
<div class="table-responsive">
|
|
<table class="table table-dark table-hover mb-0 align-middle">
|
|
<thead class="bg-black bg-opacity-50 text-white small border-secondary">
|
|
<tr>
|
|
<th class="ps-4 py-3 border-secondary" style="width: 25%;"><?= __('coin') ?></th>
|
|
<th class="py-3 border-secondary" style="width: 20%;"><?= __('available_balance') ?></th>
|
|
<th class="py-3 border-secondary" style="width: 20%;"><?= __('frozen') ?></th>
|
|
<th class="py-3 border-secondary" style="width: 20%;"><?= __('converted_to') ?></th>
|
|
<th class="text-end pe-4 py-3 border-secondary" style="width: 15%;"><?= __('operation') ?></th>
|
|
</tr>
|
|
</thead>
|
|
</table>
|
|
</div>
|
|
<!-- Scrollable Body - Limited to 4 rows (approx 210px) -->
|
|
<div class="asset-list-container" style="height: 210px; overflow-y: auto; scrollbar-width: none; -ms-overflow-style: none;">
|
|
<style>
|
|
.asset-list-container::-webkit-scrollbar { display: none; }
|
|
</style>
|
|
<table class="table table-dark table-hover mb-0 align-middle">
|
|
<tbody class="border-0">
|
|
<?php foreach ($balances as $b): ?>
|
|
<tr class="border-secondary">
|
|
<td class="ps-4 py-3" style="width: 25%;">
|
|
<div class="d-flex align-items-center gap-3">
|
|
<img src="<?= getCoinIcon($b['symbol']) ?>" width="24" height="24" class="rounded-circle">
|
|
<span class="fw-bold text-white small"><?= $b['symbol'] ?></span>
|
|
</div>
|
|
</td>
|
|
<td class="py-3" style="width: 20%;">
|
|
<span class="text-white small fw-bold"><?= number_format($b['available'], 4) ?></span>
|
|
</td>
|
|
<td class="py-3" style="width: 20%;">
|
|
<span class="text-white-50 small"><?= number_format($b['frozen'], 4) ?></span>
|
|
</td>
|
|
<td class="py-3" style="width: 20%;">
|
|
<span class="text-white-50 small">≈ <?= number_format(($b['available'] + $b['frozen']) * getCoinPrice($b['symbol']), 2) ?></span>
|
|
</td>
|
|
<td class="text-end pe-4 py-3" style="width: 15%;">
|
|
<a href="/trade.php?symbol=<?= $b['symbol'] ?>" class="text-primary text-decoration-none small"><?= __('trade') ?></a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Asset Records -->
|
|
<div class="mt-5 text-center mb-3">
|
|
<h5 class="text-white fw-bold"><?= __('asset_records') ?></h5>
|
|
</div>
|
|
<div class="card bg-surface border-secondary rounded-4 overflow-hidden shadow-lg">
|
|
<div class="table-responsive">
|
|
<table class="table table-dark table-hover mb-0 align-middle small">
|
|
<thead class="bg-black bg-opacity-20 text-white-50 border-secondary">
|
|
<tr>
|
|
<th class="ps-4 py-3 border-secondary" style="width: 25%;"><?= __('type') ?></th>
|
|
<th class="py-3 border-secondary" style="width: 30%;"><?= __('amount') ?></th>
|
|
<th class="py-3 border-secondary" style="width: 20%;"><?= __('status') ?></th>
|
|
<th class="text-end pe-4 py-3 border-secondary" style="width: 25%;"><?= __('time') ?></th>
|
|
</tr>
|
|
</thead>
|
|
</table>
|
|
</div>
|
|
<!-- Scrollable Body for Transactions - Limited to 4 rows (approx 210px) -->
|
|
<div class="transaction-list-container" style="height: 240px; overflow-y: auto; scrollbar-width: none; -ms-overflow-style: none;">
|
|
<style>
|
|
.transaction-list-container::-webkit-scrollbar { display: none; }
|
|
</style>
|
|
<table class="table table-dark table-hover mb-0 align-middle small">
|
|
<tbody class="border-0">
|
|
<?php if (empty($transactions)): ?>
|
|
<tr>
|
|
<td colspan="4" class="text-center py-5 text-white-50">
|
|
<i class="bi bi-inbox fs-2 d-block mb-2"></i>
|
|
<?= __('no_records_found') ?>
|
|
</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($transactions as $t):
|
|
$typeColor = 'text-primary';
|
|
$typeName = __($t['type']);
|
|
|
|
if (strpos($t['type'], 'win') !== false || $t['type'] === 'deposit' || $t['type'] === 'binary_win' || $t['type'] === 'recharge') $typeColor = 'text-success';
|
|
elseif (strpos($t['type'], 'loss') !== false || $t['type'] === 'withdraw' || $t['type'] === 'withdrawal' || $t['type'] === 'binary_loss') $typeColor = 'text-danger';
|
|
elseif ($t['type'] === 'flash_exchange') $typeColor = 'text-info';
|
|
elseif ($t['type'] === 'contract_settle') $typeColor = 'text-info';
|
|
|
|
$prefix = '';
|
|
if ($t['type'] === 'binary_win' || $t['type'] === 'deposit' || $t['type'] === 'recharge' || $t['type'] === 'contract_settle') $prefix = '+';
|
|
if ($t['type'] === 'binary_loss' || $t['type'] === 'withdraw' || $t['type'] === 'withdrawal' || $t['type'] === 'contract_margin') $prefix = '-';
|
|
|
|
$statusText = __('pending') ?? '处理中';
|
|
$statusClass = 'bg-warning text-warning';
|
|
if ($t['status'] === 'completed' || $t['status'] === 'approved') {
|
|
$statusText = __('approved') ?? '通过';
|
|
$statusClass = 'bg-success text-success';
|
|
} elseif ($t['status'] === 'rejected') {
|
|
$statusText = __('rejected') ?? '拒绝';
|
|
$statusClass = 'bg-danger text-danger';
|
|
}
|
|
?>
|
|
<tr class="border-secondary">
|
|
<td class="ps-4 py-3" style="width: 25%;">
|
|
<span class="<?= $typeColor ?> fw-bold"><?= $typeName ?></span>
|
|
</td>
|
|
<td class="py-3" style="width: 30%;">
|
|
<span class="text-white fw-bold"><?= $prefix . number_format($t['amount'], 4) ?></span>
|
|
<span class="text-white-50 small"><?= $t['symbol'] ?></span>
|
|
</td>
|
|
<td class="py-3" style="width: 20%;">
|
|
<span class="badge bg-opacity-10 <?= $statusClass ?> border border-opacity-25 px-2 py-1"><?= $statusText ?></span>
|
|
</td>
|
|
<td class="text-end pe-4 py-3" style="width: 25%;">
|
|
<span class="text-white-50 x-small"><?= date('Y-m-d H:i', strtotime($t['created_at'])) ?></span>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include __DIR__ . '/includes/footer.php'; ?>
|