statistics_bill.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>机器人统计账单</title>
  7. <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
  8. <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css" rel="stylesheet">
  9. <style>
  10. body {
  11. background-color: #f5f5f5;
  12. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  13. }
  14. .container {
  15. max-width: 1200px;
  16. margin: 20px auto;
  17. padding: 20px;
  18. }
  19. .card {
  20. background: #fff;
  21. border-radius: 8px;
  22. box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  23. margin-bottom: 20px;
  24. }
  25. .card-header {
  26. background: #fff;
  27. border-bottom: 1px solid #eee;
  28. padding: 15px 20px;
  29. font-weight: 600;
  30. display: flex;
  31. justify-content: space-between;
  32. align-items: center;
  33. }
  34. .stat-card {
  35. background: linear-gradient(45deg, #2196F3, #1976D2);
  36. color: white;
  37. border-radius: 8px;
  38. padding: 20px;
  39. margin-bottom: 20px;
  40. box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  41. }
  42. .stat-card .title {
  43. font-size: 14px;
  44. opacity: 0.8;
  45. }
  46. .stat-card .value {
  47. font-size: 24px;
  48. font-weight: bold;
  49. margin: 10px 0;
  50. }
  51. .table {
  52. margin-bottom: 0;
  53. }
  54. .table th {
  55. background: #f8f9fa;
  56. font-weight: 600;
  57. }
  58. .badge {
  59. padding: 5px 10px;
  60. border-radius: 4px;
  61. }
  62. .badge-success {
  63. background-color: #28a745;
  64. }
  65. .badge-danger {
  66. background-color: #dc3545;
  67. }
  68. .pagination {
  69. margin: 20px 0;
  70. }
  71. .pagination .page-link {
  72. color: #2196F3;
  73. }
  74. .pagination .page-item.active .page-link {
  75. background-color: #2196F3;
  76. border-color: #2196F3;
  77. }
  78. .summary-table {
  79. width: 100%;
  80. border-collapse: collapse;
  81. margin-top: 20px;
  82. }
  83. .summary-table th,
  84. .summary-table td {
  85. padding: 12px;
  86. text-align: left;
  87. border-bottom: 1px solid #eee;
  88. }
  89. .summary-table th {
  90. background-color: #f8f9fa;
  91. font-weight: 600;
  92. }
  93. .summary-table tr:last-child td {
  94. border-bottom: none;
  95. font-weight: bold;
  96. }
  97. .nav-tabs {
  98. border-bottom: 1px solid #dee2e6;
  99. margin-bottom: 20px;
  100. }
  101. .nav-tabs .nav-link {
  102. border: none;
  103. color: #6c757d;
  104. padding: 10px 20px;
  105. font-weight: 500;
  106. }
  107. .nav-tabs .nav-link.active {
  108. color: #2196F3;
  109. border-bottom: 2px solid #2196F3;
  110. background: none;
  111. }
  112. .tab-content {
  113. padding: 20px 0;
  114. }
  115. </style>
  116. </head>
  117. <body>
  118. <div class="container">
  119. <div class="row">
  120. <div class="col-md-3">
  121. <div class="stat-card">
  122. <div class="title">今日收入</div>
  123. <div class="value" id="todayIncome">¥0.00</div>
  124. </div>
  125. </div>
  126. <div class="col-md-3">
  127. <div class="stat-card">
  128. <div class="title">本月收入</div>
  129. <div class="value" id="monthlyIncome">¥0.00</div>
  130. </div>
  131. </div>
  132. <div class="col-md-3">
  133. <div class="stat-card">
  134. <div class="title">总收入</div>
  135. <div class="value" id="totalIncome">¥0.00</div>
  136. </div>
  137. </div>
  138. <div class="col-md-3">
  139. <div class="stat-card">
  140. <div class="title">今日订单数</div>
  141. <div class="value" id="todayOrders">0</div>
  142. </div>
  143. </div>
  144. </div>
  145. <div class="card">
  146. <div class="card-header">
  147. <span>交易记录</span>
  148. <ul class="nav nav-tabs card-header-tabs">
  149. <li class="nav-item">
  150. <a class="nav-link active" data-bs-toggle="tab" href="#deposits">入款记录</a>
  151. </li>
  152. <li class="nav-item">
  153. <a class="nav-link" data-bs-toggle="tab" href="#withdrawals">下发记录</a>
  154. </li>
  155. </ul>
  156. </div>
  157. <div class="card-body">
  158. <div class="tab-content">
  159. <div class="tab-pane fade show active" id="deposits">
  160. <div class="table-responsive">
  161. <table class="table table-hover">
  162. <thead>
  163. <tr>
  164. <th>交易ID</th>
  165. <th>时间</th>
  166. <th>金额</th>
  167. <th>操作人</th>
  168. <th>回复人</th>
  169. </tr>
  170. </thead>
  171. <tbody id="depositsList">
  172. </tbody>
  173. </table>
  174. </div>
  175. <nav>
  176. <ul class="pagination justify-content-center" id="depositsPagination">
  177. </ul>
  178. </nav>
  179. </div>
  180. <div class="tab-pane fade" id="withdrawals">
  181. <div class="table-responsive">
  182. <table class="table table-hover">
  183. <thead>
  184. <tr>
  185. <th>交易ID</th>
  186. <th>时间</th>
  187. <th>金额</th>
  188. <th>操作人</th>
  189. <th>回复人</th>
  190. </tr>
  191. </thead>
  192. <tbody id="withdrawalsList">
  193. </tbody>
  194. </table>
  195. </div>
  196. <nav>
  197. <ul class="pagination justify-content-center" id="withdrawalsPagination">
  198. </ul>
  199. </nav>
  200. </div>
  201. </div>
  202. </div>
  203. </div>
  204. <div class="card">
  205. <div class="card-header">
  206. 账单总结
  207. </div>
  208. <div class="card-body">
  209. <table class="summary-table">
  210. <thead>
  211. <tr>
  212. <th>项目</th>
  213. <th>金额</th>
  214. <th>笔数</th>
  215. </tr>
  216. </thead>
  217. <tbody id="summaryTable">
  218. <tr>
  219. <td>总入款</td>
  220. <td id="totalDeposit">¥0.00</td>
  221. <td id="totalDepositCount">0</td>
  222. </tr>
  223. <tr>
  224. <td>入款费率</td>
  225. <td id="depositFeeRate">0%</td>
  226. <td>-</td>
  227. </tr>
  228. <tr>
  229. <td>应下发</td>
  230. <td id="shouldWithdraw">¥0.00</td>
  231. <td>-</td>
  232. </tr>
  233. <tr>
  234. <td>总下发</td>
  235. <td id="totalWithdraw">¥0.00</td>
  236. <td id="totalWithdrawCount">0</td>
  237. </tr>
  238. <tr>
  239. <td>下发费率</td>
  240. <td id="withdrawFeeRate">0%</td>
  241. <td>-</td>
  242. </tr>
  243. <tr>
  244. <td>下发单笔附加费</td>
  245. <td id="singleWithdrawFee">¥0.00</td>
  246. <td>-</td>
  247. </tr>
  248. <tr>
  249. <td>单笔附费加总计</td>
  250. <td id="totalWithdrawFee">¥0.00</td>
  251. <td>-</td>
  252. </tr>
  253. <tr>
  254. <td>余额</td>
  255. <td id="balance">¥0.00</td>
  256. <td>-</td>
  257. </tr>
  258. </tbody>
  259. </table>
  260. </div>
  261. </div>
  262. </div>
  263. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
  264. <script>
  265. let currentPage = 1;
  266. const pageSize = 10;
  267. // 获取URL参数
  268. function getUrlParams() {
  269. const params = new URLSearchParams(window.location.search);
  270. return {
  271. groupId: params.get('groupId')
  272. };
  273. }
  274. // 加载交易记录
  275. async function loadTransactions(page = 1) {
  276. try {
  277. const { groupId } = getUrlParams();
  278. if (!groupId) {
  279. alert('缺少群组ID参数');
  280. return;
  281. }
  282. console.log('正在加载数据,群组ID:', groupId);
  283. const response = await fetch(`/api/public/transactions?page=${page}&limit=${pageSize}&groupId=${groupId}`);
  284. console.log('API响应:', response);
  285. if (!response.ok) {
  286. const errorData = await response.json();
  287. throw new Error(errorData.message || '获取数据失败');
  288. }
  289. const data = await response.json();
  290. console.log('获取到的数据:', data);
  291. updateTransactionsList(data.transactions);
  292. updatePagination(data.total, page);
  293. updateStatistics(data.statistics);
  294. updateSummary(data.summary);
  295. } catch (error) {
  296. console.error('加载交易记录失败:', error);
  297. alert(error.message || '加载数据失败,请稍后重试');
  298. }
  299. }
  300. // 更新交易记录列表
  301. function updateTransactionsList(transactions) {
  302. const depositsList = document.getElementById('depositsList');
  303. const withdrawalsList = document.getElementById('withdrawalsList');
  304. if (!transactions || transactions.length === 0) {
  305. depositsList.innerHTML = '<tr><td colspan="5" class="text-center">暂无入款记录</td></tr>';
  306. withdrawalsList.innerHTML = '<tr><td colspan="5" class="text-center">暂无下发记录</td></tr>';
  307. return;
  308. }
  309. const deposits = transactions.filter(t => t.type === 'deposit');
  310. const withdrawals = transactions.filter(t => t.type === 'withdrawal');
  311. depositsList.innerHTML = deposits.length ? deposits.map(transaction => `
  312. <tr>
  313. <td>${transaction.id}</td>
  314. <td>${new Date(transaction.time).toLocaleString('zh-CN')}</td>
  315. <td class="text-success">¥${parseFloat(transaction.amount).toFixed(2)}</td>
  316. <td>${transaction.operator_id || '-'}</td>
  317. <td>${transaction.replier_id || '-'}</td>
  318. </tr>
  319. `).join('') : '<tr><td colspan="5" class="text-center">暂无入款记录</td></tr>';
  320. withdrawalsList.innerHTML = withdrawals.length ? withdrawals.map(transaction => `
  321. <tr>
  322. <td>${transaction.id}</td>
  323. <td>${new Date(transaction.time).toLocaleString('zh-CN')}</td>
  324. <td class="text-danger">¥${parseFloat(transaction.amount).toFixed(2)}</td>
  325. <td>${transaction.operator_id || '-'}</td>
  326. <td>${transaction.replier_id || '-'}</td>
  327. </tr>
  328. `).join('') : '<tr><td colspan="5" class="text-center">暂无下发记录</td></tr>';
  329. }
  330. // 更新分页
  331. function updatePagination(total, currentPage) {
  332. const totalPages = Math.ceil(total / pageSize);
  333. const pagination = document.getElementById('depositsPagination');
  334. const withdrawalsPagination = document.getElementById('withdrawalsPagination');
  335. let html = '';
  336. // 上一页
  337. html += `
  338. <li class="page-item ${currentPage === 1 ? 'disabled' : ''}">
  339. <a class="page-link" href="#" onclick="loadTransactions(${currentPage - 1})">上一页</a>
  340. </li>
  341. `;
  342. // 页码
  343. for (let i = 1; i <= totalPages; i++) {
  344. html += `
  345. <li class="page-item ${i === currentPage ? 'active' : ''}">
  346. <a class="page-link" href="#" onclick="loadTransactions(${i})">${i}</a>
  347. </li>
  348. `;
  349. }
  350. // 下一页
  351. html += `
  352. <li class="page-item ${currentPage === totalPages ? 'disabled' : ''}">
  353. <a class="page-link" href="#" onclick="loadTransactions(${currentPage + 1})">下一页</a>
  354. </li>
  355. `;
  356. pagination.innerHTML = html;
  357. withdrawalsPagination.innerHTML = html;
  358. }
  359. // 更新统计数据
  360. function updateStatistics(statistics) {
  361. if (!statistics) return;
  362. const formatAmount = (amount) => {
  363. return amount ? `¥${parseFloat(amount).toFixed(2)}` : '¥0.00';
  364. };
  365. document.getElementById('todayIncome').textContent = formatAmount(statistics.todayIncome);
  366. document.getElementById('monthlyIncome').textContent = formatAmount(statistics.monthlyIncome);
  367. document.getElementById('totalIncome').textContent = formatAmount(statistics.totalIncome);
  368. document.getElementById('todayOrders').textContent = statistics.todayOrders || 0;
  369. }
  370. // 更新总结表格
  371. function updateSummary(summary) {
  372. if (!summary) return;
  373. const formatAmount = (amount) => {
  374. return amount ? `¥${parseFloat(amount).toFixed(2)}` : '¥0.00';
  375. };
  376. document.getElementById('totalDeposit').textContent = formatAmount(summary.totalDeposit);
  377. document.getElementById('totalDepositCount').textContent = summary.depositCount || 0;
  378. document.getElementById('depositFeeRate').textContent = `${summary.depositFeeRate || 0}%`;
  379. document.getElementById('shouldWithdraw').textContent = formatAmount(summary.shouldWithdraw);
  380. document.getElementById('totalWithdraw').textContent = formatAmount(summary.totalWithdraw);
  381. document.getElementById('totalWithdrawCount').textContent = summary.withdrawCount || 0;
  382. document.getElementById('withdrawFeeRate').textContent = `${summary.withdrawFeeRate || 0}%`;
  383. document.getElementById('singleWithdrawFee').textContent = formatAmount(summary.singleWithdrawFee);
  384. document.getElementById('totalWithdrawFee').textContent = formatAmount(summary.totalWithdrawFee);
  385. document.getElementById('balance').textContent = formatAmount(summary.balance);
  386. }
  387. // 页面加载时加载数据
  388. loadTransactions();
  389. </script>
  390. </body>
  391. </html>