From f44af3a2ed5e0cbf4476f333aa8205b4d33425e2 Mon Sep 17 00:00:00 2001 From: hailin Date: Thu, 22 Jan 2026 00:04:35 -0800 Subject: [PATCH] =?UTF-8?q?fix(batch-mining):=20=E4=BF=AE=E6=AD=A3grandTot?= =?UTF-8?q?alAmount=E9=87=8D=E5=A4=8D=E7=B4=AF=E5=8A=A0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户可能在多个批次中出现,之前按批次累加batchTotalAmount会导致 同一用户的收益被重复计算。改为直接累加所有用户的amount(去重)。 Co-Authored-By: Claude Opus 4.5 --- .../application/services/batch-mining.service.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/services/mining-service/src/application/services/batch-mining.service.ts b/backend/services/mining-service/src/application/services/batch-mining.service.ts index 803fdbdc..b13d1297 100644 --- a/backend/services/mining-service/src/application/services/batch-mining.service.ts +++ b/backend/services/mining-service/src/application/services/batch-mining.service.ts @@ -273,7 +273,6 @@ export class BatchMiningService { } // 构建返回结果 - let grandTotalAmount = new Decimal(0); const batchResults: BatchMiningPreviewResult['batches'] = []; // 计算用户总算力(用于显示) @@ -283,6 +282,17 @@ export class BatchMiningService { } this.logger.log(`[preview] 用户总算力: ${totalUserContribution.toFixed(2)}`); + // 计算 grandTotalAmount:所有用户的收益总和(去重) + let grandTotalAmount = new Decimal(0); + const processedUsers = new Set(); + for (const [accountSequence, amount] of userAmounts) { + if (!processedUsers.has(accountSequence)) { + processedUsers.add(accountSequence); + grandTotalAmount = grandTotalAmount.plus(amount); + } + } + this.logger.log(`[preview] 计算的总金额: ${grandTotalAmount.toFixed(8)} (${processedUsers.size}个用户)`); + for (const batchNum of sortedBatches) { const batchItems = batchGroups.get(batchNum)!; const batchContribution = batchContributions.get(batchNum)!; @@ -330,8 +340,6 @@ export class BatchMiningService { cumulativeNetworkContribution: cumulativeContribution.toFixed(10), batchTotalAmount: batchTotalAmount.toFixed(8), }); - - grandTotalAmount = grandTotalAmount.plus(batchTotalAmount); } const result = {