diff --git a/backend/services/wallet-service/src/application/services/wallet-application.service.ts b/backend/services/wallet-service/src/application/services/wallet-application.service.ts index 3c568686..d16634fc 100644 --- a/backend/services/wallet-service/src/application/services/wallet-application.service.ts +++ b/backend/services/wallet-service/src/application/services/wallet-application.service.ts @@ -1967,19 +1967,32 @@ export class WalletApplicationService { } // 计算收支 + // 排除临时性流水类型(冻结/解冻),避免双重计算 + // 例如:认种流程会产生 PLANT_FREEZE(-100) + PLANT_PAYMENT(-100),实际只支出 100 + const excludeFromStats = new Set([ + 'PLANT_FREEZE', // 认种冻结(临时) + 'PLANT_UNFREEZE', // 认种解冻(回滚) + 'FREEZE', // 通用冻结(临时) + 'UNFREEZE', // 通用解冻(回滚) + ]); + let totalIncome = 0; let totalExpense = 0; const byTypeMap = new Map(); for (const entry of entries) { const amount = Number(entry.amount); - if (amount > 0) { - totalIncome += amount; - } else { - totalExpense += Math.abs(amount); + + // 只计算非临时性流水的收支统计 + if (!excludeFromStats.has(entry.entryType)) { + if (amount > 0) { + totalIncome += amount; + } else { + totalExpense += Math.abs(amount); + } } - // 按类型汇总 + // 按类型汇总(包含所有类型,方便查看明细) const existing = byTypeMap.get(entry.entryType) || { totalAmount: 0, count: 0 }; existing.totalAmount += amount; existing.count += 1; @@ -2047,6 +2060,14 @@ export class WalletApplicationService { } // 填充数据 + // 排除临时性流水类型(冻结/解冻),避免双重计算 + const excludeFromStats = new Set([ + 'PLANT_FREEZE', // 认种冻结(临时) + 'PLANT_UNFREEZE', // 认种解冻(回滚) + 'FREEZE', // 通用冻结(临时) + 'UNFREEZE', // 通用解冻(回滚) + ]); + let periodIncome = 0; let periodExpense = 0; @@ -2055,12 +2076,15 @@ export class WalletApplicationService { const amount = Number(entry.amount); const existing = dailyMap.get(dateStr) || { income: 0, expense: 0, count: 0 }; - if (amount > 0) { - existing.income += amount; - periodIncome += amount; - } else { - existing.expense += Math.abs(amount); - periodExpense += Math.abs(amount); + // 只计算非临时性流水的收支统计 + if (!excludeFromStats.has(entry.entryType)) { + if (amount > 0) { + existing.income += amount; + periodIncome += amount; + } else { + existing.expense += Math.abs(amount); + periodExpense += Math.abs(amount); + } } existing.count += 1; dailyMap.set(dateStr, existing);