fix(batch-mining): 简化计算逻辑

- 移除分阶段计算,改用简单公式
- 用户收益 = (用户算力/全网算力) × 每日产出 × 天数
- 全网算力 = 用户算力 / 0.7

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-21 21:16:14 -08:00
parent 97b3a20a7c
commit 4dcbe38309
1 changed files with 30 additions and 50 deletions

View File

@ -136,11 +136,11 @@ export class BatchMiningService {
/** /**
* *
* *
* *
* - 1311 * - = × 86400
* - 221+2 * - = ( / ) × ×
* - 311+2+3 * - 70% = / 0.7
* - 4 * - : (1000000/365/2)*70%*74 = 70958.90411
*/ */
async preview(items: BatchMiningItem[]): Promise<BatchMiningPreviewResult> { async preview(items: BatchMiningItem[]): Promise<BatchMiningPreviewResult> {
this.logger.log(`[preview] 开始预览批量补发, 共 ${items.length} 条数据`); this.logger.log(`[preview] 开始预览批量补发, 共 ${items.length} 条数据`);
@ -170,7 +170,8 @@ export class BatchMiningService {
} }
const secondDistribution = config.secondDistribution.value; const secondDistribution = config.secondDistribution.value;
this.logger.log(`[preview] 每秒分配量: ${secondDistribution.toString()}`); const dailyDistribution = secondDistribution.times(SECONDS_PER_DAY);
this.logger.log(`[preview] 每秒分配量: ${secondDistribution.toString()}, 每日分配量: ${dailyDistribution.toFixed(6)}`);
// 按批次分组并排序 // 按批次分组并排序
const batchGroups = this.groupByBatch(items); const batchGroups = this.groupByBatch(items);
@ -189,61 +190,40 @@ export class BatchMiningService {
this.logger.log(`[preview] 批次${batchNum}算力: ${batchTotal.toFixed(2)}`); this.logger.log(`[preview] 批次${batchNum}算力: ${batchTotal.toFixed(2)}`);
} }
// 计算每个用户的算力 // 计算用户总算力和全网算力
const userContributions = new Map<string, Decimal>(); let totalUserContribution = new Decimal(0);
for (const item of items) { for (const contribution of batchContributions.values()) {
userContributions.set(item.accountSequence, this.calculateUserContribution(item.treeCount)); totalUserContribution = totalUserContribution.plus(contribution);
} }
// 用户只占全网的70%30%是系统、运营、层级、团队),所以全网算力 = 用户算力 / 0.7
const networkContribution = totalUserContribution.dividedBy(USER_NETWORK_RATIO);
this.logger.log(`[preview] 用户总算力: ${totalUserContribution.toFixed(2)}, 全网算力(用户占70%): ${networkContribution.toFixed(2)}`);
// 定义挖矿阶段 // 获取最大总挖矿天数
// 阶段1: 批次1独挖3天 let maxTotalMiningDays = 0;
// 阶段2: 批次1+2共挖2天 for (const item of items) {
// 阶段3: 批次1+2+3共挖1天 if (item.totalMiningDays && item.totalMiningDays > maxTotalMiningDays) {
// 阶段4: 所有批次共挖(剩余天数) maxTotalMiningDays = item.totalMiningDays;
const phases = this.buildMiningPhases(items, sortedBatches, batchContributions); }
this.logger.log(`[preview] 挖矿阶段: ${JSON.stringify(phases.map(p => ({ }
phase: p.phaseNumber, this.logger.log(`[preview] 最大总挖矿天数: ${maxTotalMiningDays}`);
days: p.daysInPhase,
batches: p.participatingBatches,
networkContribution: p.networkContribution.toFixed(2)
})))}`);
// 计算每个用户在各阶段的收益 // 简化计算:所有用户按各自的总挖矿天数计算收益
// 用户收益 = (用户算力 / 全网算力) × 每日产出 × 天数
const userAmounts = new Map<string, Decimal>(); const userAmounts = new Map<string, Decimal>();
for (const item of items) { for (const item of items) {
userAmounts.set(item.accountSequence, new Decimal(0)); const userContribution = this.calculateUserContribution(item.treeCount);
} const ratio = userContribution.dividedBy(networkContribution);
const days = item.totalMiningDays || maxTotalMiningDays;
for (const phase of phases) { const amount = dailyDistribution.times(ratio).times(days);
const dailyDistribution = secondDistribution.times(SECONDS_PER_DAY); userAmounts.set(item.accountSequence, amount);
const phaseDistribution = dailyDistribution.times(phase.daysInPhase); this.logger.debug(`[preview] 用户 ${item.accountSequence}: 算力=${userContribution.toFixed(2)}, 占比=${ratio.toFixed(6)}, 天数=${days}, 金额=${amount.toFixed(8)}`);
for (const item of items) {
// 检查该用户的批次是否参与此阶段
if (phase.participatingBatches.includes(item.batch)) {
const userContribution = userContributions.get(item.accountSequence)!;
const ratio = userContribution.dividedBy(phase.networkContribution);
const phaseAmount = phaseDistribution.times(ratio);
const currentAmount = userAmounts.get(item.accountSequence)!;
userAmounts.set(item.accountSequence, currentAmount.plus(phaseAmount));
}
}
} }
// 构建返回结果 // 构建返回结果
let grandTotalAmount = new Decimal(0); let grandTotalAmount = new Decimal(0);
const batchResults: BatchMiningPreviewResult['batches'] = []; const batchResults: BatchMiningPreviewResult['batches'] = [];
// 计算累计全网算力(最终状态)
// 用户只占全网的70%30%是系统、运营、层级、团队),所以全网算力 = 用户算力 / 0.7
let totalUserContribution = new Decimal(0);
for (const contribution of batchContributions.values()) {
totalUserContribution = totalUserContribution.plus(contribution);
}
const finalNetworkContribution = totalUserContribution.dividedBy(USER_NETWORK_RATIO);
this.logger.log(`[preview] 用户总算力: ${totalUserContribution.toFixed(2)}, 全网算力(用户占70%): ${finalNetworkContribution.toFixed(2)}`);
for (const batchNum of sortedBatches) { for (const batchNum of sortedBatches) {
const batchItems = batchGroups.get(batchNum)!; const batchItems = batchGroups.get(batchNum)!;
const batchContribution = batchContributions.get(batchNum)!; const batchContribution = batchContributions.get(batchNum)!;