diff --git a/backend/services/authorization-service/src/application/services/authorization-application.service.ts b/backend/services/authorization-service/src/application/services/authorization-application.service.ts index 085e52b6..82c326fd 100644 --- a/backend/services/authorization-service/src/application/services/authorization-application.service.ts +++ b/backend/services/authorization-service/src/application/services/authorization-application.service.ts @@ -1417,6 +1417,11 @@ export class AuthorizationApplicationService { // 4. 检查权益状态 if (nearestAuthProvince.benefitActive) { + // 权益已激活,全部给该省团队 + // 累加月度新增树数(用于月度考核) + nearestAuthProvince.addMonthlyTrees(treeCount) + await this.authorizationRepository.save(nearestAuthProvince) + return { distributions: [ { accountSequence: nearestAuthProvince.userId.accountSequence, treeCount, reason: '省团队权益已激活' }, @@ -1455,13 +1460,20 @@ export class AuthorizationApplicationService { const distributions: Array<{ accountSequence: string; treeCount: number; reason: string }> = [] if (currentTeamCount >= initialTarget) { + // 已达标但权益未激活(可能是月度考核失败),全部给该省团队 + // 注:这种情况下应该由系统自动激活权益,但这里作为兜底处理 distributions.push({ accountSequence: nearestAuthProvince.userId.accountSequence, treeCount, reason: '已达初始考核目标', }) + // 自动激活权益 await this.tryActivateBenefit(nearestAuthProvince) + + // 累加月度新增树数(用于月度考核) + nearestAuthProvince.addMonthlyTrees(treeCount) + await this.authorizationRepository.save(nearestAuthProvince) } else { // toReachTarget: 还差多少棵达到考核目标(包括达标那一棵) // 业务规则:达标前的全部给上级/总部,超过达标点后才给该省团队 @@ -1490,7 +1502,7 @@ export class AuthorizationApplicationService { reason: `初始考核(${currentTeamCount}+${toReachTarget}=${initialTarget}/${initialTarget}),${parentReason}`, }) } - // 超过达标点的部分,给该省团队 + // 超过达标点的部分(第501棵开始),给该省团队 const afterTargetCount = treeCount - toReachTarget if (afterTargetCount > 0) { distributions.push({ @@ -1499,8 +1511,15 @@ export class AuthorizationApplicationService { reason: `考核达标后权益生效(第${initialTarget + 1}棵起)`, }) } + // 自动激活权益(本次认种使其达标) await this.tryActivateBenefit(nearestAuthProvince) + + // 激活后累加月度新增树数(只计算归自己的那部分) + if (afterTargetCount > 0) { + nearestAuthProvince.addMonthlyTrees(afterTargetCount) + await this.authorizationRepository.save(nearestAuthProvince) + } } }