|
- package plan
-
- import (
- "fmt"
-
- "applet/app/comm/utils"
- "applet/app/comm/utils/logx"
- )
-
- // 佣金 积分 区块币计算
- func CalReturnAmountAndRatio(level, ownbuyReturnType, peerNum int, userType string, fee, integralFee float64, opt *PlanOpt) (commission, commissionRatio float64, amountList, ratioList []*VirtualCoinCommission) {
- // 佣金的比例兼容旧系统 比例独立出来的 所以这样算
- commissionRatio = getCommissionRatio(userType, level, peerNum, opt.UserRate)
- commission = fee * commissionRatio
-
- // 新版支持多种虚拟币 支持的种类id保存在ReturnType id=0代表现金佣金 其他为虚拟币
- if opt.UserRate[level].ReturnType != nil { //返佣类型
-
- for _, coinId := range opt.UserRate[level].ReturnType {
- newFee := integralFee
- if coinId == "0" {
- newFee = fee
- }
- ratio := getVirtualCoinRatio(userType, level, peerNum, opt.UserRate, coinId)
- amount := getCoinAmount(ratio, utils.StrToInt(coinId), newFee, opt.VirtualCoinMoneyRatioList)
- amountList = append(amountList, &VirtualCoinCommission{
- Cid: coinId,
- Val: amount,
- })
- ratioList = append(ratioList, &VirtualCoinCommission{
- Cid: coinId,
- Val: utils.AnyToFloat64(ratio),
- })
- }
- }
-
- if ownbuyReturnType == 1 { //自购不返利
- commission = 0
- for i := range amountList {
- amountList[i].Val = 0
- }
- }
- commission = utils.FloatFormat(commission, 6)
-
- for i, coin := range amountList {
- amountList[i].Val = utils.FloatFormat(coin.Val, 6)
- }
-
- return commission, commissionRatio, amountList, ratioList
- }
-
- // 按总佣金的比例进行划分计算
- func CalcAll(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64) error {
- grade := opt.UserRate
- if len(grade) == 0 {
- return 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 * utils.AnyToFloat64(rate)
- }
- totalAmtList = append(totalAmtList, &VirtualCoinCommission{
- Cid: 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) // 各虚拟币累计比例
- //integralPeerRate float64 = 0 // 同级累计比例
- //blockIconsPeerRate float64 = 0 // 同级累计比例
- restAmt = totalAmt - userList.Profit // 剩余比例
- //integralRestAmt = totalAmt - userList.IntegralProfit // 积分剩余比例
- //blockIconsRestAmt = totalAmt - userList.BlockIconsProfit // 区块币剩余比例
- totalCommissionRatio = commissionRatio // 累计佣金比例
- //integralBili = integralLeaveBili // 积分累计佣金比例
- //blockIconsBili = blockIconsLeaveBili // 区块币累计佣金比例
- )
- // 计算剩余额度
- restAmtList, _ = CalVirtualCommissionMinus(totalAmtList, amountList)
- // 累计比例
- accumulateRatioList = ratioList
- restAmt = utils.FloatFormat(restAmt, 6)
-
- Loop:
- for node.ParentUser != nil { //查找上级用户
- node.ParentUser.Profit = 0
-
- //佣金补贴奖励
- subsidyFee, subsidyRatio, isOnlySubsidyFee, subsidyFeeList, subsidyRatioList := subsidyFee(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)
- // 虚拟币 newProfitList, newRestAmtList, newTotalRatioList, newPeerRateList, newSubsidyFeeList, zeroList
- 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 logx.Warn("level grade node.Lv is not set")
- }
- if _, ok := grade[node.ParentUser.Lv]; !ok {
- return logx.Warn("level grade node.ParentUser.Lv is not set")
- }
- commission, _, amountList, teamRatioList := CalReturnAmountAndRatio(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, 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
- }
- node.Profit = utils.StrToFloat64(fmt.Sprintf("%.4f", node.Profit))
-
- node = node.ParentUser
-
- }
-
- return nil
- }
-
- // 公共处理同级计算 (只计算佣金 旧版本用)
- func sameMoney(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.UserRate[lv].PayMode == 0 && isOnlySubsidy == 0 {
- restAmt -= profit // 剩余可分
- restAmt = 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 = utils.FloatFormat(restAmt, 6)
- totalRatio += utils.FloatFormat(subsidyBili, 6)
- }
- }
- return profit, restAmt, totalRatio, peerRate, subsidyFee, false
- }
-
- func sameMoneyV2(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)
- subsidyRatioMap := convertList2Map(subsidyRatioList)
-
- 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.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
- }
-
- // 公共处理下团队-上一层 (用于旧版的制度 只有佣金时)
- func teamDiffMoney(profit float64, payMode, isOnlySubsidy int, totalAmt, restAmt, teamRatio, totalRatio, peerRate, subsidyFee, subsidyRatio float64) (float64, float64, float64, float64, bool) {
- // 如果是团队内部支出团队比例大于同级累计比例 或站长支出
- if payMode == 1 || teamRatio > peerRate {
- teamRatio = utils.FloatFormat(teamRatio-totalRatio, 6)
- }
- //极差返利
- if isOnlySubsidy == 0 {
- totalRatio += teamRatio
- //出现负数跳过
- if teamRatio <= 0 {
- profit = 0
- return profit, restAmt, totalRatio, subsidyFee, true
- }
- profit = utils.FloatFormat(teamRatio*totalAmt, 6)
- if restAmt < profit {
- profit = 0
- return profit, restAmt, totalRatio, subsidyFee, true
- }
- restAmt -= profit // 剩余可分
-
- } else if isOnlySubsidy == 1 { //如果只返补贴 当成是极差的一部分 所以要扣 不是额外的
- totalRatio += utils.FloatFormat(subsidyRatio, 6)
- profit = 0
- if restAmt < subsidyFee {
- profit = 0
- subsidyFee = 0
- return profit, restAmt, totalRatio, subsidyFee, true
- }
- restAmt -= subsidyFee // 剩余可分
- }
- restAmt = utils.FloatFormat(restAmt, 6)
- return profit, restAmt, totalRatio, subsidyFee, false
- }
-
- // 处理多虚拟币团队的
- func teamDiffMoneyV2(profitList []*VirtualCoinCommission, payMode, isOnlySubsidy int, totalAmtList, restAmtList, teamRatioList, totalRatioList, peerRateList, subsidyFeeList, subsidyRatioList []*VirtualCoinCommission) (newProfitList, newRestAmtList, newTotalRatioList, newSubsidyFeeList []*VirtualCoinCommission, zeroList map[string]struct{}) {
- restAmtMap := convertList2Map(restAmtList)
- totalAmtMap := convertList2Map(totalAmtList)
- profitMap := convertList2Map(profitList)
- totalRatioMap := convertList2Map(totalRatioList)
- peerRateMap := convertList2Map(peerRateList)
- subsidyFeeMap := convertList2Map(subsidyFeeList)
- subsidyRatioMap := convertList2Map(subsidyRatioList)
- teamRatioMap := convertList2Map(teamRatioList)
-
- zeroList = make(map[string]struct{})
- newProfitList = make([]*VirtualCoinCommission, 0)
-
- for _, coin := range profitList {
- // 如果是团队内部支出团队比例大于同级累计比例 或站长支出
- if payMode == 1 || teamRatioMap[coin.Cid] > peerRateMap[coin.Cid] {
- teamRatioMap[coin.Cid] = utils.FloatFormat(teamRatioMap[coin.Cid]-totalRatioMap[coin.Cid], 6)
- }
-
- if isOnlySubsidy == 0 {
- totalRatioMap[coin.Cid] += teamRatioMap[coin.Cid]
-
- profitOne := &VirtualCoinCommission{}
- profitOne.Cid = coin.Cid
- profitOne.Val = utils.FloatFormat(totalAmtMap[coin.Cid]*teamRatioMap[coin.Cid], 6)
- // 剩余不足或比例小于0
- if teamRatioMap[coin.Cid] < 0 || restAmtMap[coin.Cid] < profitOne.Val {
- zeroList[coin.Cid] = struct{}{}
- profitOne.Val = 0
- }
- newProfitList = append(newProfitList, profitOne)
-
- restAmtMap[coin.Cid] -= profitOne.Val
- } else if isOnlySubsidy == 1 { //如果只返补贴 当成是极差的一部分 所以要扣 不是额外的
- totalRatioMap[coin.Cid] += utils.FloatFormat(subsidyRatioMap[coin.Cid], 6)
- profitMap[coin.Cid] = 0
- if restAmtMap[coin.Cid] < subsidyFeeMap[coin.Cid] {
- subsidyFeeMap[coin.Cid] = 0
- }
- restAmtMap[coin.Cid] -= subsidyFeeMap[coin.Cid]
- }
- }
- newTotalRatioList = convertMap2List(totalRatioMap)
- newRestAmtList = convertMap2List(restAmtMap)
- newSubsidyFeeList = convertMap2List(subsidyFeeMap)
-
- return newProfitList, newRestAmtList, newTotalRatioList, newSubsidyFeeList, zeroList
- }
-
- // 补贴金额计算 仅针对会员费
- // types 支持的返佣类型
- func subsidyFee(opt *PlanOpt, totalAmt, integralTotalAmt float64, lvuser *LvUser, newLv int, pvd string, sysFee, integralSysFee float64) (subsidyFee, subsidyRatio float64, isOnlySubsidyFee int, subsidyFeeList, subsidyRatioList []*VirtualCoinCommission) {
- grade := opt.UserRate
- lv := lvuser.Lv
- //会员费分佣只有直推的奖励
- pvdBool := utils.InArr(pvd, []string{"user_level_up", "mall_goods_user_lv"})
- if opt.IsCanRunSubsidy == 1 { //后台推演用
- if grade[lv].UserSubsidyType == "buy_goods" {
- pvdBool = false
- } else {
- pvdBool = true
- }
- }
- if pvdBool && lvuser.Diff != 1 {
- return 0, 0, 0, nil, nil
- }
- if _, ok := grade[lv]; !ok {
- return 0, 0, 0, nil, nil
- }
- if grade[lv].UserSubsidyType == "" {
- grade[lv].UserSubsidyType = "up_lv"
- }
-
- // 各等级 各虚拟币补贴设置
- userLvUpSubsidyList := grade[lv].UserLvUpSubsidyList
- if userLvUpSubsidyList == nil {
- return 0, 0, 0, nil, nil
-
- }
- //只有额外补贴跟 分销补贴按钮都开启才有的分
- if grade[lv].SubsidyEnable == 1 && grade[lv].UserLvUpSubsidyEnable == 1 {
- //判断有没有开启 如果不是推荐会员模式
- if pvdBool && grade[lv].UserSubsidyType != "up_lv" { // 分享会员补贴
- return 0, 0, 0, nil, nil
- }
- //如果不是购买商品模式 跳过
- if pvdBool == false && grade[lv].UserSubsidyType != "buy_goods" { // 购买商品补贴
- return 0, 0, 0, nil, nil
- }
- //处理每个条件的返利
- if grade[lv].UserLvUpSubsidyList != nil {
- fmt.Println(grade[lv].UserLvUpSubsidyList)
- for k, v1 := range grade[lv].UserLvUpSubsidyList {
- v, ok := v1.(map[string]interface{})
-
- if ok {
- //如果不相等并且是会员升级的没的返
- if newLv != int(utils.AnyToInt64(v["lv"])) && pvdBool {
- continue
- }
- //如果层级不是当前层级 且不是会员升级
- if pvdBool == false && k+1 != lvuser.Diff {
- continue
- }
- if pvdBool == false { //如果不是会员升级 newLv=旧的等级
- newLv = lv
- }
- //如果没开启与补贴共存 只能拿这个奖励
- if int(utils.AnyToInt64(v["is_use"])) != 1 {
- isOnlySubsidyFee = 1
- }
-
- modeList := grade[lv].SubsidyModeList // 每一种币按比例还是固定金额
- if modeList == nil {
- return 0, 0, 0, nil, nil
- }
- subsidyReturnType := grade[lv].SubsidyReturnType // 补贴支持的虚拟币
- if subsidyReturnType == nil {
- return 0, 0, 0, nil, nil
- }
-
- for _, coinId := range subsidyReturnType {
- ratio := GetLvUpSubsidyVirtualCoinRatio(lv, newLv, lvuser.Diff, grade, coinId)
- mode := modeList[coinId]
- if mode != "bili" && mode != "money" {
- continue
- }
- modeStr := mode.(string)
- subsidyMode := grade[lv].SubsidyMode
- newAmt := integralTotalAmt
- newSysFee := integralSysFee
- var moneyRate = ""
- if coinId == "0" {
- newAmt = totalAmt
- newSysFee = sysFee
- } else if mode == "bili" {
- rateList := opt.VirtualCoinMoneyRatioList
- moneyRates, ok := rateList[utils.StrToInt(coinId)]
- if ok {
- moneyRate = moneyRates
- }
- }
- amount, subsidyRatio := GetSubsidyVirtualCoinAmount(ratio, moneyRate, modeStr, newAmt, newSysFee, subsidyMode)
- subsidyFeeList = append(subsidyFeeList, &VirtualCoinCommission{
- Cid: coinId,
- Val: amount,
- })
- subsidyRatioList = append(subsidyRatioList, &VirtualCoinCommission{
- Cid: coinId,
- Val: subsidyRatio,
- })
- }
- }
- }
- }
-
- }
- subsidyFee = utils.FloatFormat(subsidyFee, 6)
- for i, coin := range subsidyFeeList {
- subsidyFeeList[i].Val = utils.FloatFormat(subsidyFeeList[i].Val, 6)
-
- if coin.Cid == "0" {
- subsidyFee += coin.Val // 添加上额外补贴到外部的补贴金额
- }
- }
- return subsidyFee, subsidyRatio, isOnlySubsidyFee, subsidyFeeList, subsidyRatioList
- }
-
- // 获取佣金比例
- func getCommissionRatio(typ string, level, peerNum int, grade map[int]*LvGrade) (ratio float64) {
- switch typ {
- case "team":
- ratio = grade[level].TeamRate
- case "same_lv":
- if len(grade[level].PeerRate) == 0 {
- ratio = 0
- } else {
- ratio = grade[level].PeerRate[peerNum]
- }
- default:
- ratio = grade[level].SelfRate
- }
- return
- }
-
- // 获取佣金、虚拟币比例 0=佣金
- func getVirtualCoinRatio(typ string, level, peerNum int, grade map[int]*LvGrade, coinId string) (ratio string) {
- ok := false
- switch typ {
- case "team":
- ratio, ok = grade[level].TeamRateList[coinId]
- case "same_lv":
- ratio, ok = grade[level].PeerRateList[peerNum][coinId]
- default:
- ratio, ok = grade[level].SelfRateList[coinId]
- }
- if !ok {
- ratio = "0"
- }
- return
- }
-
- // GetLvUpSubsidyVirtualCoinRatio 获取各币种分销补贴比例
- func GetLvUpSubsidyVirtualCoinRatio(level, newLevel, diff int, grade map[int]*LvGrade, coinId string) (ratio string) {
- gradeCfg, ok := grade[level]
- if !ok || gradeCfg == nil {
- return "0"
- }
- levelSubsidyCfg := gradeCfg.UserLvUpSubsidyList
- if levelSubsidyCfg == nil {
- return "0"
- }
- // 找出对应等级的配置
- var levelRateListArr = make([]interface{}, 0)
- for oneKey, oneLevel := range levelSubsidyCfg {
- oneLevelMap, ok := oneLevel.(map[string]interface{})
- if !ok || oneLevelMap == nil {
- continue
- }
- if oneLevelMap["lv"] == "" && diff == 0 {
- continue
- }
- if oneLevelMap["lv"] == utils.AnyToString(newLevel) || (oneKey+1 == diff && diff > 0) {
- //可能不是这个类型
- jsons, ok := oneLevelMap["rate_list"].([]interface{})
- if ok {
- levelRateListArr = jsons
- }
-
- }
- }
- if len(levelRateListArr) == 0 {
- return "0"
- }
- // 各币种的补贴比例
- coinIdInt := utils.StrToInt(coinId)
- ratio = levelRateListArr[coinIdInt].(string)
- if utils.StrToFloat64(ratio) == 0 {
- return "0"
- }
-
- return ratio
- }
-
- // GetSubsidyVirtualCoinAmount 获取各币种补贴值
- // ratio 比例
- // typ 模式 bili money
- func GetSubsidyVirtualCoinAmount(ratio, moneyRate, typ string, fee, sysFee float64, subsidyMode int) (amount, subsidyRatio float64) {
- ratioF := utils.AnyToFloat64(ratio)
- if typ == "money" {
- amount = ratioF
- subsidyRatio = ratioF / fee
- } else {
- subsidyRatio = ratioF / 100
- if utils.StrToFloat64(moneyRate) > 0 {
- sysFee = sysFee * utils.StrToFloat64(moneyRate)
- }
- if utils.StrToFloat64(moneyRate) > 0 {
- fee = fee * utils.StrToFloat64(moneyRate)
- }
- if subsidyMode == 1 { // 按利润
- amount = sysFee * subsidyRatio
- } else { // 按佣金
- amount = fee * subsidyRatio
- }
- }
- return
- }
-
- // 计算佣金、虚拟币额度
- func getCoinAmount(ratio string, coinId int, fee float64, rateList map[int]string) (amount float64) {
- moneyRate, ok := rateList[coinId]
- if !ok {
- amount = 0.00
- return
- }
- if coinId == 0 { // 金额
- amount = fee * utils.StrToFloat64(ratio)
- } else { // 虚拟币 需要将金额按设置的比例兑换成虚拟币 这里不乘比例了 会影响后面的极差
- //amount = fee * utils.AnyToFloat64(moneyRate) * utils.StrToFloat64(ratio)
- amount = fee * utils.AnyToFloat64(moneyRate)
- }
- return
- }
-
- // 计算各币种数量扣除
- func CalVirtualCommissionMinus(a, b []*VirtualCoinCommission) (c []*VirtualCoinCommission, zeroList map[string]struct{}) {
- var amount float64
- zeroList = make(map[string]struct{})
- for _, coinA := range a {
- for _, coinB := range b {
- if coinA.Cid == coinB.Cid {
- amount = coinA.Val - coinB.Val
- if amount < 0 {
- zeroList[coinA.Cid] = struct{}{}
- amount = 0
- }
- c = append(c, &VirtualCoinCommission{
- Cid: coinA.Cid,
- Val: amount,
- })
- }
- }
- }
- return c, zeroList
- }
-
- func convertList2Map(a []*VirtualCoinCommission) (b map[string]float64) {
- b = make(map[string]float64)
- for _, i := range a {
- b[i.Cid] = i.Val
- }
- return b
- }
-
- func convertMap2List(a map[string]float64) (b []*VirtualCoinCommission) {
- for cid, val := range a {
- b = append(b, &VirtualCoinCommission{
- Cid: cid,
- Val: val,
- })
- }
-
- return b
- }
|