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 统计)
|
// 获取每笔认种的实际分配明细(从 contribution_records 统计)
|
||||||
const adoptionIds = adoptions.map((a) => a.originalAdoptionId);
|
const adoptionMap = new Map(adoptions.map((a) => [
|
||||||
const distributionByAdoption = await this.getDistributionByAdoptions(adoptionIds);
|
a.originalAdoptionId.toString(),
|
||||||
|
{ treeCount: a.treeCount, contributionPerTree: Number(a.contributionPerTree) },
|
||||||
|
]));
|
||||||
|
const distributionByAdoption = await this.getDistributionByAdoptions(adoptionMap);
|
||||||
|
|
||||||
// 格式化认种记录,包含分配明细
|
// 格式化认种记录,包含分配明细
|
||||||
const items = adoptions.map((a) => {
|
const items = adoptions.map((a) => {
|
||||||
|
|
@ -1014,72 +1017,54 @@ export class UsersService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取认种的实际分配明细
|
* 获取认种的实际分配明细
|
||||||
* 从 contribution_records 表统计每笔认种的实际分配
|
* 基于认种的总算力计算各项分配金额
|
||||||
*/
|
*/
|
||||||
private async getDistributionByAdoptions(
|
private async getDistributionByAdoptions(
|
||||||
adoptionIds: bigint[],
|
adoptionMap: Map<string, { treeCount: number; contributionPerTree: number }>,
|
||||||
): Promise<Map<string, any>> {
|
): Promise<Map<string, any>> {
|
||||||
const result = new 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({
|
const records = await this.prisma.syncedContributionRecord.findMany({
|
||||||
where: { sourceAdoptionId: { in: adoptionIds } },
|
where: { sourceAdoptionId: { in: adoptionIds } },
|
||||||
select: {
|
select: {
|
||||||
sourceAdoptionId: true,
|
sourceAdoptionId: true,
|
||||||
sourceType: true,
|
sourceType: true,
|
||||||
amount: true,
|
amount: true,
|
||||||
baseContribution: true,
|
|
||||||
treeCount: true,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// 按认种ID分组统计
|
// 按认种ID分组统计团队分配的实际发放
|
||||||
const byAdoption = new Map<string, {
|
const teamDistributedByAdoption = new Map<string, number>();
|
||||||
personalAmount: number;
|
|
||||||
teamLevelAmount: number;
|
|
||||||
teamBonusAmount: number;
|
|
||||||
totalContribution: number;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
const adoptionId = record.sourceAdoptionId.toString();
|
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);
|
const amount = Number(record.amount);
|
||||||
switch (record.sourceType) {
|
|
||||||
case 'PERSONAL':
|
// 只统计团队部分(TEAM_LEVEL 和 TEAM_BONUS)
|
||||||
stats.personalAmount += amount;
|
if (record.sourceType === 'TEAM_LEVEL' || record.sourceType === 'TEAM_BONUS') {
|
||||||
break;
|
teamDistributedByAdoption.set(
|
||||||
case 'TEAM_LEVEL':
|
adoptionId,
|
||||||
stats.teamLevelAmount += amount;
|
(teamDistributedByAdoption.get(adoptionId) || 0) + amount,
|
||||||
break;
|
);
|
||||||
case 'TEAM_BONUS':
|
|
||||||
stats.teamBonusAmount += amount;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建分配明细
|
// 为每个认种构建分配明细
|
||||||
for (const [adoptionId, stats] of byAdoption) {
|
for (const [adoptionId, adoption] of adoptionMap) {
|
||||||
const totalContribution = stats.totalContribution;
|
const totalContribution = adoption.treeCount * adoption.contributionPerTree;
|
||||||
const teamTotal = totalContribution * 0.15;
|
const teamTotal = totalContribution * 0.15;
|
||||||
const teamDistributed = stats.teamLevelAmount + stats.teamBonusAmount;
|
const teamDistributed = teamDistributedByAdoption.get(adoptionId) || 0;
|
||||||
const teamUnallocated = teamTotal - teamDistributed;
|
const teamUnallocated = teamTotal - teamDistributed;
|
||||||
|
|
||||||
result.set(adoptionId, {
|
result.set(adoptionId, {
|
||||||
personal: {
|
personal: {
|
||||||
rate: 0.70,
|
rate: 0.70,
|
||||||
amount: stats.personalAmount.toFixed(4),
|
amount: (totalContribution * 0.70).toFixed(4),
|
||||||
label: '认种人账户',
|
label: '认种人账户',
|
||||||
},
|
},
|
||||||
operation: {
|
operation: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue