|
|
@@ -7,11 +7,12 @@ import ( |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" |
|
|
|
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" |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
func IntegralRelease(engine *xorm.Engine, uid, level int, returnAllLevel bool, IsShowExtend, pvd string, user *model.User, comf float64, price string, cfg *comm_plan.PlanOpt, isGoods string, commArr map[string]string) (pvdFee, sysFee, subsidyFee float64, lvUser *comm_plan.LvUser, err error) { |
|
|
|
func IntegralRelease(engine *xorm.Engine, uid, level int, returnAllLevel bool, IsShowExtend, pvd string, user *model.User, comf float64, price string, cfg *comm_plan.PlanOpt, isGoods string, commArr map[string]string, virtualCoinMoneyRate map[int]string) (pvdFee, sysFee, subsidyFee float64, lvUser *comm_plan.LvUser, err error) { |
|
|
|
//佣金扣除抽成后 |
|
|
|
fee, pvdFee, sysFee := CommFee(comf, cfg, "commission", isGoods) |
|
|
|
////积分扣除抽成后 |
|
|
@@ -74,7 +75,33 @@ func IntegralRelease(engine *xorm.Engine, uid, level int, returnAllLevel bool, I |
|
|
|
node = node.ParentUser |
|
|
|
} |
|
|
|
} |
|
|
|
err = CalIntegralRelease(cfg, fee, integralFee, integralFeeCom, lvUser, commArr) |
|
|
|
// 根据供应商 |
|
|
|
rewardOpt, err := db.DbsPlanRewardByPvd(engine, pvd) |
|
|
|
if err != nil { |
|
|
|
return 0, 0, 0, nil, err |
|
|
|
} |
|
|
|
if rewardOpt == nil { |
|
|
|
return 0, 0, 0, nil, zhios_order_relate_logx.Warn("找不到方案记录") |
|
|
|
} |
|
|
|
if rewardOpt.State == 0 { |
|
|
|
return 0, 0, 0, nil, zhios_order_relate_logx.Warn("抽成方案未开启") |
|
|
|
} |
|
|
|
if rewardOpt.PlanCommissionId == 0 { |
|
|
|
return 0, 0, 0, nil, zhios_order_relate_logx.Warn("抽成方案未设置佣金方案id") |
|
|
|
} |
|
|
|
commissionOpt, err := db.DbsPlanCommissionById(engine, rewardOpt.PlanCommissionId) |
|
|
|
if err != nil || commissionOpt == nil || commissionOpt.Id == 0 { |
|
|
|
return 0, 0, 0, nil, err |
|
|
|
} |
|
|
|
var subsidyTmp = make(map[string]*md.IntegralReleaseLvGrade) |
|
|
|
var tmp map[string]*md.IntegralReleaseLvGrade |
|
|
|
if err := json.Unmarshal([]byte(commissionOpt.Data), &tmp); err != nil { |
|
|
|
return 0, 0, 0, nil, zhios_order_relate_logx.Warn("分佣方案数据设置错误") |
|
|
|
} |
|
|
|
for _, v := range tmp { |
|
|
|
subsidyTmp[zhios_order_relate_utils.IntToStr(v.Lv)] = v |
|
|
|
} |
|
|
|
err = CalIntegralRelease(subsidyTmp, fee, integralFee, integralFeeCom, lvUser, commArr, virtualCoinMoneyRate) |
|
|
|
if err != nil { |
|
|
|
return 0, 0, 0, nil, err |
|
|
|
} |
|
|
@@ -82,13 +109,10 @@ func IntegralRelease(engine *xorm.Engine, uid, level int, returnAllLevel bool, I |
|
|
|
} |
|
|
|
|
|
|
|
// 按总佣金的比例进行划分计算 |
|
|
|
func CalIntegralRelease(opt *comm_plan.PlanOpt, totalAmt, integralTotalAmt, integralTotalAmtCom float64, userList *comm_plan.LvUser, commArr map[string]string) error { |
|
|
|
grade := opt.UserRate |
|
|
|
if len(grade) == 0 { |
|
|
|
return zhios_order_relate_logx.Warn("level grade is not set") |
|
|
|
} |
|
|
|
func CalIntegralRelease(subsidyTmp map[string]*md.IntegralReleaseLvGrade, totalAmt, integralTotalAmt, integralTotalAmtCom float64, userList *comm_plan.LvUser, commArr map[string]string, virtualCoinMoneyRate map[int]string) error { |
|
|
|
|
|
|
|
//查出用户自购佣金 |
|
|
|
commission, _, amountList, ratioList := CalReturnAmountAndRatio(userList.Lv, userList.OwnbuyReturnType, "own", totalAmt, integralTotalAmt, integralTotalAmtCom, opt, commArr) |
|
|
|
commission, _, amountList, ratioList := CalReturnAmountAndRatio(userList.Lv, userList.OwnbuyReturnType, "own", totalAmt, integralTotalAmt, integralTotalAmtCom, subsidyTmp, commArr, virtualCoinMoneyRate) |
|
|
|
userList.Profit = commission // 另外出来的佣金 兼容旧的 |
|
|
|
userList.ProfitList = amountList // 各币种分佣 |
|
|
|
ratioListMap := convertList2Map(ratioList) |
|
|
@@ -97,7 +121,7 @@ func CalIntegralRelease(opt *comm_plan.PlanOpt, totalAmt, integralTotalAmt, inte |
|
|
|
} |
|
|
|
// 各种币换算出总的额度 |
|
|
|
totalAmtList := make([]*comm_plan.VirtualCoinCommission, 0) |
|
|
|
for coinId, rate := range opt.VirtualCoinMoneyRatioList { |
|
|
|
for coinId, rate := range virtualCoinMoneyRate { |
|
|
|
var amount float64 |
|
|
|
if coinId == 0 { |
|
|
|
amount = totalAmt |
|
|
@@ -118,10 +142,10 @@ func CalIntegralRelease(opt *comm_plan.PlanOpt, totalAmt, integralTotalAmt, inte |
|
|
|
node.ParentUser.Profit = 0 |
|
|
|
// 如果父级比当前级别低, 跳过 |
|
|
|
if node.ParentUser.LevelWeight >= maxLevelWeight && node.ParentUser.Diff <= 2 { |
|
|
|
if _, ok := grade[node.Lv]; !ok { |
|
|
|
if _, ok := subsidyTmp[zhios_order_relate_utils.IntToStr(node.Lv)]; !ok { |
|
|
|
return zhios_order_relate_logx.Warn("level grade node.Lv is not set") |
|
|
|
} |
|
|
|
if _, ok := grade[node.ParentUser.Lv]; !ok { |
|
|
|
if _, ok := subsidyTmp[zhios_order_relate_utils.IntToStr(node.ParentUser.Lv)]; !ok { |
|
|
|
return zhios_order_relate_logx.Warn("level grade node.ParentUser.Lv is not set") |
|
|
|
} |
|
|
|
userType := "" |
|
|
@@ -131,7 +155,7 @@ func CalIntegralRelease(opt *comm_plan.PlanOpt, totalAmt, integralTotalAmt, inte |
|
|
|
if node.ParentUser.Diff == 2 { |
|
|
|
userType = "second_extend" |
|
|
|
} |
|
|
|
commission, _, amountList, ratioList := CalReturnAmountAndRatio(node.ParentUser.Lv, userList.OwnbuyReturnType, userType, totalAmt, integralTotalAmt, integralTotalAmtCom, opt, commArr) |
|
|
|
commission, _, amountList, ratioList := CalReturnAmountAndRatio(node.ParentUser.Lv, userList.OwnbuyReturnType, userType, totalAmt, integralTotalAmt, integralTotalAmtCom, subsidyTmp, commArr, virtualCoinMoneyRate) |
|
|
|
//佣金 |
|
|
|
node.ParentUser.Profit = commission |
|
|
|
//积分 |
|
|
@@ -151,13 +175,16 @@ func CalIntegralRelease(opt *comm_plan.PlanOpt, totalAmt, integralTotalAmt, inte |
|
|
|
} |
|
|
|
|
|
|
|
//佣金 积分 区块币计算 |
|
|
|
func CalReturnAmountAndRatio(level, ownbuyReturnType int, userType string, fee, integralFee, integralFeeCom float64, opt *comm_plan.PlanOpt, commArr map[string]string) (commission, commissionRatio float64, amountList, ratioList []*comm_plan.VirtualCoinCommission) { |
|
|
|
func CalReturnAmountAndRatio(level, ownbuyReturnType int, userType string, fee, integralFee, integralFeeCom float64, subsidyTmp map[string]*md.IntegralReleaseLvGrade, commArr map[string]string, virtualCoinMoneyRatio map[int]string) (commission, commissionRatio float64, amountList, ratioList []*comm_plan.VirtualCoinCommission) { |
|
|
|
lvGrade := subsidyTmp[zhios_order_relate_utils.IntToStr(level)] |
|
|
|
if lvGrade == nil { |
|
|
|
return commission, commissionRatio, amountList, ratioList |
|
|
|
} |
|
|
|
if userType != "own" { |
|
|
|
integralFee = integralFeeCom |
|
|
|
} |
|
|
|
lvGrade := opt.UserRate[level] |
|
|
|
if lvGrade.SelfRateList != nil { |
|
|
|
commissionRatioStr := getVirtualCoinRatio(userType, level, opt.UserRate, "0") |
|
|
|
commissionRatioStr := getVirtualCoinRatio(userType, level, subsidyTmp, "0") |
|
|
|
commissionRatio = zhios_order_relate_utils.StrToFloat64(commissionRatioStr) |
|
|
|
} |
|
|
|
//(商品价格*佣金比例10%-手续费%)*(可分配系数31%-税3%-运营费用1%)*15% |
|
|
@@ -168,7 +195,7 @@ func CalReturnAmountAndRatio(level, ownbuyReturnType int, userType string, fee, |
|
|
|
|
|
|
|
var maxReturnTypeCount = 0 |
|
|
|
var returnType = make([]string, 0) |
|
|
|
for _, v := range opt.UserRate { |
|
|
|
for _, v := range subsidyTmp { |
|
|
|
if v.ReturnType != nil { |
|
|
|
if len(v.ReturnType) > maxReturnTypeCount { |
|
|
|
maxReturnTypeCount = len(v.ReturnType) |
|
|
@@ -187,11 +214,8 @@ func CalReturnAmountAndRatio(level, ownbuyReturnType int, userType string, fee, |
|
|
|
if userType == "first_extend" || userType == "second_extend" { |
|
|
|
newFee = getfee(newFee, commArr) |
|
|
|
} |
|
|
|
ratio := getVirtualCoinRatio(userType, level, opt.UserRate, coinId) |
|
|
|
amount := getCoinAmount(ratio, zhios_order_relate_utils.StrToInt(coinId), newFee, opt.VirtualCoinMoneyRatioList) |
|
|
|
if coinId != "0" && opt.Mode == "lv_winery" && userType == "own" { //酒庄模式不在这里计算 |
|
|
|
amount = 0 |
|
|
|
} |
|
|
|
ratio := getVirtualCoinRatio(userType, level, subsidyTmp, coinId) |
|
|
|
amount := getCoinAmount(ratio, zhios_order_relate_utils.StrToInt(coinId), newFee, virtualCoinMoneyRatio) |
|
|
|
amountList = append(amountList, &comm_plan.VirtualCoinCommission{ |
|
|
|
Cid: coinId, |
|
|
|
Val: amount, |
|
|
@@ -235,21 +259,21 @@ func getfee(fee float64, commArr map[string]string) float64 { |
|
|
|
} |
|
|
|
|
|
|
|
// 获取佣金、虚拟币比例 0=佣金 |
|
|
|
func getVirtualCoinRatio(typ string, level int, grade map[int]*comm_plan.LvGrade, coinId string) (ratio string) { |
|
|
|
if grade[level].ReturnType == nil { |
|
|
|
func getVirtualCoinRatio(typ string, level int, grade map[string]*md.IntegralReleaseLvGrade, coinId string) (ratio string) { |
|
|
|
if grade[zhios_order_relate_utils.IntToStr(level)].ReturnType == nil { |
|
|
|
return "0" |
|
|
|
} |
|
|
|
if zhios_order_relate_utils.InArr(coinId, grade[level].ReturnType) == false { |
|
|
|
if zhios_order_relate_utils.InArr(coinId, grade[zhios_order_relate_utils.IntToStr(level)].ReturnType) == false { |
|
|
|
return "0" |
|
|
|
} |
|
|
|
ok := false |
|
|
|
switch typ { |
|
|
|
case "first_extend": |
|
|
|
ratio, ok = grade[level].FirstExtend[coinId] |
|
|
|
ratio, ok = grade[zhios_order_relate_utils.IntToStr(level)].FirstExtend[coinId] |
|
|
|
case "second_extend": |
|
|
|
ratio, ok = grade[level].SecondExtend[coinId] |
|
|
|
ratio, ok = grade[zhios_order_relate_utils.IntToStr(level)].SecondExtend[coinId] |
|
|
|
default: |
|
|
|
ratio, ok = grade[level].SelfRateList[coinId] |
|
|
|
ratio, ok = grade[zhios_order_relate_utils.IntToStr(level)].SelfRateList[coinId] |
|
|
|
} |
|
|
|
if !ok { |
|
|
|
ratio = "0" |
|
|
|