fix(mining-admin): calculate distribution amounts from actual adoption data
Use treeCount * contributionPerTree from adoption record to calculate the actual distribution amounts (70%, 12%, 1%, 2%, 15%) instead of deriving from contribution_records table. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
e71f2aadfc
commit
95e009966e
|
|
@ -769,8 +769,11 @@ export class UsersService {
|
|||
}
|
||||
|
||||
// 获取每笔认种的实际分配明细(从 contribution_records 统计)
|
||||
const adoptionIds = adoptions.map((a) => a.originalAdoptionId);
|
||||
const distributionByAdoption = await this.getDistributionByAdoptions(adoptionIds);
|
||||
const adoptionMap = new Map(adoptions.map((a) => [
|
||||
a.originalAdoptionId.toString(),
|
||||
{ treeCount: a.treeCount, contributionPerTree: Number(a.contributionPerTree) },
|
||||
]));
|
||||
const distributionByAdoption = await this.getDistributionByAdoptions(adoptionMap);
|
||||
|
||||
// 格式化认种记录,包含分配明细
|
||||
const items = adoptions.map((a) => {
|
||||
|
|
@ -1014,72 +1017,54 @@ export class UsersService {
|
|||
|
||||
/**
|
||||
* 获取认种的实际分配明细
|
||||
* 从 contribution_records 表统计每笔认种的实际分配
|
||||
* 基于认种的总算力计算各项分配金额
|
||||
*/
|
||||
private async getDistributionByAdoptions(
|
||||
adoptionIds: bigint[],
|
||||
adoptionMap: Map<string, { treeCount: number; contributionPerTree: number }>,
|
||||
): Promise<Map<string, any>> {
|
||||
const result = new Map<string, any>();
|
||||
|
||||
if (adoptionIds.length === 0) return result;
|
||||
if (adoptionMap.size === 0) return result;
|
||||
|
||||
// 查询这些认种产生的所有算力记录
|
||||
const adoptionIds = Array.from(adoptionMap.keys()).map((id) => BigInt(id));
|
||||
|
||||
// 查询这些认种产生的算力记录(只统计团队分配部分的实际发放)
|
||||
const records = await this.prisma.syncedContributionRecord.findMany({
|
||||
where: { sourceAdoptionId: { in: adoptionIds } },
|
||||
select: {
|
||||
sourceAdoptionId: true,
|
||||
sourceType: true,
|
||||
amount: true,
|
||||
baseContribution: true,
|
||||
treeCount: true,
|
||||
},
|
||||
});
|
||||
|
||||
// 按认种ID分组统计
|
||||
const byAdoption = new Map<string, {
|
||||
personalAmount: number;
|
||||
teamLevelAmount: number;
|
||||
teamBonusAmount: number;
|
||||
totalContribution: number;
|
||||
}>();
|
||||
// 按认种ID分组统计团队分配的实际发放
|
||||
const teamDistributedByAdoption = new Map<string, number>();
|
||||
|
||||
for (const record of records) {
|
||||
const adoptionId = record.sourceAdoptionId.toString();
|
||||
if (!byAdoption.has(adoptionId)) {
|
||||
byAdoption.set(adoptionId, {
|
||||
personalAmount: 0,
|
||||
teamLevelAmount: 0,
|
||||
teamBonusAmount: 0,
|
||||
totalContribution: record.treeCount * Number(record.baseContribution),
|
||||
});
|
||||
}
|
||||
const stats = byAdoption.get(adoptionId)!;
|
||||
|
||||
const amount = Number(record.amount);
|
||||
switch (record.sourceType) {
|
||||
case 'PERSONAL':
|
||||
stats.personalAmount += amount;
|
||||
break;
|
||||
case 'TEAM_LEVEL':
|
||||
stats.teamLevelAmount += amount;
|
||||
break;
|
||||
case 'TEAM_BONUS':
|
||||
stats.teamBonusAmount += amount;
|
||||
break;
|
||||
|
||||
// 只统计团队部分(TEAM_LEVEL 和 TEAM_BONUS)
|
||||
if (record.sourceType === 'TEAM_LEVEL' || record.sourceType === 'TEAM_BONUS') {
|
||||
teamDistributedByAdoption.set(
|
||||
adoptionId,
|
||||
(teamDistributedByAdoption.get(adoptionId) || 0) + amount,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 构建分配明细
|
||||
for (const [adoptionId, stats] of byAdoption) {
|
||||
const totalContribution = stats.totalContribution;
|
||||
// 为每个认种构建分配明细
|
||||
for (const [adoptionId, adoption] of adoptionMap) {
|
||||
const totalContribution = adoption.treeCount * adoption.contributionPerTree;
|
||||
const teamTotal = totalContribution * 0.15;
|
||||
const teamDistributed = stats.teamLevelAmount + stats.teamBonusAmount;
|
||||
const teamDistributed = teamDistributedByAdoption.get(adoptionId) || 0;
|
||||
const teamUnallocated = teamTotal - teamDistributed;
|
||||
|
||||
result.set(adoptionId, {
|
||||
personal: {
|
||||
rate: 0.70,
|
||||
amount: stats.personalAmount.toFixed(4),
|
||||
amount: (totalContribution * 0.70).toFixed(4),
|
||||
label: '认种人账户',
|
||||
},
|
||||
operation: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue