Files
pk10/App/Views/Web/agent_dashboard.php
T

264 lines
16 KiB
PHP

<?php use App\Core\I18n; I18n::init(); $t = function($k,$p=[]){return I18n::t($k,$p);}; $page=$page??'home'; ?>
<!DOCTYPE html><html lang="<?=I18n::getLang()?>">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>代理后台</title><script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<style>body{background:#0f172a;color:#fff;font-family:system-ui}.sidebar a.active{background:rgba(234,179,8,.15);color:#eab308;border-right:3px solid #eab308}</style>
</head>
<body class="min-h-screen flex">
<!-- 侧边栏 -->
<aside class="sidebar w-56 bg-slate-900 border-r border-white/5 min-h-screen hidden md:block shrink-0">
<div class="p-4 border-b border-white/5">
<div class="text-yellow-400 font-bold text-lg">🏎️ 代理后台</div>
<div class="text-white/40 text-xs mt-1"><?=htmlspecialchars($user['username']??'')?></div>
<div class="text-xs mt-1"><span class="text-white/30">邀请码:</span> <span class="text-yellow-400 font-mono"><?=htmlspecialchars($agent['agent_code']??'')?></span></div>
</div>
<nav class="p-2 space-y-1">
<a href="/agent" class="flex items-center gap-3 px-3 py-2 rounded text-sm hover:bg-white/5 <?=$page==='home'?'active':''?>"><i class="fas fa-home w-5 text-center"></i>数据总览</a>
<a href="/agent/odds" class="flex items-center gap-3 px-3 py-2 rounded text-sm hover:bg-white/5 <?=$page==='odds'?'active':''?>"><i class="fas fa-sliders-h w-5 text-center"></i>赔率设置</a>
<a href="/agent/bets" class="flex items-center gap-3 px-3 py-2 rounded text-sm hover:bg-white/5 <?=$page==='bets'?'active':''?>"><i class="fas fa-list-alt w-5 text-center"></i>投注记录</a>
<a href="/agent/commissions" class="flex items-center gap-3 px-3 py-2 rounded text-sm hover:bg-white/5 <?=$page==='commissions'?'active':''?>"><i class="fas fa-coins w-5 text-center"></i>佣金明细</a>
<div class="border-t border-white/5 my-2"></div>
<a href="/" class="flex items-center gap-3 px-3 py-2 rounded text-sm text-white/40 hover:bg-white/5"><i class="fas fa-gamepad w-5 text-center"></i>返回投注</a>
<a href="/logout" class="flex items-center gap-3 px-3 py-2 rounded text-sm text-red-400/60 hover:bg-white/5"><i class="fas fa-sign-out-alt w-5 text-center"></i>退出</a>
</nav>
</aside>
<!-- 手机顶部导航 -->
<div class="md:hidden fixed top-0 left-0 right-0 z-50 bg-slate-900 border-b border-white/5 px-4 py-2 flex items-center justify-between">
<span class="text-yellow-400 font-bold">🏎️ 代理后台</span>
<button onclick="document.getElementById('mobileMenu').classList.toggle('hidden')" class="text-white/60"><i class="fas fa-bars"></i></button>
</div>
<div id="mobileMenu" class="md:hidden fixed top-10 left-0 right-0 z-40 bg-slate-900 border-b border-white/5 hidden">
<div class="flex flex-wrap gap-1 p-2">
<a href="/agent" class="px-3 py-1 rounded text-xs <?=$page==='home'?'bg-yellow-500/20 text-yellow-400':'text-white/60'?>">总览</a>
<a href="/agent/odds" class="px-3 py-1 rounded text-xs <?=$page==='odds'?'bg-yellow-500/20 text-yellow-400':'text-white/60'?>">赔率</a>
<a href="/agent/bets" class="px-3 py-1 rounded text-xs <?=$page==='bets'?'bg-yellow-500/20 text-yellow-400':'text-white/60'?>">投注</a>
<a href="/agent/commissions" class="px-3 py-1 rounded text-xs <?=$page==='commissions'?'bg-yellow-500/20 text-yellow-400':'text-white/60'?>">佣金</a>
<a href="/" class="px-3 py-1 rounded text-xs text-white/40">返回</a>
</div>
</div>
<!-- 主内容 -->
<main class="flex-1 p-4 md:p-6 mt-12 md:mt-0 overflow-auto">
<?php if($page==='home'): ?>
<!-- ========== 数据总览 ========== -->
<h2 class="text-xl font-bold mb-4">📊 数据总览</h2>
<div class="grid grid-cols-2 md:grid-cols-4 gap-3 mb-6">
<div class="bg-white/5 rounded-xl p-4 text-center">
<div class="text-white/40 text-xs">玩家数</div>
<div class="text-2xl font-bold mt-1"><?=count($players??[])?></div>
</div>
<div class="bg-white/5 rounded-xl p-4 text-center">
<div class="text-white/40 text-xs">总投注额</div>
<div class="text-yellow-400 font-bold text-lg mt-1"><?=number_format($totalBets??0,2)?></div>
</div>
<div class="bg-white/5 rounded-xl p-4 text-center">
<div class="text-white/40 text-xs">今日佣金</div>
<div class="text-green-400 font-bold text-lg mt-1"><?=number_format($todayComm,2)?></div>
</div>
<div class="bg-white/5 rounded-xl p-4 text-center">
<div class="text-white/40 text-xs">累计佣金</div>
<div class="text-green-400 font-bold text-lg mt-1"><?=number_format($totalComm,2)?></div>
</div>
</div>
<!-- 分享链接 -->
<div class="bg-white/5 rounded-xl p-4 mb-4">
<h3 class="text-sm font-bold mb-2">📎 邀请链接</h3>
<div class="flex gap-2">
<input type="text" readonly value="<?=($_SERVER['REQUEST_SCHEME']??'http').'://'.$_SERVER['HTTP_HOST']?>/login?invite=<?=htmlspecialchars($agent['agent_code']??'')?>" class="flex-1 px-3 py-2 bg-white/5 border border-white/10 rounded text-xs text-white font-mono" id="shareLink">
<button onclick="navigator.clipboard.writeText(document.getElementById('shareLink').value);this.textContent='已复制!';setTimeout(()=>this.textContent='复制',1500)" class="px-4 py-2 bg-yellow-500 text-black rounded text-xs font-bold hover:bg-yellow-400">复制</button>
</div>
</div>
<!-- 下级代理 -->
<?php if(!empty($subAgents)): ?>
<div class="bg-white/5 rounded-xl p-4 mb-4">
<h3 class="text-sm font-bold mb-3">👥 下级代理</h3>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="text-white/40 text-xs border-b border-white/5"><th class="text-left py-2 px-2">用户名</th><th class="px-2">邀请码</th><th class="px-2">佣金%</th><th class="px-2">玩家数</th><th class="px-2">状态</th></tr></thead>
<tbody>
<?php foreach($subAgents as $sa): ?>
<tr class="border-b border-white/5 text-xs">
<td class="py-2 px-2"><?=htmlspecialchars($sa['user']['username']??'')?></td>
<td class="px-2 text-center font-mono text-yellow-400"><?=$sa['agent_code']?></td>
<td class="px-2 text-center"><?=$sa['commission_rate']?>%</td>
<td class="px-2 text-center"><?=$sa['player_count']?></td>
<td class="px-2 text-center"><?=$sa['status']?'<span class="text-green-400">启用</span>':'<span class="text-red-400">禁用</span>'?></td>
</tr>
<?php endforeach; ?>
</tbody></table></div>
</div>
<?php endif; ?>
<!-- 玩家列表 -->
<div class="bg-white/5 rounded-xl p-4">
<h3 class="text-sm font-bold mb-3">🎮 我的玩家</h3>
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="text-white/40 text-xs border-b border-white/5"><th class="text-left py-2 px-2">ID</th><th class="text-left px-2">用户名</th><th class="px-2">余额</th><th class="px-2">注册时间</th><th class="px-2">状态</th></tr></thead>
<tbody>
<?php foreach($players??[] as $p): ?>
<tr class="border-b border-white/5 text-xs">
<td class="py-2 px-2 text-white/40"><?=$p['id']?></td>
<td class="px-2"><?=htmlspecialchars($p['username'])?></td>
<td class="px-2 text-center text-yellow-400"><?=number_format($p['balance'],2)?></td>
<td class="px-2 text-center text-white/40"><?=date('m-d H:i',strtotime($p['created_at']))?></td>
<td class="px-2 text-center"><?=$p['status']?'<span class="text-green-400">✓</span>':'<span class="text-red-400">✗</span>'?></td>
</tr>
<?php endforeach; ?>
<?php if(empty($players)): ?><tr><td colspan="5" class="text-center py-6 text-white/20">暂无玩家</td></tr><?php endif; ?>
</tbody></table></div>
</div>
<?php elseif($page==='odds'): ?>
<!-- ========== 赔率设置 ========== -->
<h2 class="text-xl font-bold mb-4">⚙️ 赔率设置</h2>
<p class="text-white/40 text-xs mb-4">设置你名下玩家的赔率。赔率不能超过上级设定的上限。</p>
<div class="space-y-4">
<?php
$oddsGroups = [
'大小 (Big/Small)' => ['type'=>'bs','targets'=>[]],
'单双 (Odd/Even)' => ['type'=>'oe','targets'=>[]],
'龙虎 (Dragon/Tiger)' => ['type'=>'dt','targets'=>[]],
'冠亚和大小 (Sum BS)' => ['type'=>'sum_bs','targets'=>[]],
];
// 大小
for($r=1;$r<=10;$r++){$oddsGroups['大小 (Big/Small)']['targets'][]=['target'=>"rank{$r}_big",'label'=>"第{$r}名 大"];$oddsGroups['大小 (Big/Small)']['targets'][]=['target'=>"rank{$r}_small",'label'=>"第{$r}名 小"];}
// 单双
for($r=1;$r<=10;$r++){$oddsGroups['单双 (Odd/Even)']['targets'][]=['target'=>"rank{$r}_odd",'label'=>"第{$r}名 单"];$oddsGroups['单双 (Odd/Even)']['targets'][]=['target'=>"rank{$r}_even",'label'=>"第{$r}名 双"];}
// 龙虎
$dtPairs=[[1,10],[2,9],[3,8],[4,7],[5,6]];
foreach($dtPairs as $i=>$p){$n=$i+1;$oddsGroups['龙虎 (Dragon/Tiger)']['targets'][]=['target'=>"dt{$n}_dragon",'label'=>"第{$p[0]}vs{$p[1]} 龙"];$oddsGroups['龙虎 (Dragon/Tiger)']['targets'][]=['target'=>"dt{$n}_tiger",'label'=>"第{$p[0]}vs{$p[1]} 虎"];}
// 冠亚和大小
$oddsGroups['冠亚和大小 (Sum BS)']['targets']=[['target'=>'sum_big','label'=>'和大'],['target'=>'sum_small','label'=>'和小'],['target'=>'sum_odd','label'=>'和单'],['target'=>'sum_even','label'=>'和双']];
?>
<?php foreach($oddsGroups as $groupName=>$group): ?>
<div class="bg-white/5 rounded-xl p-4">
<h3 class="text-sm font-bold mb-3"><?=$groupName?></h3>
<div class="grid grid-cols-2 md:grid-cols-4 gap-2">
<?php
// 同类型只显示一个代表(大小/单双每个名次赔率相同)
$type=$group['type'];
$firstTarget=$group['targets'][0]['target']??'';
$parentKey=$type.'_'.$firstTarget;
$parentVal=$parentMap[$parentKey]??1.95;
$myVal=$myMap[$parentKey]??$parentVal;
?>
<div class="col-span-full flex items-center gap-3 bg-white/5 rounded p-3">
<span class="text-white/40 text-xs w-24">统一赔率</span>
<span class="text-white/30 text-xs">上限: <?=$parentVal?></span>
<input type="number" step="0.01" min="1" max="<?=$parentVal?>" value="<?=$myVal?>" class="w-24 px-2 py-1 bg-white/10 border border-white/10 rounded text-sm text-white" data-type="<?=$type?>" data-targets='<?=json_encode(array_column($group['targets'],'target'))?>'>
</div>
</div>
</div>
<?php endforeach; ?>
<!-- 名次赔率 -->
<div class="bg-white/5 rounded-xl p-4">
<h3 class="text-sm font-bold mb-3">名次投注 (Rank) — 猜车号</h3>
<?php $parentRank=$parentMap['rank_rank1_1']??9.80; $myRank=$myMap['rank_rank1_1']??$parentRank; ?>
<div class="flex items-center gap-3 bg-white/5 rounded p-3">
<span class="text-white/40 text-xs w-24">统一赔率</span>
<span class="text-white/30 text-xs">上限: <?=$parentRank?></span>
<input type="number" step="0.01" min="1" max="<?=$parentRank?>" value="<?=$myRank?>" class="w-24 px-2 py-1 bg-white/10 border border-white/10 rounded text-sm text-white" id="rankOddsInput" data-type="rank">
</div>
</div>
<button onclick="saveAllOdds()" class="w-full py-3 bg-yellow-500 text-black font-bold rounded-xl hover:bg-yellow-400 text-sm">保存所有赔率</button>
</div>
<script>
async function saveAllOdds(){
const odds=[];
const gameId=<?=$game['id']??0?>;
// 收集各类型
document.querySelectorAll('input[data-type]').forEach(inp=>{
const type=inp.dataset.type;
const val=parseFloat(inp.value);
if(type==='rank'){
// 名次:100个target
for(let r=1;r<=10;r++)for(let c=1;c<=10;c++) odds.push({bet_type:'rank',bet_target:'rank'+r+'_'+c,odds:val});
} else if(inp.dataset.targets){
JSON.parse(inp.dataset.targets).forEach(t=>odds.push({bet_type:type,bet_target:t,odds:val}));
}
});
const r=await fetch('/api/agent/set-odds',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({game_id:gameId,odds:odds})});
const d=await r.json();
alert(d.message||'完成');if(d.success)location.reload();
}
</script>
<?php elseif($page==='bets'): ?>
<!-- ========== 投注记录 ========== -->
<h2 class="text-xl font-bold mb-4">📋 玩家投注记录</h2>
<div class="bg-white/5 rounded-xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="text-white/40 text-xs border-b border-white/5 bg-white/5">
<th class="text-left py-3 px-3">玩家</th><th class="px-3">期号</th><th class="px-3">下注内容</th><th class="px-3">金额</th><th class="px-3">赔率</th><th class="px-3">状态</th><th class="px-3">赢额</th><th class="px-3">时间</th>
</tr></thead>
<tbody>
<?php foreach($betRecords??[] as $b):
// 投注类型中文转换
$bt=$b['bet_type']; $bv=$b['bet_value']; $label='';
if($bt==='rank'&&preg_match('/^rank(\d+)_(\d+)$/',$bv,$m)){$rn=(int)$m[1];$label=($rn===1?'冠军':($rn===2?'亚军':'第'.$rn.'名')).' '.$m[2].'号车';}
elseif($bt==='bs'&&preg_match('/^rank(\d+)_(big|small)$/',$bv,$m)){$rn=(int)$m[1];$label=($rn===1?'冠军':($rn===2?'亚军':'第'.$rn.'名')).' '.($m[2]==='big'?'大':'小');}
elseif($bt==='oe'&&preg_match('/^rank(\d+)_(odd|even)$/',$bv,$m)){$rn=(int)$m[1];$label=($rn===1?'冠军':($rn===2?'亚军':'第'.$rn.'名')).' '.($m[2]==='odd'?'单':'双');}
elseif($bt==='dt'&&preg_match('/^dt(\d+)_(dragon|tiger)$/',$bv,$m)){$ps=[1=>[1,10],2=>[2,9],3=>[3,8],4=>[4,7],5=>[5,6]];$p=$ps[(int)$m[1]]??[0,0];$label='龙虎 '.$p[0].'vs'.$p[1].' '.($m[2]==='dragon'?'龙':'虎');}
elseif($bt==='sum'&&preg_match('/^sum_(\d+)$/',$bv,$m)){$label='冠亚和 '.$m[1];}
elseif($bt==='sum_bs'){$sm=['sum_big'=>'和大','sum_small'=>'和小','sum_odd'=>'和单','sum_even'=>'和双'];$label=$sm[$bv]??$bv;}
else{$tm=['xiu'=>'小','tai'=>'大','chan'=>'双','le'=>'单','number'=>'点数','dice'=>'单骰','combo'=>'豹子','big_small'=>'大小','odd_even'=>'单双'];$vm=['big'=>'大','small'=>'小','odd'=>'单','even'=>'双','4red'=>'4红','4white'=>'4白','3red1white'=>'3红1白','1red3white'=>'1红3白'];$label=($tm[$bt]??$bt).' '.($vm[$bv]??$bv);}
?>
<tr class="border-b border-white/5 text-xs hover:bg-white/5">
<td class="py-2 px-3"><?=htmlspecialchars($b['username'])?></td>
<td class="px-3 font-mono text-white/40"><?=$b['period_number']?></td>
<td class="px-3"><?=htmlspecialchars($label)?></td>
<td class="px-3 text-yellow-400"><?=number_format($b['amount'],2)?></td>
<td class="px-3"><?=$b['odds']?></td>
<td class="px-3"><?php
$sc=['pending'=>'text-white/40','win'=>'text-green-400','lose'=>'text-red-400','settled'=>'text-blue-400'];
$sl=['pending'=>'待开','win'=>'赢','lose'=>'输','settled'=>'已结'];
echo '<span class="'.($sc[$b['status']]??'').'">'.($sl[$b['status']]??$b['status']).'</span>';
?></td>
<td class="px-3 <?=($b['win_amount']??0)>0?'text-green-400':'text-white/30'?>"><?=number_format($b['win_amount']??0,2)?></td>
<td class="px-3 text-white/30"><?=date('m-d H:i',strtotime($b['created_at']))?></td>
</tr>
<?php endforeach; ?>
<?php if(empty($betRecords)): ?><tr><td colspan="8" class="text-center py-8 text-white/20">暂无投注记录</td></tr><?php endif; ?>
</tbody></table></div>
</div>
<?php elseif($page==='commissions'): ?>
<!-- ========== 佣金明细 ========== -->
<h2 class="text-xl font-bold mb-4">💰 佣金明细</h2>
<div class="bg-white/5 rounded-xl overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead><tr class="text-white/40 text-xs border-b border-white/5 bg-white/5">
<th class="text-left py-3 px-3">来源玩家</th><th class="px-3">投注额</th><th class="px-3">佣金</th><th class="px-3">类型</th><th class="px-3">时间</th>
</tr></thead>
<tbody>
<?php foreach($records??[] as $r): ?>
<tr class="border-b border-white/5 text-xs hover:bg-white/5">
<td class="py-2 px-3"><?=htmlspecialchars($r['username'])?></td>
<td class="px-3 text-yellow-400"><?=number_format($r['bet_amount'],2)?></td>
<td class="px-3 text-green-400 font-bold"><?=number_format($r['commission'],2)?></td>
<td class="px-3"><?=$r['type']==='bet'?'投注佣金':'反水'?></td>
<td class="px-3 text-white/30"><?=date('m-d H:i',strtotime($r['created_at']))?></td>
</tr>
<?php endforeach; ?>
<?php if(empty($records)): ?><tr><td colspan="5" class="text-center py-8 text-white/20">暂无佣金记录</td></tr><?php endif; ?>
</tbody></table></div>
</div>
<?php endif; ?>
</main>
</body></html>