Forráskód Böngészése

总金额数据计算

Taio_O 1 hónapja
szülő
commit
a5bdf3b2d3
3 módosított fájl, 46 hozzáadás és 26 törlés
  1. 6 6
      admin/config/initDb.js
  2. 33 13
      admin/index.js
  3. 7 7
      admin/models/Transaction.js

+ 6 - 6
admin/config/initDb.js

@@ -71,12 +71,12 @@ async function initDatabase() {
                 status ENUM('pending', 'approved', 'rejected') DEFAULT 'pending' COMMENT '状态',
                 fee_rate DECIMAL(5,2) DEFAULT NULL COMMENT '费率',
                 exchange_rate DECIMAL(10,4) DEFAULT NULL COMMENT '汇率',
-                total_deposit DECIMAL(10,2) DEFAULT 0 COMMENT '总入款人民币金额',
-                total_withdrawal DECIMAL(10,2) DEFAULT 0 COMMENT '总下发人民币金额',
-                deposit_fee DECIMAL(10,2) DEFAULT 0 COMMENT '入款手续费',
-                withdrawal_fee DECIMAL(10,2) DEFAULT 0 COMMENT '下发手续费',
-                total_u_deposit DECIMAL(10,2) DEFAULT 0 COMMENT '总入款usdt金额',
-                total_u_withdrawal DECIMAL(10,2) DEFAULT 0 COMMENT '总下发usdt金额',
+                totalDeposit DECIMAL(10,2) DEFAULT 0 COMMENT '总入款人民币金额',
+                totalWithdrawal DECIMAL(10,2) DEFAULT 0 COMMENT '总下发人民币金额',
+                depositFee DECIMAL(10,2) DEFAULT 0 COMMENT '入款手续费',
+                withdrawalFee DECIMAL(10,2) DEFAULT 0 COMMENT '下发手续费',
+                totalUDeposit DECIMAL(10,2) DEFAULT 0 COMMENT '总入款usdt金额',
+                totalUWithdrawal DECIMAL(10,2) DEFAULT 0 COMMENT '总下发usdt金额',
                 FOREIGN KEY (operator_id) REFERENCES users(id),
                 FOREIGN KEY (responder_id) REFERENCES users(id),
                 FOREIGN KEY (group_id) REFERENCES groups(group_id),

+ 33 - 13
admin/index.js

@@ -674,6 +674,8 @@ bot.on('message', async (msg) => {
 // 生成账单消息
 async function generateBillMessage(chatId) {
     try {
+        console.log(`开始生成账单消息 - 群组ID: ${chatId}`);
+
         // 获取群组的最后加入时间和费率信息
         const [groupInfo] = await pool.query(
             'SELECT last_join_time, in_fee_rate, in_exchange_rate, out_fee_rate, out_exchange_rate FROM groups WHERE group_id = ?',
@@ -681,9 +683,12 @@ async function generateBillMessage(chatId) {
         );
 
         if (!groupInfo || groupInfo.length === 0) {
+            console.log(`群组信息不存在 - 群组ID: ${chatId}`);
             return '暂无交易记录';
         }
 
+        console.log(`获取到群组信息:`, groupInfo[0]);
+
         const lastJoinTime = groupInfo[0].last_join_time;
         const inFeeRate = parseFloat(groupInfo[0].in_fee_rate) || 0;
         const inExchangeRate = parseFloat(groupInfo[0].in_exchange_rate) || 0;
@@ -695,12 +700,12 @@ async function generateBillMessage(chatId) {
             SELECT t.*, 
                    COALESCE(t.fee_rate, g.in_fee_rate) as fee_rate,
                    COALESCE(t.exchange_rate, g.in_exchange_rate) as exchange_rate,
-                   t.total_deposit,
-                   t.total_withdrawal,
-                   t.deposit_fee,
-                   t.withdrawal_fee,
-                   t.total_u_deposit,
-                   t.total_u_withdrawal
+                   t.totalDeposit as total_deposit,
+                   t.totalWithdrawal as total_withdrawal,
+                   t.depositFee as deposit_fee,
+                   t.withdrawalFee as withdrawal_fee,
+                   t.totalUDeposit as total_u_deposit,
+                   t.totalUWithdrawal as total_u_withdrawal
             FROM transactions t
             LEFT JOIN groups g ON t.group_id = g.group_id
             WHERE t.group_id = ? 
@@ -709,15 +714,20 @@ async function generateBillMessage(chatId) {
         `, [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;
@@ -725,10 +735,14 @@ async function generateBillMessage(chatId) {
         const totalUDeposit = parseFloat(latestRecord.total_u_deposit) || 0;
         const totalUWithdrawal = parseFloat(latestRecord.total_u_withdrawal) || 0;
 
-        // 计算剩余金额:总入款 - 入款手续费 - 总下发 - 下发手续费
-        const remaining = totalDeposit - depositFee - totalWithdrawal - withdrawalFee;
-        // 将剩余金额转换为U币:剩余金额 ÷ 入款汇率,保留2位小数
-        const remainingU = (remaining / inExchangeRate).toFixed(2);
+        console.log(`金额数据:`, {
+            totalDeposit,
+            totalWithdrawal,
+            depositFee,
+            withdrawalFee,
+            totalUDeposit,
+            totalUWithdrawal
+        });
 
         // 获取当前日期
         const today = new Date();
@@ -771,13 +785,19 @@ async function generateBillMessage(chatId) {
         message += `<b>出款合计</b>:<code>${(totalWithdrawal - withdrawalFee).toFixed(2)}|${totalUWithdrawal.toFixed(2)}U</code>\n\n`;
 
         // 添加余额信息
-        message += `<b>应下发</b>:<code>${remainingU}U</code>\n`;
+        message += `<b>应下发</b>:<code>${totalUDeposit.toFixed(2)}U</code>\n`;
         message += `<b>已下发</b>:<code>${totalUWithdrawal.toFixed(2)}U</code>\n`;
-        message += `<b>未下发</b>:<code>${(remainingU - totalUWithdrawal).toFixed(2)}U</code>`;
+        message += `<b>未下发</b>:<code>${(totalUDeposit - totalUWithdrawal).toFixed(2)}U</code>`;
 
+        console.log(`账单消息生成成功 - 群组ID: ${chatId}`);
         return message;
     } catch (error) {
-        console.error(formatLog('生成账单消息失败', error));
+        console.error('生成账单消息失败:', error);
+        console.error('错误详情:', {
+            message: error.message,
+            stack: error.stack,
+            chatId: chatId
+        });
         return '获取账单信息失败,请稍后重试';
     }
 }

+ 7 - 7
admin/models/Transaction.js

@@ -125,7 +125,7 @@ const Transaction = {
 
             // 获取上一条记录的总金额数据
             const [lastRecord] = await pool.query(
-                'SELECT total_deposit, total_withdrawal, total_u_deposit, total_u_withdrawal FROM transactions WHERE group_id = ? ORDER BY time DESC LIMIT 1',
+                'SELECT totalDeposit, totalWithdrawal, totalUDeposit, totalUWithdrawal FROM transactions WHERE group_id = ? ORDER BY time DESC LIMIT 1',
                 [transactionData.groupId]
             );
 
@@ -137,10 +137,10 @@ const Transaction = {
 
             // 如果有上一条记录,使用其数据
             if (lastRecord && lastRecord.length > 0) {
-                totalDeposit = parseFloat(lastRecord[0].total_deposit) || 0;
-                totalWithdrawal = parseFloat(lastRecord[0].total_withdrawal) || 0;
-                totalUDeposit = parseFloat(lastRecord[0].total_u_deposit) || 0;
-                totalUWithdrawal = parseFloat(lastRecord[0].total_u_withdrawal) || 0;
+                totalDeposit = parseFloat(lastRecord[0].totalDeposit) || 0;
+                totalWithdrawal = parseFloat(lastRecord[0].totalWithdrawal) || 0;
+                totalUDeposit = parseFloat(lastRecord[0].totalUDeposit) || 0;
+                totalUWithdrawal = parseFloat(lastRecord[0].totalUWithdrawal) || 0;
             }
 
             // 计算本条交易的手续费
@@ -164,8 +164,8 @@ const Transaction = {
             const [result] = await pool.query(
                 `INSERT INTO transactions (
                     group_id, group_name, type, amount, remark, operator_id, 
-                    fee_rate, exchange_rate, total_deposit, total_withdrawal,
-                    deposit_fee, withdrawal_fee, total_u_deposit, total_u_withdrawal
+                    fee_rate, exchange_rate, totalDeposit, totalWithdrawal,
+                    depositFee, withdrawalFee, totalUDeposit, totalUWithdrawal
                 ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
                 [
                     transactionData.groupId,