refactor: 佣金计算适配梯度阶梯 Operator 比较,套餐服务集成代理强充逻辑

commission_calculation: matchOneTimeCommissionTier() 接收 agentTiers 参数,根据 tier.Operator(>、>=、<、<=,默认 >=)执行对应比较逻辑,支持代理专属梯度阶梯计算。package/service: 套餐购买预检调用更新后的强充层级判断接口。

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-03-04 11:37:02 +08:00
parent 2ca33b7172
commit c7b8ecfebf
2 changed files with 41 additions and 9 deletions

View File

@@ -449,13 +449,24 @@ func (s *Service) calculateChainOneTimeCommission(ctx context.Context, bottomSho
var myAmount int64
if config.CommissionType == "tiered" && len(config.Tiers) > 0 {
tieredAmount, tierErr := s.matchOneTimeCommissionTier(ctx, currentShopID, seriesID, currentSeriesAllocation.ID, config.Tiers)
// 获取该代理的专属阶梯金额列表
agentTiers, tiersErr := currentSeriesAllocation.GetCommissionTiers()
if tiersErr != nil {
s.logger.Warn("解析代理阶梯佣金失败,使用固定金额", zap.Uint("shop_id", currentShopID), zap.Error(tiersErr))
myAmount = currentSeriesAllocation.OneTimeCommissionAmount
} else if len(agentTiers) == 0 {
// commission_tiers_json 为空(历史数据),降级到 OneTimeCommissionAmount
s.logger.Warn("代理专属阶梯为空fallback 到固定金额", zap.Uint("shop_id", currentShopID))
myAmount = currentSeriesAllocation.OneTimeCommissionAmount
} else {
tieredAmount, tierErr := s.matchOneTimeCommissionTier(ctx, currentShopID, seriesID, currentSeriesAllocation.ID, config.Tiers, agentTiers)
if tierErr != nil {
s.logger.Warn("匹配梯度佣金失败,使用固定金额", zap.Uint("shop_id", currentShopID), zap.Error(tierErr))
myAmount = currentSeriesAllocation.OneTimeCommissionAmount
} else {
myAmount = tieredAmount
}
}
} else {
myAmount = currentSeriesAllocation.OneTimeCommissionAmount
}
@@ -512,7 +523,7 @@ func (s *Service) calculateChainOneTimeCommission(ctx context.Context, bottomSho
return records, nil
}
func (s *Service) matchOneTimeCommissionTier(ctx context.Context, shopID uint, seriesID uint, allocationID uint, tiers []model.OneTimeCommissionTier) (int64, error) {
func (s *Service) matchOneTimeCommissionTier(ctx context.Context, shopID uint, seriesID uint, allocationID uint, tiers []model.OneTimeCommissionTier, agentTiers []model.AllocationCommissionTier) (int64, error) {
if len(tiers) == 0 {
return 0, nil
}
@@ -553,8 +564,29 @@ func (s *Service) matchOneTimeCommissionTier(ctx context.Context, shopID uint, s
currentValue = salesAmount
}
if currentValue >= tier.Threshold && tier.Amount > matchedAmount {
matchedAmount = tier.Amount
// 根据 tier.Operator 判断是否命中阈值Operator 为空时默认 >=
var hit bool
switch tier.Operator {
case model.TierOperatorGT:
hit = currentValue > tier.Threshold
case model.TierOperatorLT:
hit = currentValue < tier.Threshold
case model.TierOperatorLTE:
hit = currentValue <= tier.Threshold
default: // >= 或空字符串
hit = currentValue >= tier.Threshold
}
if !hit {
continue
}
// 从代理专属阶梯列表中按 threshold 查找对应金额
for _, agentTier := range agentTiers {
if agentTier.Threshold == tier.Threshold && agentTier.Amount > matchedAmount {
matchedAmount = agentTier.Amount
break
}
}
}

View File

@@ -616,8 +616,8 @@ func (s *Service) fillCommissionInfo(resp *dto.PackageResponse, seriesID uint, s
return
}
// 检查是否启用一次性佣金
if !seriesAllocation.EnableOneTimeCommission || !config.Enable {
// 一次性佣金是否启用由 PackageSeries.enable_one_time_commission 控制
if !config.Enable {
return
}