Browse Source

单页面仅显示今日账单

Taio_O 3 weeks ago
parent
commit
be59becb2e
2 changed files with 66 additions and 53 deletions
  1. 18 17
      admin/routes/public.js
  2. 48 36
      admin/views/statistics_bill.html

+ 18 - 17
admin/routes/public.js

@@ -1,6 +1,7 @@
 const express = require('express');
 const router = express.Router();
 const Transaction = require('../models/Transaction');
+const Group = require('../models/Group');
 
 // 获取群组交易记录(不需要认证)
 router.get('/transactions', async (req, res) => {
@@ -73,8 +74,18 @@ router.get('/transactions', async (req, res) => {
         );
         const todayOrders = todayOrdersResult.transactions.length;
 
-        // 计算总结数据
+        // 获取群组信息(包含费率和汇率)
+        const groupInfo = await Group.findByGroupId(groupId.toString());
+        if (!groupInfo) {
+            return res.status(404).json({ message: '群组不存在' });
+        }
+
+        // 计算入款相关数据
         const depositCount = totalResult.transactions.length;
+        const depositFeeRate = parseFloat(groupInfo.in_fee_rate) || 0;
+        const depositExchangeRate = parseFloat(groupInfo.in_exchange_rate) || 1;
+
+        // 计算出款相关数据
         const withdrawResult = await Transaction.findAll(
             { 
                 groupId: groupId.toString(),
@@ -85,20 +96,11 @@ router.get('/transactions', async (req, res) => {
         );
         const withdrawCount = withdrawResult.transactions.length;
         const totalWithdraw = withdrawResult.transactions.reduce((sum, t) => sum + parseFloat(t.amount), 0);
+        const withdrawFeeRate = parseFloat(groupInfo.out_fee_rate) || 0;
+        const withdrawExchangeRate = parseFloat(groupInfo.out_exchange_rate) || 1;
 
-        // 计算费率(示例:入款费率1%,下发费率0.5%)
-        const depositFeeRate = 1;
-        const withdrawFeeRate = 0.5;
-        const singleWithdrawFee = 1; // 单笔附加费1元
-
-        // 计算应下发金额(入款总额 * (1 - 入款费率))
-        const shouldWithdraw = totalIncome * (1 - depositFeeRate / 100);
-
-        // 计算下发附加费总额
-        const totalWithdrawFee = withdrawCount * singleWithdrawFee;
-
-        // 计算余额(应下发 - 总下发 - 下发附加费总额)
-        const balance = shouldWithdraw - totalWithdraw - totalWithdrawFee;
+        // 计算余额
+        const balance = totalIncome - totalWithdraw;
 
         res.json({
             transactions: result.transactions,
@@ -113,12 +115,11 @@ router.get('/transactions', async (req, res) => {
                 totalDeposit: totalIncome,
                 depositCount,
                 depositFeeRate,
-                shouldWithdraw,
+                depositExchangeRate,
                 totalWithdraw,
                 withdrawCount,
                 withdrawFeeRate,
-                singleWithdrawFee,
-                totalWithdrawFee,
+                withdrawExchangeRate,
                 balance
             }
         });

+ 48 - 36
admin/views/statistics_bill.html

@@ -117,25 +117,13 @@
 <body>
     <div class="container">
         <div class="row">
-            <div class="col-md-3">
+            <div class="col-md-6">
                 <div class="stat-card">
                     <div class="title">今日收入</div>
                     <div class="value" id="todayIncome">¥0.00</div>
                 </div>
             </div>
-            <div class="col-md-3">
-                <div class="stat-card">
-                    <div class="title">本月收入</div>
-                    <div class="value" id="monthlyIncome">¥0.00</div>
-                </div>
-            </div>
-            <div class="col-md-3">
-                <div class="stat-card">
-                    <div class="title">总收入</div>
-                    <div class="value" id="totalIncome">¥0.00</div>
-                </div>
-            </div>
-            <div class="col-md-3">
+            <div class="col-md-6">
                 <div class="stat-card">
                     <div class="title">今日订单数</div>
                     <div class="value" id="todayOrders">0</div>
@@ -232,8 +220,8 @@
                             <td>-</td>
                         </tr>
                         <tr>
-                            <td>应下发</td>
-                            <td id="shouldWithdraw">¥0.00</td>
+                            <td>入款汇率</td>
+                            <td id="depositExchangeRate">1.0000</td>
                             <td>-</td>
                         </tr>
                         <tr>
@@ -247,13 +235,8 @@
                             <td>-</td>
                         </tr>
                         <tr>
-                            <td>下发单笔附加费</td>
-                            <td id="singleWithdrawFee">¥0.00</td>
-                            <td>-</td>
-                        </tr>
-                        <tr>
-                            <td>单笔附费加总计</td>
-                            <td id="totalWithdrawFee">¥0.00</td>
+                            <td>下发汇率</td>
+                            <td id="withdrawExchangeRate">1.0000</td>
                             <td>-</td>
                         </tr>
                         <tr>
@@ -289,8 +272,20 @@
                     return;
                 }
 
-                console.log('正在加载数据,群组ID:', groupId);
-                const response = await fetch(`/api/public/transactions?page=${page}&limit=${pageSize}&groupId=${groupId}`);
+                // 获取今天的日期(考虑时区)
+                const today = new Date();
+                const year = today.getFullYear();
+                const month = String(today.getMonth() + 1).padStart(2, '0');
+                const day = String(today.getDate()).padStart(2, '0');
+                const startDate = `${year}-${month}-${day}`;
+                const endDate = startDate;
+
+                console.log('日期范围:', { startDate, endDate });
+
+                const url = `/api/public/transactions?page=${page}&limit=${pageSize}&groupId=${groupId}&startDate=${startDate}&endDate=${endDate}`;
+                console.log('请求URL:', url);
+
+                const response = await fetch(url);
                 console.log('API响应:', response);
                 
                 if (!response.ok) {
@@ -301,9 +296,29 @@
                 const data = await response.json();
                 console.log('获取到的数据:', data);
                 
-                updateTransactionsList(data.transactions);
-                updatePagination(data.total, page);
-                updateStatistics(data.statistics);
+                // 过滤掉非今天的记录
+                const todayTransactions = data.transactions.filter(transaction => {
+                    const transactionDate = new Date(transaction.time).toISOString().split('T')[0];
+                    return transactionDate === startDate;
+                });
+                
+                // 计算今日收入
+                const todayIncome = todayTransactions.reduce((sum, transaction) => {
+                    if (transaction.type === 'deposit') {
+                        return sum + parseFloat(transaction.amount);
+                    }
+                    return sum;
+                }, 0);
+
+                // 更新统计数据
+                const statistics = {
+                    todayIncome: todayIncome,
+                    todayOrders: todayTransactions.length
+                };
+                
+                updateTransactionsList(todayTransactions);
+                updatePagination(todayTransactions.length, page);
+                updateStatistics(statistics);
                 updateSummary(data.summary);
             } catch (error) {
                 console.error('加载交易记录失败:', error);
@@ -361,7 +376,7 @@
             // 上一页
             html += `
                 <li class="page-item ${currentPage === 1 ? 'disabled' : ''}">
-                    <a class="page-link" href="#" onclick="loadTransactions(${currentPage - 1})">上一页</a>
+                    <a class="page-link" href="#" onclick="event.preventDefault(); loadTransactions(${currentPage - 1})">上一页</a>
                 </li>
             `;
             
@@ -369,7 +384,7 @@
             for (let i = 1; i <= totalPages; i++) {
                 html += `
                     <li class="page-item ${i === currentPage ? 'active' : ''}">
-                        <a class="page-link" href="#" onclick="loadTransactions(${i})">${i}</a>
+                        <a class="page-link" href="#" onclick="event.preventDefault(); loadTransactions(${i})">${i}</a>
                     </li>
                 `;
             }
@@ -377,7 +392,7 @@
             // 下一页
             html += `
                 <li class="page-item ${currentPage === totalPages ? 'disabled' : ''}">
-                    <a class="page-link" href="#" onclick="loadTransactions(${currentPage + 1})">下一页</a>
+                    <a class="page-link" href="#" onclick="event.preventDefault(); loadTransactions(${currentPage + 1})">下一页</a>
                 </li>
             `;
             
@@ -394,8 +409,6 @@
             };
             
             document.getElementById('todayIncome').textContent = formatAmount(statistics.todayIncome);
-            document.getElementById('monthlyIncome').textContent = formatAmount(statistics.monthlyIncome);
-            document.getElementById('totalIncome').textContent = formatAmount(statistics.totalIncome);
             document.getElementById('todayOrders').textContent = statistics.todayOrders || 0;
         }
 
@@ -410,12 +423,11 @@
             document.getElementById('totalDeposit').textContent = formatAmount(summary.totalDeposit);
             document.getElementById('totalDepositCount').textContent = summary.depositCount || 0;
             document.getElementById('depositFeeRate').textContent = `${summary.depositFeeRate || 0}%`;
-            document.getElementById('shouldWithdraw').textContent = formatAmount(summary.shouldWithdraw);
+            document.getElementById('depositExchangeRate').textContent = `${summary.depositExchangeRate || 0}`;
             document.getElementById('totalWithdraw').textContent = formatAmount(summary.totalWithdraw);
             document.getElementById('totalWithdrawCount').textContent = summary.withdrawCount || 0;
             document.getElementById('withdrawFeeRate').textContent = `${summary.withdrawFeeRate || 0}%`;
-            document.getElementById('singleWithdrawFee').textContent = formatAmount(summary.singleWithdrawFee);
-            document.getElementById('totalWithdrawFee').textContent = formatAmount(summary.totalWithdrawFee);
+            document.getElementById('withdrawExchangeRate').textContent = `${summary.withdrawExchangeRate || 0}`;
             document.getElementById('balance').textContent = formatAmount(summary.balance);
         }