From 3f9bab01770ee33b3d0f8114679f1877a4028778 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 14 Feb 2023 17:25:00 +0800 Subject: [PATCH] test --- lib/comm_plan/all.go | 15 ++++++++++----- lib/comm_plan/init.go | 1 + lib/comm_plan/winery.go | 33 ++++++++++++++++++++++++++------- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/lib/comm_plan/all.go b/lib/comm_plan/all.go index 7392476..5b4cb0a 100644 --- a/lib/comm_plan/all.go +++ b/lib/comm_plan/all.go @@ -30,7 +30,7 @@ func CalReturnAmountAndRatio(level, ownbuyReturnType, peerNum int, userType stri if coinId == "0" { newFee = fee } - ratio := getVirtualCoinRatio(userType, level, peerNum, opt.UserRate, coinId) + ratio := getVirtualCoinRatio(userType, level, peerNum, opt.UserRate, coinId, 0) amount := getCoinAmount(ratio, zhios_order_relate_utils.StrToInt(coinId), newFee, opt.VirtualCoinMoneyRatioList) if coinId != "0" && opt.Mode == "lv_winery" && userType == "own" { //酒庄模式不在这里计算 amount = 0 @@ -78,7 +78,7 @@ func CalReturnAmountAndRatioByLevel(level, ownbuyReturnType, peerNum int, userTy // 新版支持多种虚拟币 支持的种类id保存在ReturnType id=0代表现金佣金 其他为虚拟币 if returnType != nil { //返佣类型 for _, coinId := range returnType { - ratio := getVirtualCoinRatio(userType, level, peerNum, opt.UserRate, coinId) + ratio := getVirtualCoinRatio(userType, level, peerNum, opt.UserRate, coinId, 0) ratioList = append(ratioList, &VirtualCoinCommission{ Cid: coinId, Val: zhios_order_relate_utils.AnyToFloat64(ratio), @@ -701,7 +701,7 @@ func getCommissionRatio(typ string, level, peerNum int, grade map[int]*LvGrade) } // 获取佣金、虚拟币比例 0=佣金 -func getVirtualCoinRatio(typ string, level, peerNum int, grade map[int]*LvGrade, coinId string) (ratio string) { +func getVirtualCoinRatio(typ string, level, peerNum int, grade map[int]*LvGrade, coinId string, isPostion int) (ratio string) { if grade[level].ReturnType == nil { return "0" } @@ -711,8 +711,13 @@ func getVirtualCoinRatio(typ string, level, peerNum int, grade map[int]*LvGrade, ok := false switch typ { case "extend_lv": - ratio, ok = grade[level].NewExtendList[coinId] - ratio = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(ratio)/100, 4) + if isPostion == 1 { + ratio, ok = grade[level].SecondExtendList[coinId] + ratio = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(ratio)/100, 4) + } else { + ratio, ok = grade[level].NewExtendList[coinId] + ratio = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(ratio)/100, 4) + } case "team": ratio, ok = grade[level].TeamRateList[coinId] case "new_team": diff --git a/lib/comm_plan/init.go b/lib/comm_plan/init.go index fdf991d..8c1eb74 100644 --- a/lib/comm_plan/init.go +++ b/lib/comm_plan/init.go @@ -64,6 +64,7 @@ type LvGrade struct { TeamRateList map[string]string `json:"team_rate_list"` // 团队最高比例 NewTeamList map[string]string `json:"new_team_list"` // 新团队比例 NewExtendList map[string]string `json:"new_extend_list"` // 直推比例 + SecondExtendList map[string]string `json:"second_extend_list"` // 直推比例 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/lib/comm_plan/winery.go b/lib/comm_plan/winery.go index b2edf00..3d0f1c5 100644 --- a/lib/comm_plan/winery.go +++ b/lib/comm_plan/winery.go @@ -43,6 +43,7 @@ func CalcWinery(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUs var ( node = userList maxLv = node.Lv // 当前等级 + firstLevelWeight = node.LevelWeight // 当前权重 maxLevelWeight = node.LevelWeight // 当前权重 peerNum = 0 // 存在同级数 peerRate float64 = 0 // 同级累计比例 @@ -82,7 +83,24 @@ Loop: var isBreak bool zeroList := make(map[string]struct{}) if node.ParentUser.Diff == 1 { - commission, _, amountList, teamRatioList := CalReturnAmountAndRatioExtendWinery(node.ParentUser.Lv, userList.OwnbuyReturnType, peerNum, "extend_lv", totalAmt, integralTotalAmt, opt) + //找出前两个人 如果不是就分团队奖 如果是就再找 + sql := `SELECT u.uid,u.first_arrive_at FROM user_profile up + LEFT JOIN user u on u.uid=up.uid + WHERE up.parent_uid=? ORDER BY u.first_arrive_at asc,u.uid asc LIMIT 2` + nativeString, err := db.QueryNativeString(eg, sql, node.ParentUser.ParentUser.Uid) + if err != nil { + return zhios_order_relate_logx.Warn("sql error") + } + //定位 + isPostion := 0 + if len(nativeString) > 0 { + for _, v := range nativeString { + if zhios_order_relate_utils.StrToInt(v["uid"]) == node.ParentUser.Uid { + isPostion = 1 + } + } + } + commission, _, amountList, teamRatioList := CalReturnAmountAndRatioExtendWinery(node.ParentUser.Lv, userList.OwnbuyReturnType, peerNum, "extend_lv", totalAmt, integralTotalAmt, opt, isPostion) //佣金 node.ParentUser.Profit = commission node.ParentUser.Profit, restAmt, totalCommissionRatio, node.ParentUser.SubsidyFee, isBreak = extendDiffMoney(node.ParentUser.Profit, grade[node.Lv].PayMode, isOnlySubsidyFee, totalAmt, restAmt, grade[node.ParentUser.Lv].TeamRate, totalCommissionRatio, peerRate, node.ParentUser.SubsidyFee, subsidyRatio) @@ -101,8 +119,8 @@ Loop: isCus = 1 extendUid = node.ParentUser.Uid } + isPostion = 0 maxLevelWeight, maxLv, peerRate, peerRateList, peerNum, sameProfit, sameProfitList, isCus, extendUid = node.ParentUser.LevelWeight, node.ParentUser.Lv, 0, nil, 0, node.ParentUser.Profit, node.ParentUser.ProfitList, isCus, extendUid - } else { if node.ParentUser.Lv > 2 && maxLvData != nil { node.ParentUser.LevelWeight = maxLvData.LevelWeight @@ -125,6 +143,7 @@ Loop: } } } + maxLevelWeight = firstLevelWeight } if isNext == 0 { // 同级奖 @@ -385,7 +404,7 @@ func CalReturnAmountAndRatioWineryTeam(level, ownbuyReturnType, peerNum int, use if coinId == "0" { newFee = fee } - ratio := getVirtualCoinRatio(userType, level, peerNum, opt.UserRate, coinId) + ratio := getVirtualCoinRatio(userType, level, peerNum, opt.UserRate, coinId, 0) amount := getCoinAmount(ratio, zhios_order_relate_utils.StrToInt(coinId), newFee, opt.VirtualCoinMoneyRatioList) if coinId != "0" && opt.Mode == "lv_winery" && userType == "own" { //酒庄模式不在这里计算 amount = 0 @@ -434,7 +453,7 @@ func CalReturnAmountAndRatioWineryTeamNew(level, ownbuyReturnType, peerNum int, if coinId == "0" { newFee = fee } - ratio := getVirtualCoinRatio(userType, level, peerNum, opt.UserRate, coinId) + ratio := getVirtualCoinRatio(userType, level, peerNum, opt.UserRate, coinId, 0) amount := getCoinAmount(ratio, zhios_order_relate_utils.StrToInt(coinId), newFee, opt.VirtualCoinMoneyRatioList) if coinId != "0" && opt.Mode == "lv_winery" && userType == "own" { //酒庄模式不在这里计算 amount = 0 @@ -494,7 +513,7 @@ func CalReturnAmountAndRatioWinery(level, ownbuyReturnType, peerNum int, userTyp if coinId == "0" { newFee = profit } - ratio := getVirtualCoinRatio(userType, level, peerNum, opt.UserRate, coinId) + ratio := getVirtualCoinRatio(userType, level, peerNum, opt.UserRate, coinId, 0) amount := getCoinAmount(ratio, zhios_order_relate_utils.StrToInt(coinId), newFee, opt.VirtualCoinMoneyRatioList) if coinId != "0" && opt.Mode == "lv_winery" && userType == "own" { //酒庄模式不在这里计算 amount = 0 @@ -524,7 +543,7 @@ func CalReturnAmountAndRatioWinery(level, ownbuyReturnType, peerNum int, userTyp return commission, commissionRatio, amountList, ratioList } -func CalReturnAmountAndRatioExtendWinery(level, ownbuyReturnType, peerNum int, userType string, fee, integralFee float64, opt *PlanOpt) (commission, commissionRatio float64, amountList, ratioList []*VirtualCoinCommission) { +func CalReturnAmountAndRatioExtendWinery(level, ownbuyReturnType, peerNum int, userType string, fee, integralFee float64, opt *PlanOpt, isPostion int) (commission, commissionRatio float64, amountList, ratioList []*VirtualCoinCommission) { var maxReturnTypeCount = 0 var returnType = make([]string, 0) for _, v := range opt.UserRate { @@ -542,7 +561,7 @@ func CalReturnAmountAndRatioExtendWinery(level, ownbuyReturnType, peerNum int, u if coinId == "0" { newFee = fee } - ratio := getVirtualCoinRatio(userType, level, peerNum, opt.UserRate, coinId) + ratio := getVirtualCoinRatio(userType, level, peerNum, opt.UserRate, coinId, isPostion) amount := getCoinAmount(ratio, zhios_order_relate_utils.StrToInt(coinId), newFee, opt.VirtualCoinMoneyRatioList) if coinId != "0" && opt.Mode == "lv_winery" && userType == "own" { //酒庄模式不在这里计算 amount = 0