70 lines
3.8 KiB
PHP
70 lines
3.8 KiB
PHP
<?php $empCode=$_SESSION['emp_code']??''; $perms=$_SESSION['emp_permissions']??[]; ?>
|
|
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>员工面板 - <?=$empCode?></title><script src="https://cdn.tailwindcss.com"></script>
|
|
<style>body{background:#111827;color:#fff;font-family:system-ui}</style>
|
|
</head>
|
|
<body class="min-h-screen">
|
|
<header class="bg-gray-900 border-b border-gray-700 px-4 py-3 flex justify-between items-center">
|
|
<span class="font-bold">👷 <?=$empCode?></span>
|
|
<span class="text-xs text-gray-400">权限:<?php $pm=['deposit'=>'充值','withdraw'=>'提现']; echo implode(', ', array_map(function($p) use($pm){return $pm[$p]??$p;}, $perms)); ?></span>
|
|
<a href="/logout" class="text-red-400 text-sm">退出</a>
|
|
</header>
|
|
<div class="max-w-4xl mx-auto p-4 space-y-4">
|
|
|
|
<!-- 搜索用户 -->
|
|
<div class="bg-gray-800 rounded-xl p-4">
|
|
<input type="text" id="searchUser" placeholder="搜索用户名..." oninput="filterUsers()" class="w-full px-4 py-2 bg-gray-700 border border-gray-600 rounded text-white text-sm focus:border-blue-400 focus:outline-none">
|
|
</div>
|
|
|
|
<!-- 用户列表 -->
|
|
<div class="bg-gray-800 rounded-xl p-4">
|
|
<h3 class="text-sm font-bold mb-3">用户列表</h3>
|
|
<div class="space-y-2 max-h-96 overflow-y-auto" id="userList">
|
|
<?php foreach($users??[] as $u): ?>
|
|
<div class="user-row flex items-center justify-between py-2 border-b border-gray-700 text-sm" data-name="<?=strtolower($u['username'])?>">
|
|
<div>
|
|
<span class="text-white"><?=htmlspecialchars($u['username'])?></span>
|
|
<span class="text-gray-400 ml-2">余额: <span class="text-yellow-400" id="bal_<?=$u['id']?>"><?=number_format($u['balance'],2)?></span></span>
|
|
</div>
|
|
<div class="flex gap-2">
|
|
<?php if(in_array('deposit',$perms)): ?>
|
|
<button onclick="doAdjust(<?=$u['id']?>,'deposit','<?=htmlspecialchars($u['username'])?>')" class="px-3 py-1 bg-green-600 rounded text-xs hover:bg-green-700">+ 充值</button>
|
|
<?php endif; ?>
|
|
<?php if(in_array('withdraw',$perms)): ?>
|
|
<button onclick="doAdjust(<?=$u['id']?>,'withdraw','<?=htmlspecialchars($u['username'])?>')" class="px-3 py-1 bg-red-600 rounded text-xs hover:bg-red-700">- 提现</button>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 操作日志 -->
|
|
<div class="bg-gray-800 rounded-xl p-4">
|
|
<h3 class="text-sm font-bold mb-3">操作日志</h3>
|
|
<div class="space-y-1 max-h-48 overflow-y-auto text-xs">
|
|
<?php foreach($logs??[] as $log): ?>
|
|
<div class="flex justify-between py-1 border-b border-gray-700">
|
|
<span class="<?=$log['action']==='deposit'?'text-green-400':'text-red-400'?>"><?=$log['action']==='deposit'?'充值':'提现'?> → 用户#<?=$log['target_user_id']?></span>
|
|
<span class="text-white"><?=number_format($log['amount'],2)?></span>
|
|
<span class="text-gray-500"><?=$log['created_at']?></span>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function filterUsers(){const q=document.getElementById('searchUser').value.toLowerCase();document.querySelectorAll('.user-row').forEach(r=>r.style.display=r.dataset.name.includes(q)?'':'none');}
|
|
async function doAdjust(uid,action,name){
|
|
const label=action==='deposit'?'充值':'提现';
|
|
const amount=prompt(label+'金额(用户:'+name+'):');
|
|
if(!amount||isNaN(amount)||parseFloat(amount)<=0)return;
|
|
const remark=prompt('备注(可选):')||'';
|
|
const r=await fetch('/employee/adjust-balance',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({user_id:uid,action,amount:parseFloat(amount),remark})});
|
|
const d=await r.json();
|
|
if(d.success){alert('操作成功!');document.getElementById('bal_'+uid).textContent=parseFloat(d.new_balance).toFixed(2);}else alert(d.message);
|
|
}
|
|
</script>
|
|
</body></html>
|