feat(authorization-service): 为 getProvinceTeamRewardDistribution 添加 addMonthlyTrees 调用

参考 getCommunityRewardDistribution 的实现,在以下三个场景添加月度新增树数累计:
1. benefitActive=true 时:全部 treeCount 给该省团队,累加 treeCount
2. currentTeamCount >= initialTarget 时(兜底处理):累加 treeCount
3. 跨越考核达标点时:只累加归自己的部分 afterTargetCount

这确保了省团队权益与社区权益的月度考核追踪逻辑一致。
- 考核目标:500棵(省团队)
- 奖励:20 USDT
- 无上级时分配到系统省团队账户

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-13 21:55:28 -08:00
parent 8f91a5b985
commit 4a2a1e3855
1 changed files with 20 additions and 1 deletions

View File

@ -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)
}
}
}