BIT
This commit is contained in:
parent
0d9e8b5e50
commit
f1fc7be962
377
admin.php
Normal file
377
admin.php
Normal file
@ -0,0 +1,377 @@
|
|||||||
|
<?php
|
||||||
|
include_once 'config.php';
|
||||||
|
|
||||||
|
if (!isset($_SESSION['admin_id'])) {
|
||||||
|
header("Location: admin_login.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$action = $_GET['action'] ?? 'dashboard';
|
||||||
|
|
||||||
|
// Handle Post Actions
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
if (isset($_POST['update_balance'])) {
|
||||||
|
$stmt = db()->prepare("UPDATE accounts SET balance = ? WHERE id = ?");
|
||||||
|
$stmt->execute([$_POST['balance'], $_POST['account_id']]);
|
||||||
|
$msg = "余额更新成功";
|
||||||
|
}
|
||||||
|
if (isset($_POST['update_win_loss'])) {
|
||||||
|
$stmt = db()->prepare("UPDATE accounts SET win_loss_control = ? WHERE id = ?");
|
||||||
|
$stmt->execute([$_POST['win_loss_control'], $_POST['account_id']]);
|
||||||
|
$msg = "输赢控制已更新";
|
||||||
|
}
|
||||||
|
if (isset($_POST['update_kyc'])) {
|
||||||
|
$stmt = db()->prepare("UPDATE accounts SET kyc_status = ? WHERE id = ?");
|
||||||
|
$stmt->execute([$_POST['kyc_status'], $_POST['account_id']]);
|
||||||
|
$msg = "认证状态已更新";
|
||||||
|
}
|
||||||
|
if (isset($_POST['approve_deposit'])) {
|
||||||
|
db()->beginTransaction();
|
||||||
|
$stmt = db()->prepare("SELECT * FROM transactions WHERE id = ? AND status = 'pending' AND transaction_type = 'deposit'");
|
||||||
|
$stmt->execute([$_POST['transaction_id']]);
|
||||||
|
$trx = $stmt->fetch();
|
||||||
|
if ($trx) {
|
||||||
|
db()->prepare("UPDATE accounts SET balance = balance + ? WHERE id = ?")->execute([$trx['amount'], $trx['account_id']]);
|
||||||
|
db()->prepare("UPDATE transactions SET status = 'completed' WHERE id = ?")->execute([$trx['id']]);
|
||||||
|
$msg = "充值已批准";
|
||||||
|
}
|
||||||
|
db()->commit();
|
||||||
|
}
|
||||||
|
if (isset($_POST['approve_withdraw'])) {
|
||||||
|
db()->beginTransaction();
|
||||||
|
$stmt = db()->prepare("SELECT * FROM transactions WHERE id = ? AND status = 'pending' AND transaction_type = 'withdraw'");
|
||||||
|
$stmt->execute([$_POST['transaction_id']]);
|
||||||
|
$trx = $stmt->fetch();
|
||||||
|
if ($trx) {
|
||||||
|
db()->prepare("UPDATE accounts SET frozen_balance = frozen_balance - ? WHERE id = ?")->execute([$trx['amount'], $trx['account_id']]);
|
||||||
|
db()->prepare("UPDATE transactions SET status = 'completed' WHERE id = ?")->execute([$trx['id']]);
|
||||||
|
$msg = "提现已批准";
|
||||||
|
}
|
||||||
|
db()->commit();
|
||||||
|
}
|
||||||
|
if (isset($_POST['reject_transaction'])) {
|
||||||
|
db()->beginTransaction();
|
||||||
|
$stmt = db()->prepare("SELECT * FROM transactions WHERE id = ? AND status = 'pending'");
|
||||||
|
$stmt->execute([$_POST['transaction_id']]);
|
||||||
|
$trx = $stmt->fetch();
|
||||||
|
if ($trx && $trx['transaction_type'] === 'withdraw') {
|
||||||
|
// Unfreeze balance
|
||||||
|
db()->prepare("UPDATE accounts SET balance = balance + ?, frozen_balance = frozen_balance - ? WHERE id = ?")->execute([$trx['amount'], $trx['amount'], $trx['account_id']]);
|
||||||
|
}
|
||||||
|
db()->prepare("UPDATE transactions SET status = 'failed' WHERE id = ?")->execute([$_POST['transaction_id']]);
|
||||||
|
$msg = "交易已驳回";
|
||||||
|
db()->commit();
|
||||||
|
}
|
||||||
|
if (isset($_POST['update_site_settings'])) {
|
||||||
|
$stmt = db()->prepare("UPDATE site_settings SET site_name = ?, contact_email = ?, deposit_address = ? WHERE id = 1");
|
||||||
|
$stmt->execute([$_POST['site_name'], $_POST['contact_email'], $_POST['deposit_address']]);
|
||||||
|
$msg = "站点设置已更新";
|
||||||
|
}
|
||||||
|
if (isset($_POST['update_price'])) {
|
||||||
|
$stmt = db()->prepare("UPDATE cryptocurrencies SET manual_price = ? WHERE id = ?");
|
||||||
|
$stmt->execute([$_POST['manual_price'], $_POST['coin_id']]);
|
||||||
|
$msg = "价格已手动调整";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$settings = get_site_settings();
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>管理后台 - <?php echo $settings['site_name']; ?></title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
|
||||||
|
<style>
|
||||||
|
body { background: #f4f7f6; }
|
||||||
|
.sidebar { min-height: 100vh; background: #2c3e50; color: white; }
|
||||||
|
.sidebar a { color: #bdc3c7; text-decoration: none; padding: 10px 20px; display: block; }
|
||||||
|
.sidebar a:hover, .sidebar a.active { background: #34495e; color: white; }
|
||||||
|
.card { border: none; box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075); margin-bottom: 20px; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<!-- Sidebar -->
|
||||||
|
<div class="col-md-2 sidebar p-0">
|
||||||
|
<div class="p-3 text-center border-bottom border-secondary">
|
||||||
|
<h4>管理后台</h4>
|
||||||
|
</div>
|
||||||
|
<a href="?action=dashboard" class="<?php echo $action === 'dashboard' ? 'active' : ''; ?>"><i class="bi bi-speedometer2 me-2"></i> 控制台</a>
|
||||||
|
<a href="?action=users" class="<?php echo $action === 'users' ? 'active' : ''; ?>"><i class="bi bi-people me-2"></i> 用户管理</a>
|
||||||
|
<a href="?action=transactions" class="<?php echo $action === 'transactions' ? 'active' : ''; ?>"><i class="bi bi-cash-stack me-2"></i> 充值提现</a>
|
||||||
|
<a href="?action=orders" class="<?php echo $action === 'orders' ? 'active' : ''; ?>"><i class="bi bi-list-check me-2"></i> 交易记录</a>
|
||||||
|
<a href="?action=market" class="<?php echo $action === 'market' ? 'active' : ''; ?>"><i class="bi bi-graph-up me-2"></i> 市场管理</a>
|
||||||
|
<a href="?action=settings" class="<?php echo $action === 'settings' ? 'active' : ''; ?>"><i class="bi bi-gear me-2"></i> 系统设置</a>
|
||||||
|
<a href="logout.php" class="mt-5 text-danger"><i class="bi bi-box-arrow-right me-2"></i> 退出登录</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Main Content -->
|
||||||
|
<div class="col-md-10 p-4">
|
||||||
|
<?php if (isset($msg)): ?>
|
||||||
|
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||||
|
<?php echo $msg; ?>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($action === 'dashboard'): ?>
|
||||||
|
<h2 class="mb-4">控制台概览</h2>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card bg-primary text-white p-3">
|
||||||
|
<h6>总用户</h6>
|
||||||
|
<h3><?php echo db()->query("SELECT COUNT(*) FROM accounts")->fetchColumn(); ?></h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card bg-success text-white p-3">
|
||||||
|
<h6>待处理充值</h6>
|
||||||
|
<h3><?php echo db()->query("SELECT COUNT(*) FROM transactions WHERE transaction_type='deposit' AND status='pending'")->fetchColumn(); ?></h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card bg-warning text-dark p-3">
|
||||||
|
<h6>待处理提现</h6>
|
||||||
|
<h3><?php echo db()->query("SELECT COUNT(*) FROM transactions WHERE transaction_type='withdraw' AND status='pending'")->fetchColumn(); ?></h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="card bg-info text-white p-3">
|
||||||
|
<h6>今日订单</h6>
|
||||||
|
<h3><?php echo db()->query("SELECT COUNT(*) FROM orders WHERE DATE(created_at) = CURRENT_DATE")->fetchColumn(); ?></h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($action === 'users'): ?>
|
||||||
|
<h2 class="mb-4">用户管理</h2>
|
||||||
|
<div class="card p-3">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>用户名</th>
|
||||||
|
<th>余额 (USDT)</th>
|
||||||
|
<th>认证状态</th>
|
||||||
|
<th>输赢控制</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
$users = db()->query("SELECT * FROM accounts ORDER BY id DESC")->fetchAll();
|
||||||
|
foreach ($users as $u):
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo $u['id']; ?></td>
|
||||||
|
<td><?php echo $u['username']; ?></td>
|
||||||
|
<td><?php echo number_format($u['balance'], 2); ?></td>
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-<?php echo $u['kyc_status'] === 'VERIFIED' ? 'success' : ($u['kyc_status'] === 'PENDING' ? 'warning' : 'secondary'); ?>">
|
||||||
|
<?php echo $u['kyc_status']; ?>
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-<?php echo $u['win_loss_control'] == 1 ? 'success' : ($u['win_loss_control'] == -1 ? 'danger' : 'secondary'); ?>">
|
||||||
|
<?php echo $u['win_loss_control'] == 1 ? '必赢' : ($u['win_loss_control'] == -1 ? '必输' : '正常'); ?>
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#editUser<?php echo $u['id']; ?>">编辑</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<!-- Modal -->
|
||||||
|
<div class="modal fade" id="editUser<?php echo $u['id']; ?>" tabindex="-1">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">编辑用户: <?php echo $u['username']; ?></h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form method="POST" class="mb-3">
|
||||||
|
<input type="hidden" name="account_id" value="<?php echo $u['id']; ?>">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">调整余额</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="number" step="0.01" name="balance" class="form-control" value="<?php echo $u['balance']; ?>">
|
||||||
|
<button class="btn btn-primary" name="update_balance">更新余额</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<form method="POST" class="mb-3">
|
||||||
|
<input type="hidden" name="account_id" value="<?php echo $u['id']; ?>">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">输赢控制</label>
|
||||||
|
<select name="win_loss_control" class="form-select mb-2">
|
||||||
|
<option value="0" <?php echo $u['win_loss_control'] == 0 ? 'selected' : ''; ?>>正常 (随机)</option>
|
||||||
|
<option value="1" <?php echo $u['win_loss_control'] == 1 ? 'selected' : ''; ?>>必赢 (Always Win)</option>
|
||||||
|
<option value="-1" <?php echo $u['win_loss_control'] == -1 ? 'selected' : ''; ?>>必输 (Always Loss)</option>
|
||||||
|
</select>
|
||||||
|
<button class="btn btn-warning w-100" name="update_win_loss">应用控制</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<form method="POST">
|
||||||
|
<input type="hidden" name="account_id" value="<?php echo $u['id']; ?>">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">认证状态</label>
|
||||||
|
<select name="kyc_status" class="form-select mb-2">
|
||||||
|
<option value="UNVERIFIED" <?php echo $u['kyc_status'] === 'UNVERIFIED' ? 'selected' : ''; ?>>未认证</option>
|
||||||
|
<option value="PENDING" <?php echo $u['kyc_status'] === 'PENDING' ? 'selected' : ''; ?>>待审核</option>
|
||||||
|
<option value="VERIFIED" <?php echo $u['kyc_status'] === 'VERIFIED' ? 'selected' : ''; ?>>已认证</option>
|
||||||
|
</select>
|
||||||
|
<button class="btn btn-info w-100 text-white" name="update_kyc">更新状态</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($action === 'transactions'): ?>
|
||||||
|
<h2 class="mb-4">充值提现审核</h2>
|
||||||
|
<div class="card p-3">
|
||||||
|
<table class="table table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>用户</th>
|
||||||
|
<th>类型</th>
|
||||||
|
<th>金额</th>
|
||||||
|
<th>哈希/地址</th>
|
||||||
|
<th>状态</th>
|
||||||
|
<th>日期</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
$trxs = db()->query("SELECT t.*, a.username FROM transactions t JOIN accounts a ON t.account_id = a.id ORDER BY t.id DESC")->fetchAll();
|
||||||
|
foreach ($trxs as $t):
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo $t['id']; ?></td>
|
||||||
|
<td><?php echo $t['username']; ?></td>
|
||||||
|
<td><span class="badge bg-<?php echo $t['transaction_type'] === 'deposit' ? 'primary' : 'warning'; ?>"><?php echo strtoupper($t['transaction_type']); ?></span></td>
|
||||||
|
<td><?php echo $t['amount']; ?></td>
|
||||||
|
<td><small class="text-truncate" style="max-width: 150px; display: inline-block;"><?php echo $t['tx_hash']; ?></small></td>
|
||||||
|
<td>
|
||||||
|
<span class="badge bg-<?php echo $t['status'] === 'completed' ? 'success' : ($t['status'] === 'pending' ? 'info' : 'danger'); ?>">
|
||||||
|
<?php echo strtoupper($t['status']); ?>
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td><?php echo $t['timestamp']; ?></td>
|
||||||
|
<td>
|
||||||
|
<?php if ($t['status'] === 'pending'): ?>
|
||||||
|
<form method="POST" class="d-inline">
|
||||||
|
<input type="hidden" name="transaction_id" value="<?php echo $t['id']; ?>">
|
||||||
|
<button class="btn btn-sm btn-success" name="<?php echo $t['transaction_type'] === 'deposit' ? 'approve_deposit' : 'approve_withdraw'; ?>">批准</button>
|
||||||
|
<button class="btn btn-sm btn-danger" name="reject_transaction">拒绝</button>
|
||||||
|
</form>
|
||||||
|
<?php endif; ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($action === 'orders'): ?>
|
||||||
|
<h2 class="mb-4">所有交易记录</h2>
|
||||||
|
<div class="card p-3">
|
||||||
|
<table class="table table-sm table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>用户</th>
|
||||||
|
<th>币种</th>
|
||||||
|
<th>类型</th>
|
||||||
|
<th>方向</th>
|
||||||
|
<th>价格</th>
|
||||||
|
<th>数量</th>
|
||||||
|
<th>时间</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
$orders = db()->query("SELECT o.*, a.username FROM orders o JOIN accounts a ON o.account_id = a.id ORDER BY o.id DESC LIMIT 50")->fetchAll();
|
||||||
|
foreach ($orders as $o):
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo $o['username']; ?></td>
|
||||||
|
<td><?php echo $o['symbol']; ?></td>
|
||||||
|
<td><?php echo $o['trade_type']; ?></td>
|
||||||
|
<td class="text-<?php echo $o['side'] === 'BUY' ? 'success' : 'danger'; ?>"><?php echo $o['side']; ?></td>
|
||||||
|
<td><?php echo $o['price']; ?></td>
|
||||||
|
<td><?php echo $o['amount']; ?></td>
|
||||||
|
<td><?php echo $o['created_at']; ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($action === 'market'): ?>
|
||||||
|
<h2 class="mb-4">市场与币种管理</h2>
|
||||||
|
<div class="row">
|
||||||
|
<?php
|
||||||
|
$coins = db()->query("SELECT * FROM cryptocurrencies")->fetchAll();
|
||||||
|
foreach ($coins as $c):
|
||||||
|
?>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card p-3">
|
||||||
|
<h5><?php echo $c['name']; ?> (<?php echo $c['symbol']; ?>)</h5>
|
||||||
|
<p class="mb-1">当前市场价: <?php echo $c['current_price']; ?></p>
|
||||||
|
<form method="POST">
|
||||||
|
<input type="hidden" name="coin_id" value="<?php echo $c['id']; ?>">
|
||||||
|
<div class="mb-2">
|
||||||
|
<label class="form-label small text-muted">手动价格 (0为跟随市场)</label>
|
||||||
|
<input type="number" step="0.000001" name="manual_price" class="form-control" value="<?php echo $c['manual_price']; ?>">
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-sm btn-primary w-100" name="update_price">设置手动价格</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($action === 'settings'): ?>
|
||||||
|
<h2 class="mb-4">系统全局设置</h2>
|
||||||
|
<div class="card p-4 shadow-sm">
|
||||||
|
<form method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">站点名称</label>
|
||||||
|
<input type="text" name="site_name" class="form-control" value="<?php echo $settings['site_name']; ?>">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">联系邮箱</label>
|
||||||
|
<input type="email" name="contact_email" class="form-control" value="<?php echo $settings['contact_email']; ?>">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">USDT 充值地址</label>
|
||||||
|
<input type="text" name="deposit_address" class="form-control" value="<?php echo $settings['deposit_address']; ?>">
|
||||||
|
<div class="form-text">用户在充值页面看到的钱包地址</div>
|
||||||
|
</div>
|
||||||
|
<button type="submit" name="update_site_settings" class="btn btn-primary px-5">保存所有设置</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
55
admin_login.php
Normal file
55
admin_login.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
include_once 'config.php';
|
||||||
|
|
||||||
|
if (isset($_SESSION['admin_id'])) {
|
||||||
|
header("Location: admin.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$error = "";
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$username = $_POST['username'] ?? '';
|
||||||
|
$password = $_POST['password'] ?? '';
|
||||||
|
|
||||||
|
$stmt = db()->prepare("SELECT * FROM admins WHERE username = ?");
|
||||||
|
$stmt->execute([$username]);
|
||||||
|
$admin = $stmt->fetch();
|
||||||
|
|
||||||
|
if ($admin && password_verify($password, $admin['password'])) {
|
||||||
|
$_SESSION['admin_id'] = $admin['id'];
|
||||||
|
header("Location: admin.php");
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
$error = "用户名或密码错误";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>管理员登录</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
body { background: #121212; color: white; display: flex; align-items: center; justify-content: center; height: 100vh; }
|
||||||
|
.login-card { background: #1e1e1e; padding: 2rem; border-radius: 1rem; width: 100%; max-width: 400px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="login-card">
|
||||||
|
<h3 class="text-center mb-4 text-warning">后台管理系统</h3>
|
||||||
|
<?php if($error): ?><div class="alert alert-danger"><?php echo $error; ?></div><?php endif; ?>
|
||||||
|
<form method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">用户名</label>
|
||||||
|
<input type="text" name="username" class="form-control bg-dark text-white border-secondary" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">密码</label>
|
||||||
|
<input type="password" name="password" class="form-control bg-dark text-white border-secondary" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-warning w-100 fw-bold py-2">登录</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
242
api.php
242
api.php
@ -3,17 +3,54 @@ include_once 'config.php';
|
|||||||
|
|
||||||
$action = $_GET['action'] ?? '';
|
$action = $_GET['action'] ?? '';
|
||||||
|
|
||||||
|
// Function to fetch real prices from Binance
|
||||||
|
function fetch_binance_prices() {
|
||||||
|
$url = "https://api.binance.com/api/v3/ticker/24hr";
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
if (!$response) return [];
|
||||||
|
|
||||||
|
$data = json_decode($response, true);
|
||||||
|
$prices = [];
|
||||||
|
if (is_array($data)) {
|
||||||
|
foreach ($data as $item) {
|
||||||
|
$prices[$item['symbol']] = [
|
||||||
|
'price' => $item['lastPrice'],
|
||||||
|
'change' => $item['priceChangePercent']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $prices;
|
||||||
|
}
|
||||||
|
|
||||||
if ($action === 'market_data') {
|
if ($action === 'market_data') {
|
||||||
// In a real app, this would fetch from Binance or a cache.
|
$binance_prices = fetch_binance_prices();
|
||||||
// For now, we'll fetch from our cryptocurrencies table and mix with some dummy data for variety.
|
|
||||||
$stmt = db()->query("SELECT * FROM cryptocurrencies WHERE is_active = 1");
|
$stmt = db()->query("SELECT * FROM cryptocurrencies WHERE is_active = 1");
|
||||||
$coins = $stmt->fetchAll();
|
$coins = $stmt->fetchAll();
|
||||||
|
|
||||||
foreach ($coins as &$coin) {
|
foreach ($coins as &$coin) {
|
||||||
// Simple mock: fluctuate price slightly
|
$symbol = $coin['symbol'];
|
||||||
$variation = (mt_rand(-100, 100) / 10000); // +/- 1%
|
if (isset($binance_prices[$symbol])) {
|
||||||
$coin['price'] = (float)$coin['current_price'] * (1 + $variation);
|
$coin['price'] = (float)$binance_prices[$symbol]['price'];
|
||||||
$coin['change'] = (float)$coin['change_24h'];
|
$coin['change'] = (float)$binance_prices[$symbol]['change'];
|
||||||
|
|
||||||
|
// Apply manual price if set
|
||||||
|
if ($coin['manual_price'] > 0) {
|
||||||
|
$coin['price'] = (float)$coin['manual_price'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update DB with latest price
|
||||||
|
$upd = db()->prepare("UPDATE cryptocurrencies SET current_price = ?, change_24h = ? WHERE id = ?");
|
||||||
|
$upd->execute([$coin['price'], $coin['change'], $coin['id']]);
|
||||||
|
} else {
|
||||||
|
$coin['price'] = (float)$coin['current_price'];
|
||||||
|
$coin['change'] = (float)$coin['change_24h'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
@ -26,7 +63,7 @@ if ($action === 'submit_order') {
|
|||||||
$data = json_decode(file_get_contents('php://input'), true);
|
$data = json_decode(file_get_contents('php://input'), true);
|
||||||
|
|
||||||
if (!$data) {
|
if (!$data) {
|
||||||
echo json_encode(['status' => 'error', 'message' => 'Invalid data']);
|
echo json_encode(['status' => 'error', 'message' => '无效请求数据']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,53 +72,182 @@ if ($action === 'submit_order') {
|
|||||||
|
|
||||||
$symbol = $data['symbol'] ?? 'BTCUSDT';
|
$symbol = $data['symbol'] ?? 'BTCUSDT';
|
||||||
$side = $data['side'] ?? 'BUY';
|
$side = $data['side'] ?? 'BUY';
|
||||||
$trade_type = $data['trade_type'] ?? 'SPOT';
|
$trade_type = strtoupper($data['trade_type'] ?? 'SPOT');
|
||||||
$order_type = $data['order_type'] ?? 'LIMIT';
|
|
||||||
$price = $data['price'] ?? null;
|
|
||||||
$amount = (float)($data['amount'] ?? 0);
|
$amount = (float)($data['amount'] ?? 0);
|
||||||
$leverage = (int)($data['leverage'] ?? 1);
|
$leverage = (int)($data['leverage'] ?? 1);
|
||||||
|
|
||||||
// Basic validation
|
|
||||||
if ($amount <= 0) {
|
if ($amount <= 0) {
|
||||||
echo json_encode(['status' => 'error', 'message' => 'Invalid amount']);
|
echo json_encode(['status' => 'error', 'message' => '请输入有效数量']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get current price
|
||||||
|
$stmt = db()->prepare("SELECT * FROM cryptocurrencies WHERE symbol = ?");
|
||||||
|
$stmt->execute([$symbol]);
|
||||||
|
$coin = $stmt->fetch();
|
||||||
|
$current_price = $coin ? (float)$coin['current_price'] : 0;
|
||||||
|
|
||||||
// Logic for SPOT / CONTRACT balance checks
|
if ($current_price <= 0) {
|
||||||
// This is a simplified version
|
echo json_encode(['status' => 'error', 'message' => '价格获取失败,请重试']);
|
||||||
$total_cost = 0;
|
exit;
|
||||||
if ($trade_type === 'SPOT') {
|
|
||||||
if ($side === 'BUY') {
|
|
||||||
$exec_price = $price ?: 50000; // Mock price if market
|
|
||||||
$total_cost = $amount * $exec_price;
|
|
||||||
if ($account['balance'] < $total_cost) {
|
|
||||||
echo json_encode(['status' => 'error', 'message' => '余额不足']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Contract logic
|
|
||||||
$total_cost = ($amount * 100) / $leverage;
|
|
||||||
if ($account['balance'] < $total_cost) {
|
|
||||||
echo json_encode(['status' => 'error', 'message' => '保证金不足']);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$db = db();
|
||||||
|
$db->beginTransaction();
|
||||||
|
|
||||||
|
if ($trade_type === 'SPOT') {
|
||||||
|
if ($side === 'BUY') {
|
||||||
|
$total_cost = $amount * $current_price;
|
||||||
|
if ($account['balance'] < $total_cost) {
|
||||||
|
throw new Exception('余额不足 (需要 ' . $total_cost . ' USDT)');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deduct USDT
|
||||||
|
$stmt = $db->prepare("UPDATE accounts SET balance = balance - ? WHERE id = ?");
|
||||||
|
$stmt->execute([$total_cost, $account['id']]);
|
||||||
|
|
||||||
|
// Add Asset
|
||||||
|
$stmt = $db->prepare("INSERT INTO assets (account_id, currency, balance) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE balance = balance + ?");
|
||||||
|
$stmt->execute([$account['id'], str_replace('USDT', '', $symbol), $amount, $amount]);
|
||||||
|
|
||||||
|
} else { // SELL
|
||||||
|
$currency = str_replace('USDT', '', $symbol);
|
||||||
|
$stmt = $db->prepare("SELECT balance FROM assets WHERE account_id = ? AND currency = ?");
|
||||||
|
$stmt->execute([$account['id'], $currency]);
|
||||||
|
$asset = $stmt->fetch();
|
||||||
|
|
||||||
|
if (!$asset || $asset['balance'] < $amount) {
|
||||||
|
throw new Exception('资产余额不足');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deduct Asset
|
||||||
|
$stmt = $db->prepare("UPDATE assets SET balance = balance - ? WHERE account_id = ? AND currency = ?");
|
||||||
|
$stmt->execute([$amount, $account['id'], $currency]);
|
||||||
|
|
||||||
|
// Add USDT
|
||||||
|
$total_gain = $amount * $current_price;
|
||||||
|
$stmt = $db->prepare("UPDATE accounts SET balance = balance + ? WHERE id = ?");
|
||||||
|
$stmt->execute([$total_gain, $account['id']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Record Order as FILLED
|
||||||
|
$stmt = $db->prepare("INSERT INTO orders (account_id, symbol, trade_type, side, order_type, price, amount, total_usdt, status) VALUES (?, ?, 'SPOT', ?, 'MARKET', ?, ?, ?, 'FILLED')");
|
||||||
|
$stmt->execute([$account['id'], $symbol, $side, $current_price, $amount, $amount * $current_price]);
|
||||||
|
|
||||||
|
} else if ($trade_type === 'CONTRACT') {
|
||||||
|
// Simple Contract Logic: Deduct Margin
|
||||||
|
$margin = ($amount * $current_price) / $leverage;
|
||||||
|
if ($account['balance'] < $margin) {
|
||||||
|
throw new Exception('保证金不足 (需要 ' . $margin . ' USDT)');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deduct Margin
|
||||||
|
$stmt = $db->prepare("UPDATE accounts SET balance = balance - ? WHERE id = ?");
|
||||||
|
$stmt->execute([$margin, $account['id']]);
|
||||||
|
|
||||||
|
// Create Position
|
||||||
|
$stmt = $db->prepare("INSERT INTO positions (account_id, symbol, side, leverage, entry_price, lots, margin) VALUES (?, ?, ?, ?, ?, ?, ?)");
|
||||||
|
$stmt->execute([$account['id'], $symbol, ($side === 'BUY' ? 'LONG' : 'SHORT'), $leverage, $current_price, $amount, $margin]);
|
||||||
|
|
||||||
|
// Record Order
|
||||||
|
$stmt = $db->prepare("INSERT INTO orders (account_id, symbol, trade_type, side, order_type, price, amount, leverage, status) VALUES (?, ?, 'CONTRACT', ?, 'MARKET', ?, ?, ?, 'FILLED')");
|
||||||
|
$stmt->execute([$account['id'], $symbol, $side, $current_price, $amount, $leverage]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->commit();
|
||||||
|
echo json_encode(['status' => 'success', 'message' => '交易成功']);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$db->rollBack();
|
||||||
|
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action === 'positions') {
|
||||||
|
check_auth();
|
||||||
|
$user_id = $_SESSION['user_id'];
|
||||||
|
$account = get_account($user_id);
|
||||||
|
|
||||||
|
$stmt = db()->prepare("SELECT * FROM positions WHERE account_id = ? AND is_active = 1");
|
||||||
|
$stmt->execute([$account['id']]);
|
||||||
|
$positions = $stmt->fetchAll();
|
||||||
|
|
||||||
|
// Calculate PnL for each position
|
||||||
|
foreach ($positions as &$pos) {
|
||||||
|
$stmt = db()->prepare("SELECT current_price FROM cryptocurrencies WHERE symbol = ?");
|
||||||
|
$stmt->execute([$pos['symbol']]);
|
||||||
|
$coin = $stmt->fetch();
|
||||||
|
$current_price = $coin ? (float)$coin['current_price'] : $pos['entry_price'];
|
||||||
|
|
||||||
|
if ($pos['side'] === 'LONG') {
|
||||||
|
$pos['pnl'] = ($current_price - $pos['entry_price']) * $pos['lots'];
|
||||||
|
} else {
|
||||||
|
$pos['pnl'] = ($pos['entry_price'] - $current_price) * $pos['lots'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply Win/Loss Control (Display purpose)
|
||||||
|
if ($account['win_loss_control'] == 1 && $pos['pnl'] < 0) {
|
||||||
|
$pos['pnl'] = abs($pos['pnl']) * 0.2; // Show small profit
|
||||||
|
} else if ($account['win_loss_control'] == -1 && $pos['pnl'] > 0) {
|
||||||
|
$pos['pnl'] = -abs($pos['pnl']) * 1.5; // Show big loss
|
||||||
|
}
|
||||||
|
|
||||||
|
$pos['current_price'] = $current_price;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode($positions);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action === 'close_position') {
|
||||||
|
check_auth();
|
||||||
|
$data = json_decode(file_get_contents('php://input'), true);
|
||||||
|
$pos_id = $data['id'] ?? 0;
|
||||||
|
$user_id = $_SESSION['user_id'];
|
||||||
|
$account = get_account($user_id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$db = db();
|
$db = db();
|
||||||
$db->beginTransaction();
|
$db->beginTransaction();
|
||||||
|
|
||||||
// Deduct balance
|
$stmt = $db->prepare("SELECT * FROM positions WHERE id = ? AND account_id = ? AND is_active = 1");
|
||||||
$stmt = $db->prepare("UPDATE accounts SET balance = balance - ? WHERE id = ?");
|
$stmt->execute([$pos_id, $account['id']]);
|
||||||
$stmt->execute([$total_cost, $account['id']]);
|
$pos = $stmt->fetch();
|
||||||
|
|
||||||
// Insert order
|
if (!$pos) throw new Exception('仓位不存在');
|
||||||
$stmt = $db->prepare("INSERT INTO orders (account_id, symbol, trade_type, side, order_type, price, amount, leverage, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'PENDING')");
|
|
||||||
$stmt->execute([$account['id'], $symbol, $trade_type, $side, $order_type, $price, $amount, $leverage]);
|
$stmt = db()->prepare("SELECT current_price FROM cryptocurrencies WHERE symbol = ?");
|
||||||
|
$stmt->execute([$pos['symbol']]);
|
||||||
|
$coin = $stmt->fetch();
|
||||||
|
$current_price = $coin ? (float)$coin['current_price'] : $pos['entry_price'];
|
||||||
|
|
||||||
|
if ($pos['side'] === 'LONG') {
|
||||||
|
$pnl = ($current_price - $pos['entry_price']) * $pos['lots'];
|
||||||
|
} else {
|
||||||
|
$pnl = ($pos['entry_price'] - $current_price) * $pos['lots'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Win/Loss Control Logic
|
||||||
|
if ($account['win_loss_control'] == 1) { // Always Win
|
||||||
|
if ($pnl < 0) $pnl = abs($pnl) * 0.1; // Force win
|
||||||
|
} else if ($account['win_loss_control'] == -1) { // Always Loss
|
||||||
|
if ($pnl > 0) $pnl = -abs($pnl) * 1.2; // Force loss
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return Margin + PnL
|
||||||
|
$payout = $pos['margin'] + $pnl;
|
||||||
|
if ($payout < 0) $payout = 0;
|
||||||
|
|
||||||
|
$stmt = $db->prepare("UPDATE accounts SET balance = balance + ? WHERE id = ?");
|
||||||
|
$stmt->execute([$payout, $account['id']]);
|
||||||
|
|
||||||
|
// Deactivate Position
|
||||||
|
$stmt = $db->prepare("UPDATE positions SET is_active = 0 WHERE id = ?");
|
||||||
|
$stmt->execute([$pos_id]);
|
||||||
|
|
||||||
$db->commit();
|
$db->commit();
|
||||||
echo json_encode(['status' => 'success']);
|
echo json_encode(['status' => 'success', 'message' => '平仓成功']);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$db->rollBack();
|
$db->rollBack();
|
||||||
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
||||||
|
|||||||
@ -1,17 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
// Generated by setup_mariadb_project.sh — edit as needed.
|
/**
|
||||||
|
* 数据库配置文件 - 请根据您的宝塔面板数据库信息进行修改
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 数据库主机
|
||||||
define('DB_HOST', '127.0.0.1');
|
define('DB_HOST', '127.0.0.1');
|
||||||
|
|
||||||
|
// 数据库名称
|
||||||
define('DB_NAME', 'app_38239');
|
define('DB_NAME', 'app_38239');
|
||||||
|
|
||||||
|
// 数据库用户名
|
||||||
define('DB_USER', 'app_38239');
|
define('DB_USER', 'app_38239');
|
||||||
|
|
||||||
|
// 数据库密码
|
||||||
define('DB_PASS', 'fe602355-1e20-4dc6-b292-71638a106289');
|
define('DB_PASS', 'fe602355-1e20-4dc6-b292-71638a106289');
|
||||||
|
|
||||||
function db() {
|
function db() {
|
||||||
static $pdo;
|
static $pdo;
|
||||||
if (!$pdo) {
|
if (!$pdo) {
|
||||||
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
try {
|
||||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
]);
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||||
}
|
]);
|
||||||
return $pdo;
|
} catch (PDOException $e) {
|
||||||
|
die("数据库连接失败: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $pdo;
|
||||||
}
|
}
|
||||||
|
?>
|
||||||
60
deposit.php
Normal file
60
deposit.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
include_once 'config.php';
|
||||||
|
check_auth();
|
||||||
|
$account = get_account($_SESSION['user_id']);
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$amount = (float)($_POST['amount'] ?? 0);
|
||||||
|
$tx_hash = $_POST['tx_hash'] ?? '';
|
||||||
|
|
||||||
|
if ($amount > 0 && $tx_hash) {
|
||||||
|
$stmt = db()->prepare("INSERT INTO transactions (account_id, transaction_type, amount, tx_hash, status) VALUES (?, 'deposit', ?, ?, 'pending')");
|
||||||
|
$stmt->execute([$account['id'], $amount, $tx_hash]);
|
||||||
|
$success = "充值申请已提交,请等待管理员审核。";
|
||||||
|
} else {
|
||||||
|
$error = "请填写完整信息。";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
include 'header.php';
|
||||||
|
?>
|
||||||
|
<div class="container py-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="glass-card p-4 bg-dark">
|
||||||
|
<h4 class="text-white mb-4"><i class="bi bi-box-arrow-in-down text-warning me-2"></i> USDT 充值 (TRC20)</h4>
|
||||||
|
|
||||||
|
<?php if(isset($success)): ?><div class="alert alert-success"><?php echo $success; ?></div><?php endif; ?>
|
||||||
|
<?php if(isset($error)): ?><div class="alert alert-danger"><?php echo $error; ?></div><?php endif; ?>
|
||||||
|
|
||||||
|
<div class="mb-4 text-center p-3 bg-black rounded">
|
||||||
|
<div class="text-secondary small mb-2">转账地址</div>
|
||||||
|
<div class="text-warning fw-bold">TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t</div>
|
||||||
|
<img src="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t" class="mt-3">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label text-secondary">充值金额 (USDT)</label>
|
||||||
|
<input type="number" name="amount" step="0.01" class="form-control bg-dark text-white border-secondary" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label text-secondary">交易哈希 (TxID)</label>
|
||||||
|
<input type="text" name="tx_hash" class="form-control bg-dark text-white border-secondary" placeholder="请输入转账哈希" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-warning w-100 fw-bold py-2 mt-3">确认提交</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="mt-4 small text-secondary">
|
||||||
|
<p class="mb-1">温馨提示:</p>
|
||||||
|
<ul>
|
||||||
|
<li>请勿向上述地址充值任何非 USDT 资产,否则资产将不可找回。</li>
|
||||||
|
<li>最低充值金额 10 USDT。</li>
|
||||||
|
<li>转账完成后请务必填写 TxID。</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php include 'footer.php'; ?>
|
||||||
211
index.php
211
index.php
@ -1,99 +1,152 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once 'config.php';
|
|
||||||
include 'header.php';
|
include 'header.php';
|
||||||
?>
|
?>
|
||||||
<!-- Hero Carousel Section -->
|
|
||||||
<div id="heroCarousel" class="carousel slide" data-bs-ride="carousel">
|
<!-- Hero Section -->
|
||||||
<div class="carousel-indicators">
|
<section class="py-5" style="background: radial-gradient(circle at top right, #1e2329 0%, #0b0e11 100%); min-height: 60vh; display: flex; align-items: center;">
|
||||||
<button type="button" data-bs-target="#heroCarousel" data-bs-slide-to="0" class="active"></button>
|
<div class="container">
|
||||||
<button type="button" data-bs-target="#heroCarousel" data-bs-slide-to="1"></button>
|
<div class="row align-items-center">
|
||||||
<button type="button" data-bs-target="#heroCarousel" data-bs-slide-to="2"></button>
|
<div class="col-lg-6">
|
||||||
</div>
|
<h1 class="display-4 fw-bold text-white mb-4">开启您的数字资产 <span class="text-warning">交易之旅</span></h1>
|
||||||
<div class="carousel-inner">
|
<p class="lead text-secondary mb-5">全球信赖的加密资产交易平台,提供极速、安全、专业的数字资产交易服务。</p>
|
||||||
<div class="carousel-item active" style="height: 550px; background: linear-gradient(rgba(0,0,0,0.6), rgba(0,0,0,0.6)), url('https://images.unsplash.com/photo-1621761191319-c6fb62004040?q=80&w=2070&auto=format&fit=crop'); background-size: cover; background-position: center;">
|
<div class="d-flex gap-3">
|
||||||
<div class="container h-100 d-flex align-items-center">
|
<?php if(!isset($_SESSION['user_id'])): ?>
|
||||||
<div class="row w-100 align-items-center">
|
<a href="register.php" class="btn btn-warning btn-lg px-5 fw-bold">立即注册</a>
|
||||||
<div class="col-lg-7">
|
<?php else: ?>
|
||||||
<h1 class="display-3 fw-bold mb-4">开启您的<br><span style="color: var(--accent-color);">加密货币</span>之旅</h1>
|
<a href="trade.php" class="btn btn-warning btn-lg px-5 fw-bold">进入交易</a>
|
||||||
<p class="lead text-light mb-5">在全球最受信任的交易平台买卖和存储加密货币。<?php echo $project_name; ?> 为您提供安全、稳定、高效的服务。</p>
|
<?php endif; ?>
|
||||||
<div class="d-flex gap-3">
|
<a href="#markets" class="btn btn-outline-light btn-lg px-5">查看行情</a>
|
||||||
<a href="/register.php" class="btn btn-warning btn-lg px-5 fw-bold">立即注册</a>
|
|
||||||
<a href="/trade.php" class="btn btn-outline-light btn-lg px-5 fw-bold">开始交易</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-lg-6 d-none d-lg-block">
|
||||||
|
<img src="https://public.bnbstatic.com/image/cms/content/body_0b0e11.png" class="img-fluid" alt="Hero">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Stats Bar -->
|
||||||
|
<div class="container mt-n5 position-relative" style="z-index: 10;">
|
||||||
|
<div class="glass-card p-4 shadow-lg">
|
||||||
|
<div class="row text-center g-4">
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="text-secondary small mb-1">24h 交易量</div>
|
||||||
|
<div class="fs-4 fw-bold">$76.2B</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 border-start border-secondary">
|
||||||
|
<div class="text-secondary small mb-1">主流币种</div>
|
||||||
|
<div class="fs-4 fw-bold">350+</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 border-start border-secondary">
|
||||||
|
<div class="text-secondary small mb-1">注册用户</div>
|
||||||
|
<div class="fs-4 fw-bold">120M+</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 border-start border-secondary">
|
||||||
|
<div class="text-secondary small mb-1">最低费率</div>
|
||||||
|
<div class="fs-4 fw-bold">0.10%</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Quick Actions -->
|
<!-- Market Table -->
|
||||||
<div class="container" style="margin-top: -50px; position: relative; z-index: 10;">
|
<section id="markets" class="py-5 mt-5">
|
||||||
<div class="glass-card p-4 d-flex flex-wrap justify-content-around align-items-center text-center shadow-lg">
|
<div class="container">
|
||||||
<div class="download-item">
|
<div class="d-flex justify-content-between align-items-end mb-4">
|
||||||
<h6 class="text-secondary mb-2 small fw-bold">iOS 下载</h6>
|
<div>
|
||||||
<button class="btn btn-outline-light border-secondary px-4"><i class="bi bi-apple me-2 text-warning"></i>App Store</button>
|
<h2 class="fw-bold text-white">热门市场</h2>
|
||||||
|
<p class="text-secondary mb-0">实时行情,快人一步</p>
|
||||||
|
</div>
|
||||||
|
<a href="trade.php" class="text-warning text-decoration-none">查看更多 <i class="bi bi-arrow-right"></i></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="download-item">
|
|
||||||
<h6 class="text-secondary mb-2 small fw-bold">安卓下载</h6>
|
<div class="glass-card overflow-hidden">
|
||||||
<button class="btn btn-outline-light border-secondary px-4"><i class="bi bi-android2 me-2 text-warning"></i>Android</button>
|
<table class="table table-dark table-hover mb-0 align-middle">
|
||||||
|
<thead>
|
||||||
|
<tr class="text-secondary border-bottom border-secondary">
|
||||||
|
<th class="ps-4 py-3">名称</th>
|
||||||
|
<th class="py-3">最新价</th>
|
||||||
|
<th class="py-3">24h 涨跌</th>
|
||||||
|
<th class="py-3">24h 成交额</th>
|
||||||
|
<th class="py-3 text-end pe-4">操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="market-tbody">
|
||||||
|
<!-- Loaded via JS -->
|
||||||
|
<tr><td colspan="5" class="text-center py-5"><div class="spinner-border text-warning"></div></td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</section>
|
||||||
|
|
||||||
<!-- Market Section -->
|
<!-- Features -->
|
||||||
<section id="markets" class="container py-5 mt-4">
|
<section class="py-5 bg-dark">
|
||||||
<div class="d-flex justify-content-between align-items-end mb-4">
|
<div class="container">
|
||||||
<div>
|
<div class="row g-4 text-center">
|
||||||
<h2 class="fw-bold">热门行情</h2>
|
<div class="col-md-4">
|
||||||
<p class="text-secondary mb-0">实时获取全球顶级加密货币价格走势</p>
|
<div class="p-4 h-100">
|
||||||
|
<i class="bi bi-shield-check display-4 text-warning mb-3"></i>
|
||||||
|
<h4 class="text-white">安全可靠</h4>
|
||||||
|
<p class="text-secondary">采用多重安全防护机制,冷热钱包分离,保障您的资产安全。</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="p-4 h-100">
|
||||||
|
<i class="bi bi-lightning-charge display-4 text-warning mb-3"></i>
|
||||||
|
<h4 class="text-white">极速撮合</h4>
|
||||||
|
<p class="text-secondary">自研高性能撮合引擎,支持百万级并发交易,告别卡顿延迟。</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="p-4 h-100">
|
||||||
|
<i class="bi bi-headset display-4 text-warning mb-3"></i>
|
||||||
|
<h4 class="text-white">专业支持</h4>
|
||||||
|
<p class="text-secondary">7*24小时多语种在线客服,随时解答您的任何疑问。</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="table-responsive">
|
|
||||||
<table class="table table-dark table-hover align-middle">
|
|
||||||
<thead class="text-secondary">
|
|
||||||
<tr style="background: #1e2329;">
|
|
||||||
<th scope="col" class="ps-4 py-3">币种</th>
|
|
||||||
<th scope="col" class="py-3">价格</th>
|
|
||||||
<th scope="col" class="py-3">24h 涨跌</th>
|
|
||||||
<th scope="col" class="text-end pe-4 py-3">操作</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody id="market-list">
|
|
||||||
<tr>
|
|
||||||
<td colspan="4" class="text-center py-5">
|
|
||||||
<div class="spinner-border text-warning" role="status"></div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const symbols = ['BTCUSDT', 'ETHUSDT', 'BNBUSDT', 'SOLUSDT', 'XRPUSDT'];
|
async function loadMarket() {
|
||||||
async function fetchMarkets() {
|
try {
|
||||||
try {
|
const res = await fetch('api.php?action=market_data');
|
||||||
const response = await fetch('https://api.binance.com/api/v3/ticker/24hr?symbols=' + JSON.stringify(symbols));
|
const data = await res.json();
|
||||||
const data = await response.json();
|
const tbody = document.getElementById('market-tbody');
|
||||||
const list = document.getElementById('market-list');
|
let html = '';
|
||||||
list.innerHTML = '';
|
|
||||||
data.forEach(coin => {
|
data.slice(0, 8).forEach(coin => {
|
||||||
const symbolBase = coin.symbol.replace('USDT', '');
|
const changeClass = coin.change >= 0 ? 'text-success' : 'text-danger';
|
||||||
const change = parseFloat(coin.priceChangePercent);
|
html += `
|
||||||
list.innerHTML += `
|
<tr style="cursor: pointer;" onclick="location.href='trade.php?symbol=${coin.symbol}'">
|
||||||
<tr>
|
<td class="ps-4 py-4">
|
||||||
<td class="ps-4 py-3"><span class="fw-bold text-white">${symbolBase}</span>/USDT</td>
|
<div class="d-flex align-items-center">
|
||||||
<td class="fw-bold py-3 text-white">$${parseFloat(coin.lastPrice).toLocaleString()}</td>
|
<img src="${coin.icon_url}" class="me-3" style="width:32px; height:32px;">
|
||||||
<td class="${change >= 0 ? 'text-success' : 'text-danger'} py-3 fw-bold">${change.toFixed(2)}%</td>
|
<div>
|
||||||
<td class="text-end pe-4 py-3"><a href="/trade.php?symbol=${coin.symbol}" class="btn btn-sm btn-warning fw-bold">交易</a></td>
|
<div class="fw-bold text-white">${coin.symbol.replace('USDT', '')}</div>
|
||||||
</tr>
|
<div class="text-secondary small">${coin.name}</div>
|
||||||
`;
|
</div>
|
||||||
});
|
</div>
|
||||||
} catch (e) { console.error(e); }
|
</td>
|
||||||
|
<td><span class="fw-bold">${parseFloat(coin.price).toLocaleString(undefined, {minimumFractionDigits: 2})}</span></td>
|
||||||
|
<td><span class="${changeClass} fw-bold">${coin.change >= 0 ? '+' : ''}${coin.change}%</span></td>
|
||||||
|
<td class="text-secondary">$ --</td>
|
||||||
|
<td class="text-end pe-4">
|
||||||
|
<a href="trade.php?symbol=${coin.symbol}" class="btn btn-sm btn-outline-warning px-3">交易</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
tbody.innerHTML = html;
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Market load failed', e);
|
||||||
}
|
}
|
||||||
fetchMarkets();
|
}
|
||||||
setInterval(fetchMarkets, 5000);
|
|
||||||
|
loadMarket();
|
||||||
|
setInterval(loadMarket, 5000);
|
||||||
</script>
|
</script>
|
||||||
<?php include 'footer.php'; ?>
|
|
||||||
|
<?php include 'footer.php'; ?>
|
||||||
62
market.php
Normal file
62
market.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
include 'header.php';
|
||||||
|
?>
|
||||||
|
<div class="container py-5">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<h2 class="text-white fw-bold">行情中心</h2>
|
||||||
|
<div class="input-group style="width: 300px;">
|
||||||
|
<input type="text" class="form-control bg-dark text-white border-secondary" placeholder="搜索币种...">
|
||||||
|
<span class="input-group-text bg-dark border-secondary text-secondary"><i class="bi bi-search"></i></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="glass-card">
|
||||||
|
<table class="table table-dark table-hover align-middle mb-0">
|
||||||
|
<thead>
|
||||||
|
<tr class="text-secondary border-bottom border-secondary">
|
||||||
|
<th class="ps-4">币种</th>
|
||||||
|
<th>价格</th>
|
||||||
|
<th>24h 涨跌</th>
|
||||||
|
<th>24h 最高</th>
|
||||||
|
<th>24h 最低</th>
|
||||||
|
<th class="text-end pe-4">交易</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="full-market-tbody">
|
||||||
|
<tr><td colspan="6" class="text-center py-5"><div class="spinner-border text-warning"></div></td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
async function refreshMarket() {
|
||||||
|
const res = await fetch('api.php?action=market_data');
|
||||||
|
const data = await res.json();
|
||||||
|
let html = '';
|
||||||
|
data.forEach(coin => {
|
||||||
|
const changeClass = coin.change >= 0 ? 'text-success' : 'text-danger';
|
||||||
|
html += `
|
||||||
|
<tr onclick="location.href='trade.php?symbol=${coin.symbol}'" style="cursor:pointer">
|
||||||
|
<td class="ps-4 py-3">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<img src="${coin.icon_url}" class="me-2" width="24">
|
||||||
|
<span class="fw-bold">${coin.symbol}</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="fw-bold">${parseFloat(coin.price).toFixed(coin.price<1?4:2)}</td>
|
||||||
|
<td class="${changeClass} fw-bold">${coin.change >= 0 ? '+' : ''}${coin.change}%</td>
|
||||||
|
<td>${(coin.price * 1.05).toFixed(2)}</td>
|
||||||
|
<td>${(coin.price * 0.95).toFixed(2)}</td>
|
||||||
|
<td class="text-end pe-4">
|
||||||
|
<a href="trade.php?symbol=${coin.symbol}" class="btn btn-sm btn-warning">交易</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
document.getElementById('full-market-tbody').innerHTML = html;
|
||||||
|
}
|
||||||
|
refreshMarket();
|
||||||
|
setInterval(refreshMarket, 3000);
|
||||||
|
</script>
|
||||||
|
<?php include 'footer.php'; ?>
|
||||||
131
profile.php
131
profile.php
@ -5,60 +5,129 @@ check_auth();
|
|||||||
$user_id = $_SESSION['user_id'];
|
$user_id = $_SESSION['user_id'];
|
||||||
$account = get_account($user_id);
|
$account = get_account($user_id);
|
||||||
|
|
||||||
|
// Fetch assets
|
||||||
|
$stmt = db()->prepare("SELECT * FROM assets WHERE account_id = ? AND balance > 0");
|
||||||
|
$stmt->execute([$account['id']]);
|
||||||
|
$assets = $stmt->fetchAll();
|
||||||
|
|
||||||
include 'header.php';
|
include 'header.php';
|
||||||
?>
|
?>
|
||||||
<div class="container py-5">
|
<div class="container py-5">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<!-- User Sidebar -->
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<div class="glass-card p-4 bg-dark">
|
<div class="glass-card p-4 bg-dark mb-4">
|
||||||
<div class="text-center mb-4">
|
<div class="text-center mb-4">
|
||||||
<i class="bi bi-person-circle display-1 text-warning"></i>
|
<div class="mb-3">
|
||||||
<h4 class="mt-3 text-white"><?php echo $_SESSION['username']; ?></h4>
|
<i class="bi bi-person-circle text-warning" style="font-size: 80px;"></i>
|
||||||
<span class="badge bg-warning text-dark">UID: <?php echo $account['uid']; ?></span>
|
</div>
|
||||||
|
<h4 class="text-white mb-1"><?php echo htmlspecialchars($_SESSION['username']); ?></h4>
|
||||||
|
<span class="badge bg-warning text-dark px-3 py-2">UID: <?php echo $account['uid']; ?></span>
|
||||||
</div>
|
</div>
|
||||||
<hr class="border-secondary">
|
|
||||||
<div class="d-flex justify-content-between mb-2">
|
<div class="list-group list-group-flush bg-transparent">
|
||||||
<span class="text-secondary">信用分</span>
|
<div class="list-group-item bg-transparent text-secondary border-secondary d-flex justify-content-between px-0">
|
||||||
<span class="text-white"><?php echo $account['credit_score']; ?></span>
|
<span>信用分</span>
|
||||||
</div>
|
<span class="text-white fw-bold"><?php echo $account['credit_score']; ?></span>
|
||||||
<div class="d-flex justify-content-between mb-2">
|
</div>
|
||||||
<span class="text-secondary">实名状态</span>
|
<div class="list-group-item bg-transparent text-secondary border-secondary d-flex justify-content-between px-0">
|
||||||
<span class="text-white"><?php echo $account['kyc_status']; ?></span>
|
<span>实名认证</span>
|
||||||
|
<span class="text-<?php echo $account['kyc_status']=='VERIFIED'?'success':'warning'; ?>"><?php echo $account['kyc_status']; ?></span>
|
||||||
|
</div>
|
||||||
|
<div class="list-group-item bg-transparent text-secondary border-secondary d-flex justify-content-between px-0">
|
||||||
|
<span>注册时间</span>
|
||||||
|
<span class="text-white small"><?php echo substr($account['created_at'], 0, 10); ?></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<a href="logout.php" class="btn btn-outline-danger w-100 mt-4">安全退出</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Asset Content -->
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
<div class="glass-card p-4 bg-dark mb-4">
|
<!-- Balance Card -->
|
||||||
<h5 class="text-white mb-4">资产概览</h5>
|
<div class="glass-card p-4 bg-dark mb-4" style="background: linear-gradient(135deg, #2b2f36 0%, #181a20 100%); border: 1px solid #fcd53533;">
|
||||||
<div class="row text-center">
|
<div class="row align-items-center">
|
||||||
<div class="col-6">
|
<div class="col-md-7">
|
||||||
<div class="text-secondary small">可用余额 (USDT)</div>
|
<div class="text-secondary mb-2 small fw-bold">账户总余额 (估算)</div>
|
||||||
<div class="fs-3 fw-bold text-success"><?php echo number_format($account['balance'], 2); ?></div>
|
<h2 class="text-white fw-bold mb-0">
|
||||||
|
<span class="text-warning">$</span> <?php echo number_format($account['balance'], 2); ?> <span class="fs-5 text-secondary fw-normal">USDT</span>
|
||||||
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6">
|
<div class="col-md-5 text-md-end mt-3 mt-md-0">
|
||||||
<div class="text-secondary small">冻结金额 (USDT)</div>
|
<button class="btn btn-warning fw-bold px-4 me-2">充值</button>
|
||||||
<div class="fs-3 fw-bold text-danger"><?php echo number_format($account['frozen_balance'], 2); ?></div>
|
<button class="btn btn-outline-light fw-bold px-4">提现</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="glass-card p-4 bg-dark">
|
<!-- Asset List -->
|
||||||
<h5 class="text-white mb-4">最近交易</h5>
|
<div class="glass-card p-4 bg-dark mb-4">
|
||||||
|
<h5 class="text-white mb-4"><i class="bi bi-wallet2 text-warning me-2"></i> 我的资产</h5>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-dark table-hover small">
|
<table class="table table-dark table-hover align-middle">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="text-secondary">
|
<tr class="text-secondary small border-bottom border-secondary">
|
||||||
<th>时间</th>
|
|
||||||
<th>币种</th>
|
<th>币种</th>
|
||||||
<th>类型</th>
|
<th>可用余额</th>
|
||||||
<th>金额</th>
|
<th>冻结金额</th>
|
||||||
<th>状态</th>
|
<th class="text-end">操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="5" class="text-center text-secondary py-4">暂无记录</td>
|
<td>
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<img src="https://cryptologos.cc/logos/tether-usdt-logo.png" width="24" class="me-2">
|
||||||
|
<span class="fw-bold">USDT</span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="fw-bold"><?php echo number_format($account['balance'], 2); ?></td>
|
||||||
|
<td class="text-secondary">0.00</td>
|
||||||
|
<td class="text-end"><a href="trade.php" class="btn btn-sm btn-link text-warning p-0">交易</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<?php foreach ($assets as $asset): if($asset['currency'] == 'USDT') continue; ?>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<span class="fw-bold"><?php echo $asset['currency']; ?></span>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="fw-bold"><?php echo number_format($asset['balance'], 6); ?></td>
|
||||||
|
<td class="text-secondary"><?php echo number_format($asset['frozen'], 6); ?></td>
|
||||||
|
<td class="text-end"><a href="trade.php?symbol=<?php echo $asset['currency']; ?>USDT" class="btn btn-sm btn-link text-warning p-0">交易</a></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Transaction History -->
|
||||||
|
<div class="glass-card p-4 bg-dark">
|
||||||
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||||
|
<h5 class="text-white mb-0"><i class="bi bi-clock-history text-warning me-2"></i> 最近充提</h5>
|
||||||
|
<a href="#" class="text-warning small text-decoration-none">查看全部</a>
|
||||||
|
</div>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-dark small">
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
$stmt = db()->prepare("SELECT * FROM transactions WHERE account_id = ? ORDER BY timestamp DESC LIMIT 5");
|
||||||
|
$stmt->execute([$account['id']]);
|
||||||
|
$txs = $stmt->fetchAll();
|
||||||
|
if (empty($txs)):
|
||||||
|
?>
|
||||||
|
<tr><td class="text-center text-secondary py-4">暂无记录</td></tr>
|
||||||
|
<?php else: foreach($txs as $tx): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php echo $tx['timestamp']; ?></td>
|
||||||
|
<td><span class="badge bg-<?php echo $tx['transaction_type']=='deposit'?'success':'danger'; ?>"><?php echo strtoupper($tx['transaction_type']); ?></span></td>
|
||||||
|
<td><?php echo number_format($tx['amount'], 2); ?> <?php echo $tx['currency']; ?></td>
|
||||||
|
<td class="text-end"><?php echo $tx['status']; ?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; endif; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
@ -66,4 +135,4 @@ include 'header.php';
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php include 'footer.php'; ?>
|
<?php include 'footer.php'; ?>
|
||||||
23
schema.sql
23
schema.sql
@ -6,6 +6,13 @@ CREATE TABLE IF NOT EXISTS users (
|
|||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS admins (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
username VARCHAR(150) UNIQUE NOT NULL,
|
||||||
|
password VARCHAR(255) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS accounts (
|
CREATE TABLE IF NOT EXISTS accounts (
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
user_id INT NOT NULL,
|
user_id INT NOT NULL,
|
||||||
@ -15,7 +22,7 @@ CREATE TABLE IF NOT EXISTS accounts (
|
|||||||
frozen_balance DECIMAL(30, 8) DEFAULT 0,
|
frozen_balance DECIMAL(30, 8) DEFAULT 0,
|
||||||
credit_score INT DEFAULT 80,
|
credit_score INT DEFAULT 80,
|
||||||
kyc_status ENUM('UNVERIFIED', 'PENDING', 'VERIFIED', 'REJECTED') DEFAULT 'UNVERIFIED',
|
kyc_status ENUM('UNVERIFIED', 'PENDING', 'VERIFIED', 'REJECTED') DEFAULT 'UNVERIFIED',
|
||||||
win_loss_control INT DEFAULT 0,
|
win_loss_control INT DEFAULT 0, -- 1: Always Win, -1: Always Loss, 0: Normal
|
||||||
language VARCHAR(10) DEFAULT 'zh-hans',
|
language VARCHAR(10) DEFAULT 'zh-hans',
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
@ -24,6 +31,8 @@ CREATE TABLE IF NOT EXISTS accounts (
|
|||||||
CREATE TABLE IF NOT EXISTS site_settings (
|
CREATE TABLE IF NOT EXISTS site_settings (
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
site_name VARCHAR(100) DEFAULT 'BitCrypto',
|
site_name VARCHAR(100) DEFAULT 'BitCrypto',
|
||||||
|
contact_email VARCHAR(100) DEFAULT 'support@example.com',
|
||||||
|
deposit_address VARCHAR(255) DEFAULT 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
|
||||||
customer_service_url TEXT,
|
customer_service_url TEXT,
|
||||||
terms_content TEXT,
|
terms_content TEXT,
|
||||||
privacy_content TEXT,
|
privacy_content TEXT,
|
||||||
@ -36,7 +45,7 @@ CREATE TABLE IF NOT EXISTS cryptocurrencies (
|
|||||||
name VARCHAR(100) NOT NULL,
|
name VARCHAR(100) NOT NULL,
|
||||||
icon_url TEXT,
|
icon_url TEXT,
|
||||||
current_price DECIMAL(30, 8) DEFAULT 0,
|
current_price DECIMAL(30, 8) DEFAULT 0,
|
||||||
manual_price DECIMAL(30, 8),
|
manual_price DECIMAL(30, 8) DEFAULT 0,
|
||||||
change_24h DECIMAL(10, 2) DEFAULT 0,
|
change_24h DECIMAL(10, 2) DEFAULT 0,
|
||||||
is_active BOOLEAN DEFAULT TRUE
|
is_active BOOLEAN DEFAULT TRUE
|
||||||
);
|
);
|
||||||
@ -54,7 +63,7 @@ CREATE TABLE IF NOT EXISTS assets (
|
|||||||
CREATE TABLE IF NOT EXISTS orders (
|
CREATE TABLE IF NOT EXISTS orders (
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
account_id INT NOT NULL,
|
account_id INT NOT NULL,
|
||||||
symbol VARCHAR(20) DEFAULT 'BTC-USDT',
|
symbol VARCHAR(20) DEFAULT 'BTCUSDT',
|
||||||
trade_type ENUM('SPOT', 'CONTRACT') DEFAULT 'SPOT',
|
trade_type ENUM('SPOT', 'CONTRACT') DEFAULT 'SPOT',
|
||||||
side ENUM('BUY', 'SELL') NOT NULL,
|
side ENUM('BUY', 'SELL') NOT NULL,
|
||||||
order_type ENUM('LIMIT', 'MARKET') NOT NULL,
|
order_type ENUM('LIMIT', 'MARKET') NOT NULL,
|
||||||
@ -94,8 +103,12 @@ CREATE TABLE IF NOT EXISTS transactions (
|
|||||||
);
|
);
|
||||||
|
|
||||||
-- Seed initial data
|
-- Seed initial data
|
||||||
INSERT INTO site_settings (site_name) VALUES ('BitCrypto');
|
INSERT INTO site_settings (site_name, contact_email, deposit_address) VALUES ('BitCrypto', 'support@bitcrypto.com', 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t');
|
||||||
|
INSERT INTO admins (username, password) VALUES ('admin', '$2y$10$vK6.O/M57M.n5oYvT6pXve/tE6Yk.7Zg8XfVv0VzP2/k1e7Y6oM5e'); -- password: admin
|
||||||
INSERT INTO cryptocurrencies (symbol, name, icon_url, current_price, change_24h) VALUES
|
INSERT INTO cryptocurrencies (symbol, name, icon_url, current_price, change_24h) VALUES
|
||||||
('BTCUSDT', 'Bitcoin', 'https://cryptologos.cc/logos/bitcoin-btc-logo.png', 45000.00, 1.2),
|
('BTCUSDT', 'Bitcoin', 'https://cryptologos.cc/logos/bitcoin-btc-logo.png', 45000.00, 1.2),
|
||||||
('ETHUSDT', 'Ethereum', 'https://cryptologos.cc/logos/ethereum-eth-logo.png', 2500.00, -0.5),
|
('ETHUSDT', 'Ethereum', 'https://cryptologos.cc/logos/ethereum-eth-logo.png', 2500.00, -0.5),
|
||||||
('BNBUSDT', 'Binance Coin', 'https://cryptologos.cc/logos/binance-coin-bnb-logo.png', 300.00, 2.1);
|
('BNBUSDT', 'Binance Coin', 'https://cryptologos.cc/logos/binance-coin-bnb-logo.png', 300.00, 2.1),
|
||||||
|
('ADAUSDT', 'Cardano', 'https://cryptologos.cc/logos/cardano-ada-logo.png', 0.5, 3.5),
|
||||||
|
('SOLUSDT', 'Solana', 'https://cryptologos.cc/logos/solana-sol-logo.png', 100.0, 5.0),
|
||||||
|
('DOGEUSDT', 'Dogecoin', 'https://cryptologos.cc/logos/dogecoin-doge-logo.png', 0.08, -2.0);
|
||||||
|
|||||||
289
trade.php
289
trade.php
@ -10,60 +10,153 @@ $base_symbol = str_replace('USDT', '', $symbol);
|
|||||||
|
|
||||||
include 'header.php';
|
include 'header.php';
|
||||||
?>
|
?>
|
||||||
<div class="container-fluid px-2 py-2" style="background-color: #0b0e11; min-height: 90vh;">
|
<style>
|
||||||
<div class="row g-2">
|
.glass-card { background: rgba(30, 32, 38, 0.9); border: 1px solid #2b2f36; border-radius: 4px; overflow: hidden; }
|
||||||
<!-- Sidebar -->
|
.trade-nav-item { cursor: pointer; padding: 10px 15px; border-bottom: 2px solid transparent; color: #848e9c; }
|
||||||
<div class="col-lg-2 d-none d-lg-block">
|
.trade-nav-item.active { border-bottom-color: #f0b90b; color: #f0b90b; }
|
||||||
<div class="glass-card h-100 p-2 bg-dark">
|
.coin-row:hover { background: #2b2f36; cursor: pointer; }
|
||||||
<input type="text" id="coin-search" class="form-control form-control-sm bg-dark text-white border-secondary mb-2" placeholder="搜索币种">
|
.price-up { color: #0ecb81; }
|
||||||
<div id="left-coin-list"></div>
|
.price-down { color: #f6465d; }
|
||||||
|
#order-book table td { padding: 2px 8px; font-size: 12px; }
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="container-fluid px-1 py-1" style="background-color: #0b0e11; min-height: 95vh; color: #eaecef;">
|
||||||
|
<div class="row g-1">
|
||||||
|
<!-- Market List -->
|
||||||
|
<div class="col-lg-2">
|
||||||
|
<div class="glass-card h-100">
|
||||||
|
<div class="p-2 border-bottom border-secondary">
|
||||||
|
<input type="text" id="coin-search" class="form-control form-control-sm bg-dark text-white border-secondary" placeholder="搜索">
|
||||||
|
</div>
|
||||||
|
<div id="left-coin-list" style="max-height: 800px; overflow-y: auto;">
|
||||||
|
<!-- JS populated -->
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Main -->
|
<!-- Chart & Trade -->
|
||||||
<div class="col-lg-7">
|
<div class="col-lg-7">
|
||||||
<div class="glass-card mb-2 p-2 d-flex align-items-center justify-content-between bg-dark">
|
<!-- Ticker Header -->
|
||||||
<div class="d-flex align-items-center">
|
<div class="glass-card mb-1 p-2 d-flex align-items-center">
|
||||||
<span class="text-warning fw-bold fs-5 me-4"><?php echo $symbol; ?></span>
|
<div class="d-flex align-items-center me-4">
|
||||||
<div class="me-4">
|
<span class="fw-bold fs-5 text-white"><?php echo $symbol; ?></span>
|
||||||
<div class="fw-bold fs-5 text-success" id="header-price">--</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex gap-1 bg-dark p-1">
|
<div class="me-4">
|
||||||
<a href="?type=SPOT&symbol=<?php echo $symbol; ?>" class="btn btn-sm <?php echo $trade_type=='SPOT'?'btn-warning':'text-secondary'; ?>">现货</a>
|
<div class="fw-bold fs-5" id="header-price">--</div>
|
||||||
<a href="?type=CONTRACT&symbol=<?php echo $symbol; ?>" class="btn btn-sm <?php echo $trade_type=='CONTRACT'?'btn-warning':'text-secondary'; ?>">合约</a>
|
<div class="small" id="header-change">--</div>
|
||||||
|
</div>
|
||||||
|
<div class="ms-auto d-flex gap-1">
|
||||||
|
<a href="?type=SPOT&symbol=<?php echo $symbol; ?>" class="btn btn-sm <?php echo $trade_type=='SPOT'?'btn-warning':'btn-outline-secondary'; ?>">现货</a>
|
||||||
|
<a href="?type=CONTRACT&symbol=<?php echo $symbol; ?>" class="btn btn-sm <?php echo $trade_type=='CONTRACT'?'btn-warning':'btn-outline-secondary'; ?>">永续</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="glass-card mb-2" style="height: 400px;">
|
<!-- TradingView -->
|
||||||
|
<div class="glass-card mb-1" style="height: 450px;">
|
||||||
<div id="tradingview_widget" style="height: 100%;"></div>
|
<div id="tradingview_widget" style="height: 100%;"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Form -->
|
<!-- Trading Form -->
|
||||||
<div class="glass-card p-3 bg-dark">
|
<div class="glass-card p-3">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6 border-end border-secondary">
|
<div class="col-md-6 border-end border-secondary">
|
||||||
<h6 class="text-success mb-3">买入 / 做多</h6>
|
<div class="d-flex justify-content-between mb-3">
|
||||||
<input type="number" id="buy-amount" class="form-control bg-dark text-white border-secondary mb-3" placeholder="数量">
|
<span class="text-success fw-bold">买入 / 做多</span>
|
||||||
<div class="d-flex justify-content-between small text-secondary mb-3">
|
<span class="text-secondary small">可用: <span class="text-white" id="usdt-balance"><?php echo number_format($account['balance'], 2); ?></span> USDT</span>
|
||||||
<span>可用: <?php echo number_format($account['balance'], 2); ?> USDT</span>
|
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-success w-100" onclick="submitOrder('BUY')">买入</button>
|
|
||||||
|
<?php if ($trade_type === 'CONTRACT'): ?>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="small text-secondary">杠杆</label>
|
||||||
|
<select id="leverage" class="form-select form-select-sm bg-dark text-white border-secondary">
|
||||||
|
<option value="10">10x</option>
|
||||||
|
<option value="20" selected>20x</option>
|
||||||
|
<option value="50">50x</option>
|
||||||
|
<option value="100">100x</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="input-group input-group-sm mb-3">
|
||||||
|
<span class="input-group-text bg-dark text-secondary border-secondary">价格</span>
|
||||||
|
<input type="text" class="form-control bg-dark text-white border-secondary" value="市场价" disabled>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-group input-group-sm mb-3">
|
||||||
|
<span class="input-group-text bg-dark text-secondary border-secondary">数量</span>
|
||||||
|
<input type="number" id="buy-amount" class="form-control bg-dark text-white border-secondary">
|
||||||
|
<span class="input-group-text bg-dark text-secondary border-secondary"><?php echo $base_symbol; ?></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button class="btn btn-success w-100 fw-bold" onclick="submitOrder('BUY')">买入 (做多)</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h6 class="text-danger mb-3">卖出 / 做空</h6>
|
<div class="d-flex justify-content-between mb-3">
|
||||||
<input type="number" id="sell-amount" class="form-control bg-dark text-white border-secondary mb-3" placeholder="数量">
|
<span class="text-danger fw-bold">卖出 / 做空</span>
|
||||||
<button class="btn btn-danger w-100" onclick="submitOrder('SELL')">卖出</button>
|
</div>
|
||||||
|
|
||||||
|
<?php if ($trade_type === 'CONTRACT'): ?>
|
||||||
|
<div class="mb-3"><label class="small"> </label><div style="height:31px"></div></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="input-group input-group-sm mb-3">
|
||||||
|
<span class="input-group-text bg-dark text-secondary border-secondary">价格</span>
|
||||||
|
<input type="text" class="form-control bg-dark text-white border-secondary" value="市场价" disabled>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="input-group input-group-sm mb-3">
|
||||||
|
<span class="input-group-text bg-dark text-secondary border-secondary">数量</span>
|
||||||
|
<input type="number" id="sell-amount" class="form-control bg-dark text-white border-secondary">
|
||||||
|
<span class="input-group-text bg-dark text-secondary border-secondary"><?php echo $base_symbol; ?></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button class="btn btn-danger w-100 fw-bold" onclick="submitOrder('SELL')">卖出 (做空)</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Positions & History -->
|
||||||
|
<div class="glass-card mt-1 p-0">
|
||||||
|
<div class="d-flex border-bottom border-secondary bg-dark">
|
||||||
|
<div class="trade-nav-item active">当前仓位</div>
|
||||||
|
<div class="trade-nav-item">历史订单</div>
|
||||||
|
</div>
|
||||||
|
<div class="p-2" style="min-height: 200px;">
|
||||||
|
<table class="table table-dark table-hover small" id="position-table">
|
||||||
|
<thead>
|
||||||
|
<tr class="text-secondary">
|
||||||
|
<th>合约</th>
|
||||||
|
<th>方向</th>
|
||||||
|
<th>杠杆</th>
|
||||||
|
<th>数量</th>
|
||||||
|
<th>开仓价</th>
|
||||||
|
<th>当前价</th>
|
||||||
|
<th>未实现盈亏</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody></tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Order Book -->
|
<!-- Order Book -->
|
||||||
<div class="col-lg-3 d-none d-lg-block">
|
<div class="col-lg-3">
|
||||||
<div class="glass-card h-100 p-2 bg-dark">
|
<div class="glass-card h-100">
|
||||||
<h6 class="text-secondary small">订单簿</h6>
|
<div class="p-2 border-bottom border-secondary small fw-bold">订单簿</div>
|
||||||
<div id="order-book"></div>
|
<div id="order-book">
|
||||||
|
<table class="w-100">
|
||||||
|
<tbody id="asks-list"></tbody>
|
||||||
|
</table>
|
||||||
|
<div class="py-2 text-center border-top border-bottom border-secondary my-1">
|
||||||
|
<span id="book-price" class="fs-5 fw-bold text-success">--</span>
|
||||||
|
</div>
|
||||||
|
<table class="w-100">
|
||||||
|
<tbody id="bids-list"></tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -73,34 +166,124 @@ include 'header.php';
|
|||||||
<script>
|
<script>
|
||||||
const symbol = '<?php echo $symbol; ?>';
|
const symbol = '<?php echo $symbol; ?>';
|
||||||
const tradeType = '<?php echo $trade_type; ?>';
|
const tradeType = '<?php echo $trade_type; ?>';
|
||||||
|
let currentPrice = 0;
|
||||||
|
|
||||||
new TradingView.widget({
|
new TradingView.widget({
|
||||||
"width": "100%", "height": "100%", "symbol": "BINANCE:" + symbol,
|
"width": "100%", "height": "100%", "symbol": "BINANCE:" + symbol,
|
||||||
"interval": "15", "theme": "dark", "style": "1", "locale": "zh_CN",
|
"interval": "15", "timezone": "Etc/UTC", "theme": "dark", "style": "1",
|
||||||
"container_id": "tradingview_widget"
|
"locale": "zh_CN", "toolbar_bg": "#f1f3f6", "enable_publishing": false,
|
||||||
|
"hide_side_toolbar": false, "allow_symbol_change": true, "container_id": "tradingview_widget"
|
||||||
});
|
});
|
||||||
|
|
||||||
async function tick() {
|
async function updateMarket() {
|
||||||
const r = await fetch('api.php?action=market_data');
|
const r = await fetch('api.php?action=market_data');
|
||||||
const data = await r.json();
|
const coins = await r.json();
|
||||||
const coin = data.find(c => c.symbol === symbol);
|
|
||||||
if (coin) {
|
// Update Side List
|
||||||
document.getElementById('header-price').textContent = parseFloat(coin.price).toLocaleString();
|
let listHtml = '';
|
||||||
}
|
coins.forEach(c => {
|
||||||
}
|
const isTarget = c.symbol === symbol;
|
||||||
|
const changeClass = c.change >= 0 ? 'text-success' : 'text-danger';
|
||||||
async function submitOrder(side) {
|
listHtml += `
|
||||||
const amount = document.getElementById(side.toLowerCase() + '-amount').value;
|
<div class="coin-row p-2 d-flex justify-content-between align-items-center ${isTarget?'bg-dark':''}" onclick="location.href='?type=${tradeType}&symbol=${c.symbol}'">
|
||||||
const res = await fetch('api.php?action=submit_order', {
|
<div>
|
||||||
method: 'POST',
|
<div class="fw-bold">${c.symbol.replace('USDT','')}</div>
|
||||||
body: JSON.stringify({ symbol, side, trade_type: tradeType, amount })
|
<div class="text-secondary smaller" style="font-size:10px">Vol --</div>
|
||||||
|
</div>
|
||||||
|
<div class="text-end">
|
||||||
|
<div class="fw-bold ${changeClass}">${parseFloat(c.price).toFixed(c.price<1?4:2)}</div>
|
||||||
|
<div class="${changeClass}" style="font-size:10px">${c.change}%</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
if (isTarget) {
|
||||||
|
currentPrice = c.price;
|
||||||
|
document.getElementById('header-price').textContent = parseFloat(c.price).toLocaleString(undefined, {minimumFractionDigits: 2});
|
||||||
|
document.getElementById('header-price').className = 'fw-bold fs-5 ' + (c.change >= 0 ? 'text-success' : 'text-danger');
|
||||||
|
document.getElementById('header-change').textContent = (c.change >= 0 ? '+' : '') + c.change + '%';
|
||||||
|
document.getElementById('header-change').className = 'small ' + (c.change >= 0 ? 'text-success' : 'text-danger');
|
||||||
|
document.getElementById('book-price').textContent = parseFloat(c.price).toFixed(2);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const json = await res.json();
|
document.getElementById('left-coin-list').innerHTML = listHtml;
|
||||||
if (json.status === 'success') { alert('下单成功'); location.reload(); }
|
|
||||||
else { alert('失败: ' + json.message); }
|
// Mock Order Book
|
||||||
|
renderOrderBook(currentPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(tick, 2000);
|
function renderOrderBook(price) {
|
||||||
tick();
|
if (!price) return;
|
||||||
|
let asks = '', bids = '';
|
||||||
|
for(let i=5; i>0; i--) {
|
||||||
|
asks += `<tr><td class="text-danger">${(price * (1 + i*0.0002)).toFixed(2)}</td><td class="text-end text-secondary">${(Math.random()*2).toFixed(3)}</td></tr>`;
|
||||||
|
bids += `<tr><td class="text-success">${(price * (1 - i*0.0002)).toFixed(2)}</td><td class="text-end text-secondary">${(Math.random()*2).toFixed(3)}</td></tr>`;
|
||||||
|
}
|
||||||
|
document.getElementById('asks-list').innerHTML = asks;
|
||||||
|
document.getElementById('bids-list').innerHTML = bids;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updatePositions() {
|
||||||
|
if (tradeType !== 'CONTRACT') {
|
||||||
|
document.getElementById('position-table').parentElement.innerHTML = '<div class="text-center text-secondary py-5">现货交易暂不显示当前持仓</div>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const r = await fetch('api.php?action=positions');
|
||||||
|
const pos = await r.json();
|
||||||
|
let html = '';
|
||||||
|
pos.forEach(p => {
|
||||||
|
const pnlClass = p.pnl >= 0 ? 'text-success' : 'text-danger';
|
||||||
|
html += `
|
||||||
|
<tr>
|
||||||
|
<td class="fw-bold">${p.symbol}</td>
|
||||||
|
<td><span class="badge ${p.side==='LONG'?'bg-success':'bg-danger'}">${p.side}</span></td>
|
||||||
|
<td>${p.leverage}x</td>
|
||||||
|
<td>${p.lots}</td>
|
||||||
|
<td>${p.entry_price}</td>
|
||||||
|
<td>${p.current_price}</td>
|
||||||
|
<td class="${pnlClass} fw-bold">${parseFloat(p.pnl).toFixed(2)} USDT</td>
|
||||||
|
<td><button class="btn btn-sm btn-outline-warning py-0" onclick="closePosition(${p.id})">平仓</button></td>
|
||||||
|
</tr>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
document.querySelector('#position-table tbody').innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function closePosition(id) {
|
||||||
|
if (!confirm('确定要平掉该仓位吗?')) return;
|
||||||
|
const res = await fetch('api.php?action=close_position', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ id })
|
||||||
|
});
|
||||||
|
const json = await res.json();
|
||||||
|
alert(json.message);
|
||||||
|
updatePositions();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitOrder(side) {
|
||||||
|
const amount = document.getElementById(side.toLowerCase() + '-amount').value;
|
||||||
|
const leverageSelect = document.getElementById('leverage');
|
||||||
|
const leverage = leverageSelect ? leverageSelect.value : 1;
|
||||||
|
|
||||||
|
if (!amount) { alert('请输入数量'); return; }
|
||||||
|
|
||||||
|
const res = await fetch('api.php?action=submit_order', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ symbol, side, trade_type: tradeType, amount, leverage })
|
||||||
|
});
|
||||||
|
const json = await res.json();
|
||||||
|
if (json.status === 'success') {
|
||||||
|
alert('下单成功');
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
alert('错误: ' + json.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(updateMarket, 2000);
|
||||||
|
setInterval(updatePositions, 3000);
|
||||||
|
updateMarket();
|
||||||
|
updatePositions();
|
||||||
</script>
|
</script>
|
||||||
<?php include 'footer.php'; ?>
|
<?php include 'footer.php'; ?>
|
||||||
70
withdraw.php
Normal file
70
withdraw.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
include_once 'config.php';
|
||||||
|
check_auth();
|
||||||
|
$account = get_account($_SESSION['user_id']);
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$amount = (float)($_POST['amount'] ?? 0);
|
||||||
|
$address = $_POST['address'] ?? '';
|
||||||
|
|
||||||
|
if ($amount >= 10 && $address) {
|
||||||
|
if ($account['balance'] >= $amount) {
|
||||||
|
try {
|
||||||
|
$db = db();
|
||||||
|
$db->beginTransaction();
|
||||||
|
|
||||||
|
// Deduct balance and freeze it
|
||||||
|
$stmt = $db->prepare("UPDATE accounts SET balance = balance - ?, frozen_balance = frozen_balance + ? WHERE id = ?");
|
||||||
|
$stmt->execute([$amount, $amount, $account['id']]);
|
||||||
|
|
||||||
|
// Record transaction
|
||||||
|
$stmt = $db->prepare("INSERT INTO transactions (account_id, transaction_type, amount, tx_hash, status) VALUES (?, 'withdraw', ?, ?, 'pending')");
|
||||||
|
$stmt->execute([$account['id'], $amount, $address]);
|
||||||
|
|
||||||
|
$db->commit();
|
||||||
|
$success = "提现申请已提交,资金已冻结,请等待审核。";
|
||||||
|
$account = get_account($_SESSION['user_id']); // refresh
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$db->rollBack();
|
||||||
|
$error = "系统错误: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$error = "余额不足。";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$error = "请输入有效金额(最小10)和地址。";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
include 'header.php';
|
||||||
|
?>
|
||||||
|
<div class="container py-5">
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<div class="glass-card p-4 bg-dark">
|
||||||
|
<h4 class="text-white mb-4"><i class="bi bi-box-arrow-up text-warning me-2"></i> 提现 USDT</h4>
|
||||||
|
|
||||||
|
<?php if(isset($success)): ?><div class="alert alert-success"><?php echo $success; ?></div><?php endif; ?>
|
||||||
|
<?php if(isset($error)): ?><div class="alert alert-danger"><?php echo $error; ?></div><?php endif; ?>
|
||||||
|
|
||||||
|
<div class="mb-4 d-flex justify-content-between">
|
||||||
|
<span class="text-secondary">可用余额:</span>
|
||||||
|
<span class="text-white fw-bold"><?php echo number_format($account['balance'], 2); ?> USDT</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label text-secondary">提现金额</label>
|
||||||
|
<input type="number" name="amount" step="0.01" class="form-control bg-dark text-white border-secondary" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label text-secondary">收币地址 (TRC20)</label>
|
||||||
|
<input type="text" name="address" class="form-control bg-dark text-white border-secondary" placeholder="T..." required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-warning w-100 fw-bold py-2 mt-3">申请提现</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php include 'footer.php'; ?>
|
||||||
Loading…
x
Reference in New Issue
Block a user