fix(mining-admin): restore MINING_ENABLED status filter for adoption stats

Revert the previous change that removed the status filter. The stats
should only count adoptions with MINING_ENABLED status, as only those
are active for mining. The issue is likely that the status field in
synced_adoptions table doesn't have the correct value.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-13 01:32:39 -08:00
parent 65bd4f9b65
commit 20eabbb85f
1 changed files with 13 additions and 8 deletions

View File

@ -111,11 +111,12 @@ export class UsersService {
if (accountSequences.length === 0) return result;
// 获取每个用户的个人认种数量和订单数(统计所有已同步的认种记录
// 获取每个用户的个人认种数量和订单数(只统计 MINING_ENABLED 状态
const personalAdoptions = await this.prisma.syncedAdoption.groupBy({
by: ['accountSequence'],
where: {
accountSequence: { in: accountSequences },
status: 'MINING_ENABLED',
},
_sum: { treeCount: true },
_count: { id: true },
@ -158,6 +159,7 @@ export class UsersService {
const teamAdoptionStats = await this.prisma.syncedAdoption.aggregate({
where: {
accountSequence: { in: teamMembers.map((m) => m.accountSequence) },
status: 'MINING_ENABLED',
},
_sum: { treeCount: true },
_count: { id: true },
@ -219,9 +221,9 @@ export class UsersService {
throw new NotFoundException(`用户 ${accountSequence} 不存在`);
}
// 获取个人认种数量(从 synced_adoptions 统计
// 获取个人认种数量(从 synced_adoptions 统计,只统计 MINING_ENABLED 状态
const personalAdoptionStats = await this.prisma.syncedAdoption.aggregate({
where: { accountSequence },
where: { accountSequence, status: 'MINING_ENABLED' },
_sum: { treeCount: true },
_count: { id: true },
});
@ -233,7 +235,7 @@ export class UsersService {
});
const directReferralCount = directReferrals.length;
// 获取直推认种数量
// 获取直推认种数量(只统计 MINING_ENABLED 状态)
let directReferralAdoptions = 0;
if (directReferrals.length > 0) {
const directAdoptionStats = await this.prisma.syncedAdoption.aggregate({
@ -241,6 +243,7 @@ export class UsersService {
accountSequence: {
in: directReferrals.map((r) => r.accountSequence),
},
status: 'MINING_ENABLED',
},
_sum: { treeCount: true },
});
@ -274,6 +277,7 @@ export class UsersService {
accountSequence: {
in: teamMembers.map((m) => m.accountSequence),
},
status: 'MINING_ENABLED',
},
_sum: { treeCount: true },
});
@ -575,14 +579,14 @@ export class UsersService {
}
/**
*
* MINING_ENABLED
*/
private async getUserAdoptionStats(
accountSequence: string,
): Promise<{ personal: number; team: number }> {
// 个人认种
// 个人认种(只统计 MINING_ENABLED 状态)
const personalStats = await this.prisma.syncedAdoption.aggregate({
where: { accountSequence },
where: { accountSequence, status: 'MINING_ENABLED' },
_sum: { treeCount: true },
});
@ -594,7 +598,7 @@ export class UsersService {
let teamCount = 0;
if (referral?.originalUserId) {
// 团队认种 = 所有下级的认种总和
// 团队认种 = 所有下级的认种总和(只统计 MINING_ENABLED 状态)
const teamMembers = await this.prisma.syncedReferral.findMany({
where: {
ancestorPath: { contains: referral.originalUserId.toString() },
@ -606,6 +610,7 @@ export class UsersService {
const teamStats = await this.prisma.syncedAdoption.aggregate({
where: {
accountSequence: { in: teamMembers.map((m) => m.accountSequence) },
status: 'MINING_ENABLED',
},
_sum: { treeCount: true },
});