statistics_bill.html 17 KB

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