Browse Source

add reverse:for v3.8.5 test

tags/v3.8.5
huangjiajun 2 years ago
parent
commit
53d383d733
5 changed files with 322 additions and 25 deletions
  1. +15
    -14
      db/model/integral_release_basic.go
  2. +10
    -8
      lib/comm_plan/init.go
  3. +19
    -3
      rule/relate_commission.go
  4. +11
    -0
      svc/reward_commission.go
  5. +267
    -0
      svc/svc_integral_release.go

+ 15
- 14
db/model/integral_release_basic.go View File

@@ -5,18 +5,19 @@ import (
)

type IntegralReleaseBasic struct {
Id int `json:"id" xorm:"not null pk autoincr comment('主键id') INT(11)"`
IsUse int `json:"is_use" xorm:"not null default 0 comment('是否开启(否:0;是:1)') TINYINT(1)"`
Coin1 int `json:"coin_1" xorm:"coin_1 not null default 0 comment('coinId_1(类似于红积分)') INT(11)"`
Coin2 int `json:"coin_2" xorm:"coin_2 not null default 0 comment('coinId_2(类似于绿积分)') INT(11)"`
RegisterGiveCoinNum string `json:"register_give_coin_num" xorm:"not null default 0.0000 comment('注册赠送积分数量') DECIMAL(10,4)"`
SignInReleaseRatio string `json:"sign_in_release_ratio" xorm:"not null default 0.0000 comment('签到释放比例') DECIMAL(10,4)"`
BusinessDiscountSet string `json:"business_discount_set" xorm:"not null comment('商家让利释放速度设置') TEXT"`
AlipayServiceChargeRate string `json:"alipay_service_charge_rate" xorm:"not null default 0.0000 comment('支付宝手续费比例') DECIMAL(10,4)"`
TaxRevenueRate string `json:"tax_revenue_rate" xorm:"not null default 0.0000 comment('税收比例') DECIMAL(10,4)"`
OperatingExpenseRate string `json:"operating_expense_rate" xorm:"not null default 0.0000 comment('服务费比例') DECIMAL(10,4)"`
ReleaseDate string `json:"release_date" xorm:"not null default '0000-00-00' comment('释放日期') VARCHAR(50)"`
Ext string `json:"ext" xorm:"TEXT"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') TIMESTAMP"`
UpdateAt time.Time `json:"update_at" xorm:"default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
Id int `json:"id" xorm:"not null pk autoincr comment('主键id') INT(11)"`
IsUse int `json:"is_use" xorm:"not null default 0 comment('是否开启(否:0;是:1)') TINYINT(1)"`
Coin1 int `json:"coin_1" xorm:"coin_1 not null default 0 comment('coinId_1(类似于红积分)') INT(11)"`
Coin2 int `json:"coin_2" xorm:"coin_2 not null default 0 comment('coinId_2(类似于绿积分)') INT(11)"`
RegisterGiveCoinNum string `json:"register_give_coin_num" xorm:"not null default 0.0000 comment('注册赠送积分数量') DECIMAL(10,4)"`
SignInReleaseRatio string `json:"sign_in_release_ratio" xorm:"not null default 0.0000 comment('签到释放比例') DECIMAL(10,4)"`
BusinessDiscountSet string `json:"business_discount_set" xorm:"not null comment('商家让利释放速度设置') TEXT"`
AlipayServiceChargeRate string `json:"alipay_service_charge_rate" xorm:"not null default 0.0000 comment('支付宝手续费比例') DECIMAL(10,4)"`
TaxRevenueRate string `json:"tax_revenue_rate" xorm:"not null default 0.0000 comment('税收比例') DECIMAL(10,4)"`
OperatingExpenseRate string `json:"operating_expense_rate" xorm:"not null default 0.0000 comment('服务费比例') DECIMAL(10,4)"`
DistributableCoefficientRate string `json:"distributable_coefficient_rate" xorm:"not null default 0.0000 comment('可分配系数比例') DECIMAL(10,4)"`
ReleaseDate string `json:"release_date" xorm:"not null default '0000-00-00' comment('释放日期') VARCHAR(50)"`
Ext string `json:"ext" xorm:"TEXT"`
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') TIMESTAMP"`
UpdateAt time.Time `json:"update_at" xorm:"default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
}

+ 10
- 8
lib/comm_plan/init.go View File

@@ -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,level,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,
@@ -18,14 +18,14 @@ type PlanOpt struct {
CommissionMode string // 佣金返佣方式
//IntegralMode string // 积分返佣方式
//BlockIconsMode string // 区块币返佣方式
SysRate float64 // 系统占佣比例
PvdRate float64 // 供应商占佣比例
RegionRate float64 // 区域代理占佣比例
GlobalRate float64 // 全球分红占佣比例
MerchantRate float64 //商家占佣比例
NewAgentRate float64 //代理分红占佣比例
SysRate float64 // 系统占佣比例
PvdRate float64 // 供应商占佣比例
RegionRate float64 // 区域代理占佣比例
GlobalRate float64 // 全球分红占佣比例
MerchantRate float64 //商家占佣比例
NewAgentRate float64 //代理分红占佣比例
OrderBeforeRate float64
PushHandRate float64 //推手占佣比例
PushHandRate float64 //推手占佣比例
//IntegralBili float64 // 积分兑换比例
//BlockIconsBili float64 // 区块币兑换比例
UserRate map[int]*LvGrade // 供应商对应的等级比例
@@ -53,6 +53,8 @@ type LvGrade struct {
ReturnType []string `json:"return_type"` //返利类型
SelfRateList map[string]string `json:"self_rate_list"` // 自购比例
TeamRateList map[string]string `json:"team_rate_list"` // 团队最高比例
FirstExtend map[string]string `json:"first_extend"` //
SecondExtend map[string]string `json:"second_extend"` //
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 固定金额


+ 19
- 3
rule/relate_commission.go View File

@@ -20,15 +20,31 @@ func GetComm(eg *xorm.Engine) map[string]string {
virType = virCfg.Val
}
var arg = map[string]string{
"virType": virType,
"integralRewardMultiple": "0",
"integralCoinId": "0",
"virType": virType,
"integralRewardMultiple": "0",
"integralCoinId": "0",
"alipayServiceChargeRate": "0",
"taxRevenueRate": "0",
"operatingExpenseRate": "0",
"distributableCoefficientRate": "0",
}
chain := db.GetGreenChain(eg)
if chain != nil {
arg["integralRewardMultiple"] = zhios_order_relate_utils.IntToStr(chain.IntegralRewardMultiple)
arg["integralCoinId"] = zhios_order_relate_utils.IntToStr(chain.Coin2)
}
//1、查找 `integral_release` 基础设置
integralRelease, _ := db.IntegralReleaseGetOneByParamsEg(eg, map[string]interface{}{
"key": "is_use",
"value": 1,
})
if integralRelease != nil {
arg["alipayServiceChargeRate"] = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(integralRelease.AlipayServiceChargeRate)/100, 6)
arg["taxRevenueRate"] = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(integralRelease.TaxRevenueRate)/100, 6)
arg["operatingExpenseRate"] = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(integralRelease.OperatingExpenseRate)/100, 6)
arg["distributableCoefficientRate"] = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(integralRelease.DistributableCoefficientRate)/100, 6)
}

return arg
}



+ 11
- 0
svc/reward_commission.go View File

@@ -161,6 +161,17 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b
comm(commArr, ulink)
return profit, pvdFee, sysFee, 0, ulink, nil
}
if cfg.Mode == "lv_integral_release" { //公排
pvdFee, sysFee, _, ulink, err := IntegralRelease(engine, uid, newLevel, returnAllLevel, rmd.IsShowExtend, newProvider, user, comf, price, cfg, rmd.IsGoods, commArr)
if err != nil {
return 0, 0, 0, 0, nil, nil
}
if ulink == nil {
return 0, 0, 0, 0, nil, nil
}
comm(commArr, ulink)
return ulink.Profit, pvdFee, sysFee, 0, ulink, nil
}
if cfg.Mode == "extend_price" { //直推奖励
var ulink = &comm_plan.LvUser{}
if rmd.IsGoods == "1" { //自购没奖励,就不计算了


+ 267
- 0
svc/svc_integral_release.go View File

@@ -0,0 +1,267 @@
package svc

import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model"
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/lib/comm_plan"
"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"
"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) {
//佣金扣除抽成后
fee, pvdFee, sysFee := CommFee(comf, cfg, "commission", isGoods)
////积分扣除抽成后
integralFee, _, _ := CommFee(zhios_order_relate_utils.StrToFloat64(price), cfg, "integral", isGoods)
//常规级差
var userRelationship *[]md.UserRelation
if returnAllLevel {
userRelationship, err = UserRelativeNetwork(engine, uid, 2)
} else if IsShowExtend == "1" {
//userRelationship, err = UserRelativeNetwork(engine, uid, 1)
userRelationship = &[]md.UserRelation{
{
CurUid: user.Uid,
Uid: user.Uid,
Diff: 1,
Level: user.Level,
},
}
uid = 0
level = 0
} else {
userRelationship = nil
}
//如果没登录,要找出权重最低的那个
if uid == 0 {
lvList, err := db.UserLevelInIDescByWeightLow(engine)
if err != nil {
fmt.Println(err)
}
if lvList != nil {
for _, v := range lvList {
level = v.Id
}
}
}
//查出所有等级替换权重
levelList, _ := db.UserLevlEgAll(engine)
levelWeight := 0
for _, v1 := range levelList {
if v1.Id == level {
levelWeight = v1.LevelWeight
}
}
lvUser = &comm_plan.LvUser{Uid: uid, Lv: level, Diff: 0, LevelWeight: levelWeight}
var node = lvUser
if userRelationship != nil {
//关系链处理
for _, v := range *userRelationship {
if v.Uid == 0 {
continue
}
for _, v1 := range levelList {
levelId := v.Level
if v1.Id == levelId {
levelWeight = v1.LevelWeight
}
}
node.ParentUser = &comm_plan.LvUser{Uid: v.Uid, Lv: v.Level, Diff: v.Diff, OldDiff: v.OldDiff, LevelWeight: levelWeight}
node = node.ParentUser
}
}
err = CalIntegralRelease(cfg, fee, integralFee, lvUser, commArr)
if err != nil {
return 0, 0, 0, nil, err
}
return pvdFee, sysFee, subsidyFee, lvUser, nil
}

// 按总佣金的比例进行划分计算
func CalIntegralRelease(opt *comm_plan.PlanOpt, totalAmt, integralTotalAmt 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")
}
//查出用户自购佣金
commission, _, amountList, ratioList := CalReturnAmountAndRatio(userList.Lv, userList.OwnbuyReturnType, "own", totalAmt, integralTotalAmt, opt, commArr)
userList.Profit = commission // 另外出来的佣金 兼容旧的
userList.ProfitList = amountList // 各币种分佣
ratioListMap := convertList2Map(ratioList)
for k, v := range userList.ProfitList {
userList.ProfitList[k].Val = ratioListMap[v.Cid] * v.Val
}
// 各种币换算出总的额度
totalAmtList := make([]*comm_plan.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, &comm_plan.VirtualCoinCommission{
Cid: zhios_order_relate_utils.AnyToString(coinId),
Val: amount,
})
}

var (
node = userList
maxLevelWeight = node.LevelWeight // 当前权重
)
for node.ParentUser != nil { //查找上级用户
node.ParentUser.Profit = 0
// 如果父级比当前级别低, 跳过
if node.ParentUser.LevelWeight >= maxLevelWeight && node.ParentUser.Diff <= 2 {
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")
}
userType := ""
if node.ParentUser.Diff == 1 {
userType = "first_extend"
}
if node.ParentUser.Diff == 2 {
userType = "second_extend"
}
commission, _, amountList, _ := CalReturnAmountAndRatio(node.ParentUser.Lv, userList.OwnbuyReturnType, userType, totalAmt, integralTotalAmt, opt, commArr)
//佣金
node.ParentUser.Profit = commission
//积分
node.ParentUser.ProfitList = amountList
// 等级往上升则置0
maxLevelWeight = node.ParentUser.LevelWeight
}
node.Profit = zhios_order_relate_utils.StrToFloat64(fmt.Sprintf("%.4f", node.Profit))
node = node.ParentUser
}

return nil
}

//佣金 积分 区块币计算
func CalReturnAmountAndRatio(level, ownbuyReturnType int, userType string, fee, integralFee float64, opt *comm_plan.PlanOpt, commArr map[string]string) (commission, commissionRatio float64, amountList, ratioList []*comm_plan.VirtualCoinCommission) {

lvGrade := opt.UserRate[level]
if lvGrade.SelfRateList != nil {
commissionRatioStr := getVirtualCoinRatio(userType, level, opt.UserRate, "0")
commissionRatio = zhios_order_relate_utils.StrToFloat64(commissionRatioStr)
}
//(商品价格*佣金比例10%-手续费%)*(可分配系数31%-税3%-运营费用1%)*15%
if userType == "first_extend" || userType == "second_extend" {
fee = getfee(fee, commArr)
}
commission = fee * commissionRatio

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
}
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
}
amountList = append(amountList, &comm_plan.VirtualCoinCommission{
Cid: coinId,
Val: amount,
})
ratioList = append(ratioList, &comm_plan.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 getfee(fee float64, commArr map[string]string) float64 {
newfee := fee
if zhios_order_relate_utils.StrToFloat64(commArr["alipayServiceChargeRate"]) > 0 {
newfee = fee - fee*zhios_order_relate_utils.StrToFloat64(commArr["alipayServiceChargeRate"])
}
if zhios_order_relate_utils.StrToFloat64(commArr["taxRevenueRate"]) > 0 {
newfee = newfee - newfee*zhios_order_relate_utils.StrToFloat64(commArr["taxRevenueRate"])
}
if zhios_order_relate_utils.StrToFloat64(commArr["operatingExpenseRate"]) > 0 {
newfee = newfee - newfee*zhios_order_relate_utils.StrToFloat64(commArr["operatingExpenseRate"])
}
if zhios_order_relate_utils.StrToFloat64(commArr["distributableCoefficientRate"]) > 0 {
newfee = newfee - newfee*zhios_order_relate_utils.StrToFloat64(commArr["distributableCoefficientRate"])
}
return newfee
}

// 获取佣金、虚拟币比例 0=佣金
func getVirtualCoinRatio(typ string, level int, grade map[int]*comm_plan.LvGrade, coinId string) (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 "first_extend":
ratio, ok = grade[level].FirstExtend[coinId]
case "second_extend":
ratio, ok = grade[level].SecondExtend[coinId]
default:
ratio, ok = grade[level].SelfRateList[coinId]
}
if !ok {
ratio = "0"
}
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 * zhios_order_relate_utils.StrToFloat64(ratio)
} else { // 虚拟币 需要将金额按设置的比例兑换成虚拟币 这里不乘比例了 会影响后面的极差
//amount = fee * zhios_order_relate_utils.AnyToFloat64(moneyRate) * zhios_order_relate_utils.StrToFloat64(ratio)
amount = fee * zhios_order_relate_utils.AnyToFloat64(moneyRate)
}
return
}

Loading…
Cancel
Save