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:
@@ -449,12 +449,23 @@ func (s *Service) calculateChainOneTimeCommission(ctx context.Context, bottomSho
|
|||||||
var myAmount int64
|
var myAmount int64
|
||||||
|
|
||||||
if config.CommissionType == "tiered" && len(config.Tiers) > 0 {
|
if config.CommissionType == "tiered" && len(config.Tiers) > 0 {
|
||||||
tieredAmount, tierErr := s.matchOneTimeCommissionTier(ctx, currentShopID, seriesID, currentSeriesAllocation.ID, config.Tiers)
|
// 获取该代理的专属阶梯金额列表
|
||||||
if tierErr != nil {
|
agentTiers, tiersErr := currentSeriesAllocation.GetCommissionTiers()
|
||||||
s.logger.Warn("匹配梯度佣金失败,使用固定金额", zap.Uint("shop_id", currentShopID), zap.Error(tierErr))
|
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
|
myAmount = currentSeriesAllocation.OneTimeCommissionAmount
|
||||||
} else {
|
} else {
|
||||||
myAmount = tieredAmount
|
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 {
|
} else {
|
||||||
myAmount = currentSeriesAllocation.OneTimeCommissionAmount
|
myAmount = currentSeriesAllocation.OneTimeCommissionAmount
|
||||||
@@ -512,7 +523,7 @@ func (s *Service) calculateChainOneTimeCommission(ctx context.Context, bottomSho
|
|||||||
return records, nil
|
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 {
|
if len(tiers) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@@ -553,8 +564,29 @@ func (s *Service) matchOneTimeCommissionTier(ctx context.Context, shopID uint, s
|
|||||||
currentValue = salesAmount
|
currentValue = salesAmount
|
||||||
}
|
}
|
||||||
|
|
||||||
if currentValue >= tier.Threshold && tier.Amount > matchedAmount {
|
// 根据 tier.Operator 判断是否命中阈值,Operator 为空时默认 >=
|
||||||
matchedAmount = tier.Amount
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -616,8 +616,8 @@ func (s *Service) fillCommissionInfo(resp *dto.PackageResponse, seriesID uint, s
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否启用一次性佣金
|
// 一次性佣金是否启用由 PackageSeries.enable_one_time_commission 控制
|
||||||
if !seriesAllocation.EnableOneTimeCommission || !config.Enable {
|
if !config.Enable {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user