statistics_bill.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. <th>操作人</th>
  170. <th>回复人</th>
  171. </tr>
  172. </thead>
  173. <tbody id="depositsList">
  174. </tbody>
  175. </table>
  176. </div>
  177. <nav>
  178. <ul class="pagination justify-content-center" id="depositsPagination">
  179. </ul>
  180. </nav>
  181. </div>
  182. <div class="tab-pane fade" id="withdrawals">
  183. <div class="table-responsive">
  184. <table class="table table-hover">
  185. <thead>
  186. <tr>
  187. <th>交易ID</th>
  188. <th>时间</th>
  189. <th>金额</th>
  190. <th>费率</th>
  191. <th>汇率</th>
  192. <th>操作人</th>
  193. <th>回复人</th>
  194. </tr>
  195. </thead>
  196. <tbody id="withdrawalsList">
  197. </tbody>
  198. </table>
  199. </div>
  200. <nav>
  201. <ul class="pagination justify-content-center" id="withdrawalsPagination">
  202. </ul>
  203. </nav>
  204. </div>
  205. </div>
  206. </div>
  207. </div>
  208. <div class="card">
  209. <div class="card-header">
  210. 账单总结
  211. </div>
  212. <div class="card-body">
  213. <table class="summary-table">
  214. <thead>
  215. <tr>
  216. <th>项目</th>
  217. <th>金额</th>
  218. <th>笔数</th>
  219. </tr>
  220. </thead>
  221. <tbody id="summaryTable">
  222. <tr>
  223. <td>总入款</td>
  224. <td id="totalDeposit">¥0.00</td>
  225. <td id="totalDepositCount">0</td>
  226. </tr>
  227. <tr>
  228. <td>入款费率</td>
  229. <td id="depositFeeRate">0%</td>
  230. <td>-</td>
  231. </tr>
  232. <tr>
  233. <td>应下发</td>
  234. <td id="shouldWithdraw">¥0.00</td>
  235. <td>-</td>
  236. </tr>
  237. <tr>
  238. <td>总下发</td>
  239. <td id="totalWithdraw">¥0.00</td>
  240. <td id="totalWithdrawCount">0</td>
  241. </tr>
  242. <tr>
  243. <td>下发费率</td>
  244. <td id="withdrawFeeRate">0%</td>
  245. <td>-</td>
  246. </tr>
  247. <tr>
  248. <td>下发单笔附加费</td>
  249. <td id="singleWithdrawFee">¥0.00</td>
  250. <td>-</td>
  251. </tr>
  252. <tr>
  253. <td>单笔附费加总计</td>
  254. <td id="totalWithdrawFee">¥0.00</td>
  255. <td>-</td>
  256. </tr>
  257. <tr>
  258. <td>余额</td>
  259. <td id="balance">¥0.00</td>
  260. <td>-</td>
  261. </tr>
  262. </tbody>
  263. </table>
  264. </div>
  265. </div>
  266. </div>
  267. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
  268. <script>
  269. let currentPage = 1;
  270. const pageSize = 10;
  271. // 获取URL参数
  272. function getUrlParams() {
  273. const params = new URLSearchParams(window.location.search);
  274. return {
  275. groupId: params.get('groupId')
  276. };
  277. }
  278. // 加载交易记录
  279. async function loadTransactions(page = 1) {
  280. try {
  281. const { groupId } = getUrlParams();
  282. if (!groupId) {
  283. alert('缺少群组ID参数');
  284. return;
  285. }
  286. console.log('正在加载数据,群组ID:', groupId);
  287. const response = await fetch(`/api/public/transactions?page=${page}&limit=${pageSize}&groupId=${groupId}`);
  288. console.log('API响应:', response);
  289. if (!response.ok) {
  290. const errorData = await response.json();
  291. throw new Error(errorData.message || '获取数据失败');
  292. }
  293. const data = await response.json();
  294. console.log('获取到的数据:', data);
  295. updateTransactionsList(data.transactions);
  296. updatePagination(data.total, page);
  297. updateStatistics(data.statistics);
  298. updateSummary(data.summary);
  299. } catch (error) {
  300. console.error('加载交易记录失败:', error);
  301. alert(error.message || '加载数据失败,请稍后重试');
  302. }
  303. }
  304. // 更新交易记录列表
  305. function updateTransactionsList(transactions) {
  306. const depositsList = document.getElementById('depositsList');
  307. const withdrawalsList = document.getElementById('withdrawalsList');
  308. if (!transactions || transactions.length === 0) {
  309. depositsList.innerHTML = '<tr><td colspan="7" class="text-center">暂无入款记录</td></tr>';
  310. withdrawalsList.innerHTML = '<tr><td colspan="7" class="text-center">暂无下发记录</td></tr>';
  311. return;
  312. }
  313. const deposits = transactions.filter(t => t.type === 'deposit');
  314. const withdrawals = transactions.filter(t => t.type === 'withdrawal');
  315. depositsList.innerHTML = deposits.length ? deposits.map(transaction => `
  316. <tr>
  317. <td>${transaction.id}</td>
  318. <td>${new Date(transaction.time).toLocaleString('zh-CN')}</td>
  319. <td class="text-success">¥${parseFloat(transaction.amount).toFixed(2)}</td>
  320. <td>${transaction.fee_rate ? transaction.fee_rate + '%' : '-'}</td>
  321. <td>${transaction.exchange_rate ? Number(transaction.exchange_rate).toFixed(4) : '-'}</td>
  322. <td>${transaction.operator_id || '-'}</td>
  323. <td>${transaction.replier_id || '-'}</td>
  324. </tr>
  325. `).join('') : '<tr><td colspan="7" class="text-center">暂无入款记录</td></tr>';
  326. withdrawalsList.innerHTML = withdrawals.length ? withdrawals.map(transaction => `
  327. <tr>
  328. <td>${transaction.id}</td>
  329. <td>${new Date(transaction.time).toLocaleString('zh-CN')}</td>
  330. <td class="text-danger">¥${parseFloat(transaction.amount).toFixed(2)}</td>
  331. <td>${transaction.fee_rate ? transaction.fee_rate + '%' : '-'}</td>
  332. <td>${transaction.exchange_rate ? Number(transaction.exchange_rate).toFixed(4) : '-'}</td>
  333. <td>${transaction.operator_id || '-'}</td>
  334. <td>${transaction.replier_id || '-'}</td>
  335. </tr>
  336. `).join('') : '<tr><td colspan="7" class="text-center">暂无下发记录</td></tr>';
  337. }
  338. // 更新分页
  339. function updatePagination(total, currentPage) {
  340. const totalPages = Math.ceil(total / pageSize);
  341. const pagination = document.getElementById('depositsPagination');
  342. const withdrawalsPagination = document.getElementById('withdrawalsPagination');
  343. let html = '';
  344. // 上一页
  345. html += `
  346. <li class="page-item ${currentPage === 1 ? 'disabled' : ''}">
  347. <a class="page-link" href="#" onclick="loadTransactions(${currentPage - 1})">上一页</a>
  348. </li>
  349. `;
  350. // 页码
  351. for (let i = 1; i <= totalPages; i++) {
  352. html += `
  353. <li class="page-item ${i === currentPage ? 'active' : ''}">
  354. <a class="page-link" href="#" onclick="loadTransactions(${i})">${i}</a>
  355. </li>
  356. `;
  357. }
  358. // 下一页
  359. html += `
  360. <li class="page-item ${currentPage === totalPages ? 'disabled' : ''}">
  361. <a class="page-link" href="#" onclick="loadTransactions(${currentPage + 1})">下一页</a>
  362. </li>
  363. `;
  364. pagination.innerHTML = html;
  365. withdrawalsPagination.innerHTML = html;
  366. }
  367. // 更新统计数据
  368. function updateStatistics(statistics) {
  369. if (!statistics) return;
  370. const formatAmount = (amount) => {
  371. return amount ? `¥${parseFloat(amount).toFixed(2)}` : '¥0.00';
  372. };
  373. document.getElementById('todayIncome').textContent = formatAmount(statistics.todayIncome);
  374. document.getElementById('monthlyIncome').textContent = formatAmount(statistics.monthlyIncome);
  375. document.getElementById('totalIncome').textContent = formatAmount(statistics.totalIncome);
  376. document.getElementById('todayOrders').textContent = statistics.todayOrders || 0;
  377. }
  378. // 更新总结表格
  379. function updateSummary(summary) {
  380. if (!summary) return;
  381. const formatAmount = (amount) => {
  382. return amount ? `¥${parseFloat(amount).toFixed(2)}` : '¥0.00';
  383. };
  384. document.getElementById('totalDeposit').textContent = formatAmount(summary.totalDeposit);
  385. document.getElementById('totalDepositCount').textContent = summary.depositCount || 0;
  386. document.getElementById('depositFeeRate').textContent = `${summary.depositFeeRate || 0}%`;
  387. document.getElementById('shouldWithdraw').textContent = formatAmount(summary.shouldWithdraw);
  388. document.getElementById('totalWithdraw').textContent = formatAmount(summary.totalWithdraw);
  389. document.getElementById('totalWithdrawCount').textContent = summary.withdrawCount || 0;
  390. document.getElementById('withdrawFeeRate').textContent = `${summary.withdrawFeeRate || 0}%`;
  391. document.getElementById('singleWithdrawFee').textContent = formatAmount(summary.singleWithdrawFee);
  392. document.getElementById('totalWithdrawFee').textContent = formatAmount(summary.totalWithdrawFee);
  393. document.getElementById('balance').textContent = formatAmount(summary.balance);
  394. }
  395. // 页面加载时加载数据
  396. loadTransactions();
  397. </script>
  398. </body>
  399. </html>