fix: 修复未启用一次性佣金的系列无法创建授权的问题
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m18s

This commit is contained in:
2026-04-02 14:27:09 +08:00
parent ecfa417c15
commit 322ded0012

View File

@@ -202,15 +202,13 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateShopSeriesGrantRequ
operatorShopID := middleware.GetShopIDFromContext(ctx) operatorShopID := middleware.GetShopIDFromContext(ctx)
operatorType := middleware.GetUserTypeFromContext(ctx) operatorType := middleware.GetUserTypeFromContext(ctx)
// 1. 查询套餐系列,确认佣金类型 // 1. 查询套餐系列,解析一次性佣金配置(可选)
// 系列授权同时作为套餐销售权限的入口记录,未启用一次性佣金的系列也可创建授权,佣金金额默认为 0
series, err := s.packageSeriesStore.GetByID(ctx, req.SeriesID) series, err := s.packageSeriesStore.GetByID(ctx, req.SeriesID)
if err != nil { if err != nil {
return nil, errors.New(errors.CodeNotFound, "套餐系列不存在") return nil, errors.New(errors.CodeNotFound, "套餐系列不存在")
} }
config, err := series.GetOneTimeCommissionConfig() config, _ := series.GetOneTimeCommissionConfig()
if err != nil || config == nil || !config.Enable {
return nil, errors.New(errors.CodeInvalidParam, "该系列未启用一次性佣金,无法创建授权")
}
// 1.5 校验目标店铺是否存在 // 1.5 校验目标店铺是否存在
_, err = s.shopStore.GetByID(ctx, req.ShopID) _, err = s.shopStore.GetByID(ctx, req.ShopID)
@@ -238,7 +236,7 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateShopSeriesGrantRequ
} }
// 平台/超管 allocatorShopID = 0 // 平台/超管 allocatorShopID = 0
// 4. 参数验证:固定模式 or 梯度模式 // 4. 参数验证:仅启用一次性佣金的系列才需要配置佣金金额
allocation := &model.ShopSeriesAllocation{ allocation := &model.ShopSeriesAllocation{
ShopID: req.ShopID, ShopID: req.ShopID,
SeriesID: req.SeriesID, SeriesID: req.SeriesID,
@@ -249,6 +247,7 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateShopSeriesGrantRequ
allocation.Creator = operatorID allocation.Creator = operatorID
allocation.Updater = operatorID allocation.Updater = operatorID
if config != nil && config.Enable {
if config.CommissionType == "fixed" { if config.CommissionType == "fixed" {
if req.OneTimeCommissionAmount == nil { if req.OneTimeCommissionAmount == nil {
return nil, errors.New(errors.CodeInvalidParam, "固定模式必须填写佣金金额") return nil, errors.New(errors.CodeInvalidParam, "固定模式必须填写佣金金额")
@@ -304,6 +303,7 @@ func (s *Service) Create(ctx context.Context, req *dto.CreateShopSeriesGrantRequ
allocation.ForceRechargeAmount = *req.ForceRechargeAmount allocation.ForceRechargeAmount = *req.ForceRechargeAmount
} }
} }
}
// 6. 事务中创建 ShopSeriesAllocation + N 条 ShopPackageAllocation // 6. 事务中创建 ShopSeriesAllocation + N 条 ShopPackageAllocation
err = s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { err = s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {