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

Only count adoptions with status='MINING_ENABLED' when calculating:
- Personal adoption count (user list)
- Team adoption count (user list)
- Personal adoption stats (user detail)
- Direct referral adoptions (user detail)
- Team adoptions (user detail)
- Referral tree adoption stats

This fixes incorrect adoption counts that included pending/unconfirmed orders.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-13 00:58:01 -08:00
parent 1d7d38a82c
commit 56ff8290c1
1 changed files with 16 additions and 9 deletions

View File

@ -111,10 +111,13 @@ export class UsersService {
if (accountSequences.length === 0) return result; if (accountSequences.length === 0) return result;
// 获取每个用户的个人认种数量 // 获取每个用户的个人认种数量(只统计 MINING_ENABLED 状态)
const personalAdoptions = await this.prisma.syncedAdoption.groupBy({ const personalAdoptions = await this.prisma.syncedAdoption.groupBy({
by: ['accountSequence'], by: ['accountSequence'],
where: { accountSequence: { in: accountSequences } }, where: {
accountSequence: { in: accountSequences },
status: 'MINING_ENABLED',
},
_sum: { treeCount: true }, _sum: { treeCount: true },
}); });
@ -153,6 +156,7 @@ export class UsersService {
const teamAdoptionStats = await this.prisma.syncedAdoption.aggregate({ const teamAdoptionStats = await this.prisma.syncedAdoption.aggregate({
where: { where: {
accountSequence: { in: teamMembers.map((m) => m.accountSequence) }, accountSequence: { in: teamMembers.map((m) => m.accountSequence) },
status: 'MINING_ENABLED',
}, },
_sum: { treeCount: true }, _sum: { treeCount: true },
}); });
@ -212,9 +216,9 @@ export class UsersService {
throw new NotFoundException(`用户 ${accountSequence} 不存在`); throw new NotFoundException(`用户 ${accountSequence} 不存在`);
} }
// 获取个人认种数量(从 synced_adoptions 统计 // 获取个人认种数量(从 synced_adoptions 统计,只统计 MINING_ENABLED 状态
const personalAdoptionStats = await this.prisma.syncedAdoption.aggregate({ const personalAdoptionStats = await this.prisma.syncedAdoption.aggregate({
where: { accountSequence }, where: { accountSequence, status: 'MINING_ENABLED' },
_sum: { treeCount: true }, _sum: { treeCount: true },
_count: { id: true }, _count: { id: true },
}); });
@ -226,7 +230,7 @@ export class UsersService {
}); });
const directReferralCount = directReferrals.length; const directReferralCount = directReferrals.length;
// 获取直推认种数量 // 获取直推认种数量(只统计 MINING_ENABLED 状态)
let directReferralAdoptions = 0; let directReferralAdoptions = 0;
if (directReferrals.length > 0) { if (directReferrals.length > 0) {
const directAdoptionStats = await this.prisma.syncedAdoption.aggregate({ const directAdoptionStats = await this.prisma.syncedAdoption.aggregate({
@ -234,6 +238,7 @@ export class UsersService {
accountSequence: { accountSequence: {
in: directReferrals.map((r) => r.accountSequence), in: directReferrals.map((r) => r.accountSequence),
}, },
status: 'MINING_ENABLED',
}, },
_sum: { treeCount: true }, _sum: { treeCount: true },
}); });
@ -267,6 +272,7 @@ export class UsersService {
accountSequence: { accountSequence: {
in: teamMembers.map((m) => m.accountSequence), in: teamMembers.map((m) => m.accountSequence),
}, },
status: 'MINING_ENABLED',
}, },
_sum: { treeCount: true }, _sum: { treeCount: true },
}); });
@ -568,14 +574,14 @@ export class UsersService {
} }
/** /**
* * MINING_ENABLED
*/ */
private async getUserAdoptionStats( private async getUserAdoptionStats(
accountSequence: string, accountSequence: string,
): Promise<{ personal: number; team: number }> { ): Promise<{ personal: number; team: number }> {
// 个人认种 // 个人认种(只统计 MINING_ENABLED 状态)
const personalStats = await this.prisma.syncedAdoption.aggregate({ const personalStats = await this.prisma.syncedAdoption.aggregate({
where: { accountSequence }, where: { accountSequence, status: 'MINING_ENABLED' },
_sum: { treeCount: true }, _sum: { treeCount: true },
}); });
@ -587,7 +593,7 @@ export class UsersService {
let teamCount = 0; let teamCount = 0;
if (referral?.originalUserId) { if (referral?.originalUserId) {
// 团队认种 = 所有下级的认种总和 // 团队认种 = 所有下级的认种总和(只统计 MINING_ENABLED 状态)
const teamMembers = await this.prisma.syncedReferral.findMany({ const teamMembers = await this.prisma.syncedReferral.findMany({
where: { where: {
ancestorPath: { contains: referral.originalUserId.toString() }, ancestorPath: { contains: referral.originalUserId.toString() },
@ -599,6 +605,7 @@ export class UsersService {
const teamStats = await this.prisma.syncedAdoption.aggregate({ const teamStats = await this.prisma.syncedAdoption.aggregate({
where: { where: {
accountSequence: { in: teamMembers.map((m) => m.accountSequence) }, accountSequence: { in: teamMembers.map((m) => m.accountSequence) },
status: 'MINING_ENABLED',
}, },
_sum: { treeCount: true }, _sum: { treeCount: true },
}); });