Files
shuiguoji/index.php
T
2026-07-23 08:58:13 +08:00

84 lines
15 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
require __DIR__ . '/includes/bootstrap.php';
$user = current_user();
$view = (string) ($_GET['view'] ?? ($user ? 'home' : 'login'));
$allowed = $user ? ['home', 'recharge', 'invite', 'security'] : ['login', 'register'];
if (!in_array($view, $allowed, true)) $view = $user ? 'home' : 'login';
$flash = take_flash();
$siteName = setting('site_name', $config['app_name']);
$orders = $referrals = [];
$inviteStats = ['count'=>0,'amount'=>0.0];
$commissionStats = ['direct_amount'=>0.0,'second_amount'=>0.0];
$inviteLink = '';
if ($user) {
$stmt = db()->prepare('SELECT * FROM recharge_orders WHERE user_id = ? ORDER BY id DESC LIMIT 30');
$stmt->execute([$user['id']]); $orders = $stmt->fetchAll();
$stmt = db()->prepare("SELECT COUNT(*) AS count,COALESCE(SUM(reward_amount),0) AS amount FROM referral_rewards WHERE inviter_id=? AND status='rewarded'");
$stmt->execute([$user['id']]); $inviteStats = $stmt->fetch() ?: $inviteStats;
$stmt = db()->prepare('SELECT COALESCE(SUM(CASE WHEN level=1 THEN commission_amount ELSE 0 END),0) AS direct_amount,COALESCE(SUM(CASE WHEN level=2 THEN commission_amount ELSE 0 END),0) AS second_amount FROM recharge_commissions WHERE beneficiary_user_id=? AND reversed_at IS NULL');
$stmt->execute([$user['id']]); $commissionStats = $stmt->fetch() ?: $commissionStats;
if ($view === 'invite') {
$stmt = db()->prepare('SELECT r.*,u.username AS invitee_name FROM referral_rewards r JOIN users u ON u.id=r.invitee_id WHERE r.inviter_id=? ORDER BY r.id DESC LIMIT 50');
$stmt->execute([$user['id']]); $referrals = $stmt->fetchAll();
}
$inviteLink = $config['app_url'].'/index.php?view=register&invite='.rawurlencode((string)$user['invite_code']);
}
$methodNames = ['wechat' => '微信', 'alipay' => '支付宝', 'bank' => '银行卡'];
$statusNames = ['pending' => '待审核', 'approved' => '已到账', 'rejected' => '已拒绝'];
?>
<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><title><?= e($siteName) ?></title><link rel="stylesheet" href="/assets/app.css?v=20260721"><link rel="stylesheet" href="/assets/invite.css?v=20260721"></head>
<body class="<?= $user ? 'app-page' : 'auth-page' ?>">
<?php if (!$user): ?>
<main class="auth-shell">
<section class="auth-art" aria-label="<?= e($siteName) ?>"><div class="brand-mark"><span>金</span></div><div><p class="eyebrow">欢乐街机 · 好运开局</p><h1><?= e($siteName) ?></h1><p>每一次开局,都值得期待。</p></div></section>
<section class="auth-panel">
<div class="mobile-brand"><span>金</span><b><?= e($siteName) ?></b></div>
<div class="auth-title"><span><?= $view === 'register' ? '创建账号' : '欢迎回来' ?></span><small><?= $view === 'register' ? '注册后即可进入游戏' : '登录您的游戏账号' ?></small></div>
<?php if ($flash): ?><div class="alert <?= e($flash['type']) ?>"><?= e($flash['message']) ?></div><?php endif; ?>
<?php if ($view === 'register'): ?>
<form method="post" action="/actions.php" class="form-stack"><input type="hidden" name="csrf" value="<?= e(csrf_token()) ?>"><input type="hidden" name="action" value="register"><input type="hidden" name="return" value="/index.php?view=register">
<label><span>账号</span><input name="username" minlength="6" maxlength="20" pattern="[A-Za-z0-9_]+" autocomplete="username" placeholder="6-20 位字母或数字" required></label>
<label><span>手机号 <i>选填</i></span><input name="phone" inputmode="tel" autocomplete="tel" placeholder="用于账号联系"></label>
<label><span>邀请码 <i>选填</i></span><input name="invite_code" maxlength="16" value="<?=e(strtoupper(trim((string)($_GET['invite']??''))))?>" autocomplete="off" placeholder="输入邀请人的邀请码"></label>
<label><span>密码</span><input type="password" name="password" minlength="8" maxlength="72" autocomplete="new-password" placeholder="至少 8 位" required></label>
<label><span>确认密码</span><input type="password" name="password_confirm" minlength="8" maxlength="72" autocomplete="new-password" required></label>
<button class="btn primary" type="submit">立即注册</button>
</form><p class="auth-switch">已有账号?<a href="/index.php?view=login">返回登录</a></p>
<?php else: ?>
<form method="post" action="/actions.php" class="form-stack"><input type="hidden" name="csrf" value="<?= e(csrf_token()) ?>"><input type="hidden" name="action" value="login"><input type="hidden" name="return" value="/index.php?view=login">
<label><span>账号</span><input name="username" autocomplete="username" placeholder="请输入账号" required autofocus></label>
<label><span>密码</span><input type="password" name="password" autocomplete="current-password" placeholder="请输入密码" required></label>
<button class="btn primary" type="submit">登录</button>
</form><p class="auth-switch">还没有账号?<a href="/index.php?view=register">免费注册</a></p>
<?php endif; ?>
</section>
</main>
<?php else: ?>
<header class="topbar"><a class="logo" href="/index.php"><span>金</span><b><?= e($siteName) ?></b></a><div class="top-user"><span class="balance-small">余额 <b>¥<?= number_format((float)$user['balance'], 2) ?></b></span><span class="avatar"><?= e(mb_substr($user['username'], 0, 1)) ?></span><span class="username"><?= e($user['username']) ?></span><form method="post" action="/actions.php"><input type="hidden" name="csrf" value="<?= e(csrf_token()) ?>"><input type="hidden" name="action" value="logout"><button class="icon-btn" title="退出登录" aria-label="退出登录">→</button></form></div></header>
<div class="app-shell">
<aside class="sidebar"><nav><a class="<?= $view==='home'?'active':'' ?>" href="/index.php"><i>◈</i><span>账户首页</span></a><a href="/game/index.php"><i>▶</i><span>进入游戏</span></a><a class="<?= $view==='recharge'?'active':'' ?>" href="/index.php?view=recharge"><i>¥</i><span>账户充值</span></a><a class="<?= $view==='invite'?'active':'' ?>" href="/index.php?view=invite"><i></i><span>邀请奖励</span></a><a class="<?= $view==='security'?'active':'' ?>" href="/index.php?view=security"><i>●</i><span>安全设置</span></a></nav><div class="service-box"><small>客服微信</small><b><?= e(setting('customer_service')) ?></b><span>服务时间 09:00-24:00</span></div></aside>
<main class="content">
<?php if ($flash): ?><div class="alert <?= e($flash['type']) ?>"><?= e($flash['message']) ?></div><?php endif; ?>
<?php if ($view === 'home'): ?>
<section class="welcome"><div><span class="tag">账户 ID <?= (int)$user['id'] ?></span><h1>你好,<?= e($user['username']) ?></h1><p><?= e(setting('announcement')) ?></p><div class="hero-actions"><a class="btn gold" href="/game/index.php">立即开始</a><a class="btn ghost" href="/index.php?view=recharge">充值</a></div></div><img src="/game/res/raw-assets/20/20449d73-f812-4c05-af4a-7135ef9ebd61.png" alt="金币财神"></section>
<section class="stat-grid"><article><span>可用余额</span><strong><small>¥</small><?= number_format((float)$user['balance'], 2) ?></strong><a href="/index.php?view=recharge">去充值 →</a></article><article><span>累计充值</span><strong><small>¥</small><?php $stmt=db()->prepare("SELECT COALESCE(SUM(amount),0) FROM recharge_orders WHERE user_id=? AND status='approved'");$stmt->execute([$user['id']]);echo number_format((float)$stmt->fetchColumn(),2); ?></strong><a href="/index.php?view=recharge">充值记录 →</a></article><article><span>邀请收益</span><strong><small>¥</small><?=number_format((float)$inviteStats['amount'],2)?></strong><a href="/index.php?view=invite">邀请好友 →</a></article></section>
<?php elseif ($view === 'recharge'): ?>
<div class="page-title"><div><h1>账户充值</h1><p>选择充值方式或兑换充值卡</p></div><div class="title-balance">当前余额 <b>¥<?=number_format((float)$user['balance'],2)?></b></div></div>
<div class="two-col"><section class="panel form-panel"><div class="panel-head"><div><h2>提交充值</h2><p><?=e(setting('recharge_instructions'))?></p></div></div><form method="post" action="/actions.php" class="form-stack"><input type="hidden" name="csrf" value="<?=e(csrf_token())?>"><input type="hidden" name="action" value="recharge"><input type="hidden" name="return" value="/index.php?view=recharge"><label><span>充值金额</span><div class="money-input"><b>¥</b><input type="number" name="amount" min="10" max="100000" step="0.01" placeholder="0.00" required></div></label><div class="quick-amounts"><?php foreach([100,300,500,1000] as $a):?><button type="button" data-amount="<?=$a?>">¥<?=$a?></button><?php endforeach;?></div><label><span>充值方式</span><select name="method"><option value="wechat">微信</option><option value="alipay">支付宝</option><option value="bank">银行卡</option></select></label><label><span>付款备注</span><input name="payer_note" maxlength="200" placeholder="请输入付款人姓名或流水号" required></label><button class="btn primary" type="submit">提交充值申请</button></form></section>
<section class="panel card-panel"><div class="panel-head"><div><h2>充值卡兑换</h2><p>输入后即时到账</p></div></div><form method="post" action="/actions.php" class="form-stack"><input type="hidden" name="csrf" value="<?=e(csrf_token())?>"><input type="hidden" name="action" value="redeem_card"><input type="hidden" name="return" value="/index.php?view=recharge"><label><span>充值卡号</span><input name="card_code" maxlength="32" autocomplete="off" placeholder="请输入卡号" required></label><button class="btn gold" type="submit">立即兑换</button></form><div class="service-line"><span>遇到问题?</span><b>微信 <?=e(setting('customer_service'))?></b></div></section></div>
<section class="panel"><div class="panel-head"><div><h2>充值记录</h2><p>最近 30 笔充值申请</p></div></div><div class="table-wrap"><table><thead><tr><th>订单号</th><th>时间</th><th>方式</th><th>金额</th><th>状态</th></tr></thead><tbody><?php foreach($orders as $o):?><tr><td class="mono"><?=e($o['order_no'])?></td><td><?=e($o['created_at'])?></td><td><?=e($methodNames[$o['method']]??$o['method'])?></td><td>¥<?=number_format((float)$o['amount'],2)?></td><td><span class="badge <?=$o['status']?>"><?=e($statusNames[$o['status']]??$o['status'])?></span></td></tr><?php endforeach;?><?php if(!$orders):?><tr><td colspan="5" class="empty-cell">暂无充值记录</td></tr><?php endif;?></tbody></table></div></section>
<?php elseif ($view === 'invite'): ?>
<div class="page-title"><div><h1>邀请奖励</h1><p>一级下线充值奖励 <?=number_format((float)setting('direct_commission_rate','10'),2)?>%,二级下线充值奖励 <?=number_format((float)setting('second_commission_rate','1'),2)?>%</p></div><div class="title-balance">每人注册奖励 <b>¥<?=number_format((float)setting('invite_reward','0'),2)?></b></div></div>
<section class="stat-grid invite-stats"><article><span>成功邀请</span><strong><?=number_format((int)$inviteStats['count'])?><small> 人</small></strong></article><article><span>一级充值佣金</span><strong><small>¥</small><?=number_format((float)$commissionStats['direct_amount'],2)?></strong></article><article><span>二级充值佣金</span><strong><small>¥</small><?=number_format((float)$commissionStats['second_amount'],2)?></strong></article></section>
<section class="panel"><div class="panel-head"><div><h2>邀请链接</h2><p>同一 IP 仅发放一次邀请奖励</p></div></div><div class="invite-tools"><label><span>邀请码</span><div><input id="invite-code" readonly value="<?=e($user['invite_code'])?>"><button class="btn primary" type="button" data-copy="#invite-code">复制邀请码</button></div></label><label><span>邀请链接</span><div><input id="invite-link" readonly value="<?=e($inviteLink)?>"><button class="btn primary" type="button" data-copy="#invite-link">复制链接</button></div></label></div></section>
<section class="panel"><div class="panel-head"><div><h2>邀请记录</h2><p>最近 50 条记录</p></div></div><div class="table-wrap"><table><thead><tr><th>注册用户</th><th>奖励</th><th>状态</th><th>说明</th><th>时间</th></tr></thead><tbody><?php foreach($referrals as $r):?><tr><td><?=e($r['invitee_name'])?></td><td>¥<?=number_format((float)$r['reward_amount'],2)?></td><td><span class="badge <?=e($r['status'])?>"><?=$r['status']==='rewarded'?'已奖励':'未奖励'?></span></td><td><?=e($r['reason']?:'-')?></td><td><?=e($r['created_at'])?></td></tr><?php endforeach;?><?php if(!$referrals):?><tr><td colspan="5" class="empty-cell">暂无邀请记录</td></tr><?php endif;?></tbody></table></div></section>
<?php else: ?>
<div class="page-title"><div><h1>安全设置</h1><p>管理联系方式与登录密码</p></div></div><div class="two-col"><section class="panel form-panel"><div class="panel-head"><div><h2>账户资料</h2><p>账号 <?=e($user['username'])?> · ID <?= (int)$user['id']?></p></div></div><form method="post" action="/actions.php" class="form-stack"><input type="hidden" name="csrf" value="<?=e(csrf_token())?>"><input type="hidden" name="action" value="profile"><input type="hidden" name="return" value="/index.php?view=security"><label><span>手机号</span><input name="phone" value="<?=e($user['phone'])?>" inputmode="tel"></label><button class="btn primary" type="submit">保存资料</button></form></section><section class="panel form-panel"><div class="panel-head"><div><h2>修改密码</h2><p>建议定期更换高强度密码</p></div></div><form method="post" action="/actions.php" class="form-stack"><input type="hidden" name="csrf" value="<?=e(csrf_token())?>"><input type="hidden" name="action" value="password"><input type="hidden" name="return" value="/index.php?view=security"><label><span>原密码</span><input type="password" name="old_password" required></label><label><span>新密码</span><input type="password" name="new_password" minlength="8" required></label><label><span>确认新密码</span><input type="password" name="new_password_confirm" minlength="8" required></label><button class="btn primary" type="submit">更新密码</button></form></section></div>
<?php endif; ?>
</main>
</div>
<nav class="mobile-nav"><a class="<?= $view==='home'?'active':'' ?>" href="/index.php"><i>◈</i><span>首页</span></a><a href="/game/index.php"><i>▶</i><span>游戏</span></a><a class="<?= $view==='recharge'?'active':'' ?>" href="/index.php?view=recharge"><i>¥</i><span>充值</span></a><a class="<?= $view==='invite'?'active':'' ?>" href="/index.php?view=invite"><i></i><span>邀请</span></a><a class="<?= $view==='security'?'active':'' ?>" href="/index.php?view=security"><i>●</i><span>我的</span></a></nav>
<?php endif; ?><script src="/assets/app.js?v=20260722-cards2"></script></body></html>