diff --git a/db/db_user_level.go b/db/db_user_level.go index e593754..1727392 100644 --- a/db/db_user_level.go +++ b/db/db_user_level.go @@ -17,6 +17,20 @@ func UserLevelInIDescByWeightLow(Db *xorm.Engine) ([]*model.UserLevel, error) { } +//UserLevelByID is 根据用户id 获取对应的等级信息 +func UserLevelByID(Db *xorm.Engine, id interface{}) (*model.UserLevel, error) { + m := new(model.UserLevel) + has, err := Db.Where("id = ?", id).Get(m) + if err != nil { + return nil, err + } + if !has { + return nil, errors.New("no found") + } + + return m, nil +} + //UserLevelDescByWeightLow 查询获取 权重最低 对应等级 func UserLevelDescByWeightLow(session *xorm.Session) (userIds []int, err error) { var m model.UserLevel diff --git a/lib/comm_plan/all.go b/lib/comm_plan/all.go index 6538cb4..7392476 100644 --- a/lib/comm_plan/all.go +++ b/lib/comm_plan/all.go @@ -4,6 +4,7 @@ import ( 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" "fmt" + "xorm.io/xorm" ) //佣金 积分 区块币计算 @@ -116,7 +117,7 @@ func CalReturnAmountAndRatioToWinery(level int, fee, integralFee float64, opt *P } // 按总佣金的比例进行划分计算 -func CalcAll(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int) error { +func CalcAll(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int, eg *xorm.Engine) error { grade := opt.UserRate if len(grade) == 0 { return zhios_order_relate_logx.Warn("level grade is not set") diff --git a/lib/comm_plan/init.go b/lib/comm_plan/init.go index a8f6f0d..fdf991d 100644 --- a/lib/comm_plan/init.go +++ b/lib/comm_plan/init.go @@ -1,6 +1,8 @@ package comm_plan -var Fn = map[string]func(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int) error{ +import "xorm.io/xorm" + +var Fn = map[string]func(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int, eg *xorm.Engine) error{ "lv_all": CalcAll, "niubei_commission": NiuBeiCalcAll, "niubei_amount": NiuBeiCalcAll, diff --git a/lib/comm_plan/niubei_all.go b/lib/comm_plan/niubei_all.go index eb2ad29..3cb89e8 100644 --- a/lib/comm_plan/niubei_all.go +++ b/lib/comm_plan/niubei_all.go @@ -60,7 +60,7 @@ func NiuBeiCalReturnAmountAndRatio(eg *xorm.Engine, pvd, bili string, integralFe } // 按总佣金的比例进行划分计算 -func NiuBeiCalcAll(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int) error { +func NiuBeiCalcAll(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int, eg *xorm.Engine) error { grade := opt.UserRate if len(grade) == 0 { return zhios_order_relate_logx.Warn("level grade is not set") diff --git a/lib/comm_plan/other.go b/lib/comm_plan/other.go index bf3a18d..3e0d1dd 100644 --- a/lib/comm_plan/other.go +++ b/lib/comm_plan/other.go @@ -4,10 +4,11 @@ import ( 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" "fmt" + "xorm.io/xorm" ) // 按总佣金的比例进行划分计算 -func CalcOther(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int) error { +func CalcOther(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int, eg *xorm.Engine) error { grade := opt.UserRate if len(grade) == 0 { return zhios_order_relate_logx.Warn("level grade is not set") diff --git a/lib/comm_plan/self.go b/lib/comm_plan/self.go index f1942ad..98c18ee 100644 --- a/lib/comm_plan/self.go +++ b/lib/comm_plan/self.go @@ -4,10 +4,11 @@ import ( 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" "fmt" + "xorm.io/xorm" ) // 按自购佣金进行计算 -func CalcSelf(opt *PlanOpt, totalAmt float64, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int) error { +func CalcSelf(opt *PlanOpt, totalAmt float64, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int, eg *xorm.Engine) error { grade := opt.UserRate if len(grade) == 0 { return zhios_order_relate_logx.Warn("level grade is not set") diff --git a/lib/comm_plan/winery.go b/lib/comm_plan/winery.go index 9a86e07..783dcc1 100644 --- a/lib/comm_plan/winery.go +++ b/lib/comm_plan/winery.go @@ -1,13 +1,15 @@ package comm_plan import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db" 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" "fmt" + "xorm.io/xorm" ) // 按总佣金的比例进行划分计算 -func CalcWinery(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int) error { +func CalcWinery(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int, eg *xorm.Engine) error { grade := opt.UserRate if len(grade) == 0 { return zhios_order_relate_logx.Warn("level grade is not set") @@ -19,10 +21,10 @@ func CalcWinery(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUs userList.ProfitList = amountList // 各币种分佣 userList.SubsidyFee = 0 ratioListMap := convertList2Map(ratioList) - for k, v := range userList.ProfitList { userList.ProfitList[k].Val = ratioListMap[v.Cid] * v.Val } + maxLvData, _ := db.UserLevelByID(eg, "2") // 各种币换算出总的额度 totalAmtList := make([]*VirtualCoinCommission, 0) for coinId, rate := range opt.VirtualCoinMoneyRatioList { @@ -92,6 +94,9 @@ Loop: } maxLevelWeight, maxLv, peerRate, peerRateList, peerNum, sameProfit, sameProfitList = node.ParentUser.LevelWeight, node.ParentUser.Lv, 0, nil, 0, node.ParentUser.Profit, node.ParentUser.ProfitList } else { + if node.ParentUser.Lv > 2 && maxLvData != nil { + node.ParentUser.LevelWeight = maxLvData.LevelWeight + } // 同级奖 if node.ParentUser.LevelWeight == maxLevelWeight && count > peerNum { diff --git a/svc/reward_commission.go b/svc/reward_commission.go index 51cee68..9f63718 100644 --- a/svc/reward_commission.go +++ b/svc/reward_commission.go @@ -574,7 +574,7 @@ func CalcCommission(uid, level, oldDiff, ownbuyReturnType int, fee, integralFee levelWeight1 = lvWeight.LevelWeight level1 = lvWeight.Id } - if err := comm_plan.Fn[opt.Mode](opt, fee, integralFee, lvUser, pvd, sysFee, integralSysFee, level1, levelWeight1); err != nil { + if err := comm_plan.Fn[opt.Mode](opt, fee, integralFee, lvUser, pvd, sysFee, integralSysFee, level1, levelWeight1, eg); err != nil { fmt.Println("方案有问题1") return 0, 0, 0, nil, err } @@ -662,7 +662,7 @@ func NiuBeiCalcCommission(uid, level, oldDiff, ownbuyReturnType int, fee, integr levelWeight1 = lvWeight.LevelWeight level1 = lvWeight.Id } - if err := comm_plan.Fn[opt.Mode](opt, fee, integralFee, lvUser, pvd, sysFee, integralSysFee, level1, levelWeight1); err != nil { + if err := comm_plan.Fn[opt.Mode](opt, fee, integralFee, lvUser, pvd, sysFee, integralSysFee, level1, levelWeight1, eg); err != nil { fmt.Println("方案有问题1") return 0, 0, 0, nil, err }