|
@@ -220,6 +220,16 @@ bot.on('message', async (msg) => {
|
|
|
}
|
|
|
|
|
|
if (!isNaN(amount)) {
|
|
|
+ // 检查是否是今天的第一笔交易
|
|
|
+ const [todayFirstRecord] = await pool.query(`
|
|
|
+ SELECT COUNT(*) as count
|
|
|
+ FROM transactions
|
|
|
+ WHERE group_id = ?
|
|
|
+ AND DATE(time) = CURDATE()
|
|
|
+ `, [msg.chat.id.toString()]);
|
|
|
+
|
|
|
+ const isFirstRecord = todayFirstRecord[0].count === 0;
|
|
|
+
|
|
|
const transactionData = {
|
|
|
groupId: msg.chat.id.toString(),
|
|
|
groupName: msg.chat.title || '未命名群组',
|
|
@@ -227,11 +237,10 @@ bot.on('message', async (msg) => {
|
|
|
type: 'deposit',
|
|
|
exchangeRate: exchangeRate,
|
|
|
feeRate: feeRate,
|
|
|
- operatorId: msg.from.id
|
|
|
+ operatorId: msg.from.id,
|
|
|
+ isFirstRecord: isFirstRecord // 添加标记,表示是否是今天的第一笔交易
|
|
|
};
|
|
|
|
|
|
- // console.log(transactionData);
|
|
|
-
|
|
|
try {
|
|
|
const result = await Transaction.deposit(transactionData);
|
|
|
if (result.success) {
|
|
@@ -784,8 +793,8 @@ async function generateBillMessage(chatId) {
|
|
|
ORDER BY t.time DESC
|
|
|
`, [chatId.toString()]);
|
|
|
|
|
|
- // 获取最新一条交易的累计数据
|
|
|
- const [latestRecord] = await pool.query(`
|
|
|
+ // 获取今天的最新一条交易的累计数据
|
|
|
+ const [todayLatestRecord] = 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,
|
|
@@ -798,6 +807,7 @@ 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()]);
|
|
@@ -824,19 +834,27 @@ async function generateBillMessage(chatId) {
|
|
|
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`;
|
|
|
-
|
|
|
- // 添加余额信息(使用最新一条交易的累计数据)
|
|
|
- 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`;
|
|
|
- message += `<b>未下发</b>:<code>${(remainingAmount < 0 ? 0 : remainingAmount).toFixed(2)}U</code>`;
|
|
|
+ // 只有在今天有交易记录时才显示总额信息
|
|
|
+ if (todayLatestRecord && todayLatestRecord.length > 0) {
|
|
|
+ const totalDeposit = parseFloat(todayLatestRecord[0].total_deposit) || 0;
|
|
|
+ const totalUDeposit = parseFloat(todayLatestRecord[0].total_u_deposit) || 0;
|
|
|
+ const totalUWithdrawal = parseFloat(todayLatestRecord[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`;
|
|
|
+
|
|
|
+ // 添加余额信息
|
|
|
+ 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`;
|
|
|
+ message += `<b>未下发</b>:<code>${(remainingAmount < 0 ? 0 : remainingAmount).toFixed(2)}U</code>`;
|
|
|
+ } else {
|
|
|
+ message += `<b>入款总额</b>:<code>0.00</code>\n`;
|
|
|
+ message += `<b>入款合计</b>:<code>0.00|0.00U</code>\n\n`;
|
|
|
+ message += `<b>应下发</b>:<code>0.00U</code>\n`;
|
|
|
+ message += `<b>已下发</b>:<code>0.00U</code>\n`;
|
|
|
+ message += `<b>未下发</b>:<code>0.00U</code>`;
|
|
|
+ }
|
|
|
|
|
|
console.log(`账单消息生成成功 - 群组ID: ${chatId}`);
|
|
|
return message;
|