diff --git a/rule/relate_commission.go b/rule/relate_commission.go index 58dc795..f8b7d53 100644 --- a/rule/relate_commission.go +++ b/rule/relate_commission.go @@ -59,35 +59,40 @@ func BatchGetCommissionByGoods(eg *xorm.Engine, dbName string, commissionParamLi return goodsId2lvUser, errors.New("参数错误") } - wg := sync.WaitGroup{} - mu := sync.Mutex{} + group, _ := errgroup.WithContext(context.Background()) + var mu sync.Mutex commArr := GetComm(eg) plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(eg, dbName) for _, param := range commissionParamList { param := param // 为下面的闭包创建局部变量 - wg.Add(1) - go func(param *md.CommissionFirstParam) { - defer wg.Done() - mu.Lock() + group.Go(func() error { if param.IsShare != 0 { isShare = true } if param.IsAllLevelReturn != 0 { isAllLevelReturn = true } - if param.GoodsId != "" { - param.CommissionParam.Oid = param.GoodsId - param.CommissionParam.IsGoods = "1" - param.CommissionParam.ShowLevel = param.ShowLevel - _, _, _, _, lvUser, err := svc.GetRewardCommission(eg, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, commArr, plan, commission, virtualCoinMoneyRate) - if err == nil { - goodsId2lvUser[param.GoodsId] = lvUser - } + if param.GoodsId == "" { + return errors.New("商品ID缺失") } + param.CommissionParam.Oid = param.GoodsId + param.CommissionParam.IsGoods = "1" + param.CommissionParam.ShowLevel = param.ShowLevel + _, _, _, _, lvUser, err := svc.GetRewardCommission(eg, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, commArr, plan, commission, virtualCoinMoneyRate) + if err != nil { + return err + } + mu.Lock() + goodsId2lvUser[param.GoodsId] = lvUser mu.Unlock() - }(param) + + return nil + }) } - wg.Wait() + if err := group.Wait(); err != nil { + return goodsId2lvUser, errors.New("处理错误") + } + return goodsId2lvUser, nil } diff --git a/svc/get_plan_cfg.go b/svc/get_plan_cfg.go index 8b884e0..1c8e4c9 100644 --- a/svc/get_plan_cfg.go +++ b/svc/get_plan_cfg.go @@ -126,6 +126,10 @@ func GetPlanCfg(eg *xorm.Engine, pvd, masterId string, rewardOpts map[string]*mo } } if err := json.Unmarshal([]byte(commissionOpt.Data), &subsidyTmp); err != nil { + if masterId == "68823769" { + fmt.Println("===========================分佣方案数据设置错误", commissionOpt) + fmt.Println("===========================分佣方案数据设置错误", err) + } return nil, zhios_order_relate_logx.Warn(fmt.Sprintf("%s:分佣方案数据设置错误", masterId)) } opt.UserRate = subsidyTmp