From d86d446342ff580e6a8eb16812315e8b6ebe1081 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Fri, 23 Feb 2024 14:20:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- svc/get_plan_cfg.go | 4 +- svc/public_platoon_relate_commission.go | 100 ++++++++++++++++++ svc/reward_commission.go | 16 ++- svc/small_public_platoon_relate_commission.go | 99 +++++++++++++++++ 4 files changed, 214 insertions(+), 5 deletions(-) diff --git a/svc/get_plan_cfg.go b/svc/get_plan_cfg.go index c817a80..5516a6a 100644 --- a/svc/get_plan_cfg.go +++ b/svc/get_plan_cfg.go @@ -122,7 +122,7 @@ func GetPlanCfg(eg *xorm.Engine, pvd, masterId string, rewardOpts map[string]*mo if commissionOpt == nil || commissionOpt.Id == 0 { return nil, errors.New("佣金方案有误") } - if _, ok := comm_plan.Fn[commissionOpt.Mode]; !ok && zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"public_platoon", "extend_price", "lv_integral_release"}) == false { + if _, ok := comm_plan.Fn[commissionOpt.Mode]; !ok && zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"public_platoon_level", "public_platoon", "extend_price", "lv_integral_release"}) == false { return nil, zhios_order_relate_logx.Warn("分佣模式不存在") } opt.Pvd = pvd @@ -156,7 +156,7 @@ func GetPlanCfg(eg *xorm.Engine, pvd, masterId string, rewardOpts map[string]*mo } else { opt.VirtualCoinMoneyRatioList = virtualCoinMoneyRate } - if zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"public_platoon", "extend_price", "lv_integral_release"}) { //公排 + if zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"public_platoon_level", "public_platoon", "extend_price", "lv_integral_release"}) { //公排 return opt, nil } diff --git a/svc/public_platoon_relate_commission.go b/svc/public_platoon_relate_commission.go index fdf3440..94dea20 100644 --- a/svc/public_platoon_relate_commission.go +++ b/svc/public_platoon_relate_commission.go @@ -143,3 +143,103 @@ func benefitUidByBig(engine *xorm.Engine, param *md.PublicPlatoonRelateCommissio return nowBenefitUid, nil, nil } + +func BatchGetPublicPlatoonRelateCommissionByOrderLevel(engine *xorm.Engine, masterId string, PublicPlatoonRelateCommissionReqList []*md.PublicPlatoonRelateCommissionReq) (map[string]*md.PublicPlatoonRelateCommissionResp, error) { + var resp = make(map[string]*md.PublicPlatoonRelateCommissionResp) + for _, param := range PublicPlatoonRelateCommissionReqList { + // 根据供应商 + rewardOpt, err := db.DbsPlanRewardByPvd(engine, param.Pvd) + if err != nil { + return nil, err + } + if rewardOpt == nil { + return nil, zhios_order_relate_logx.Warn("找不到方案记录") + } + if rewardOpt.State == 0 { + return nil, zhios_order_relate_logx.Warn("抽成方案未开启") + } + if rewardOpt.PlanCommissionId == 0 { + return nil, zhios_order_relate_logx.Warn("抽成方案未设置佣金方案id") + } + fmt.Println("抽成设置:", zhios_order_relate_utils.SerializeStr(rewardOpt)) + fmt.Println("commission id:", rewardOpt.PlanCommissionId) + + //TODO::计算共富收益 + commissionOpt, err := db.DbsPlanCommissionById(engine, rewardOpt.PlanCommissionId) + if err != nil || commissionOpt == nil || commissionOpt.Id == 0 { + return nil, err + } + var subsidyTmp = make(map[string]*md.LvGrade) + var tmp map[string]*md.LvGrade + if err := json.Unmarshal([]byte(commissionOpt.Data), &tmp); err != nil { + return nil, zhios_order_relate_logx.Warn(fmt.Sprintf("%s:分佣方案数据设置错误", masterId)) + } + for _, v := range tmp { + subsidyTmp[zhios_order_relate_utils.IntToStr(v.Lv)] = v + } + lvGrade := subsidyTmp[param.UserLevel] + var directPush = make(map[string]string) + var selfRateList = make(map[string]string) + var commonWealthSystem = make(map[string]string) + if lvGrade != nil { + for _, coinId := range lvGrade.ReturnType { + var pendingAmount = param.PendingAmount + if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 + pendingAmount = param.PendingIntegral + } + selfRateList[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.SelfRateList[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100) + } + } + nowBenefitUid, _, err := benefitUidByBig(engine, param) + if err != nil { + return nil, err + } + recommendUid := "" + userProfile, _ := db.UserProfileFindByID(engine, param.Uid) + if userProfile != nil && userProfile.ParentUid > 0 { + recommendUid = zhios_order_relate_utils.IntToStr(userProfile.ParentUid) + } + //直推獎勵 + if zhios_order_relate_utils.StrToInt(recommendUid) > 0 { + parentUid, _ := db.UserFindByID(engine, recommendUid) + lvGrade1 := subsidyTmp[zhios_order_relate_utils.IntToStr(parentUid.Level)] + if lvGrade1 != nil { + for _, coinId := range lvGrade1.ReturnType { + var pendingAmount = param.PendingAmount + if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 + pendingAmount = param.PendingIntegral + } + directPush[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.DirectPush[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100) + } + } + } + //共富简历 + if zhios_order_relate_utils.StrToInt(nowBenefitUid) > 0 { + parentUid, _ := db.UserFindByID(engine, nowBenefitUid) + lvGrade1 := subsidyTmp[zhios_order_relate_utils.IntToStr(parentUid.Level)] + if lvGrade1 != nil { + for _, coinId := range lvGrade1.ReturnType { + var pendingAmount = param.PendingAmount + if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 + pendingAmount = param.PendingIntegral + } + commonWealthSystem[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.CommonWealthSystem[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100) + } + } + } + + /// + resp[param.Oid] = &md.PublicPlatoonRelateCommissionResp{ + Uid: param.Uid, + CommonWealthBenefitUid: nowBenefitUid, + DirectPushBenefitUid: recommendUid, + PendingAmount: param.PendingAmount, + PendingIntegral: param.PendingIntegral, + Oid: param.Oid, + SelfRateList: selfRateList, + CommonWealthSystem: commonWealthSystem, + DirectPush: directPush, + } + } + return resp, nil +} diff --git a/svc/reward_commission.go b/svc/reward_commission.go index 3501ad8..96dd1dc 100644 --- a/svc/reward_commission.go +++ b/svc/reward_commission.go @@ -86,7 +86,7 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b if zhios_order_relate_utils.InArr(cfg.Mode, []string{"lv_price_public_platoon", "lv_price", "lv_price_other", "lv_winery", "extend_price", "niubei_amount"}) && zhios_order_relate_utils.StrToFloat64(rmd.OldPrice) > 0 { //价格为基数 comf = zhios_order_relate_utils.StrToFloat64(rmd.OldPrice) } - if cfg.Mode == "public_platoon" { + if cfg.Mode == "public_platoon" || cfg.Mode == "public_platoon_level" { //公排 //佣金扣除抽成后 fee, _, pvdFee, sysFee := CommFee(comf, cfg, "commission", rmd) @@ -117,7 +117,11 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b if rmd.IsGoods == "1" { order, err = BatchSmallGetPublicPlatoonRelateByGoods(engine, masterId, PublicPlatoonRelateCommissionReqList) } else { - order, err = BatchSmallGetPublicPlatoonRelateCommission(engine, masterId, PublicPlatoonRelateCommissionReqList) + if cfg.Mode == "public_platoon_level" { + order, err = BatchSmallGetPublicPlatoonRelateCommissionLevel(engine, masterId, PublicPlatoonRelateCommissionReqList) + } else { + order, err = BatchSmallGetPublicPlatoonRelateCommission(engine, masterId, PublicPlatoonRelateCommissionReqList) + } } if err != nil || order[rmd.Oid] == nil { return 0, 0, 0, 0, nil, nil @@ -142,7 +146,13 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b if rmd.IsGoods == "1" { order, err = BatchGetPublicPlatoonRelateCommissionByGoods(engine, masterId, PublicPlatoonRelateCommissionReqList) } else { - order, err = BatchGetPublicPlatoonRelateCommissionByOrder(engine, masterId, PublicPlatoonRelateCommissionReqList) + if cfg.Mode == "public_platoon_level" { + order, err = BatchGetPublicPlatoonRelateCommissionByOrderLevel(engine, masterId, PublicPlatoonRelateCommissionReqList) + + } else { + order, err = BatchGetPublicPlatoonRelateCommissionByOrder(engine, masterId, PublicPlatoonRelateCommissionReqList) + + } } if err != nil || order[rmd.Oid] == nil { return 0, 0, 0, 0, nil, nil diff --git a/svc/small_public_platoon_relate_commission.go b/svc/small_public_platoon_relate_commission.go index 4cede8c..2e91c2e 100644 --- a/svc/small_public_platoon_relate_commission.go +++ b/svc/small_public_platoon_relate_commission.go @@ -355,3 +355,102 @@ func BatchSmallGetPublicPlatoonRelateByGoods(engine *xorm.Engine, masterId strin } return resp, nil } + +func BatchSmallGetPublicPlatoonRelateCommissionLevel(engine *xorm.Engine, masterId string, PublicPlatoonRelateCommissionReqList []*md.SmallPublicPlatoonRelateCommissionReq) (map[string]*md.SmallPublicPlatoonRelateCommissionResp, error) { + var resp = make(map[string]*md.SmallPublicPlatoonRelateCommissionResp) + for _, param := range PublicPlatoonRelateCommissionReqList { + // 根据供应商 + rewardOpt, err := db.DbsPlanRewardByPvd(engine, param.Pvd) + if err != nil { + return nil, err + } + if rewardOpt == nil { + return nil, zhios_order_relate_logx.Warn("找不到方案记录") + } + if rewardOpt.State == 0 { + return nil, zhios_order_relate_logx.Warn("抽成方案未开启") + } + if rewardOpt.PlanCommissionId == 0 { + return nil, zhios_order_relate_logx.Warn("抽成方案未设置佣金方案id") + } + fmt.Println("抽成设置:", zhios_order_relate_utils.SerializeStr(rewardOpt)) + fmt.Println("commission id:", rewardOpt.PlanCommissionId) + + //TODO::计算共富收益 + commissionOpt, err := db.DbsPlanCommissionById(engine, rewardOpt.PlanCommissionId) + if err != nil || commissionOpt == nil || commissionOpt.Id == 0 { + return nil, err + } + var subsidyTmp = make(map[string]*md.LvGrade) + var tmp map[string]*md.LvGrade + if err := json.Unmarshal([]byte(commissionOpt.Data), &tmp); err != nil { + return nil, zhios_order_relate_logx.Warn(fmt.Sprintf("%s:分佣方案数据设置错误", masterId)) + } + for _, v := range tmp { + subsidyTmp[zhios_order_relate_utils.IntToStr(v.Lv)] = v + } + var directPush = make(map[string]string) + var selfRateList = make(map[string]string) + var commonWealthSystem = make(map[string]string) + lvGrade := subsidyTmp[param.UserLevel] + if lvGrade != nil { + for _, coinId := range lvGrade.ReturnType { + var pendingAmount = param.PendingAmount + if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 + pendingAmount = param.PendingIntegral + } + selfRateList[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.SelfRateList[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100) + } + } + //TODO::本次消费产生的共富收益给到谁 + nowBenefitUid, _, err := benefitUid(engine, param) + if err != nil { + return nil, err + } + recommendUid := "" + userProfile, _ := db.UserProfileFindByID(engine, param.Uid) + if userProfile != nil && userProfile.ParentUid > 0 { + recommendUid = zhios_order_relate_utils.IntToStr(userProfile.ParentUid) + } + //直推獎勵 + if zhios_order_relate_utils.StrToInt(recommendUid) > 0 { + parentUid, _ := db.UserFindByID(engine, recommendUid) + lvGrade1 := subsidyTmp[zhios_order_relate_utils.IntToStr(parentUid.Level)] + if lvGrade1 != nil { + for _, coinId := range lvGrade1.ReturnType { + var pendingAmount = param.PendingAmount + if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 + pendingAmount = param.PendingIntegral + } + directPush[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.DirectPush[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100) + } + } + } + //共富简历 + if zhios_order_relate_utils.StrToInt(nowBenefitUid) > 0 { + parentUid, _ := db.UserFindByID(engine, nowBenefitUid) + lvGrade1 := subsidyTmp[zhios_order_relate_utils.IntToStr(parentUid.Level)] + if lvGrade1 != nil { + for _, coinId := range lvGrade1.ReturnType { + var pendingAmount = param.PendingAmount + if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 + pendingAmount = param.PendingIntegral + } + commonWealthSystem[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.CommonWealthSystem[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100) + } + } + } + + resp[param.Oid] = &md.SmallPublicPlatoonRelateCommissionResp{ + Uid: param.Uid, + CommonWealthBenefitUid: nowBenefitUid, + DirectPushBenefitUid: recommendUid, + PendingAmount: param.PendingAmount, + Oid: param.Oid, + SelfRateList: selfRateList, + CommonWealthSystem: commonWealthSystem, + DirectPush: directPush, + } + } + return resp, nil +}