|
@@ -123,17 +123,65 @@ const Transaction = {
|
|
|
// 使用群内操作人的ID作为operator_id
|
|
|
const operatorId = transactionData.operatorId || 1;
|
|
|
|
|
|
+ // 获取上一条记录的总金额数据
|
|
|
+ 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',
|
|
|
+ [transactionData.groupId]
|
|
|
+ );
|
|
|
+
|
|
|
+ // 初始化总金额数据
|
|
|
+ let totalDeposit = 0;
|
|
|
+ let totalWithdrawal = 0;
|
|
|
+ let totalUDeposit = 0;
|
|
|
+ let totalUWithdrawal = 0;
|
|
|
+
|
|
|
+ // 如果有上一条记录,使用其数据
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算本条交易的手续费
|
|
|
+ const currentFee = Math.abs(transactionData.amount) * (feeRate / 100);
|
|
|
+
|
|
|
+ // 计算本条交易的实际金额(减去手续费)
|
|
|
+ const actualAmount = Math.abs(transactionData.amount) - currentFee;
|
|
|
+
|
|
|
+ // 计算本条交易的U币金额
|
|
|
+ const uAmount = actualAmount / exchangeRate;
|
|
|
+
|
|
|
+ // 根据交易类型更新总金额
|
|
|
+ if (transactionData.type === 'deposit') {
|
|
|
+ totalDeposit += transactionData.amount;
|
|
|
+ totalUDeposit += uAmount;
|
|
|
+ } else {
|
|
|
+ totalWithdrawal += transactionData.amount;
|
|
|
+ totalUWithdrawal += uAmount;
|
|
|
+ }
|
|
|
+
|
|
|
const [result] = await pool.query(
|
|
|
- 'INSERT INTO transactions (group_id, group_name, type, amount, remark, operator_id, fee_rate, exchange_rate) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
|
|
|
+ `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
|
|
|
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
|
[
|
|
|
transactionData.groupId,
|
|
|
transactionData.groupName,
|
|
|
transactionData.type,
|
|
|
transactionData.amount,
|
|
|
transactionData.remark || null,
|
|
|
- operatorId, // 使用群内操作人的ID
|
|
|
+ operatorId,
|
|
|
feeRate,
|
|
|
- exchangeRate
|
|
|
+ exchangeRate,
|
|
|
+ totalDeposit,
|
|
|
+ totalWithdrawal,
|
|
|
+ transactionData.type === 'deposit' ? currentFee : 0,
|
|
|
+ transactionData.type === 'withdrawal' ? currentFee : 0,
|
|
|
+ totalUDeposit,
|
|
|
+ totalUWithdrawal
|
|
|
]
|
|
|
);
|
|
|
return result.insertId;
|