소스 검색

总额和下发不清零,0点重置不弹消息

Taio_O 2 주 전
부모
커밋
30cf49ef7a
1개의 변경된 파일27개의 추가작업 그리고 65개의 파일을 삭제
  1. 27 65
      admin/index.js

+ 27 - 65
admin/index.js

@@ -771,8 +771,21 @@ async function generateBillMessage(chatId) {
         const outFeeRate = parseFloat(groupInfo[0].out_fee_rate) || 0;
         const outExchangeRate = parseFloat(groupInfo[0].out_exchange_rate) || 0;
 
-        // 获取机器人加入后的交易记录
-        const [records] = await pool.query(`
+        // 获取当天的入款记录
+        const [todayRecords] = await pool.query(`
+            SELECT t.*, 
+                   COALESCE(t.fee_rate, g.in_fee_rate) as fee_rate,
+                   COALESCE(t.exchange_rate, g.in_exchange_rate) as exchange_rate
+            FROM transactions t
+            LEFT JOIN groups g ON t.group_id = g.group_id
+            WHERE t.group_id = ? 
+            AND DATE(t.time) = CURDATE()
+            AND t.type = 'deposit'
+            ORDER BY t.time DESC
+        `, [chatId.toString()]);
+
+        // 获取最新一条交易的累计数据
+        const [latestRecord] = await pool.query(`
             SELECT t.*, 
                    COALESCE(t.fee_rate, g.in_fee_rate) as fee_rate,
                    COALESCE(t.exchange_rate, g.in_exchange_rate) as exchange_rate,
@@ -785,41 +798,10 @@ async function generateBillMessage(chatId) {
             FROM transactions t
             LEFT JOIN groups g ON t.group_id = g.group_id
             WHERE t.group_id = ? 
-            AND DATE(t.time) = CURDATE()
             ORDER BY t.time DESC
+            LIMIT 1
         `, [chatId.toString()]);
 
-        if (!records || records.length === 0) {
-            console.log(`今日无交易记录 - 群组ID: ${chatId}`);
-            return '暂无交易记录';
-        }
-
-        console.log(`获取到交易记录数量: ${records.length}`);
-
-        // 将记录按类型分类:入款和下发
-        const deposits = records.filter(r => r.type === 'deposit');
-        const withdrawals = records.filter(r => r.type === 'withdrawal');
-
-        // 获取最新一条记录的总金额数据
-        const latestRecord = records[0];
-        console.log(`最新交易记录:`, latestRecord);
-
-        const totalDeposit = parseFloat(latestRecord.total_deposit) || 0;
-        const totalWithdrawal = parseFloat(latestRecord.total_withdrawal) || 0;
-        const depositFee = parseFloat(latestRecord.deposit_fee) || 0;
-        const withdrawalFee = parseFloat(latestRecord.withdrawal_fee) || 0;
-        const totalUDeposit = parseFloat(latestRecord.total_u_deposit) || 0;
-        const totalUWithdrawal = parseFloat(latestRecord.total_u_withdrawal) || 0;
-
-        console.log(`金额数据:`, {
-            totalDeposit,
-            totalWithdrawal,
-            depositFee,
-            withdrawalFee,
-            totalUDeposit,
-            totalUWithdrawal
-        });
-
         // 获取当前日期
         const today = new Date();
         const version = 'v29';
@@ -827,10 +809,10 @@ async function generateBillMessage(chatId) {
 
         let message = `当前版本:<b>${dateStr}:${version}</b>\n\n`;
 
-        // 添加入款记录
-        if (deposits.length > 0) {
-            message += `<b>入款笔数</b>:<code>${deposits.length}</code>\n`;
-            deposits.forEach(deposit => {
+        // 添加入款记录(只显示当天的)
+        if (todayRecords && todayRecords.length > 0) {
+            message += `<b>入款笔数</b>:<code>${todayRecords.length}</code>\n`;
+            todayRecords.forEach(deposit => {
                 message += `<code>${moment(deposit.time).format('HH:mm:ss')} ${parseFloat(deposit.amount).toFixed(2)}</code>\n`;
             });
             message += '\n';
@@ -838,29 +820,19 @@ async function generateBillMessage(chatId) {
             message += `<b>入款笔数</b>:<code>0</code>\n\n`;
         }
 
-        // // 添加出款记录
-        // if (withdrawals.length > 0) {
-        //     message += `<b>出款笔数</b>:<code>${withdrawals.length}</code>\n`;
-        //     withdrawals.forEach(withdrawal => {
-        //         message += `<code>${moment(withdrawal.time).format('HH:mm:ss')} ${parseFloat(withdrawal.amount).toFixed(2)}</code>\n`;
-        //     });
-        //     message += '\n';
-        // } else {
-        //     message += `<b>出款笔数</b>:<code>0</code>\n\n`;
-        // }
-
         // 添加费率信息
         message += `<b>入款费率</b>:<code>${inFeeRate}%</code>\n`;
         message += `<b>入款汇率</b>:<code>${inExchangeRate}</code>\n`;
+        
+        // 使用最新一条交易的累计数据
+        const totalDeposit = parseFloat(latestRecord[0]?.total_deposit) || 0;
+        const totalUDeposit = parseFloat(latestRecord[0]?.total_u_deposit) || 0;
+        const totalUWithdrawal = parseFloat(latestRecord[0]?.total_u_withdrawal) || 0;
+
         message += `<b>入款总额</b>:<code>${totalDeposit.toFixed(2)}</code>\n`;
         message += `<b>入款合计</b>:<code>${totalDeposit.toFixed(2)}|${totalUDeposit.toFixed(2)}U</code>\n\n`;
 
-        // message += `<b>出款费率</b>:<code>${outFeeRate}%</code>\n`;
-        // message += `<b>出款汇率</b>:<code>${outExchangeRate}</code>\n`;
-        // message += `<b>出款总额</b>:<code>${totalWithdrawal.toFixed(2)}</code>\n`;
-        // message += `<b>出款合计</b>:<code>${(totalWithdrawal - withdrawalFee).toFixed(2)}|${totalUWithdrawal.toFixed(2)}U</code>\n\n`;
-
-        // 添加余额信息
+        // 添加余额信息(使用最新一条交易的累计数据)
         const remainingAmount = totalUDeposit - totalUWithdrawal;
         message += `<b>应下发</b>:<code>${(remainingAmount < 0 ? 0 : remainingAmount).toFixed(2)}U</code>\n`;
         message += `<b>已下发</b>:<code>${totalUWithdrawal.toFixed(2)}U</code>\n`;
@@ -1063,16 +1035,6 @@ testConnection().then(() => {
             `);
             
             console.log('每日重置完成 - 时间:', new Date().toLocaleString());
-            
-            // 向所有群组发送重置通知
-            const [groups] = await pool.query('SELECT group_id FROM groups');
-            for (const group of groups) {
-                try {
-                    await sendMessage(group.group_id, '⚠️ 系统已重置\n\n请重新设置费率和汇率后继续使用。\n\n使用以下命令设置:\n• 设置费率数字\n• 设置汇率数字');
-                } catch (error) {
-                    console.error(`发送重置通知失败 - 群组ID: ${group.group_id}`, error);
-                }
-            }
         } catch (error) {
             console.error('每日重置失败:', error);
         }