仰望星辰工作室

better-staridc-MNBT

Z zfhsh first commit 2 个月前
1<?php
2/**
3 * 管理员端 - 用户余额管理
4 */
5if (!defined('IN_CRONLITE')) {
6 exit;
7}
8
9$page_num = max(1, (int)($_GET['page_num'] ?? 1));
10$kw = trim((string)($_GET['kw'] ?? ''));
11$result = balance_admin_list($page_num, 30, $kw);
12$list = $result['list'];
13$total = $result['total'];
14$total_pages = $result['per_page'] > 0 ? (int)ceil($total / $result['per_page']) : 1;
15
16$title = $title ?? '余额管理';
17mnbt_admin_include('head');
18?>
19<link rel="stylesheet" href="<?= mnbt_asset_url('js/jquery-confirm/jquery-confirm.min.css') ?>">
20<script src="<?= mnbt_asset_url('js/jquery-confirm/jquery-confirm.min.js') ?>"></script>
21
22<div class="container-fluid p-t-15">
23 <div class="card">
24 <div class="card-header">
25 <h4 style="display:inline-block">用户余额管理</h4>
26 <small class="text-muted ml-2">共 <?= $total ?> 条记录</small>
27 </div>
28 <div class="card-body">
29 <form method="get" class="form-inline mb-3">
30 <input type="hidden" name="p" value="balance">
31 <input type="hidden" name="page" value="balances">
32 <input type="text" name="kw" class="form-control form-control-sm mr-2" placeholder="用户名" value="<?= htmlspecialchars($kw, ENT_QUOTES) ?>">
33 <button type="submit" class="btn btn-sm btn-primary">搜索</button>
34 <a href="plugin.php?p=balance&page=balances" class="btn btn-sm btn-outline-secondary ml-2">重置</a>
35 </form>
36
37 <div class="table-responsive">
38 <table class="table table-bordered table-hover">
39 <thead>
40 <tr>
41 <th style="width:60px">ID</th>
42 <th>用户名</th>
43 <th>邮箱</th>
44 <th>余额(元)</th>
45 <th>状态</th>
46 <th>更新时间</th>
47 <th style="width:180px">操作</th>
48 </tr>
49 </thead>
50 <tbody>
51 <?php if (empty($list)): ?>
52 <tr><td colspan="7" class="text-center text-muted">暂无记录</td></tr>
53 <?php else: ?>
54 <?php foreach ($list as $b): ?>
55 <tr>
56 <td><?= (int)$b['user_id'] ?></td>
57 <td><?= htmlspecialchars($b['username'] ?: ('#' . $b['user_id']), ENT_QUOTES) ?></td>
58 <td><?= htmlspecialchars($b['email'] ?: '-', ENT_QUOTES) ?></td>
59 <td><b class="text-primary">¥<?= htmlspecialchars(balance_format((int)$b['balance']), ENT_QUOTES) ?></b></td>
60 <td>
61 <?php if ((int)($b['status'] ?? 1) === 1): ?>
62 <span class="badge badge-success">正常</span>
63 <?php else: ?>
64 <span class="badge badge-danger">禁用</span>
65 <?php endif; ?>
66 </td>
67 <td class="small text-muted"><?= htmlspecialchars($b['updated_at'] ?: '-', ENT_QUOTES) ?></td>
68 <td>
69 <button type="button" class="btn btn-sm btn-outline-success" onclick="adjustBalance(<?= (int)$b['user_id'] ?>, '<?= htmlspecialchars($b['username'] ?: ('#' . $b['user_id']), ENT_QUOTES) ?>', 'add')">加款</button>
70 <button type="button" class="btn btn-sm btn-outline-danger" onclick="adjustBalance(<?= (int)$b['user_id'] ?>, '<?= htmlspecialchars($b['username'] ?: ('#' . $b['user_id']), ENT_QUOTES) ?>', 'deduct')">扣款</button>
71 </td>
72 </tr>
73 <?php endforeach; ?>
74 <?php endif; ?>
75 </tbody>
76 </table>
77 </div>
78
79 <?php if ($total_pages > 1): ?>
80 <nav>
81 <ul class="pagination justify-content-center">
82 <?php for ($i = 1; $i <= $total_pages; $i++): ?>
83 <li class="page-item <?= $i === $page_num ? 'active' : '' ?>">
84 <a class="page-link" href="plugin.php?p=balance&page=balances&page_num=<?= $i ?>&kw=<?= urlencode($kw) ?>"><?= $i ?></a>
85 </li>
86 <?php endfor; ?>
87 </ul>
88 </nav>
89 <?php endif; ?>
90 </div>
91 </div>
92</div>
93
94<script>
95function adjustBalance(uid, uname, direction) {
96 var title = direction === 'add' ? '加款' : '扣款';
97 $.confirm({
98 title: title + ' - ' + uname,
99 content: '<div class="form-group">' +
100 '<label>金额(元)</label>' +
101 '<input type="number" step="0.01" min="0.01" class="form-control" id="adj-amount" placeholder="金额">' +
102 '</div>' +
103 '<div class="form-group">' +
104 '<label>备注</label>' +
105 '<input type="text" class="form-control" id="adj-remark" placeholder="备注(选填)">' +
106 '</div>',
107 buttons: {
108 confirm: {
109 text: '确定' + title,
110 btnClass: direction === 'add' ? 'btn-success' : 'btn-danger',
111 action: function () {
112 var amount = $.trim($('#adj-amount').val());
113 var remark = $.trim($('#adj-remark').val());
114 if (!amount || parseFloat(amount) <= 0) {
115 $.alert('金额必须大于 0');
116 return false;
117 }
118 $.post('ajax.php', {
119 gn: 'balance_admin_adjust',
120 user_id: uid,
121 amount: amount,
122 direction: direction,
123 remark: remark
124 }, function (resp) {
125 var j;
126 try { j = typeof resp === 'string' ? JSON.parse(resp) : resp; } catch (e) { j = { code: resp }; }
127 var code = j.code || j.msg || '';
128 if (code === '调整成功') {
129 $.alert({ title: '成功', content: '余额调整成功', type: 'green', buttons: { ok: { action: function () { location.reload(); } } } });
130 } else {
131 $.alert({ title: '失败', content: code || '操作失败', type: 'red' });
132 }
133 }).fail(function () {
134 $.alert({ title: '错误', content: '网络错误', type: 'red' });
135 });
136 return true;
137 }
138 },
139 cancel: { text: '取消' }
140 }
141 });
142}
143</script>