Taio_O 1 ماه پیش
والد
کامیت
8cb8ab7795
4فایلهای تغییر یافته به همراه98 افزوده شده و 63 حذف شده
  1. 68 43
      admin/models/Transaction.js
  2. 19 15
      admin/views/dashboard.html
  3. 9 4
      admin/views/transactions.html
  4. 2 1
      admin/数据文件路径

+ 68 - 43
admin/models/Transaction.js

@@ -86,11 +86,11 @@ const Transaction = {
             const params = [];
 
             if (query.startDate) {
-                sql += ' AND t.time >= ?';
+                sql += ' AND DATE(t.time) >= ?';
                 params.push(query.startDate);
             }
             if (query.endDate) {
-                sql += ' AND t.time <= ?';
+                sql += ' AND DATE(t.time) <= ?';
                 params.push(query.endDate);
             }
             if (query.type) {
@@ -110,14 +110,15 @@ const Transaction = {
                 SELECT COUNT(*) as total 
                 FROM transactions t
                 WHERE 1=1
-                ${query.startDate ? 'AND t.time >= ?' : ''}
-                ${query.endDate ? 'AND t.time <= ?' : ''}
+                ${query.startDate ? 'AND DATE(t.time) >= ?' : ''}
+                ${query.endDate ? 'AND DATE(t.time) <= ?' : ''}
                 ${query.type ? 'AND t.type = ?' : ''}
                 ${query.groupId ? 'AND t.group_id = ?' : ''}
             `;
             
             const [countResult] = await pool.query(countSql, params);
             const total = countResult[0]?.total || 0;
+            console.log('查询总数:', total);
 
             // 获取分页数据
             sql += ' ORDER BY t.time DESC LIMIT ? OFFSET ?';
@@ -125,6 +126,7 @@ const Transaction = {
 
             const [rows] = await pool.query(sql, params);
             console.log('查询结果数量:', rows.length);
+            console.log('查询结果:', rows);
 
             return {
                 transactions: rows,
@@ -161,21 +163,30 @@ const Transaction = {
 
     // 获取仪表板数据
     getDashboardData: async () => {
-        const today = new Date();
-        today.setHours(0, 0, 0, 0);
-
-        const [
-            totalGroups,
-            totalTransactions,
-            totalAmount,
-            todayTransactions,
-            recentTransactions
-        ] = await Promise.all([
-            pool.query('SELECT COUNT(*) as count FROM groups').then(([rows]) => rows[0].count),
-            pool.query('SELECT COUNT(*) as count FROM transactions').then(([rows]) => rows[0].count),
-            pool.query('SELECT SUM(amount) as total FROM transactions').then(([rows]) => rows[0].total || 0),
-            pool.query('SELECT COUNT(*) as count FROM transactions WHERE time >= ?', [today]).then(([rows]) => rows[0].count),
-            pool.query(`
+        try {
+            const today = new Date();
+            today.setHours(0, 0, 0, 0);
+
+            // 获取总群组数
+            const [totalGroupsResult] = await pool.query('SELECT COUNT(*) as count FROM groups');
+            const totalGroups = totalGroupsResult[0].count;
+
+            // 获取总交易数
+            const [totalTransactionsResult] = await pool.query('SELECT COUNT(*) as count FROM transactions');
+            const totalTransactions = totalTransactionsResult[0].count;
+
+            // 获取总金额
+            const [totalAmountResult] = await pool.query('SELECT SUM(amount) as total FROM transactions');
+            const totalAmount = totalAmountResult[0].total || 0;
+
+            // 获取今日交易数
+            const [todayTransactionsResult] = await pool.query(
+                'SELECT COUNT(*) as count FROM transactions WHERE DATE(time) = CURDATE()'
+            );
+            const todayTransactions = todayTransactionsResult[0].count;
+
+            // 获取最近交易
+            const [recentTransactions] = await pool.query(`
                 SELECT 
                     t.*,
                     u.username as operator_name
@@ -183,30 +194,42 @@ const Transaction = {
                 LEFT JOIN users u ON t.operator_id = u.id
                 ORDER BY t.time DESC 
                 LIMIT 5
-            `).then(([rows]) => rows)
-        ]);
+            `);
 
-        // 获取活跃群组
-        const [activeGroups] = await pool.query(`
-            SELECT 
-                g.group_name as name,
-                COUNT(t.id) as totalTransactions,
-                SUM(CASE WHEN t.time >= ? THEN 1 ELSE 0 END) as todayTransactions
-            FROM groups g
-            LEFT JOIN transactions t ON g.group_id = t.group_id
-            GROUP BY g.id
-            ORDER BY todayTransactions DESC
-            LIMIT 5
-        `, [today]);
+            // 获取活跃群组
+            const [activeGroups] = await pool.query(`
+                SELECT 
+                    g.group_name as name,
+                    COUNT(t.id) as totalTransactions,
+                    SUM(CASE WHEN DATE(t.time) = CURDATE() THEN 1 ELSE 0 END) as todayTransactions
+                FROM groups g
+                LEFT JOIN transactions t ON g.group_id = t.group_id
+                GROUP BY g.id, g.group_name
+                ORDER BY todayTransactions DESC, totalTransactions DESC
+                LIMIT 5
+            `);
 
-        return {
-            totalGroups,
-            totalTransactions,
-            totalAmount,
-            todayTransactions,
-            recentTransactions,
-            activeGroups
-        };
+            console.log('仪表板数据:', {
+                totalGroups,
+                totalTransactions,
+                totalAmount,
+                todayTransactions,
+                recentTransactions,
+                activeGroups
+            });
+
+            return {
+                totalGroups,
+                totalTransactions,
+                totalAmount,
+                todayTransactions,
+                recentTransactions,
+                activeGroups
+            };
+        } catch (error) {
+            console.error('获取仪表板数据失败:', error);
+            throw error;
+        }
     },
 
     // 入款方法
@@ -216,7 +239,8 @@ const Transaction = {
                 groupId: transactionData.groupId,
                 groupName: transactionData.groupName,
                 type: 'deposit',
-                amount: parseFloat(transactionData.amount)
+                amount: parseFloat(transactionData.amount),
+                operatorId: transactionData.operatorId || 1  // 添加默认操作者ID
             });
 
             const transaction = await Transaction.findById(id);
@@ -248,7 +272,8 @@ const Transaction = {
                 groupId: transactionData.groupId,
                 groupName: transactionData.groupName,
                 type: 'withdrawal',
-                amount: parseFloat(transactionData.amount)
+                amount: parseFloat(transactionData.amount),
+                operatorId: transactionData.operatorId || 1  // 添加默认操作者ID
             });
 
             const transaction = await Transaction.findById(id);

+ 19 - 15
admin/views/dashboard.html

@@ -251,30 +251,34 @@
 
         // 更新仪表板统计数据
         function updateDashboardStats(data) {
-            document.getElementById('totalGroups').textContent = data.totalGroups;
-            document.getElementById('totalTransactions').textContent = data.totalTransactions;
-            document.getElementById('totalAmount').textContent = `¥${data.totalAmount.toFixed(2)}`;
-            document.getElementById('todayTransactions').textContent = data.todayTransactions;
+            document.getElementById('totalGroups').textContent = data.totalGroups || 0;
+            document.getElementById('totalTransactions').textContent = data.totalTransactions || 0;
+            document.getElementById('totalAmount').textContent = `¥${(data.totalAmount || 0).toFixed(2)}`;
+            document.getElementById('todayTransactions').textContent = data.todayTransactions || 0;
 
             // 更新最近交易
-            const recentTransactionsHtml = data.recentTransactions.map(t => `
+            const recentTransactionsHtml = (data.recentTransactions || []).map(t => `
                 <tr>
-                    <td>${new Date(t.time).toLocaleString()}</td>
-                    <td>${t.type === 'deposit' ? '入款' : '下发'}</td>
-                    <td>¥${t.amount.toFixed(2)}</td>
-                    <td>${t.groupName}</td>
+                    <td>${new Date(t.time).toLocaleString('zh-CN')}</td>
+                    <td>
+                        <span class="badge ${t.type === 'deposit' ? 'bg-success' : 'bg-danger'}">
+                            ${t.type === 'deposit' ? '入款' : '出款'}
+                        </span>
+                    </td>
+                    <td>¥${parseFloat(t.amount).toFixed(2)}</td>
+                    <td>${t.group_name || '-'}</td>
                 </tr>
-            `).join('');
+            `).join('') || '<tr><td colspan="4" class="text-center">暂无数据</td></tr>';
             document.getElementById('recentTransactions').innerHTML = recentTransactionsHtml;
 
             // 更新活跃群组
-            const activeGroupsHtml = data.activeGroups.map(g => `
+            const activeGroupsHtml = (data.activeGroups || []).map(g => `
                 <tr>
-                    <td>${g.name}</td>
-                    <td>${g.todayTransactions}</td>
-                    <td>${g.totalTransactions}</td>
+                    <td>${g.name || '-'}</td>
+                    <td>${g.todayTransactions || 0}</td>
+                    <td>${g.totalTransactions || 0}</td>
                 </tr>
-            `).join('');
+            `).join('') || '<tr><td colspan="3" class="text-center">暂无数据</td></tr>';
             document.getElementById('activeGroups').innerHTML = activeGroupsHtml;
         }
 

+ 9 - 4
admin/views/transactions.html

@@ -325,20 +325,25 @@
         // 更新交易记录列表
         function updateTransactionsList(transactions) {
             const transactionsList = document.getElementById('transactionsList');
+            if (!transactions || transactions.length === 0) {
+                transactionsList.innerHTML = '<tr><td colspan="7" class="text-center">暂无数据</td></tr>';
+                return;
+            }
+            
             transactionsList.innerHTML = transactions.map(transaction => `
                 <tr>
-                    <td>${new Date(transaction.time).toLocaleString()}</td>
-                    <td>${transaction.group_name}</td>
+                    <td>${new Date(transaction.time).toLocaleString('zh-CN')}</td>
+                    <td>${transaction.group_name || '-'}</td>
                     <td>
                         <span class="badge ${transaction.type === 'deposit' ? 'bg-success' : 'bg-danger'}">
                             ${transaction.type === 'deposit' ? '入款' : '出款'}
                         </span>
                     </td>
-                    <td>¥${transaction.amount.toFixed(2)}</td>
+                    <td>¥${parseFloat(transaction.amount).toFixed(2)}</td>
                     <td>${transaction.operator_name || '-'}</td>
                     <td>${transaction.remark || '-'}</td>
                     <td>
-                        <button class="btn btn-sm btn-danger" onclick="deleteTransaction('${transaction.id}')">
+                        <button class="btn btn-sm btn-danger" onclick="deleteTransaction(${transaction.id})">
                             <i class="bi bi-trash"></i>
                         </button>
                     </td>

+ 2 - 1
admin/数据文件路径

@@ -17,6 +17,7 @@
   "lastUpdate": "2025-05-07T03:00:11.021Z",
   "allowedGroups": [
     "4754375683",
-    "-4757139029"
+    "-4757139029",
+    "-4754375683"
   ]
 }