From 6911bfff35ed88a22c25274e1c0bd8e54e74699a Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 22 Nov 2022 10:23:35 +0800 Subject: [PATCH] =?UTF-8?q?add=20reverse:for=20v3.9.0=20=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E9=87=8A=E6=94=BE=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/comm_plan/init.go | 2 - md/integral_release.go | 10 +++++ svc/get_plan_cfg.go | 14 +------ svc/reward_commission.go | 2 +- svc/svc_integral_release.go | 78 ++++++++++++++++++++++++------------- 5 files changed, 63 insertions(+), 43 deletions(-) create mode 100644 md/integral_release.go diff --git a/lib/comm_plan/init.go b/lib/comm_plan/init.go index 1a705aa..60c28db 100644 --- a/lib/comm_plan/init.go +++ b/lib/comm_plan/init.go @@ -53,8 +53,6 @@ type LvGrade struct { ReturnType []string `json:"return_type"` //返利类型 SelfRateList map[string]string `json:"self_rate_list"` // 自购比例 TeamRateList map[string]string `json:"team_rate_list"` // 团队最高比例 - FirstExtend map[string]string `json:"first_extend"` // - SecondExtend map[string]string `json:"second_extend"` // SubsidyModeList map[string]interface{} `json:"subsidy_mode_list"` // 各币种返佣模式:bili:比例 money:固定金额 //SubsidyBlockIconsMode string `json:"subsidy_block_icons_mode"` //分销 区块币返利类型 bili 比例 money 固定金额 //SubsidyCommissionMode string `json:"subsidy_commission_mode"` //分销 佣金返利类型 bili 比例 money 固定金额 diff --git a/md/integral_release.go b/md/integral_release.go new file mode 100644 index 0000000..ddce917 --- /dev/null +++ b/md/integral_release.go @@ -0,0 +1,10 @@ +package md + +type IntegralReleaseLvGrade struct { + Lv int `json:"lv"` // 会员级别 + LvName string `json:"lv_name"` // 会员名称 + ReturnType []string `json:"return_type"` //返利类型 + FirstExtend map[string]string `json:"first_extend"` // + SecondExtend map[string]string `json:"second_extend"` // + SelfRateList map[string]string `json:"self_rate_list"` // 自购比例 +} diff --git a/svc/get_plan_cfg.go b/svc/get_plan_cfg.go index e7b5b77..92dcf57 100644 --- a/svc/get_plan_cfg.go +++ b/svc/get_plan_cfg.go @@ -80,7 +80,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"}) { //公排 + if zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"public_platoon", "extend_price", "lv_integral_release"}) { //公排 return opt, nil } @@ -91,11 +91,6 @@ func GetPlanCfg(eg *xorm.Engine, pvd, masterId string, rewardOpts map[string]*mo var subsidyTmp map[int]*comm_plan.LvGrade commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"bili\":0", "\"bili\":\"0\"") commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"buy_deliver_list\":[]", "\"buy_deliver_list\":{}") - commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"team_rate_list\":[]", "\"team_rate_list\":{}") - commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"second_extend\":[]", "\"second_extend\":{}") - commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"first_extend\":[]", "\"first_extend\":{}") - //commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"peer_rate_list\":[]", "\"peer_rate_list\":{}") - commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"peer_rate_list\":[[],[],[]]", "\"peer_rate_list\":[]") if strings.Contains(commissionOpt.Data, "\"subsidy_mode_list\":[") { //兼容旧的方案 tmp := strings.Split(commissionOpt.Data, "\"subsidy_mode_list\":[") if len(tmp) > 0 { @@ -125,13 +120,6 @@ func GetPlanCfg(eg *xorm.Engine, pvd, masterId string, rewardOpts map[string]*mo if err := json.Unmarshal([]byte(commissionOpt.Data), &subsidyTmp); err != nil { return nil, zhios_order_relate_logx.Warn(fmt.Sprintf("%s:分佣方案数据设置错误", masterId)) } - if zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"lv_integral_release"}) { - var subsidyTmp1 = make(map[int]*comm_plan.LvGrade) - for _, v := range subsidyTmp { - subsidyTmp1[v.Lv] = v - } - subsidyTmp = subsidyTmp1 - } opt.UserRate = subsidyTmp return opt, nil diff --git a/svc/reward_commission.go b/svc/reward_commission.go index 6a672a2..7d3e3b9 100644 --- a/svc/reward_commission.go +++ b/svc/reward_commission.go @@ -163,7 +163,7 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b } if cfg.Mode == "lv_integral_release" { //公排 price = rmd.OldPrice - pvdFee, sysFee, _, ulink, err := IntegralRelease(engine, uid, newLevel, returnAllLevel, rmd.IsShowExtend, newProvider, user, comf, price, cfg, rmd.IsGoods, commArr) + pvdFee, sysFee, _, ulink, err := IntegralRelease(engine, uid, newLevel, returnAllLevel, rmd.IsShowExtend, newProvider, user, comf, price, cfg, rmd.IsGoods, commArr, virtualCoinMoneyRate) if err != nil { return 0, 0, 0, 0, nil, nil } diff --git a/svc/svc_integral_release.go b/svc/svc_integral_release.go index 097cdf7..1169b91 100644 --- a/svc/svc_integral_release.go +++ b/svc/svc_integral_release.go @@ -7,11 +7,12 @@ import ( "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" + "encoding/json" "fmt" "xorm.io/xorm" ) -func IntegralRelease(engine *xorm.Engine, uid, level int, returnAllLevel bool, IsShowExtend, pvd string, user *model.User, comf float64, price string, cfg *comm_plan.PlanOpt, isGoods string, commArr map[string]string) (pvdFee, sysFee, subsidyFee float64, lvUser *comm_plan.LvUser, err error) { +func IntegralRelease(engine *xorm.Engine, uid, level int, returnAllLevel bool, IsShowExtend, pvd string, user *model.User, comf float64, price string, cfg *comm_plan.PlanOpt, isGoods string, commArr map[string]string, virtualCoinMoneyRate map[int]string) (pvdFee, sysFee, subsidyFee float64, lvUser *comm_plan.LvUser, err error) { //佣金扣除抽成后 fee, pvdFee, sysFee := CommFee(comf, cfg, "commission", isGoods) ////积分扣除抽成后 @@ -74,7 +75,33 @@ func IntegralRelease(engine *xorm.Engine, uid, level int, returnAllLevel bool, I node = node.ParentUser } } - err = CalIntegralRelease(cfg, fee, integralFee, integralFeeCom, lvUser, commArr) + // 根据供应商 + rewardOpt, err := db.DbsPlanRewardByPvd(engine, pvd) + if err != nil { + return 0, 0, 0, nil, err + } + if rewardOpt == nil { + return 0, 0, 0, nil, zhios_order_relate_logx.Warn("找不到方案记录") + } + if rewardOpt.State == 0 { + return 0, 0, 0, nil, zhios_order_relate_logx.Warn("抽成方案未开启") + } + if rewardOpt.PlanCommissionId == 0 { + return 0, 0, 0, nil, zhios_order_relate_logx.Warn("抽成方案未设置佣金方案id") + } + commissionOpt, err := db.DbsPlanCommissionById(engine, rewardOpt.PlanCommissionId) + if err != nil || commissionOpt == nil || commissionOpt.Id == 0 { + return 0, 0, 0, nil, err + } + var subsidyTmp = make(map[string]*md.IntegralReleaseLvGrade) + var tmp map[string]*md.IntegralReleaseLvGrade + if err := json.Unmarshal([]byte(commissionOpt.Data), &tmp); err != nil { + return 0, 0, 0, nil, zhios_order_relate_logx.Warn("分佣方案数据设置错误") + } + for _, v := range tmp { + subsidyTmp[zhios_order_relate_utils.IntToStr(v.Lv)] = v + } + err = CalIntegralRelease(subsidyTmp, fee, integralFee, integralFeeCom, lvUser, commArr, virtualCoinMoneyRate) if err != nil { return 0, 0, 0, nil, err } @@ -82,13 +109,10 @@ func IntegralRelease(engine *xorm.Engine, uid, level int, returnAllLevel bool, I } // 按总佣金的比例进行划分计算 -func CalIntegralRelease(opt *comm_plan.PlanOpt, totalAmt, integralTotalAmt, integralTotalAmtCom float64, userList *comm_plan.LvUser, commArr map[string]string) error { - grade := opt.UserRate - if len(grade) == 0 { - return zhios_order_relate_logx.Warn("level grade is not set") - } +func CalIntegralRelease(subsidyTmp map[string]*md.IntegralReleaseLvGrade, totalAmt, integralTotalAmt, integralTotalAmtCom float64, userList *comm_plan.LvUser, commArr map[string]string, virtualCoinMoneyRate map[int]string) error { + //查出用户自购佣金 - commission, _, amountList, ratioList := CalReturnAmountAndRatio(userList.Lv, userList.OwnbuyReturnType, "own", totalAmt, integralTotalAmt, integralTotalAmtCom, opt, commArr) + commission, _, amountList, ratioList := CalReturnAmountAndRatio(userList.Lv, userList.OwnbuyReturnType, "own", totalAmt, integralTotalAmt, integralTotalAmtCom, subsidyTmp, commArr, virtualCoinMoneyRate) userList.Profit = commission // 另外出来的佣金 兼容旧的 userList.ProfitList = amountList // 各币种分佣 ratioListMap := convertList2Map(ratioList) @@ -97,7 +121,7 @@ func CalIntegralRelease(opt *comm_plan.PlanOpt, totalAmt, integralTotalAmt, inte } // 各种币换算出总的额度 totalAmtList := make([]*comm_plan.VirtualCoinCommission, 0) - for coinId, rate := range opt.VirtualCoinMoneyRatioList { + for coinId, rate := range virtualCoinMoneyRate { var amount float64 if coinId == 0 { amount = totalAmt @@ -118,10 +142,10 @@ func CalIntegralRelease(opt *comm_plan.PlanOpt, totalAmt, integralTotalAmt, inte node.ParentUser.Profit = 0 // 如果父级比当前级别低, 跳过 if node.ParentUser.LevelWeight >= maxLevelWeight && node.ParentUser.Diff <= 2 { - if _, ok := grade[node.Lv]; !ok { + if _, ok := subsidyTmp[zhios_order_relate_utils.IntToStr(node.Lv)]; !ok { return zhios_order_relate_logx.Warn("level grade node.Lv is not set") } - if _, ok := grade[node.ParentUser.Lv]; !ok { + if _, ok := subsidyTmp[zhios_order_relate_utils.IntToStr(node.ParentUser.Lv)]; !ok { return zhios_order_relate_logx.Warn("level grade node.ParentUser.Lv is not set") } userType := "" @@ -131,7 +155,7 @@ func CalIntegralRelease(opt *comm_plan.PlanOpt, totalAmt, integralTotalAmt, inte if node.ParentUser.Diff == 2 { userType = "second_extend" } - commission, _, amountList, ratioList := CalReturnAmountAndRatio(node.ParentUser.Lv, userList.OwnbuyReturnType, userType, totalAmt, integralTotalAmt, integralTotalAmtCom, opt, commArr) + commission, _, amountList, ratioList := CalReturnAmountAndRatio(node.ParentUser.Lv, userList.OwnbuyReturnType, userType, totalAmt, integralTotalAmt, integralTotalAmtCom, subsidyTmp, commArr, virtualCoinMoneyRate) //佣金 node.ParentUser.Profit = commission //积分 @@ -151,13 +175,16 @@ func CalIntegralRelease(opt *comm_plan.PlanOpt, totalAmt, integralTotalAmt, inte } //佣金 积分 区块币计算 -func CalReturnAmountAndRatio(level, ownbuyReturnType int, userType string, fee, integralFee, integralFeeCom float64, opt *comm_plan.PlanOpt, commArr map[string]string) (commission, commissionRatio float64, amountList, ratioList []*comm_plan.VirtualCoinCommission) { +func CalReturnAmountAndRatio(level, ownbuyReturnType int, userType string, fee, integralFee, integralFeeCom float64, subsidyTmp map[string]*md.IntegralReleaseLvGrade, commArr map[string]string, virtualCoinMoneyRatio map[int]string) (commission, commissionRatio float64, amountList, ratioList []*comm_plan.VirtualCoinCommission) { + lvGrade := subsidyTmp[zhios_order_relate_utils.IntToStr(level)] + if lvGrade == nil { + return commission, commissionRatio, amountList, ratioList + } if userType != "own" { integralFee = integralFeeCom } - lvGrade := opt.UserRate[level] if lvGrade.SelfRateList != nil { - commissionRatioStr := getVirtualCoinRatio(userType, level, opt.UserRate, "0") + commissionRatioStr := getVirtualCoinRatio(userType, level, subsidyTmp, "0") commissionRatio = zhios_order_relate_utils.StrToFloat64(commissionRatioStr) } //(商品价格*佣金比例10%-手续费%)*(可分配系数31%-税3%-运营费用1%)*15% @@ -168,7 +195,7 @@ func CalReturnAmountAndRatio(level, ownbuyReturnType int, userType string, fee, var maxReturnTypeCount = 0 var returnType = make([]string, 0) - for _, v := range opt.UserRate { + for _, v := range subsidyTmp { if v.ReturnType != nil { if len(v.ReturnType) > maxReturnTypeCount { maxReturnTypeCount = len(v.ReturnType) @@ -187,11 +214,8 @@ func CalReturnAmountAndRatio(level, ownbuyReturnType int, userType string, fee, if userType == "first_extend" || userType == "second_extend" { newFee = getfee(newFee, commArr) } - ratio := getVirtualCoinRatio(userType, level, opt.UserRate, coinId) - amount := getCoinAmount(ratio, zhios_order_relate_utils.StrToInt(coinId), newFee, opt.VirtualCoinMoneyRatioList) - if coinId != "0" && opt.Mode == "lv_winery" && userType == "own" { //酒庄模式不在这里计算 - amount = 0 - } + ratio := getVirtualCoinRatio(userType, level, subsidyTmp, coinId) + amount := getCoinAmount(ratio, zhios_order_relate_utils.StrToInt(coinId), newFee, virtualCoinMoneyRatio) amountList = append(amountList, &comm_plan.VirtualCoinCommission{ Cid: coinId, Val: amount, @@ -235,21 +259,21 @@ func getfee(fee float64, commArr map[string]string) float64 { } // 获取佣金、虚拟币比例 0=佣金 -func getVirtualCoinRatio(typ string, level int, grade map[int]*comm_plan.LvGrade, coinId string) (ratio string) { - if grade[level].ReturnType == nil { +func getVirtualCoinRatio(typ string, level int, grade map[string]*md.IntegralReleaseLvGrade, coinId string) (ratio string) { + if grade[zhios_order_relate_utils.IntToStr(level)].ReturnType == nil { return "0" } - if zhios_order_relate_utils.InArr(coinId, grade[level].ReturnType) == false { + if zhios_order_relate_utils.InArr(coinId, grade[zhios_order_relate_utils.IntToStr(level)].ReturnType) == false { return "0" } ok := false switch typ { case "first_extend": - ratio, ok = grade[level].FirstExtend[coinId] + ratio, ok = grade[zhios_order_relate_utils.IntToStr(level)].FirstExtend[coinId] case "second_extend": - ratio, ok = grade[level].SecondExtend[coinId] + ratio, ok = grade[zhios_order_relate_utils.IntToStr(level)].SecondExtend[coinId] default: - ratio, ok = grade[level].SelfRateList[coinId] + ratio, ok = grade[zhios_order_relate_utils.IntToStr(level)].SelfRateList[coinId] } if !ok { ratio = "0"