Autosave: 20260207-055352
This commit is contained in:
parent
eb60696dd9
commit
0d9e8b5e50
91
api.php
Normal file
91
api.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
include_once 'config.php';
|
||||
|
||||
$action = $_GET['action'] ?? '';
|
||||
|
||||
if ($action === 'market_data') {
|
||||
// In a real app, this would fetch from Binance or a cache.
|
||||
// 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");
|
||||
$coins = $stmt->fetchAll();
|
||||
|
||||
foreach ($coins as &$coin) {
|
||||
// Simple mock: fluctuate price slightly
|
||||
$variation = (mt_rand(-100, 100) / 10000); // +/- 1%
|
||||
$coin['price'] = (float)$coin['current_price'] * (1 + $variation);
|
||||
$coin['change'] = (float)$coin['change_24h'];
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($coins);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($action === 'submit_order') {
|
||||
check_auth();
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (!$data) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Invalid data']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$account = get_account($user_id);
|
||||
|
||||
$symbol = $data['symbol'] ?? 'BTCUSDT';
|
||||
$side = $data['side'] ?? 'BUY';
|
||||
$trade_type = $data['trade_type'] ?? 'SPOT';
|
||||
$order_type = $data['order_type'] ?? 'LIMIT';
|
||||
$price = $data['price'] ?? null;
|
||||
$amount = (float)($data['amount'] ?? 0);
|
||||
$leverage = (int)($data['leverage'] ?? 1);
|
||||
|
||||
// Basic validation
|
||||
if ($amount <= 0) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Invalid amount']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Logic for SPOT / CONTRACT balance checks
|
||||
// This is a simplified version
|
||||
$total_cost = 0;
|
||||
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();
|
||||
|
||||
// Deduct balance
|
||||
$stmt = $db->prepare("UPDATE accounts SET balance = balance - ? WHERE id = ?");
|
||||
$stmt->execute([$total_cost, $account['id']]);
|
||||
|
||||
// Insert order
|
||||
$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]);
|
||||
|
||||
$db->commit();
|
||||
echo json_encode(['status' => 'success']);
|
||||
} catch (Exception $e) {
|
||||
$db->rollBack();
|
||||
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
28
config.php
Normal file
28
config.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
// PHP Core Config
|
||||
session_start();
|
||||
|
||||
// Include the existing database configuration
|
||||
require_once __DIR__ . '/db/config.php';
|
||||
|
||||
// Helper: Check if user is logged in
|
||||
function check_auth() {
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper: Get user account
|
||||
function get_account($user_id) {
|
||||
$stmt = db()->prepare("SELECT * FROM accounts WHERE user_id = ?");
|
||||
$stmt->execute([$user_id]);
|
||||
return $stmt->fetch();
|
||||
}
|
||||
|
||||
// Helper: Get site settings
|
||||
function get_site_settings() {
|
||||
$stmt = db()->query("SELECT * FROM site_settings LIMIT 1");
|
||||
return $stmt->fetch();
|
||||
}
|
||||
?>
|
||||
44
footer.php
Normal file
44
footer.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
$settings = get_site_settings();
|
||||
$project_name = $settings['site_name'] ?? 'BitCrypto';
|
||||
?>
|
||||
</main>
|
||||
|
||||
<?php if (!empty($settings['customer_service_url'])): ?>
|
||||
<a href="<?php echo $settings['customer_service_url']; ?>" target="_blank" class="cs-float" title="在线客服">
|
||||
<i class="bi bi-headset"></i>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<footer class="footer py-5 mt-5 border-top border-secondary bg-dark">
|
||||
<div class="container">
|
||||
<div class="row g-4">
|
||||
<div class="col-md-3">
|
||||
<h5 class="fw-bold mb-4 text-white"><?php echo $project_name; ?></h5>
|
||||
<p class="text-secondary small">全球领先的数字资产交易平台,致力于为用户提供安全、专业、透明的数字资产一站式服务。</p>
|
||||
</div>
|
||||
<div class="col-md-2 offset-md-1">
|
||||
<h6 class="text-white mb-3">产品服务</h6>
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="/trade.php?type=SPOT" class="text-secondary text-decoration-none small">现货交易</a></li>
|
||||
<li><a href="/trade.php?type=CONTRACT" class="text-secondary text-decoration-none small">永续合约</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<hr class="my-5 border-secondary">
|
||||
<div class="row align-items-center">
|
||||
<div class="col-md-6 text-center text-md-start">
|
||||
<p class="text-secondary small mb-0">© 2026 <?php echo $project_name; ?> Digital Asset Exchange. All rights reserved.</p>
|
||||
</div>
|
||||
<div class="col-md-6 text-center text-md-end mt-3 mt-md-0">
|
||||
<div class="text-secondary small">
|
||||
<i class="bi bi-globe me-2"></i> 简体中文 | USDT
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
122
header.php
Normal file
122
header.php
Normal file
@ -0,0 +1,122 @@
|
||||
<?php include_once 'config.php';
|
||||
$settings = get_site_settings();
|
||||
$project_name = $settings['site_name'] ?? 'BitCrypto';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-hans">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?php echo $project_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.11.1/font/bootstrap-icons.css">
|
||||
<link rel="stylesheet" href="/static/css/custom.css">
|
||||
<style>
|
||||
:root {
|
||||
--bg-dark: #0b0e11;
|
||||
--bg-card: #181a20;
|
||||
--text-primary: #eaecef;
|
||||
--text-secondary: #848e9c;
|
||||
--accent-color: #fcd535;
|
||||
--up-color: #0ecb81;
|
||||
--down-color: #f6465d;
|
||||
}
|
||||
body {
|
||||
background-color: var(--bg-dark);
|
||||
color: var(--text-primary);
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.navbar {
|
||||
background-color: var(--bg-dark);
|
||||
border-bottom: 1px solid #2b2f36;
|
||||
padding: 0.75rem 1.5rem;
|
||||
}
|
||||
.nav-link {
|
||||
color: var(--text-primary) !important;
|
||||
font-weight: 500;
|
||||
font-size: 14px;
|
||||
margin: 0 8px;
|
||||
transition: color 0.2s;
|
||||
}
|
||||
.nav-link:hover { color: var(--accent-color) !important; }
|
||||
.btn-primary {
|
||||
background-color: var(--accent-color);
|
||||
border-color: var(--accent-color);
|
||||
color: #181a20;
|
||||
font-weight: 600;
|
||||
padding: 8px 20px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.glass-card {
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
backdrop-filter: blur(10px);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
border-radius: 12px;
|
||||
}
|
||||
.cs-float {
|
||||
position: fixed;
|
||||
right: 30px;
|
||||
bottom: 40px;
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
background: var(--accent-color);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #181a20;
|
||||
font-size: 28px;
|
||||
box-shadow: 0 4px 20px rgba(252, 213, 53, 0.4);
|
||||
cursor: pointer;
|
||||
z-index: 9999;
|
||||
transition: all 0.3s;
|
||||
text-decoration: none;
|
||||
}
|
||||
.cs-float:hover {
|
||||
transform: scale(1.1) rotate(5deg);
|
||||
color: #181a20;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg sticky-top">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand d-flex align-items-center" href="/">
|
||||
<img src="/static/images/logo.png" alt="Logo" style="height: 28px; margin-right: 8px;">
|
||||
<span class="fw-bold fs-5 text-white"><?php echo $project_name; ?></span>
|
||||
</a>
|
||||
<button class="navbar-toggler border-secondary" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
||||
<i class="bi bi-list text-white"></i>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item"><a class="nav-link" href="/">首页</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="/trade.php?type=SPOT">现货交易</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="/trade.php?type=CONTRACT">合约交易</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="/market.php">行情中心</a></li>
|
||||
</ul>
|
||||
<div class="d-flex align-items-center">
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<div class="dropdown">
|
||||
<a class="nav-link dropdown-toggle d-flex align-items-center" href="#" role="button" data-bs-toggle="dropdown">
|
||||
<i class="bi bi-person-circle fs-5 me-2"></i>
|
||||
<span><?php echo $_SESSION['username']; ?></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-menu-dark dropdown-menu-end shadow">
|
||||
<li><a class="dropdown-item" href="/profile.php"><i class="bi bi-person-badge me-2"></i>个人中心</a></li>
|
||||
<li><a class="dropdown-item" href="/profile.php"><i class="bi bi-wallet2 me-2"></i>我的资产</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item text-danger" href="/logout.php"><i class="bi bi-box-arrow-right me-2"></i>安全退出</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<a href="/login.php" class="nav-link me-3">登录</a>
|
||||
<a href="/register.php" class="btn btn-primary">立即注册</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<main>
|
||||
99
index.php
Normal file
99
index.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
include_once 'config.php';
|
||||
include 'header.php';
|
||||
?>
|
||||
<!-- Hero Carousel Section -->
|
||||
<div id="heroCarousel" class="carousel slide" data-bs-ride="carousel">
|
||||
<div class="carousel-indicators">
|
||||
<button type="button" data-bs-target="#heroCarousel" data-bs-slide-to="0" class="active"></button>
|
||||
<button type="button" data-bs-target="#heroCarousel" data-bs-slide-to="1"></button>
|
||||
<button type="button" data-bs-target="#heroCarousel" data-bs-slide-to="2"></button>
|
||||
</div>
|
||||
<div class="carousel-inner">
|
||||
<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="container h-100 d-flex align-items-center">
|
||||
<div class="row w-100 align-items-center">
|
||||
<div class="col-lg-7">
|
||||
<h1 class="display-3 fw-bold mb-4">开启您的<br><span style="color: var(--accent-color);">加密货币</span>之旅</h1>
|
||||
<p class="lead text-light mb-5">在全球最受信任的交易平台买卖和存储加密货币。<?php echo $project_name; ?> 为您提供安全、稳定、高效的服务。</p>
|
||||
<div class="d-flex gap-3">
|
||||
<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>
|
||||
|
||||
<!-- Quick Actions -->
|
||||
<div class="container" style="margin-top: -50px; position: relative; z-index: 10;">
|
||||
<div class="glass-card p-4 d-flex flex-wrap justify-content-around align-items-center text-center shadow-lg">
|
||||
<div class="download-item">
|
||||
<h6 class="text-secondary mb-2 small fw-bold">iOS 下载</h6>
|
||||
<button class="btn btn-outline-light border-secondary px-4"><i class="bi bi-apple me-2 text-warning"></i>App Store</button>
|
||||
</div>
|
||||
<div class="download-item">
|
||||
<h6 class="text-secondary mb-2 small fw-bold">安卓下载</h6>
|
||||
<button class="btn btn-outline-light border-secondary px-4"><i class="bi bi-android2 me-2 text-warning"></i>Android</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Market Section -->
|
||||
<section id="markets" class="container py-5 mt-4">
|
||||
<div class="d-flex justify-content-between align-items-end mb-4">
|
||||
<div>
|
||||
<h2 class="fw-bold">热门行情</h2>
|
||||
<p class="text-secondary mb-0">实时获取全球顶级加密货币价格走势</p>
|
||||
</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>
|
||||
|
||||
<script>
|
||||
const symbols = ['BTCUSDT', 'ETHUSDT', 'BNBUSDT', 'SOLUSDT', 'XRPUSDT'];
|
||||
async function fetchMarkets() {
|
||||
try {
|
||||
const response = await fetch('https://api.binance.com/api/v3/ticker/24hr?symbols=' + JSON.stringify(symbols));
|
||||
const data = await response.json();
|
||||
const list = document.getElementById('market-list');
|
||||
list.innerHTML = '';
|
||||
data.forEach(coin => {
|
||||
const symbolBase = coin.symbol.replace('USDT', '');
|
||||
const change = parseFloat(coin.priceChangePercent);
|
||||
list.innerHTML += `
|
||||
<tr>
|
||||
<td class="ps-4 py-3"><span class="fw-bold text-white">${symbolBase}</span>/USDT</td>
|
||||
<td class="fw-bold py-3 text-white">$${parseFloat(coin.lastPrice).toLocaleString()}</td>
|
||||
<td class="${change >= 0 ? 'text-success' : 'text-danger'} py-3 fw-bold">${change.toFixed(2)}%</td>
|
||||
<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>
|
||||
</tr>
|
||||
`;
|
||||
});
|
||||
} catch (e) { console.error(e); }
|
||||
}
|
||||
fetchMarkets();
|
||||
setInterval(fetchMarkets, 5000);
|
||||
</script>
|
||||
<?php include 'footer.php'; ?>
|
||||
101
login.php
Normal file
101
login.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
include_once 'config.php';
|
||||
|
||||
$error = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$username = $_POST['username'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
if ($username && $password) {
|
||||
$stmt = db()->prepare("SELECT * FROM users WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['username'] = $user['username'];
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
} else {
|
||||
$error = '用户名或密码错误';
|
||||
}
|
||||
} else {
|
||||
$error = '请填写所有字段';
|
||||
}
|
||||
}
|
||||
|
||||
include 'header.php';
|
||||
?>
|
||||
<div class="auth-container d-flex align-items-center justify-content-center" style="min-height: 90vh; background: radial-gradient(circle at top right, #1e2329 0%, #0b0e11 100%);">
|
||||
<div class="auth-card glass-card p-5" style="width: 100%; max-width: 450px; border-radius: 16px;">
|
||||
<div class="text-center mb-5">
|
||||
<div class="logo-circle mb-4 mx-auto">
|
||||
<i class="bi bi-hexagon-fill text-warning display-4"></i>
|
||||
</div>
|
||||
<h2 class="fw-bold text-white">欢迎登录 <?php echo $project_name; ?></h2>
|
||||
<p class="text-secondary">全球领先的加密资产交易平台</p>
|
||||
</div>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-danger"><?php echo $error; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post">
|
||||
<div class="mb-4">
|
||||
<label class="form-label text-secondary small fw-bold">用户名</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-transparent border-secondary text-secondary">
|
||||
<i class="bi bi-person"></i>
|
||||
</span>
|
||||
<input type="text" name="username" class="form-control bg-transparent text-white border-secondary" placeholder="请输入用户名" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="form-label text-secondary small fw-bold">密码</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text bg-transparent border-secondary text-secondary">
|
||||
<i class="bi bi-lock"></i>
|
||||
</span>
|
||||
<input type="password" name="password" class="form-control bg-transparent text-white border-secondary" placeholder="请输入密码" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-warning w-100 py-3 fw-bold shadow-lg mb-4">登录</button>
|
||||
</form>
|
||||
|
||||
<div class="text-center">
|
||||
<p class="text-secondary small">还没有账户? <a href="/register.php" class="text-warning text-decoration-none fw-bold">立即注册</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.auth-card {
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
backdrop-filter: blur(20px);
|
||||
}
|
||||
.input-group-text {
|
||||
border-right: none;
|
||||
}
|
||||
input.form-control {
|
||||
border-left: none;
|
||||
padding: 12px;
|
||||
}
|
||||
input.form-control:focus {
|
||||
background: rgba(255, 255, 255, 0.05) !important;
|
||||
box-shadow: none;
|
||||
border-color: var(--accent-color);
|
||||
}
|
||||
.logo-circle {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background: rgba(240, 185, 11, 0.1);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
<?php include 'footer.php'; ?>
|
||||
6
logout.php
Normal file
6
logout.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_destroy();
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
?>
|
||||
69
profile.php
Normal file
69
profile.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
include_once 'config.php';
|
||||
check_auth();
|
||||
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$account = get_account($user_id);
|
||||
|
||||
include 'header.php';
|
||||
?>
|
||||
<div class="container py-5">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="glass-card p-4 bg-dark">
|
||||
<div class="text-center mb-4">
|
||||
<i class="bi bi-person-circle display-1 text-warning"></i>
|
||||
<h4 class="mt-3 text-white"><?php echo $_SESSION['username']; ?></h4>
|
||||
<span class="badge bg-warning text-dark">UID: <?php echo $account['uid']; ?></span>
|
||||
</div>
|
||||
<hr class="border-secondary">
|
||||
<div class="d-flex justify-content-between mb-2">
|
||||
<span class="text-secondary">信用分</span>
|
||||
<span class="text-white"><?php echo $account['credit_score']; ?></span>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between mb-2">
|
||||
<span class="text-secondary">实名状态</span>
|
||||
<span class="text-white"><?php echo $account['kyc_status']; ?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="glass-card p-4 bg-dark mb-4">
|
||||
<h5 class="text-white mb-4">资产概览</h5>
|
||||
<div class="row text-center">
|
||||
<div class="col-6">
|
||||
<div class="text-secondary small">可用余额 (USDT)</div>
|
||||
<div class="fs-3 fw-bold text-success"><?php echo number_format($account['balance'], 2); ?></div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="text-secondary small">冻结金额 (USDT)</div>
|
||||
<div class="fs-3 fw-bold text-danger"><?php echo number_format($account['frozen_balance'], 2); ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="glass-card p-4 bg-dark">
|
||||
<h5 class="text-white mb-4">最近交易</h5>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-dark table-hover small">
|
||||
<thead>
|
||||
<tr class="text-secondary">
|
||||
<th>时间</th>
|
||||
<th>币种</th>
|
||||
<th>类型</th>
|
||||
<th>金额</th>
|
||||
<th>状态</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="5" class="text-center text-secondary py-4">暂无记录</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include 'footer.php'; ?>
|
||||
88
register.php
Normal file
88
register.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
include_once 'config.php';
|
||||
|
||||
$error = '';
|
||||
$success = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$username = $_POST['username'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
$confirm_password = $_POST['confirm_password'] ?? '';
|
||||
|
||||
if ($username && $password && $confirm_password) {
|
||||
if ($password !== $confirm_password) {
|
||||
$error = '两次输入的密码不一致';
|
||||
} else {
|
||||
$db = db();
|
||||
$stmt = $db->prepare("SELECT id FROM users WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
if ($stmt->fetch()) {
|
||||
$error = '用户名已存在';
|
||||
} else {
|
||||
try {
|
||||
$db->beginTransaction();
|
||||
|
||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$stmt = $db->prepare("INSERT INTO users (username, password) VALUES (?, ?)");
|
||||
$stmt->execute([$username, $hashed_password]);
|
||||
$user_id = $db->lastInsertId();
|
||||
|
||||
$uid = str_pad(mt_rand(0, 999999), 6, '0', STR_PAD_LEFT);
|
||||
$stmt = $db->prepare("INSERT INTO accounts (user_id, uid, balance) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$user_id, $uid, 10000.00]); // Default 10000 USDT for simulated
|
||||
|
||||
$db->commit();
|
||||
$success = '注册成功!正在跳转到登录页...';
|
||||
header("Refresh: 2; URL=login.php");
|
||||
} catch (Exception $e) {
|
||||
$db->rollBack();
|
||||
$error = '注册失败: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error = '请填写所有字段';
|
||||
}
|
||||
}
|
||||
|
||||
include 'header.php';
|
||||
?>
|
||||
<div class="auth-container d-flex align-items-center justify-content-center" style="min-height: 90vh; background: radial-gradient(circle at top right, #1e2329 0%, #0b0e11 100%);">
|
||||
<div class="auth-card glass-card p-5" style="width: 100%; max-width: 450px; border-radius: 16px;">
|
||||
<div class="text-center mb-5">
|
||||
<h2 class="fw-bold text-white">创建账户</h2>
|
||||
<p class="text-secondary">加入全球领先的交易社区</p>
|
||||
</div>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-danger"><?php echo $error; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($success): ?>
|
||||
<div class="alert alert-success"><?php echo $success; ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="post">
|
||||
<div class="mb-4">
|
||||
<label class="form-label text-secondary small fw-bold">用户名</label>
|
||||
<input type="text" name="username" class="form-control bg-transparent text-white border-secondary" placeholder="请输入用户名" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="form-label text-secondary small fw-bold">密码</label>
|
||||
<input type="password" name="password" class="form-control bg-transparent text-white border-secondary" placeholder="请输入密码" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-4">
|
||||
<label class="form-label text-secondary small fw-bold">确认密码</label>
|
||||
<input type="password" name="confirm_password" class="form-control bg-transparent text-white border-secondary" placeholder="请再次输入密码" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-warning w-100 py-3 fw-bold shadow-lg mb-4">立即注册</button>
|
||||
</form>
|
||||
|
||||
<div class="text-center">
|
||||
<p class="text-secondary small">已有账户? <a href="/login.php" class="text-warning text-decoration-none fw-bold">立即登录</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php include 'footer.php'; ?>
|
||||
@ -1,3 +1,30 @@
|
||||
asgiref==3.10.0
|
||||
certifi==2022.9.24
|
||||
chardet==5.1.0
|
||||
charset-normalizer==3.0.1
|
||||
dbus-python==1.3.2
|
||||
distro-info==1.5+deb12u1
|
||||
Django==5.2.7
|
||||
httplib2==0.20.4
|
||||
idna==3.3
|
||||
markdown-it-py==2.1.0
|
||||
mdurl==0.1.2
|
||||
mysqlclient==2.2.7
|
||||
netifaces==0.11.0
|
||||
pycurl==7.45.2
|
||||
Pygments==2.14.0
|
||||
PyGObject==3.42.2
|
||||
pyparsing==3.0.9
|
||||
PySimpleSOAP==1.16.2
|
||||
python-apt==2.6.0
|
||||
python-debian==0.1.49
|
||||
python-debianbts==4.0.1
|
||||
python-dotenv==1.1.1
|
||||
PyYAML==6.0
|
||||
reportbug==12.0.0
|
||||
requests==2.28.1
|
||||
rich==13.3.1
|
||||
six==1.16.0
|
||||
sqlparse==0.5.3
|
||||
unattended-upgrades==0.1
|
||||
urllib3==1.26.12
|
||||
|
||||
101
schema.sql
Normal file
101
schema.sql
Normal file
@ -0,0 +1,101 @@
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(150) UNIQUE NOT NULL,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
email VARCHAR(255),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS accounts (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
uid VARCHAR(6) UNIQUE NOT NULL,
|
||||
account_type ENUM('SIMULATED', 'REAL') DEFAULT 'SIMULATED',
|
||||
balance DECIMAL(30, 8) DEFAULT 0,
|
||||
frozen_balance DECIMAL(30, 8) DEFAULT 0,
|
||||
credit_score INT DEFAULT 80,
|
||||
kyc_status ENUM('UNVERIFIED', 'PENDING', 'VERIFIED', 'REJECTED') DEFAULT 'UNVERIFIED',
|
||||
win_loss_control INT DEFAULT 0,
|
||||
language VARCHAR(10) DEFAULT 'zh-hans',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS site_settings (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
site_name VARCHAR(100) DEFAULT 'BitCrypto',
|
||||
customer_service_url TEXT,
|
||||
terms_content TEXT,
|
||||
privacy_content TEXT,
|
||||
is_pinning_active BOOLEAN DEFAULT FALSE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS cryptocurrencies (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
symbol VARCHAR(20) UNIQUE NOT NULL,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
icon_url TEXT,
|
||||
current_price DECIMAL(30, 8) DEFAULT 0,
|
||||
manual_price DECIMAL(30, 8),
|
||||
change_24h DECIMAL(10, 2) DEFAULT 0,
|
||||
is_active BOOLEAN DEFAULT TRUE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS assets (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
account_id INT NOT NULL,
|
||||
currency VARCHAR(10) NOT NULL,
|
||||
balance DECIMAL(30, 8) DEFAULT 0,
|
||||
frozen DECIMAL(30, 8) DEFAULT 0,
|
||||
UNIQUE KEY account_currency (account_id, currency),
|
||||
FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS orders (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
account_id INT NOT NULL,
|
||||
symbol VARCHAR(20) DEFAULT 'BTC-USDT',
|
||||
trade_type ENUM('SPOT', 'CONTRACT') DEFAULT 'SPOT',
|
||||
side ENUM('BUY', 'SELL') NOT NULL,
|
||||
order_type ENUM('LIMIT', 'MARKET') NOT NULL,
|
||||
price DECIMAL(30, 8),
|
||||
amount DECIMAL(30, 8) NOT NULL,
|
||||
total_usdt DECIMAL(30, 8),
|
||||
leverage INT DEFAULT 1,
|
||||
status ENUM('PENDING', 'PARTIALLY_FILLED', 'FILLED', 'CANCELED') DEFAULT 'PENDING',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS positions (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
account_id INT NOT NULL,
|
||||
symbol VARCHAR(20) NOT NULL,
|
||||
side ENUM('LONG', 'SHORT') NOT NULL,
|
||||
leverage INT DEFAULT 20,
|
||||
entry_price DECIMAL(30, 8) NOT NULL,
|
||||
lots DECIMAL(30, 8) NOT NULL,
|
||||
margin DECIMAL(30, 8) NOT NULL,
|
||||
is_active BOOLEAN DEFAULT TRUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS transactions (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
account_id INT NOT NULL,
|
||||
transaction_type ENUM('deposit', 'withdraw') NOT NULL,
|
||||
currency VARCHAR(10) DEFAULT 'USDT',
|
||||
amount DECIMAL(30, 8) DEFAULT 0,
|
||||
tx_hash VARCHAR(255),
|
||||
status ENUM('pending', 'completed', 'failed') DEFAULT 'pending',
|
||||
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- Seed initial data
|
||||
INSERT INTO site_settings (site_name) VALUES ('BitCrypto');
|
||||
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),
|
||||
('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);
|
||||
106
trade.php
Normal file
106
trade.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
include_once 'config.php';
|
||||
check_auth();
|
||||
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$account = get_account($user_id);
|
||||
$symbol = $_GET['symbol'] ?? 'BTCUSDT';
|
||||
$trade_type = $_GET['type'] ?? 'SPOT';
|
||||
$base_symbol = str_replace('USDT', '', $symbol);
|
||||
|
||||
include 'header.php';
|
||||
?>
|
||||
<div class="container-fluid px-2 py-2" style="background-color: #0b0e11; min-height: 90vh;">
|
||||
<div class="row g-2">
|
||||
<!-- Sidebar -->
|
||||
<div class="col-lg-2 d-none d-lg-block">
|
||||
<div class="glass-card h-100 p-2 bg-dark">
|
||||
<input type="text" id="coin-search" class="form-control form-control-sm bg-dark text-white border-secondary mb-2" placeholder="搜索币种">
|
||||
<div id="left-coin-list"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main -->
|
||||
<div class="col-lg-7">
|
||||
<div class="glass-card mb-2 p-2 d-flex align-items-center justify-content-between bg-dark">
|
||||
<div class="d-flex align-items-center">
|
||||
<span class="text-warning fw-bold fs-5 me-4"><?php echo $symbol; ?></span>
|
||||
<div class="me-4">
|
||||
<div class="fw-bold fs-5 text-success" id="header-price">--</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex gap-1 bg-dark p-1">
|
||||
<a href="?type=SPOT&symbol=<?php echo $symbol; ?>" class="btn btn-sm <?php echo $trade_type=='SPOT'?'btn-warning':'text-secondary'; ?>">现货</a>
|
||||
<a href="?type=CONTRACT&symbol=<?php echo $symbol; ?>" class="btn btn-sm <?php echo $trade_type=='CONTRACT'?'btn-warning':'text-secondary'; ?>">合约</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="glass-card mb-2" style="height: 400px;">
|
||||
<div id="tradingview_widget" style="height: 100%;"></div>
|
||||
</div>
|
||||
|
||||
<!-- Form -->
|
||||
<div class="glass-card p-3 bg-dark">
|
||||
<div class="row">
|
||||
<div class="col-md-6 border-end border-secondary">
|
||||
<h6 class="text-success mb-3">买入 / 做多</h6>
|
||||
<input type="number" id="buy-amount" class="form-control bg-dark text-white border-secondary mb-3" placeholder="数量">
|
||||
<div class="d-flex justify-content-between small text-secondary mb-3">
|
||||
<span>可用: <?php echo number_format($account['balance'], 2); ?> USDT</span>
|
||||
</div>
|
||||
<button class="btn btn-success w-100" onclick="submitOrder('BUY')">买入</button>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<h6 class="text-danger mb-3">卖出 / 做空</h6>
|
||||
<input type="number" id="sell-amount" class="form-control bg-dark text-white border-secondary mb-3" placeholder="数量">
|
||||
<button class="btn btn-danger w-100" onclick="submitOrder('SELL')">卖出</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Order Book -->
|
||||
<div class="col-lg-3 d-none d-lg-block">
|
||||
<div class="glass-card h-100 p-2 bg-dark">
|
||||
<h6 class="text-secondary small">订单簿</h6>
|
||||
<div id="order-book"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
|
||||
<script>
|
||||
const symbol = '<?php echo $symbol; ?>';
|
||||
const tradeType = '<?php echo $trade_type; ?>';
|
||||
|
||||
new TradingView.widget({
|
||||
"width": "100%", "height": "100%", "symbol": "BINANCE:" + symbol,
|
||||
"interval": "15", "theme": "dark", "style": "1", "locale": "zh_CN",
|
||||
"container_id": "tradingview_widget"
|
||||
});
|
||||
|
||||
async function tick() {
|
||||
const r = await fetch('api.php?action=market_data');
|
||||
const data = await r.json();
|
||||
const coin = data.find(c => c.symbol === symbol);
|
||||
if (coin) {
|
||||
document.getElementById('header-price').textContent = parseFloat(coin.price).toLocaleString();
|
||||
}
|
||||
}
|
||||
|
||||
async function submitOrder(side) {
|
||||
const amount = document.getElementById(side.toLowerCase() + '-amount').value;
|
||||
const res = await fetch('api.php?action=submit_order', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ symbol, side, trade_type: tradeType, amount })
|
||||
});
|
||||
const json = await res.json();
|
||||
if (json.status === 'success') { alert('下单成功'); location.reload(); }
|
||||
else { alert('失败: ' + json.message); }
|
||||
}
|
||||
|
||||
setInterval(tick, 2000);
|
||||
tick();
|
||||
</script>
|
||||
<?php include 'footer.php'; ?>
|
||||
Loading…
x
Reference in New Issue
Block a user