From d9cba3259bf47b54b1dc1d8fb96beb40058251d2 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Fri, 24 Mar 2023 19:25:10 +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 --- lib/comm_plan/ds_check.go | 86 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) diff --git a/lib/comm_plan/ds_check.go b/lib/comm_plan/ds_check.go index e5e9b5a..e4a4c50 100644 --- a/lib/comm_plan/ds_check.go +++ b/lib/comm_plan/ds_check.go @@ -8,6 +8,88 @@ import ( "xorm.io/xorm" ) +func CalReturnAmountAndRatioDsOwn(level, ownbuyReturnType, peerNum int, userType string, fee, integralFee float64, opt *PlanOpt) (commission, commissionRatio float64, amountList, ratioList []*VirtualCoinCommission) { + 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 { + newFee := integralFee + if coinId == "0" { + newFee = fee + } + ratio := getVirtualCoinRatioDsOwn(userType, level, peerNum, opt.UserRate, coinId, 0) + amount := getCoinAmount(ratio, zhios_order_relate_utils.StrToInt(coinId), newFee, opt.VirtualCoinMoneyRatioList) + if coinId == "0" { + commission = amount + } + amountList = append(amountList, &VirtualCoinCommission{ + Cid: coinId, + Val: amount, + }) + ratioList = append(ratioList, &VirtualCoinCommission{ + Cid: coinId, + Val: zhios_order_relate_utils.AnyToFloat64(ratio), + }) + } + } + + if ownbuyReturnType == 1 { //自购不返利 + commission = 0 + for i := range amountList { + amountList[i].Val = 0 + } + } + commission = zhios_order_relate_utils.FloatFormat(commission, 2) + + for i, coin := range amountList { + amountList[i].Val = zhios_order_relate_utils.FloatFormat(coin.Val, 6) + } + + return commission, commissionRatio, amountList, ratioList +} +func getVirtualCoinRatioDsOwn(typ string, level, peerNum int, grade map[int]*LvGrade, coinId string, isPostion int) (ratio string) { + if grade[level].ReturnType == nil { + return "0" + } + if zhios_order_relate_utils.InArr(coinId, grade[level].ReturnType) == false { + return "0" + } + ok := false + switch typ { + case "extend_lv": + if isPostion == 1 { + ratio, ok = grade[level].SecondExtendList[coinId] + } else { + ratio, ok = grade[level].NewExtendList[coinId] + } + case "team": + ratio, ok = grade[level].TeamRateList[coinId] + case "new_team": + ratio, ok = grade[level].NewTeamList[coinId] + case "same_lv": + ratio, ok = grade[level].PeerRateList[peerNum][coinId] + case "same_extend": + ratio, ok = grade[level].SameExtend[peerNum][coinId] + default: + ratio, ok = grade[level].SelfRateList[coinId] + } + ratio = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(ratio)/100, 4) + + if !ok { + ratio = "0" + } + return +} + func CalReturnAmountAndRatioDs(level, ownbuyReturnType, peerNum int, userType string, fee, integralFee float64, opt *PlanOpt) (commission, commissionRatio float64, amountList, ratioList []*VirtualCoinCommission) { var maxReturnTypeCount = 0 var returnType = make([]string, 0) @@ -116,7 +198,7 @@ func CalcDsCheck(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvU } //查出用户自购佣金 - commission, commissionRatio, amountList, ratioList := CalReturnAmountAndRatio(userList.Lv, userList.OwnbuyReturnType, 0, "own", totalAmt, integralTotalAmt, opt) + commission, commissionRatio, amountList, ratioList := CalReturnAmountAndRatioDsOwn(userList.Lv, userList.OwnbuyReturnType, 0, "own", totalAmt, integralTotalAmt, opt) userList.Profit = commission // 另外出来的佣金 兼容旧的 userList.ProfitList = amountList // 各币种分佣 userList.SubsidyFee = 0 @@ -222,7 +304,7 @@ Loop: if _, ok := grade[node.ParentUser.Lv]; !ok { return zhios_order_relate_logx.Warn("level grade node.ParentUser.Lv is not set") } - commission, _, amountList, teamRatioList := CalReturnAmountAndRatio(node.ParentUser.Lv, userList.OwnbuyReturnType, peerNum, "team", totalAmt, integralTotalAmt, opt) + commission, _, amountList, teamRatioList := CalReturnAmountAndRatioDsOwn(node.ParentUser.Lv, userList.OwnbuyReturnType, peerNum, "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, 0)