diff --git a/backend/services/planting-service/src/pre-planting/application/services/pre-planting-reward.service.ts b/backend/services/planting-service/src/pre-planting/application/services/pre-planting-reward.service.ts index 92f41bce..9986e57d 100644 --- a/backend/services/planting-service/src/pre-planting/application/services/pre-planting-reward.service.ts +++ b/backend/services/planting-service/src/pre-planting/application/services/pre-planting-reward.service.ts @@ -208,9 +208,9 @@ export class PrePlantingRewardService { this.referralClient.getReferralChain(accountSequence), this.authorizationClient.getCommunityDistribution(accountSequence), this.authorizationClient.getProvinceAreaDistribution(stdProvinceCode), - this.authorizationClient.getProvinceTeamDistribution(accountSequence), + this.authorizationClient.getProvinceTeamDistribution(accountSequence, stdProvinceCode), this.authorizationClient.getCityAreaDistribution(stdCityCode), - this.authorizationClient.getCityTeamDistribution(accountSequence), + this.authorizationClient.getCityTeamDistribution(accountSequence, stdCityCode), ]); // 推荐奖励 (SHARE_RIGHT) diff --git a/backend/services/planting-service/src/pre-planting/infrastructure/external/pre-planting-authorization.client.ts b/backend/services/planting-service/src/pre-planting/infrastructure/external/pre-planting-authorization.client.ts index 4536c3f3..6c4ff016 100644 --- a/backend/services/planting-service/src/pre-planting/infrastructure/external/pre-planting-authorization.client.ts +++ b/backend/services/planting-service/src/pre-planting/infrastructure/external/pre-planting-authorization.client.ts @@ -45,19 +45,33 @@ export class PrePlantingAuthorizationClient { /** * 社区权益分配对象 + * + * treeCount=0:预种阶段不计入社区月度考核,避免 addMonthlyTrees(NaN) 导致 Prisma 报错 */ async getCommunityDistribution( accountSequence: string, ): Promise { try { const response = await firstValueFrom( - this.httpService.get>( + this.httpService.get>( `${this.baseUrl}/api/v1/authorization/community-reward-distribution`, - { params: { accountSequence } }, + { params: { accountSequence, treeCount: 0 } }, ), ); + + const distributions = response.data.data.distributions; + if (!distributions || distributions.length === 0) { + throw new Error('Empty distributions returned'); + } + + const target = distributions.find(d => !d.isSystemAccount) || distributions[0]; + + this.logger.debug( + `Community distribution for ${accountSequence}: ${target.accountSequence} (${target.reason})`, + ); + return { - recipientAccountSequence: response.data.data.accountSequence, + recipientAccountSequence: target.accountSequence, isFallback: false, }; } catch (error) { @@ -120,19 +134,34 @@ export class PrePlantingAuthorizationClient { /** * 省团队权益分配对象 + * + * treeCount=0:预种阶段不计入省团队月度考核 */ async getProvinceTeamDistribution( accountSequence: string, + provinceCode: string, ): Promise { try { const response = await firstValueFrom( - this.httpService.get>( + this.httpService.get>( `${this.baseUrl}/api/v1/authorization/province-team-reward-distribution`, - { params: { accountSequence } }, + { params: { accountSequence, provinceCode, treeCount: 0 } }, ), ); + + const distributions = response.data.data.distributions; + if (!distributions || distributions.length === 0) { + throw new Error('Empty distributions returned'); + } + + const target = distributions.find(d => !d.isSystemAccount) || distributions[0]; + + this.logger.debug( + `Province team distribution for ${accountSequence}: ${target.accountSequence} (${target.reason})`, + ); + return { - recipientAccountSequence: response.data.data.accountSequence, + recipientAccountSequence: target.accountSequence, isFallback: false, }; } catch (error) { @@ -194,19 +223,34 @@ export class PrePlantingAuthorizationClient { /** * 市团队权益分配对象 + * + * treeCount=0:预种阶段不计入市团队月度考核 */ async getCityTeamDistribution( accountSequence: string, + cityCode: string, ): Promise { try { const response = await firstValueFrom( - this.httpService.get>( + this.httpService.get>( `${this.baseUrl}/api/v1/authorization/city-team-reward-distribution`, - { params: { accountSequence } }, + { params: { accountSequence, cityCode, treeCount: 0 } }, ), ); + + const distributions = response.data.data.distributions; + if (!distributions || distributions.length === 0) { + throw new Error('Empty distributions returned'); + } + + const target = distributions.find(d => !d.isSystemAccount) || distributions[0]; + + this.logger.debug( + `City team distribution for ${accountSequence}: ${target.accountSequence} (${target.reason})`, + ); + return { - recipientAccountSequence: response.data.data.accountSequence, + recipientAccountSequence: target.accountSequence, isFallback: false, }; } catch (error) {