|
@@ -694,7 +694,13 @@ async function generateBillMessage(chatId) {
|
|
const [records] = await pool.query(`
|
|
const [records] = await pool.query(`
|
|
SELECT t.*,
|
|
SELECT t.*,
|
|
COALESCE(t.fee_rate, g.in_fee_rate) as fee_rate,
|
|
COALESCE(t.fee_rate, g.in_fee_rate) as fee_rate,
|
|
- COALESCE(t.exchange_rate, g.in_exchange_rate) as exchange_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
|
|
FROM transactions t
|
|
FROM transactions t
|
|
LEFT JOIN groups g ON t.group_id = g.group_id
|
|
LEFT JOIN groups g ON t.group_id = g.group_id
|
|
WHERE t.group_id = ?
|
|
WHERE t.group_id = ?
|
|
@@ -706,14 +712,22 @@ async function generateBillMessage(chatId) {
|
|
return '暂无交易记录';
|
|
return '暂无交易记录';
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 将记录按类型分类:入款和下发
|
|
const deposits = records.filter(r => r.type === 'deposit');
|
|
const deposits = records.filter(r => r.type === 'deposit');
|
|
const withdrawals = records.filter(r => r.type === 'withdrawal');
|
|
const withdrawals = records.filter(r => r.type === 'withdrawal');
|
|
|
|
|
|
- const totalDeposit = deposits.reduce((sum, d) => sum + parseFloat(d.amount), 0);
|
|
|
|
- const totalWithdrawal = withdrawals.reduce((sum, w) => sum + parseFloat(w.amount), 0);
|
|
|
|
- const depositFee = totalDeposit * (inFeeRate / 100);
|
|
|
|
- const withdrawalFee = totalWithdrawal * (outFeeRate / 100);
|
|
|
|
|
|
+ // 获取最新一条记录的总金额数据
|
|
|
|
+ const latestRecord = records[0];
|
|
|
|
+ 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;
|
|
|
|
+
|
|
|
|
+ // 计算剩余金额:总入款 - 入款手续费 - 总下发 - 下发手续费
|
|
const remaining = totalDeposit - depositFee - totalWithdrawal - withdrawalFee;
|
|
const remaining = totalDeposit - depositFee - totalWithdrawal - withdrawalFee;
|
|
|
|
+ // 将剩余金额转换为U币:剩余金额 ÷ 入款汇率,保留2位小数
|
|
const remainingU = (remaining / inExchangeRate).toFixed(2);
|
|
const remainingU = (remaining / inExchangeRate).toFixed(2);
|
|
|
|
|
|
// 获取当前日期
|
|
// 获取当前日期
|
|
@@ -749,17 +763,17 @@ async function generateBillMessage(chatId) {
|
|
message += `<b>入款费率</b>:<code>${inFeeRate}%</code>\n`;
|
|
message += `<b>入款费率</b>:<code>${inFeeRate}%</code>\n`;
|
|
message += `<b>入款汇率</b>:<code>${inExchangeRate}</code>\n`;
|
|
message += `<b>入款汇率</b>:<code>${inExchangeRate}</code>\n`;
|
|
message += `<b>入款总额</b>:<code>${totalDeposit.toFixed(2)}</code>\n`;
|
|
message += `<b>入款总额</b>:<code>${totalDeposit.toFixed(2)}</code>\n`;
|
|
- message += `<b>入款合计</b>:<code>${(totalDeposit - depositFee).toFixed(2)}|${((totalDeposit - depositFee) / inExchangeRate).toFixed(2)}U</code>\n\n`;
|
|
|
|
|
|
+ message += `<b>入款合计</b>:<code>${(totalDeposit - depositFee).toFixed(2)}|${totalUDeposit.toFixed(2)}U</code>\n\n`;
|
|
|
|
|
|
message += `<b>出款费率</b>:<code>${outFeeRate}%</code>\n`;
|
|
message += `<b>出款费率</b>:<code>${outFeeRate}%</code>\n`;
|
|
message += `<b>出款汇率</b>:<code>${outExchangeRate}</code>\n`;
|
|
message += `<b>出款汇率</b>:<code>${outExchangeRate}</code>\n`;
|
|
message += `<b>出款总额</b>:<code>${totalWithdrawal.toFixed(2)}</code>\n`;
|
|
message += `<b>出款总额</b>:<code>${totalWithdrawal.toFixed(2)}</code>\n`;
|
|
- message += `<b>出款合计</b>:<code>${(totalWithdrawal - withdrawalFee).toFixed(2)}|${((totalWithdrawal - withdrawalFee) / outExchangeRate).toFixed(2)}U</code>\n\n`;
|
|
|
|
|
|
+ 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>${remainingU}U</code>\n`;
|
|
- message += `<b>已下发</b>:<code>${(totalWithdrawal / outExchangeRate).toFixed(2)}U</code>\n`;
|
|
|
|
- message += `<b>未下发</b>:<code>${(remainingU - (totalWithdrawal / outExchangeRate)).toFixed(2)}U</code>`;
|
|
|
|
|
|
+ message += `<b>已下发</b>:<code>${totalUWithdrawal.toFixed(2)}U</code>\n`;
|
|
|
|
+ message += `<b>未下发</b>:<code>${(remainingU - totalUWithdrawal).toFixed(2)}U</code>`;
|
|
|
|
|
|
return message;
|
|
return message;
|
|
} catch (error) {
|
|
} catch (error) {
|