diff --git a/backend/services/contribution-service/src/infrastructure/persistence/repositories/synced-data.repository.ts b/backend/services/contribution-service/src/infrastructure/persistence/repositories/synced-data.repository.ts index 331fe91b..c8f986f1 100644 --- a/backend/services/contribution-service/src/infrastructure/persistence/repositories/synced-data.repository.ts +++ b/backend/services/contribution-service/src/infrastructure/persistence/repositories/synced-data.repository.ts @@ -136,7 +136,10 @@ export class SyncedDataRepository implements ISyncedDataRepository { async findUndistributedAdoptions(limit: number = 100): Promise { const records = await this.client.syncedAdoption.findMany({ - where: { contributionDistributed: false }, + where: { + contributionDistributed: false, + status: 'MINING_ENABLED', // 只处理最终成功的认种订单 + }, orderBy: { adoptionDate: 'asc' }, take: limit, }); @@ -171,7 +174,10 @@ export class SyncedDataRepository implements ISyncedDataRepository { async getTotalTreesByAccountSequence(accountSequence: string): Promise { const result = await this.client.syncedAdoption.aggregate({ - where: { accountSequence }, + where: { + accountSequence, + status: 'MINING_ENABLED', // 只统计最终成功的认种订单 + }, _sum: { treeCount: true }, }); return result._sum.treeCount ?? 0; @@ -285,8 +291,12 @@ export class SyncedDataRepository implements ISyncedDataRepository { const accountSequences = directReferrals.map((r) => r.accountSequence); + // 只统计有 MINING_ENABLED 状态认种记录的直推用户数 const adoptedCount = await this.client.syncedAdoption.findMany({ - where: { accountSequence: { in: accountSequences } }, + where: { + accountSequence: { in: accountSequences }, + status: 'MINING_ENABLED', // 只统计最终成功的认种订单 + }, distinct: ['accountSequence'], }); @@ -308,7 +318,10 @@ export class SyncedDataRepository implements ISyncedDataRepository { const adoptions = await this.client.syncedAdoption.groupBy({ by: ['accountSequence'], - where: { accountSequence: { in: sequences } }, + where: { + accountSequence: { in: sequences }, + status: 'MINING_ENABLED', // 只统计最终成功的认种订单 + }, _sum: { treeCount: true }, }); @@ -358,7 +371,10 @@ export class SyncedDataRepository implements ISyncedDataRepository { async countUndistributedAdoptions(): Promise { return this.client.syncedAdoption.count({ - where: { contributionDistributed: false }, + where: { + contributionDistributed: false, + status: 'MINING_ENABLED', // 只统计最终成功的认种订单 + }, }); }