Compare commits

..

No commits in common. "d98e22f151ef0cf51b54bfd2c2ac4b94ae004841" and "2358b3ea17c5ce120971832e0023955b4d3c5e5c" have entirely different histories.

1 changed files with 39 additions and 10 deletions

View File

@ -374,33 +374,42 @@ export class BatchMiningService {
return phases; return phases;
} }
// 获取每个批次的提前天数 // 获取每个批次的提前天数和总挖矿天数
const batchPreMineDays = new Map<number, number>(); const batchPreMineDays = new Map<number, number>();
let maxTotalMiningDays = 0;
for (const item of items) { for (const item of items) {
if (!batchPreMineDays.has(item.batch)) { if (!batchPreMineDays.has(item.batch)) {
batchPreMineDays.set(item.batch, item.preMineDays); 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] 各批次提前天数: ${JSON.stringify(Object.fromEntries(batchPreMineDays))}`);
this.logger.log(`[buildMiningPhases] 最大总挖矿天数: ${maxTotalMiningDays}`);
if (maxTotalMiningDays <= 0) {
this.logger.warn('[buildMiningPhases] 总挖矿天数<=0无法计算');
return phases;
}
let currentPhase = 1; let currentPhase = 1;
let participatingBatches: number[] = []; let participatingBatches: number[] = [];
let totalDays = 0; let usedDays = 0; // 已分配的天数
// 按批次顺序添加阶段 // 按批次顺序添加阶段
// 阶段1: 只有第一批,分配第一批的 preMineDays 天 // 关键:先用当前批次的 preMineDays 创建阶段,然后下一批次加入
// 阶段2: 第一批+第二批,分配第二批的 preMineDays 天
// 阶段3: 第一批+第二批+第三批,分配第三批的 preMineDays 天
// ...依次类推,总天数 = 所有 preMineDays 之和
for (let i = 0; i < sortedBatches.length; i++) { for (let i = 0; i < sortedBatches.length; i++) {
const currentBatch = sortedBatches[i]; const currentBatch = sortedBatches[i];
const currentPreMineDays = batchPreMineDays.get(currentBatch) || 0; const currentPreMineDays = batchPreMineDays.get(currentBatch) || 0;
// 当前批次加入参与列表 // 先把当前批次加入参与列表
participatingBatches.push(currentBatch); participatingBatches.push(currentBatch);
// 该阶段持续天数 = 当前批次的 preMineDays // 该阶段持续天数 = 当前批次的 preMineDays当前批次比下一批次提前的天数
// 如果 preMineDays > 0说明当前参与批次要在下一批次加入前独挖这些天
if (currentPreMineDays > 0) { if (currentPreMineDays > 0) {
// 计算该阶段参与用户的总算力 // 计算该阶段参与用户的总算力
let participatingContribution = new Decimal(0); let participatingContribution = new Decimal(0);
@ -419,11 +428,31 @@ export class BatchMiningService {
this.logger.log(`[buildMiningPhases] 阶段${currentPhase}: ${currentPreMineDays}天, 批次[${participatingBatches.join(',')}], 参与算力=${participatingContribution.toFixed(2)}`); this.logger.log(`[buildMiningPhases] 阶段${currentPhase}: ${currentPreMineDays}天, 批次[${participatingBatches.join(',')}], 参与算力=${participatingContribution.toFixed(2)}`);
currentPhase++; currentPhase++;
totalDays += currentPreMineDays; usedDays += currentPreMineDays;
} }
} }
this.logger.log(`[buildMiningPhases] 总天数: ${totalDays}`); // 添加最后阶段:所有批次一起挖(剩余天数)
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)}`);
}
return phases; return phases;
} }