feat(authorization-service): 为 getCityTeamRewardDistribution 添加 addMonthlyTrees 调用
参考 getCommunityRewardDistribution 的实现,在以下三个场景添加月度新增树数累计: 1. benefitActive=true 时:全部 treeCount 给该市团队,累加 treeCount 2. currentTeamCount >= initialTarget 时(兜底处理):累加 treeCount 3. 跨越考核达标点时:只累加归自己的部分 afterTargetCount 这确保了市团队权益与社区权益的月度考核追踪逻辑一致。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
d12bf6df2f
commit
8f91a5b985
|
|
@ -1727,6 +1727,11 @@ export class AuthorizationApplicationService {
|
|||
|
||||
// 4. 检查权益状态
|
||||
if (nearestAuthCity.benefitActive) {
|
||||
// 权益已激活,全部给该市团队
|
||||
// 累加月度新增树数(用于月度考核)
|
||||
nearestAuthCity.addMonthlyTrees(treeCount)
|
||||
await this.authorizationRepository.save(nearestAuthCity)
|
||||
|
||||
return {
|
||||
distributions: [
|
||||
{ accountSequence: nearestAuthCity.userId.accountSequence, treeCount, reason: '市团队权益已激活' },
|
||||
|
|
@ -1765,13 +1770,20 @@ export class AuthorizationApplicationService {
|
|||
const distributions: Array<{ accountSequence: string; treeCount: number; reason: string }> = []
|
||||
|
||||
if (currentTeamCount >= initialTarget) {
|
||||
// 已达标但权益未激活(可能是月度考核失败),全部给该市团队
|
||||
// 注:这种情况下应该由系统自动激活权益,但这里作为兜底处理
|
||||
distributions.push({
|
||||
accountSequence: nearestAuthCity.userId.accountSequence,
|
||||
treeCount,
|
||||
reason: '已达初始考核目标',
|
||||
})
|
||||
|
||||
// 自动激活权益
|
||||
await this.tryActivateBenefit(nearestAuthCity)
|
||||
|
||||
// 累加月度新增树数(用于月度考核)
|
||||
nearestAuthCity.addMonthlyTrees(treeCount)
|
||||
await this.authorizationRepository.save(nearestAuthCity)
|
||||
} else {
|
||||
// toReachTarget: 还差多少棵达到考核目标(包括达标那一棵)
|
||||
// 业务规则:达标前的全部给上级/总部,超过达标点后才给该市团队
|
||||
|
|
@ -1800,7 +1812,7 @@ export class AuthorizationApplicationService {
|
|||
reason: `初始考核(${currentTeamCount}+${toReachTarget}=${initialTarget}/${initialTarget}),${parentReason}`,
|
||||
})
|
||||
}
|
||||
// 超过达标点的部分,给该市团队
|
||||
// 超过达标点的部分(第101棵开始),给该市团队
|
||||
const afterTargetCount = treeCount - toReachTarget
|
||||
if (afterTargetCount > 0) {
|
||||
distributions.push({
|
||||
|
|
@ -1809,8 +1821,15 @@ export class AuthorizationApplicationService {
|
|||
reason: `考核达标后权益生效(第${initialTarget + 1}棵起)`,
|
||||
})
|
||||
}
|
||||
|
||||
// 自动激活权益(本次认种使其达标)
|
||||
await this.tryActivateBenefit(nearestAuthCity)
|
||||
|
||||
// 激活后累加月度新增树数(只计算归自己的那部分)
|
||||
if (afterTargetCount > 0) {
|
||||
nearestAuthCity.addMonthlyTrees(afterTargetCount)
|
||||
await this.authorizationRepository.save(nearestAuthCity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue