|
@@ -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);
|