From 05c1bc6b07d67d659ffacbea17c09c6c11f28d1f Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 13 Sep 2022 11:58:05 +0800 Subject: [PATCH 1/5] =?UTF-8?q?add=20reverse:for=20v3.1.5=20=E5=88=B6?= =?UTF-8?q?=E5=BA=A6=E5=8A=A0=E5=85=A5=E6=80=BB=E9=87=91=E9=A2=9D=E5=88=86?= =?UTF-8?q?=E4=BD=A3=E4=B8=8D=E6=89=A3=E9=99=A4=E5=90=8C=E7=BA=A7=E5=A5=96?= =?UTF-8?q?=E5=8A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/comm_plan/init.go | 11 ++-- lib/comm_plan/other.go | 122 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 lib/comm_plan/other.go diff --git a/lib/comm_plan/init.go b/lib/comm_plan/init.go index b0addb0..f6ff54e 100644 --- a/lib/comm_plan/init.go +++ b/lib/comm_plan/init.go @@ -1,11 +1,12 @@ package comm_plan var Fn = map[string]func(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64) error{ - "lv_all": CalcAll, - "lv_self": CalcSelf, - "lv_subsidy": CalcAll, - "lv_price": CalcAll, - "lv_winery": CalcAll, + "lv_all": CalcAll, + "lv_self": CalcSelf, + "lv_subsidy": CalcAll, + "lv_price": CalcAll, + "lv_winery": CalcAll, + "lv_price_other": CalcOther, } type PlanOpt struct { diff --git a/lib/comm_plan/other.go b/lib/comm_plan/other.go new file mode 100644 index 0000000..21238b5 --- /dev/null +++ b/lib/comm_plan/other.go @@ -0,0 +1,122 @@ +package comm_plan + +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" +) + +// 按总佣金的比例进行划分计算 +func CalcOther(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64) error { + grade := opt.UserRate + if len(grade) == 0 { + return zhios_order_relate_logx.Warn("level grade is not set") + } + + //查出用户自购佣金 + commission, commissionRatio, amountList, ratioList := CalReturnAmountAndRatio(userList.Lv, userList.OwnbuyReturnType, 0, "own", totalAmt, integralTotalAmt, opt) + userList.Profit = commission // 另外出来的佣金 兼容旧的 + userList.ProfitList = amountList // 各币种分佣 + userList.SubsidyFee = 0 + ratioListMap := convertList2Map(ratioList) + + for k, v := range userList.ProfitList { + userList.ProfitList[k].Val = ratioListMap[v.Cid] * v.Val + } + // 各种币换算出总的额度 + totalAmtList := make([]*VirtualCoinCommission, 0) + for coinId, rate := range opt.VirtualCoinMoneyRatioList { + var amount float64 + if coinId == 0 { + amount = totalAmt + } else { + amount = integralTotalAmt * zhios_order_relate_utils.AnyToFloat64(rate) + } + totalAmtList = append(totalAmtList, &VirtualCoinCommission{ + Cid: zhios_order_relate_utils.AnyToString(coinId), + Val: amount, + }) + } + + var ( + node = userList + maxLv = node.Lv // 当前等级 + maxLevelWeight = node.LevelWeight // 当前权重 + peerNum = 0 // 存在同级数 + peerRate float64 = 0 // 同级累计比例 + peerRateList = make([]*VirtualCoinCommission, 0) // 各虚拟币同级累计 + restAmtList = make([]*VirtualCoinCommission, 0) // 各虚拟币剩余额度 + accumulateRatioList = make([]*VirtualCoinCommission, 0) // 各虚拟币累计比例 + restAmt = totalAmt - userList.Profit // 剩余比例 + totalCommissionRatio = commissionRatio // 累计佣金比例 + ) + // 计算剩余额度 + restAmtList, _ = CalVirtualCommissionMinus(totalAmtList, amountList) + // 累计比例 + accumulateRatioList = ratioList + restAmt = zhios_order_relate_utils.FloatFormat(restAmt, 6) + +Loop: + for node.ParentUser != nil { //查找上级用户 + node.ParentUser.Profit = 0 + + //佣金补贴奖励 + subsidyFee, subsidyRatio, isOnlySubsidyFee, subsidyFeeList, subsidyRatioList := subsidyFeeDo(opt, totalAmt, integralTotalAmt, node.ParentUser, userList.NewLv, pvd, sysFee, integralSysFee) + node.ParentUser.SubsidyFee = subsidyFee + node.ParentUser.SubsidyFeeList = subsidyFeeList // 各币种补贴 + + // 如果父级比当前级别低, 跳过 + // 同级奖, 如果父级别与当前级别一致,并且设置了对应比例 + count := len(grade[maxLv].PeerRate) + if grade[maxLv].PeerRateList != nil { + count = len(grade[maxLv].PeerRateList) + } + var isBreak bool + zeroList := make(map[string]struct{}) + // 同级奖 + if node.ParentUser.LevelWeight == maxLevelWeight && count > peerNum { + //同级奖励比例 + commission, commissionRatio, amountList, ratioList := CalReturnAmountAndRatio(maxLv, userList.OwnbuyReturnType, peerNum, "same_lv", totalAmt, integralTotalAmt, opt) + //佣金 (lv, isOnlySubsidy int, restAmt, profit, peerRate, totalRatio, restRatio, subsidyFee, subsidyBili float64, opt *PlanOpt) + node.ParentUser.Profit, restAmt, totalCommissionRatio, peerRate, node.ParentUser.SubsidyFee, isBreak = sameMoney(node.Lv, isOnlySubsidyFee, restAmt, commission, peerRate, totalCommissionRatio, commissionRatio, node.ParentUser.SubsidyFee, subsidyRatio, opt) + node.ParentUser.ProfitList, restAmtList, accumulateRatioList, peerRateList, node.ParentUser.SubsidyFeeList, zeroList = sameMoneyV2(node.Lv, isOnlySubsidyFee, totalAmtList, restAmtList, amountList, peerRateList, accumulateRatioList, ratioList, node.ParentUser.SubsidyFeeList, subsidyRatioList, opt) + + // 全部都没得分了 + if isBreak && len(zeroList) == len(opt.UserRate[maxLv].ReturnType) { + break Loop + } + peerNum++ + } else if node.ParentUser.LevelWeight > maxLevelWeight { + if _, ok := grade[node.Lv]; !ok { + return zhios_order_relate_logx.Warn("level grade node.Lv is not set") + } + if _, ok := grade[node.ParentUser.Lv]; !ok { + return zhios_order_relate_logx.Warn("level grade node.ParentUser.Lv is not set") + } + peerNum1 := 0 //不用扣同级 + commission, _, amountList, teamRatioList := CalReturnAmountAndRatio(node.ParentUser.Lv, userList.OwnbuyReturnType, peerNum1, "team", totalAmt, integralTotalAmt, opt) + //佣金 + node.ParentUser.Profit = commission + node.ParentUser.Profit, restAmt, totalCommissionRatio, node.ParentUser.SubsidyFee, isBreak = teamDiffMoney(node.ParentUser.Profit, grade[node.Lv].PayMode, isOnlySubsidyFee, totalAmt, restAmt, grade[node.ParentUser.Lv].TeamRate, totalCommissionRatio, peerRate, node.ParentUser.SubsidyFee, subsidyRatio) + //积分 + node.ParentUser.ProfitList = amountList + // profitList []*VirtualCoinCommission, payMode, isOnlySubsidy int, totalAmtList, restAmtList, teamRatioList, totalRatioList, peerRateList, subsidyFeeList, subsidyRatioList []*VirtualCoinCommission + node.ParentUser.ProfitList, restAmtList, accumulateRatioList, node.ParentUser.SubsidyFeeList, zeroList = teamDiffMoneyV2(node.ParentUser.ProfitList, grade[node.Lv].PayMode, isOnlySubsidyFee, totalAmtList, restAmtList, teamRatioList, accumulateRatioList, peerRateList, subsidyFeeList, subsidyRatioList) + + // 没得分了 就结束 + if isBreak && len(zeroList) == len(opt.UserRate[maxLv].ReturnType) { + break Loop + } + // 等级往上升则置0 + maxLevelWeight, maxLv, peerRate, peerRateList, peerNum = node.ParentUser.LevelWeight, node.ParentUser.Lv, 0, nil, 0 + } + //如果是酒庄制度,要看这里处理 额外的补贴 + subsidyFee, subsidyRatio, isOnlySubsidyFee, subsidyFeeList, subsidyRatioList = subsidyFeeDo(opt, totalAmt, integralTotalAmt, node.ParentUser, userList.NewLv, pvd, sysFee, integralSysFee) + node.ParentUser.SubsidyFee = subsidyFee + node.ParentUser.SubsidyFeeList = subsidyFeeList // 各币种补贴 + node.Profit = zhios_order_relate_utils.StrToFloat64(fmt.Sprintf("%.4f", node.Profit)) + node = node.ParentUser + } + + return nil +} From 311f9e78fc07c147dfc4229ac5cd7368a9cd8214 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 13 Sep 2022 16:39:42 +0800 Subject: [PATCH 2/5] =?UTF-8?q?add=20reverse:for=20v3.1.8=20=E5=88=B6?= =?UTF-8?q?=E5=BA=A6=E5=8A=A0=E5=85=A5=E6=80=BB=E9=87=91=E9=A2=9D=E5=88=86?= =?UTF-8?q?=E4=BD=A3=E4=B8=8D=E6=89=A3=E9=99=A4=E5=90=8C=E7=BA=A7=E5=A5=96?= =?UTF-8?q?=E5=8A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/comm_plan/all.go | 19 +++++- lib/comm_plan/other.go | 133 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 149 insertions(+), 3 deletions(-) diff --git a/lib/comm_plan/all.go b/lib/comm_plan/all.go index fc8d93b..948bd3e 100644 --- a/lib/comm_plan/all.go +++ b/lib/comm_plan/all.go @@ -624,8 +624,25 @@ func GetLvUpSubsidyVirtualCoinRatio(level, newLevel, diff int, grade map[int]*Lv jsons, ok := oneLevelMap["rate_list"].([]interface{}) if ok { levelRateListArr = jsons + } else { + jsons1, ok := oneLevelMap["rate_list"].(map[string]interface{}) + if ok { + max := 0 + for k, _ := range jsons1 { + if zhios_order_relate_utils.StrToInt(k) > max { + max = zhios_order_relate_utils.StrToInt(k) + } + } + for i := 0; i <= max; i++ { + bili, ok := jsons1[zhios_order_relate_utils.IntToStr(i)] + if ok { + levelRateListArr = append(levelRateListArr, bili) + } else { + levelRateListArr = append(levelRateListArr, "0") + } + } + } } - } } if len(levelRateListArr) == 0 { diff --git a/lib/comm_plan/other.go b/lib/comm_plan/other.go index 21238b5..636a2a4 100644 --- a/lib/comm_plan/other.go +++ b/lib/comm_plan/other.go @@ -78,8 +78,8 @@ Loop: //同级奖励比例 commission, commissionRatio, amountList, ratioList := CalReturnAmountAndRatio(maxLv, userList.OwnbuyReturnType, peerNum, "same_lv", totalAmt, integralTotalAmt, opt) //佣金 (lv, isOnlySubsidy int, restAmt, profit, peerRate, totalRatio, restRatio, subsidyFee, subsidyBili float64, opt *PlanOpt) - node.ParentUser.Profit, restAmt, totalCommissionRatio, peerRate, node.ParentUser.SubsidyFee, isBreak = sameMoney(node.Lv, isOnlySubsidyFee, restAmt, commission, peerRate, totalCommissionRatio, commissionRatio, node.ParentUser.SubsidyFee, subsidyRatio, opt) - node.ParentUser.ProfitList, restAmtList, accumulateRatioList, peerRateList, node.ParentUser.SubsidyFeeList, zeroList = sameMoneyV2(node.Lv, isOnlySubsidyFee, totalAmtList, restAmtList, amountList, peerRateList, accumulateRatioList, ratioList, node.ParentUser.SubsidyFeeList, subsidyRatioList, opt) + node.ParentUser.Profit, restAmt, totalCommissionRatio, peerRate, node.ParentUser.SubsidyFee, isBreak = otherSameMoney(node.Lv, isOnlySubsidyFee, restAmt, commission, peerRate, totalCommissionRatio, commissionRatio, node.ParentUser.SubsidyFee, subsidyRatio, opt) + node.ParentUser.ProfitList, restAmtList, accumulateRatioList, peerRateList, node.ParentUser.SubsidyFeeList, zeroList = otherSameMoneyV2(node.Lv, isOnlySubsidyFee, totalAmtList, restAmtList, amountList, peerRateList, accumulateRatioList, ratioList, node.ParentUser.SubsidyFeeList, subsidyRatioList, opt) // 全部都没得分了 if isBreak && len(zeroList) == len(opt.UserRate[maxLv].ReturnType) { @@ -120,3 +120,132 @@ Loop: return nil } + +//公共处理同级计算 (只计算佣金 旧版本用) +func otherSameMoney(lv, isOnlySubsidy int, restAmt, profit, peerRate, totalRatio, restRatio, subsidyFee, subsidyBili float64, opt *PlanOpt) (float64, float64, float64, float64, float64, bool) { + //如果不够扣了,并且是比例返利就跳过 + if restAmt < profit { + return 0, restAmt, totalRatio, peerRate, subsidyFee, true + } + if opt == nil { + return 0, restAmt, totalRatio, peerRate, subsidyFee, true + } + if opt.UserRate == nil { + return 0, restAmt, totalRatio, peerRate, subsidyFee, true + } + if opt.UserRate[lv] == nil { + return 0, restAmt, totalRatio, peerRate, subsidyFee, true + } + //极差返利 + if opt.UserRate[lv].PayMode == 0 && isOnlySubsidy == 0 { + restAmt -= profit // 剩余可分 + restAmt = zhios_order_relate_utils.FloatFormat(restAmt, 6) + peerRate += restRatio + totalRatio += restRatio + } else if isOnlySubsidy == 1 { //如果只返补贴 当成是极差的一部分 所以要扣 不是额外的 + profit = 0 + if opt.UserRate[lv].PayMode == 0 { + if restAmt < subsidyFee { + subsidyFee = 0 + return profit, restAmt, totalRatio, subsidyFee, peerRate, true + } + restAmt -= subsidyFee // 剩余可分 + restAmt = zhios_order_relate_utils.FloatFormat(restAmt, 6) + totalRatio += zhios_order_relate_utils.FloatFormat(subsidyBili, 6) + } + } + return profit, restAmt, totalRatio, peerRate, subsidyFee, false +} + +func otherSameMoneyV2(lv, isOnlySubsidy int, totalAmtList, restAmtList, profitList, peerRateList, totalRatioList, restRatioList, subsidyFeeList, subsidyRatioList []*VirtualCoinCommission, opt *PlanOpt) ([]*VirtualCoinCommission, []*VirtualCoinCommission, []*VirtualCoinCommission, []*VirtualCoinCommission, []*VirtualCoinCommission, map[string]struct{}) { + + restAmtMap := convertList2Map(restAmtList) + totalAmtMap := convertList2Map(totalAmtList) + //profitMap := convertList2Map(profitList) + restRatioMap := convertList2Map(restRatioList) + totalRatioMap := convertList2Map(totalRatioList) + peerRateMap := convertList2Map(peerRateList) + subsidyMap := convertList2Map(subsidyFeeList) + + zeroList := make(map[string]struct{}) + + newProfitList := make([]*VirtualCoinCommission, 0) + newRestAmtList := make([]*VirtualCoinCommission, 0) + newTotalRatioList := make([]*VirtualCoinCommission, 0) + newPeerRateList := make([]*VirtualCoinCommission, 0) + newSubsidyFeeList := subsidyFeeList + if opt == nil { + return newProfitList, newRestAmtList, newTotalRatioList, newPeerRateList, newSubsidyFeeList, zeroList + } + if opt.UserRate == nil { + return newProfitList, newRestAmtList, newTotalRatioList, newPeerRateList, newSubsidyFeeList, zeroList + } + if opt.UserRate[lv] == nil { + return newProfitList, newRestAmtList, newTotalRatioList, newPeerRateList, newSubsidyFeeList, zeroList + } + //极差返利 + if opt.UserRate[lv].PayMode == 0 && isOnlySubsidy == 0 { + for _, coin := range profitList { + profitOne := &VirtualCoinCommission{} + profitOne.Cid = coin.Cid + profitOne.Val = totalAmtMap[coin.Cid] * restRatioMap[coin.Cid] + // 不够扣了 设为0 + if restAmtMap[coin.Cid] < profitOne.Val { + profitOne.Val = 0 + zeroList[coin.Cid] = struct{}{} + } + // 分佣 + newProfitList = append(newProfitList, profitOne) + + //// 剩余 + //restAmtMap[coin.Cid] -= profitOne.Val + + //// 累计比例 + //totalRatioMap[coin.Cid] += restRatioMap[coin.Cid] + + // 同级累计比例 + if _, ok := peerRateMap[coin.Cid]; !ok { + peerRateMap[coin.Cid] = 0 + } + peerRateMap[coin.Cid] += restRatioMap[coin.Cid] + } + } else if isOnlySubsidy == 1 { + newSubsidyFeeList = make([]*VirtualCoinCommission, 0) + for _, coin := range profitList { + profitOne := &VirtualCoinCommission{} + subsidyFeeOne := &VirtualCoinCommission{} + + profitOne.Cid = coin.Cid + profitOne.Val = 0 + newProfitList = append(newProfitList, profitOne) + + if opt.UserRate[lv].PayMode == 0 { + subsidyFeeOne.Cid = coin.Cid + subsidyFeeOne.Val = subsidyMap[coin.Cid] + if restAmtMap[coin.Cid] < subsidyMap[coin.Cid] { + subsidyFeeOne.Val = 0 + zeroList[coin.Cid] = struct{}{} + } + newSubsidyFeeList = append(newSubsidyFeeList, subsidyFeeOne) + } + + //// 剩余额度 + //restAmtMap[coin.Cid] -= subsidyFeeOne.Val + + //// 累计比例 + //totalRatioMap[coin.Cid] += subsidyRatioMap[coin.Cid] + + // 同级累计比例 + if _, ok := peerRateMap[coin.Cid]; !ok { + peerRateMap[coin.Cid] = 0 + } + peerRateMap[coin.Cid] += restRatioMap[coin.Cid] + } + } + + newTotalRatioList = convertMap2List(totalRatioMap) + newPeerRateList = convertMap2List(peerRateMap) + newRestAmtList = convertMap2List(restAmtMap) + + return newProfitList, newRestAmtList, newTotalRatioList, newPeerRateList, newSubsidyFeeList, zeroList +} From 8c013e7f614722825f05805956b3a4e2187d4c44 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 13 Sep 2022 18:44:03 +0800 Subject: [PATCH 3/5] =?UTF-8?q?add=20reverse:for=20v3.1.9=20=E5=88=B6?= =?UTF-8?q?=E5=BA=A6=E5=8A=A0=E5=85=A5=E6=80=BB=E9=87=91=E9=A2=9D=E5=88=86?= =?UTF-8?q?=E4=BD=A3=E4=B8=8D=E6=89=A3=E9=99=A4=E5=90=8C=E7=BA=A7=E5=A5=96?= =?UTF-8?q?=E5=8A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/db_user_level.go | 12 ++++++++++++ lib/comm_plan/all.go | 29 ++++++++++++++++++++++++++++- lib/comm_plan/init.go | 2 +- lib/comm_plan/other.go | 10 ++++++++-- lib/comm_plan/self.go | 2 +- svc/reward_commission.go | 7 ++++++- 6 files changed, 56 insertions(+), 6 deletions(-) diff --git a/db/db_user_level.go b/db/db_user_level.go index 47ece52..e593754 100644 --- a/db/db_user_level.go +++ b/db/db_user_level.go @@ -37,6 +37,18 @@ func UserLevelDescByWeightLow(session *xorm.Session) (userIds []int, err error) } return userIds, nil +} +func UserLevelInIDescByWeightLowWithOne(Db *xorm.Engine) (*model.UserLevel, error) { + var ms model.UserLevel + has, err := Db.Asc("level_weight").Get(&ms) + if err != nil { + return nil, err + } + if has == false { + return nil, zhios_order_relate_logx.Warn(errors.New("等级不存在")) + } + return &ms, nil + } // UserLevlEgAll is 获取所有开启等级并且升序返回 diff --git a/lib/comm_plan/all.go b/lib/comm_plan/all.go index 948bd3e..a896dce 100644 --- a/lib/comm_plan/all.go +++ b/lib/comm_plan/all.go @@ -60,6 +60,33 @@ func CalReturnAmountAndRatio(level, ownbuyReturnType, peerNum int, userType stri return commission, commissionRatio, amountList, ratioList } +//佣金 积分 区块币计算 +func CalReturnAmountAndRatioByLevel(level, ownbuyReturnType, peerNum int, userType string, fee, integralFee float64, opt *PlanOpt) (commissionRatio float64, ratioList []*VirtualCoinCommission) { + // 佣金的比例兼容旧系统 比例独立出来的 所以这样算 + commissionRatio = getCommissionRatio(userType, level, peerNum, opt.UserRate) + var maxReturnTypeCount = 0 + var returnType = make([]string, 0) + for _, v := range opt.UserRate { + if v.ReturnType != nil { + if len(v.ReturnType) > maxReturnTypeCount { + maxReturnTypeCount = len(v.ReturnType) + returnType = v.ReturnType + } + } + } + // 新版支持多种虚拟币 支持的种类id保存在ReturnType id=0代表现金佣金 其他为虚拟币 + if returnType != nil { //返佣类型 + for _, coinId := range returnType { + ratio := getVirtualCoinRatio(userType, level, peerNum, opt.UserRate, coinId) + ratioList = append(ratioList, &VirtualCoinCommission{ + Cid: coinId, + Val: zhios_order_relate_utils.AnyToFloat64(ratio), + }) + } + } + return commissionRatio, ratioList +} + //佣金 积分 区块币计算 func CalReturnAmountAndRatioToWinery(level int, fee, integralFee float64, opt *PlanOpt) (commission, commissionRatio float64, amountList, ratioList []*VirtualCoinCommission) { if opt.UserRate[level].ReturnType != nil { //返佣类型 @@ -89,7 +116,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) error { +func CalcAll(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, levelWeight int) 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 f6ff54e..362fe59 100644 --- a/lib/comm_plan/init.go +++ b/lib/comm_plan/init.go @@ -1,6 +1,6 @@ package comm_plan -var Fn = map[string]func(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64) error{ +var Fn = map[string]func(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64,levelWeight int) error{ "lv_all": CalcAll, "lv_self": CalcSelf, "lv_subsidy": CalcAll, diff --git a/lib/comm_plan/other.go b/lib/comm_plan/other.go index 636a2a4..142fd3c 100644 --- a/lib/comm_plan/other.go +++ b/lib/comm_plan/other.go @@ -7,7 +7,7 @@ import ( ) // 按总佣金的比例进行划分计算 -func CalcOther(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64) error { +func CalcOther(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, levelWeight int) error { grade := opt.UserRate if len(grade) == 0 { return zhios_order_relate_logx.Warn("level grade is not set") @@ -41,7 +41,7 @@ func CalcOther(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUse var ( node = userList maxLv = node.Lv // 当前等级 - maxLevelWeight = node.LevelWeight // 当前权重 + maxLevelWeight = levelWeight // 当前权重 peerNum = 0 // 存在同级数 peerRate float64 = 0 // 同级累计比例 peerRateList = make([]*VirtualCoinCommission, 0) // 各虚拟币同级累计 @@ -49,6 +49,7 @@ func CalcOther(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUse accumulateRatioList = make([]*VirtualCoinCommission, 0) // 各虚拟币累计比例 restAmt = totalAmt - userList.Profit // 剩余比例 totalCommissionRatio = commissionRatio // 累计佣金比例 + ) // 计算剩余额度 restAmtList, _ = CalVirtualCommissionMinus(totalAmtList, amountList) @@ -93,6 +94,11 @@ Loop: if _, ok := grade[node.ParentUser.Lv]; !ok { return zhios_order_relate_logx.Warn("level grade node.ParentUser.Lv is not set") } + if maxLv == 0 { + commissionRatio1, ratioList1 := CalReturnAmountAndRatioByLevel(node.ParentUser.Lv, userList.OwnbuyReturnType, 0, "own", totalAmt, integralTotalAmt, opt) + totalCommissionRatio = commissionRatio1 + accumulateRatioList = ratioList1 + } peerNum1 := 0 //不用扣同级 commission, _, amountList, teamRatioList := CalReturnAmountAndRatio(node.ParentUser.Lv, userList.OwnbuyReturnType, peerNum1, "team", totalAmt, integralTotalAmt, opt) //佣金 diff --git a/lib/comm_plan/self.go b/lib/comm_plan/self.go index a321032..6e678f1 100644 --- a/lib/comm_plan/self.go +++ b/lib/comm_plan/self.go @@ -7,7 +7,7 @@ import ( ) // 按自购佣金进行计算 -func CalcSelf(opt *PlanOpt, totalAmt float64, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64) error { +func CalcSelf(opt *PlanOpt, totalAmt float64, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64,levelWeight int) error { grade := opt.UserRate if len(grade) == 0 { return zhios_order_relate_logx.Warn("level grade is not set") diff --git a/svc/reward_commission.go b/svc/reward_commission.go index 9e95b20..2e1c34e 100644 --- a/svc/reward_commission.go +++ b/svc/reward_commission.go @@ -483,7 +483,12 @@ func CalcCommission(uid, level, oldDiff, ownbuyReturnType int, fee, integralFee node.ParentUser = &comm_plan.LvUser{Uid: v.Uid, Lv: v.Level, Diff: v.Diff, OldDiff: v.OldDiff, LevelWeight: levelWeight} node = node.ParentUser } - if err := comm_plan.Fn[opt.Mode](opt, fee, integralFee, lvUser, pvd, sysFee, integralSysFee); err != nil { + levelWeight1 := 0 + lvWeight, _ := db.UserLevelInIDescByWeightLowWithOne(eg) + if lvWeight != nil { + levelWeight1 = lvWeight.LevelWeight + } + if err := comm_plan.Fn[opt.Mode](opt, fee, integralFee, lvUser, pvd, sysFee, integralSysFee, levelWeight1); err != nil { fmt.Println("方案有问题1") return 0, 0, 0, nil, err } From 0067b2085b6ab148205ad7ef22ab6a6d0cc5267e Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 13 Sep 2022 19:20:14 +0800 Subject: [PATCH 4/5] =?UTF-8?q?add=20reverse:for=20v3.2.0=20=E5=88=B6?= =?UTF-8?q?=E5=BA=A6=E5=8A=A0=E5=85=A5=E6=80=BB=E9=87=91=E9=A2=9D=E5=88=86?= =?UTF-8?q?=E4=BD=A3=E4=B8=8D=E6=89=A3=E9=99=A4=E5=90=8C=E7=BA=A7=E5=A5=96?= =?UTF-8?q?=E5=8A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/comm_plan/all.go | 2 +- lib/comm_plan/init.go | 2 +- lib/comm_plan/other.go | 6 +++--- lib/comm_plan/self.go | 2 +- svc/reward_commission.go | 4 +++- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/comm_plan/all.go b/lib/comm_plan/all.go index a896dce..569b70e 100644 --- a/lib/comm_plan/all.go +++ b/lib/comm_plan/all.go @@ -116,7 +116,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, levelWeight int) error { +func CalcAll(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int) 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 362fe59..ab3592c 100644 --- a/lib/comm_plan/init.go +++ b/lib/comm_plan/init.go @@ -1,6 +1,6 @@ package comm_plan -var Fn = map[string]func(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64,levelWeight int) error{ +var Fn = map[string]func(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64,level,levelWeight int) error{ "lv_all": CalcAll, "lv_self": CalcSelf, "lv_subsidy": CalcAll, diff --git a/lib/comm_plan/other.go b/lib/comm_plan/other.go index 142fd3c..e89059a 100644 --- a/lib/comm_plan/other.go +++ b/lib/comm_plan/other.go @@ -7,7 +7,7 @@ import ( ) // 按总佣金的比例进行划分计算 -func CalcOther(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, levelWeight int) error { +func CalcOther(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int) error { grade := opt.UserRate if len(grade) == 0 { return zhios_order_relate_logx.Warn("level grade is not set") @@ -40,7 +40,7 @@ func CalcOther(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUse var ( node = userList - maxLv = node.Lv // 当前等级 + maxLv = level // 当前等级 maxLevelWeight = levelWeight // 当前权重 peerNum = 0 // 存在同级数 peerRate float64 = 0 // 同级累计比例 @@ -94,7 +94,7 @@ Loop: if _, ok := grade[node.ParentUser.Lv]; !ok { return zhios_order_relate_logx.Warn("level grade node.ParentUser.Lv is not set") } - if maxLv == 0 { + if node.ParentUser.Diff == 1 { commissionRatio1, ratioList1 := CalReturnAmountAndRatioByLevel(node.ParentUser.Lv, userList.OwnbuyReturnType, 0, "own", totalAmt, integralTotalAmt, opt) totalCommissionRatio = commissionRatio1 accumulateRatioList = ratioList1 diff --git a/lib/comm_plan/self.go b/lib/comm_plan/self.go index 6e678f1..b3dd040 100644 --- a/lib/comm_plan/self.go +++ b/lib/comm_plan/self.go @@ -7,7 +7,7 @@ import ( ) // 按自购佣金进行计算 -func CalcSelf(opt *PlanOpt, totalAmt float64, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64,levelWeight int) error { +func CalcSelf(opt *PlanOpt, totalAmt float64, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64,level,levelWeight int) error { grade := opt.UserRate if len(grade) == 0 { return zhios_order_relate_logx.Warn("level grade is not set") diff --git a/svc/reward_commission.go b/svc/reward_commission.go index 2e1c34e..aa2d71e 100644 --- a/svc/reward_commission.go +++ b/svc/reward_commission.go @@ -484,11 +484,13 @@ func CalcCommission(uid, level, oldDiff, ownbuyReturnType int, fee, integralFee node = node.ParentUser } levelWeight1 := 0 + level1 := 0 lvWeight, _ := db.UserLevelInIDescByWeightLowWithOne(eg) if lvWeight != nil { levelWeight1 = lvWeight.LevelWeight + level1 = lvWeight.Id } - if err := comm_plan.Fn[opt.Mode](opt, fee, integralFee, lvUser, pvd, sysFee, integralSysFee, levelWeight1); err != nil { + if err := comm_plan.Fn[opt.Mode](opt, fee, integralFee, lvUser, pvd, sysFee, integralSysFee,level1, levelWeight1); err != nil { fmt.Println("方案有问题1") return 0, 0, 0, nil, err } From 3bfd8dfe1122ccc9389e828d9cacd66ca8a68b3f Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 13 Sep 2022 20:59:19 +0800 Subject: [PATCH 5/5] =?UTF-8?q?add=20reverse:for=20v3.2.1=20=E6=9E=81?= =?UTF-8?q?=E5=B7=AE=E8=BF=94=E5=9B=9E=E7=9B=B4=E6=8E=A8=E5=A5=96=E5=8A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/dbs_user.go | 8 ++++++-- md/commission_parameter.go | 2 ++ rule/relate_commission.go | 3 +++ svc/reward_commission.go | 7 ++++--- svc/user_relative_network.go | 4 ++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/db/dbs_user.go b/db/dbs_user.go index 7b2237b..0094799 100644 --- a/db/dbs_user.go +++ b/db/dbs_user.go @@ -17,9 +17,13 @@ func DbsUserFindByIds(eg *xorm.Engine, uid []int) (*[]model.User, error) { return &users, nil } -func DbsUserRelate(eg *xorm.Engine, uid int) (*[]model.UserRelate, error) { +func DbsUserRelate(eg *xorm.Engine, uid, level int) (*[]model.UserRelate, error) { var userRelate []model.UserRelate - if err := eg.Where("uid = ?", uid).Asc("level").Find(&userRelate); err != nil { + sess := eg.Where("uid = ?", uid) + if level > 0 { + sess.And("level<=?", level) + } + if err := sess.Asc("level").Find(&userRelate); err != nil { return nil, zhios_order_relate_logx.Error(err) } if len(userRelate) == 0 { diff --git a/md/commission_parameter.go b/md/commission_parameter.go index 9949cab..3f899de 100644 --- a/md/commission_parameter.go +++ b/md/commission_parameter.go @@ -14,6 +14,7 @@ type CommissionParam struct { PaidPrice string `json:"paid_price"` Oid string `json:"oid"` //标记 IsGoods string `json:"is_goods"` + IsShowExtend string `json:"is_show_extend"` } type CommissionFirstParam struct { CommissionParam CommissionParam `json:"commission_param"` @@ -27,4 +28,5 @@ type CommissionFirstParam struct { OwnbuyReturnType int `json:"ownbuy_return_type"` //自购是否返利 0返利 1不返利 Oid string `json:"oid"` ShowLevel string `json:"show_level"` + IsShowExtend string `json:"is_show_extend"` } diff --git a/rule/relate_commission.go b/rule/relate_commission.go index dec227c..f2fecc4 100644 --- a/rule/relate_commission.go +++ b/rule/relate_commission.go @@ -45,6 +45,8 @@ func BatchGetCommissionByGoods(eg *xorm.Engine, dbName string, commissionParamLi } param.CommissionParam.Oid = param.GoodsId param.CommissionParam.IsGoods = "1" + param.CommissionParam.IsShowExtend = param.IsShowExtend + _, _, _, _, lvUser, err := svc.GetRewardCommission(eg, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, virType) if err != nil { return err @@ -146,6 +148,7 @@ func SettleCommWithGoodsDetail(eg *xorm.Engine, dbName string, CommissionParam m } CommissionParam.CommissionParam.Oid = CommissionParam.GoodsId CommissionParam.CommissionParam.IsGoods = "1" + CommissionParam.CommissionParam.IsShowExtend = CommissionParam.IsShowExtend profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, virType) return profit, pvdFee, sysFee, subsidyFee, lvUser, err diff --git a/svc/reward_commission.go b/svc/reward_commission.go index aa2d71e..8950b24 100644 --- a/svc/reward_commission.go +++ b/svc/reward_commission.go @@ -182,10 +182,11 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b return 0, pvdFee, sysFee, 0, ulink, nil } //常规级差 - var userRelationship *[]md.UserRelation if returnAllLevel { - userRelationship, err = UserRelativeNetwork(engine, uid) + userRelationship, err = UserRelativeNetwork(engine, uid, 0) + } else if rmd.IsShowExtend == "1" { + userRelationship, err = UserRelativeNetwork(engine, uid, 1) } else { userRelationship = nil } @@ -490,7 +491,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); err != nil { fmt.Println("方案有问题1") return 0, 0, 0, nil, err } diff --git a/svc/user_relative_network.go b/svc/user_relative_network.go index 4e0ee31..cf4b980 100644 --- a/svc/user_relative_network.go +++ b/svc/user_relative_network.go @@ -7,8 +7,8 @@ import ( ) // 获取用户关系等级, 如果返回nil则没有上级用户 -func UserRelativeNetwork(eg *xorm.Engine, uid int) (*[]md.UserRelation, error) { - parent, err := db.DbsUserRelate(eg, uid) +func UserRelativeNetwork(eg *xorm.Engine, uid, level int) (*[]md.UserRelation, error) { + parent, err := db.DbsUserRelate(eg, uid, level) if err != nil || parent == nil { return nil, err }