|
@@ -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 '获取账单信息失败,请稍后重试';
|
|
|
}
|
|
|
}
|