From d98e22f151ef0cf51b54bfd2c2ac4b94ae004841 Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 21 Jan 2026 23:35:50 -0800 Subject: [PATCH] =?UTF-8?q?fix(batch-mining):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E7=9A=84=E6=9C=80=E5=90=8E=E9=98=B6=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根据需求:总天数 = 所有批次的 preMineDays 之和 - 阶段1: 只有第一批,分配第一批的 preMineDays 天 - 阶段2: 第一批+第二批,分配第二批的 preMineDays 天 - 依次类推... 没有额外的"最后阶段",不再使用 maxTotalMiningDays Co-Authored-By: Claude Opus 4.5 --- .../services/batch-mining.service.ts | 49 ++++--------------- 1 file changed, 10 insertions(+), 39 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 bf23d481..5edf8deb 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 @@ -374,42 +374,33 @@ export class BatchMiningService { return phases; } - // 获取每个批次的提前天数和总挖矿天数 + // 获取每个批次的提前天数 const batchPreMineDays = new Map(); - let maxTotalMiningDays = 0; for (const item of items) { if (!batchPreMineDays.has(item.batch)) { batchPreMineDays.set(item.batch, item.preMineDays); } - // 使用最大的总挖矿天数(第一批次的用户应该有最长的挖矿时间) - if (item.totalMiningDays && item.totalMiningDays > maxTotalMiningDays) { - maxTotalMiningDays = item.totalMiningDays; - } } this.logger.log(`[buildMiningPhases] 各批次提前天数: ${JSON.stringify(Object.fromEntries(batchPreMineDays))}`); - this.logger.log(`[buildMiningPhases] 最大总挖矿天数: ${maxTotalMiningDays}`); - - if (maxTotalMiningDays <= 0) { - this.logger.warn('[buildMiningPhases] 总挖矿天数<=0,无法计算'); - return phases; - } let currentPhase = 1; let participatingBatches: number[] = []; - let usedDays = 0; // 已分配的天数 + let totalDays = 0; // 按批次顺序添加阶段 - // 关键:先用当前批次的 preMineDays 创建阶段,然后下一批次加入 + // 阶段1: 只有第一批,分配第一批的 preMineDays 天 + // 阶段2: 第一批+第二批,分配第二批的 preMineDays 天 + // 阶段3: 第一批+第二批+第三批,分配第三批的 preMineDays 天 + // ...依次类推,总天数 = 所有 preMineDays 之和 for (let i = 0; i < sortedBatches.length; i++) { const currentBatch = sortedBatches[i]; const currentPreMineDays = batchPreMineDays.get(currentBatch) || 0; - // 先把当前批次加入参与列表 + // 当前批次加入参与列表 participatingBatches.push(currentBatch); - // 该阶段持续天数 = 当前批次的 preMineDays(当前批次比下一批次提前的天数) - // 如果 preMineDays > 0,说明当前参与批次要在下一批次加入前独挖这些天 + // 该阶段持续天数 = 当前批次的 preMineDays if (currentPreMineDays > 0) { // 计算该阶段参与用户的总算力 let participatingContribution = new Decimal(0); @@ -428,31 +419,11 @@ export class BatchMiningService { this.logger.log(`[buildMiningPhases] 阶段${currentPhase}: ${currentPreMineDays}天, 批次[${participatingBatches.join(',')}], 参与算力=${participatingContribution.toFixed(2)}`); currentPhase++; - usedDays += currentPreMineDays; + totalDays += currentPreMineDays; } } - // 添加最后阶段:所有批次一起挖(剩余天数) - const remainingDays = maxTotalMiningDays - usedDays; - if (remainingDays > 0) { - // 所有批次都参与 - let participatingContribution = new Decimal(0); - for (const batch of sortedBatches) { - participatingContribution = participatingContribution.plus(batchContributions.get(batch) || 0); - } - - phases.push({ - phaseNumber: currentPhase, - startDate: new Date(), - endDate: new Date(), - daysInPhase: remainingDays, - participatingContribution, - participatingBatches: [...sortedBatches], - }); - - this.logger.log(`[buildMiningPhases] 阶段${currentPhase}(最终): ${remainingDays}天, 所有批次[${sortedBatches.join(',')}], 参与算力=${participatingContribution.toFixed(2)}`); - } - + this.logger.log(`[buildMiningPhases] 总天数: ${totalDays}`); return phases; }