Pārlūkot izejas kodu

add reverse:for v3.6.1 佣金抽成修改

tags/v3.6.1
huangjiajun pirms 2 gadiem
vecāks
revīzija
b8155052a4
5 mainītis faili ar 108 papildinājumiem un 100 dzēšanām
  1. +1
    -0
      db/model/plan_reward.go
  2. +1
    -0
      lib/comm_plan/init.go
  3. +90
    -90
      rule/relate_commission.go
  4. +1
    -0
      svc/get_plan_cfg.go
  5. +15
    -10
      svc/reward_commission.go

+ 1
- 0
db/model/plan_reward.go Parādīt failu

@@ -17,5 +17,6 @@ type PlanReward struct {
MerchantRate float32 `json:"merchant_rate" xorm:"not null default 0.0000 comment('o2o商家抽成比例') FLOAT(6,4)"`
NewAgentRate float32 `json:"new_agent_rate" xorm:"not null default 0.0000 comment('') FLOAT(6,4)"`
PushHandRate float32 `json:"push_hand_rate" xorm:"not null default 0.0000 comment('o2o推手抽成比例') FLOAT(6,4)"`
OrderBeforeRate float32 `json:"order_before_rate" xorm:"not null default 0.0000 comment('下单前的联盟抽成') FLOAT(6,4)"`
IntegralOpen int `json:"integral_open" xorm:"not null default 0 comment('积分抽成') TINYINT(1)"`
}

+ 1
- 0
lib/comm_plan/init.go Parādīt failu

@@ -24,6 +24,7 @@ type PlanOpt struct {
GlobalRate float64 // 全球分红占佣比例
MerchantRate float64 //商家占佣比例
NewAgentRate float64 //代理分红占佣比例
OrderBeforeRate float64
PushHandRate float64 //推手占佣比例
//IntegralBili float64 // 积分兑换比例
//BlockIconsBili float64 // 区块币兑换比例


+ 90
- 90
rule/relate_commission.go Parādīt failu

@@ -47,7 +47,6 @@ func BatchGetCommissionByGoods(eg *xorm.Engine, dbName string, commissionParamLi
param.CommissionParam.Oid = param.GoodsId
param.CommissionParam.IsGoods = "1"
param.CommissionParam.ShowLevel = param.ShowLevel

_, _, _, _, lvUser, err := svc.GetRewardCommission(eg, &param.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, virType, plan, commission, virtualCoinMoneyRate)
if err != nil {
return err
@@ -120,66 +119,6 @@ func BatchGetCommissionByGoodsExtend(eg *xorm.Engine, dbName string, commissionP
return goodsId2lvUser, nil
}

// BatchGetCommission 批量分佣 订单显示
func BatchGetCommissionByOrder(engine *xorm.Engine, dbName string, CommissionParamList []*md.CommissionFirstParam) (map[string]*comm_plan.SettleCommissionToGuide, error) {
var (
isShare = false
isAllLevelReturn = false
)
goodsId2lvUser := make(map[string]*comm_plan.SettleCommissionToGuide, len(CommissionParamList))
if len(CommissionParamList) == 0 {
return goodsId2lvUser, errors.New("参数缺失")
}

group, _ := errgroup.WithContext(context.Background())
var mu sync.Mutex
virCfg, _ := db.SysCfgGetOne(engine, "virtual_coin_rebate_type")
var virType = "price"
if virCfg != nil && virCfg.Val != "" {
virType = virCfg.Val
}
plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(engine, dbName)

for _, param := range CommissionParamList {
param := param // 为下面的闭包创建局部变量
group.Go(func() error {
defer mu.Unlock()
mu.Lock()
if param.IsShare != 0 {
isShare = true
}
if param.IsAllLevelReturn != 0 {
isAllLevelReturn = true
}

if param.Oid == "" {
return errors.New("订单缺失")
}
param.CommissionParam.OldPrice = param.CommissionParam.GoodsPrice
param.CommissionParam.Oid = param.Oid

profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(engine, &param.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, virType, plan, commission, virtualCoinMoneyRate)
if err != nil {
return err
}
goodsId2lvUser[param.Oid] = &comm_plan.SettleCommissionToGuide{
Profit: profit,
PvdFee: pvdFee,
SysFee: sysFee,
SubsidyFee: subsidyFee,
LvUser: lvUser,
}

return nil
})
}
if err := group.Wait(); err != nil {
return goodsId2lvUser, err
}

return goodsId2lvUser, nil
}

//商品详情等使用
func SettleCommWithGoodsDetail(eg *xorm.Engine, dbName string, CommissionParam md.CommissionFirstParam) (float64, float64, float64, float64, *comm_plan.LvUser, error) {
var (
@@ -243,36 +182,8 @@ func SettleCommWithGoodsDetailExtend(eg *xorm.Engine, dbName string, CommissionP
profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, virType, plan, commission, virtualCoinMoneyRate)
return profit, pvdFee, sysFee, subsidyFee, lvUser, err
}
func SettleCommWithOrder(eg *xorm.Engine, dbName string, CommissionParam md.CommissionFirstParam) (float64, float64, float64, float64, *comm_plan.LvUser, error) {
var (
isShare = false
isAllLevelReturn = false
)
if CommissionParam.IsShare != 0 {
isShare = true
}

if CommissionParam.IsAllLevelReturn != 0 {
isAllLevelReturn = true
}
var mapData = map[string]string{
"old_lv": CommissionParam.OldLv,
"new_lv": CommissionParam.NewLv,
"ownbuy_return_type": zhios_order_relate_utils.IntToStr(CommissionParam.OwnbuyReturnType),
}
virCfg, _ := db.SysCfgGetOne(eg, "virtual_coin_rebate_type")
var virType = "price"
if virCfg != nil && virCfg.Val != "" {
virType = virCfg.Val
}
CommissionParam.CommissionParam.Oid = CommissionParam.GoodsId
plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(eg, dbName)

profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, virType, plan, commission, virtualCoinMoneyRate)
return profit, pvdFee, sysFee, subsidyFee, lvUser, err
}

//获取自购分享佣金的
//获取自购分享佣金的 商品显示
func GetRewardCommission(eg *xorm.Engine, dbName, mode string, CommissionParam md.CommissionFirstParam) (float64, float64, *comm_plan.LvUser, error) {
var (
isAll = false
@@ -308,3 +219,92 @@ func GetRewardCommission(eg *xorm.Engine, dbName, mode string, CommissionParam m
}
return commission, shareCommission, lvUser, nil
}

// BatchGetCommission 批量分佣 订单显示
func BatchGetCommissionByOrder(engine *xorm.Engine, dbName string, CommissionParamList []*md.CommissionFirstParam) (map[string]*comm_plan.SettleCommissionToGuide, error) {
var (
isShare = false
isAllLevelReturn = false
)
goodsId2lvUser := make(map[string]*comm_plan.SettleCommissionToGuide, len(CommissionParamList))
if len(CommissionParamList) == 0 {
return goodsId2lvUser, errors.New("参数缺失")
}

group, _ := errgroup.WithContext(context.Background())
var mu sync.Mutex
virCfg, _ := db.SysCfgGetOne(engine, "virtual_coin_rebate_type")
var virType = "price"
if virCfg != nil && virCfg.Val != "" {
virType = virCfg.Val
}
plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(engine, dbName)

for _, param := range CommissionParamList {
param := param // 为下面的闭包创建局部变量
group.Go(func() error {
defer mu.Unlock()
mu.Lock()
if param.IsShare != 0 {
isShare = true
}
if param.IsAllLevelReturn != 0 {
isAllLevelReturn = true
}

if param.Oid == "" {
return errors.New("订单缺失")
}
param.CommissionParam.OldPrice = param.CommissionParam.GoodsPrice
param.CommissionParam.Oid = param.Oid

profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(engine, &param.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, virType, plan, commission, virtualCoinMoneyRate)
if err != nil {
return err
}
goodsId2lvUser[param.Oid] = &comm_plan.SettleCommissionToGuide{
Profit: profit,
PvdFee: pvdFee,
SysFee: sysFee,
SubsidyFee: subsidyFee,
LvUser: lvUser,
}

return nil
})
}
if err := group.Wait(); err != nil {
return goodsId2lvUser, err
}

return goodsId2lvUser, nil
}

func SettleCommWithOrder(eg *xorm.Engine, dbName string, CommissionParam md.CommissionFirstParam) (float64, float64, float64, float64, *comm_plan.LvUser, error) {
var (
isShare = false
isAllLevelReturn = false
)
if CommissionParam.IsShare != 0 {
isShare = true
}

if CommissionParam.IsAllLevelReturn != 0 {
isAllLevelReturn = true
}
var mapData = map[string]string{
"old_lv": CommissionParam.OldLv,
"new_lv": CommissionParam.NewLv,
"ownbuy_return_type": zhios_order_relate_utils.IntToStr(CommissionParam.OwnbuyReturnType),
}
virCfg, _ := db.SysCfgGetOne(eg, "virtual_coin_rebate_type")
var virType = "price"
if virCfg != nil && virCfg.Val != "" {
virType = virCfg.Val
}
CommissionParam.CommissionParam.Oid = CommissionParam.GoodsId
plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(eg, dbName)

profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, virType, plan, commission, virtualCoinMoneyRate)
return profit, pvdFee, sysFee, subsidyFee, lvUser, err
}

+ 1
- 0
svc/get_plan_cfg.go Parādīt failu

@@ -72,6 +72,7 @@ func GetPlanCfg(eg *xorm.Engine, pvd, masterId string, rewardOpts map[string]*mo
opt.PushHandRate = float64(int64(rewardOpt.PushHandRate*1e4)) / 1e4
opt.MerchantRate = float64(int64(rewardOpt.MerchantRate*1e4)) / 1e4
opt.NewAgentRate = float64(int64(rewardOpt.NewAgentRate*1e4)) / 1e4
opt.OrderBeforeRate = float64(int64(rewardOpt.OrderBeforeRate*1e4)) / 1e4
opt.PlanCommissionId = rewardOpt.PlanCommissionId
// 兑换现金比例
if virtualCoinMoneyRate == nil {


+ 15
- 10
svc/reward_commission.go Parādīt failu

@@ -78,9 +78,9 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b
}
if cfg.Mode == "public_platoon" { //公排
//佣金扣除抽成后
fee, pvdFee, sysFee := CommFee(comf, cfg, "commission")
fee, pvdFee, sysFee := CommFee(comf, cfg, "commission", rmd.IsGoods)
////积分扣除抽成后
integralFee, _, _ := CommFee(zhios_order_relate_utils.StrToFloat64(price), cfg, "integral")
integralFee, _, _ := CommFee(zhios_order_relate_utils.StrToFloat64(price), cfg, "integral", rmd.IsGoods)
//调用公排制度

userPublicPlatoonSetting, err := db.UserPublicPlatoonSettingGetOneByParams(engine, map[string]interface{}{
@@ -161,9 +161,9 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b
userLevel = zhios_order_relate_utils.StrToInt(extraData["agent_lv"])
}
//佣金扣除抽成后
fee, pvdFee, sysFee := CommFee(comf, cfg, "commission")
fee, pvdFee, sysFee := CommFee(comf, cfg, "commission", rmd.IsGoods)
////积分扣除抽成后
integralFee, _, _ := CommFee(zhios_order_relate_utils.StrToFloat64(price), cfg, "integral")
integralFee, _, _ := CommFee(zhios_order_relate_utils.StrToFloat64(price), cfg, "integral", rmd.IsGoods)
var param = map[string]string{
"commission": zhios_order_relate_utils.Float64ToStr(fee),
"integral": zhios_order_relate_utils.Float64ToStr(integralFee),
@@ -205,7 +205,7 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b
userRelationship = nil
}
// userRelationship == nil 是只返回第一层 即用户自己的
pvdFee, sysFee, subsidyFee, ulink, err := CalcCommission(uid, level, 0, ownbuyReturnType, comf, zhios_order_relate_utils.StrToFloat64(price), isShare, cfg, userRelationship, newProvider, newLevel, engine)
pvdFee, sysFee, subsidyFee, ulink, err := CalcCommission(uid, level, 0, ownbuyReturnType, comf, zhios_order_relate_utils.StrToFloat64(price), isShare, cfg, userRelationship, newProvider, newLevel, engine, rmd.IsGoods)
if err != nil {
return 0, 0, 0, 0, nil, nil
}
@@ -407,7 +407,7 @@ func currentPrice(m *md.CommissionParam, pvd string) string {
return ""
}
}
func CommFee(fee float64, opt *comm_plan.PlanOpt, types string) (float64, float64, float64) {
func CommFee(fee float64, opt *comm_plan.PlanOpt, types, isGoods string) (float64, float64, float64) {
if types == "integral" && opt.IntegralOpen == 0 || opt.Mode == "lv_winery" { //积分抽成后台没开启不用扣
return fee, 0, 0
}
@@ -419,19 +419,24 @@ func CommFee(fee float64, opt *comm_plan.PlanOpt, types string) (float64, float6
merchantFee := fee * opt.MerchantRate
newAgentFee := fee * opt.NewAgentRate
// 剩余可分配的佣金
fee = float64(int64(fee*1e4)-int64(pvdFee*1e4)-int64(sysFee*1e4)-int64(regionFee*1e4)-int64(globalFee*1e4)-int64(pushHandFee*1e4)-int64(merchantFee*1e4)-int64(newAgentFee*1e4)) / 1e4
total := int64(fee*1e4) - int64(pvdFee*1e4) - int64(sysFee*1e4) - int64(regionFee*1e4) - int64(globalFee*1e4) - int64(pushHandFee*1e4) - int64(merchantFee*1e4) - int64(newAgentFee*1e4)
if isGoods == "1" {
orderBeforeRate := fee * opt.OrderBeforeRate
total = total - int64(orderBeforeRate*1e4)
}
fee = float64(total) / 1e4
return fee, pvdFee, sysFee
}

// 根据用户计算对应的手续费
//ownbuyReturnType 0返利 1不返利 (免单商品是淘礼金商品的时候用的)
//pvd 只是为了判断是会员升级的订单 可不传
func CalcCommission(uid, level, oldDiff, ownbuyReturnType int, fee, integralFee float64, isShare bool, opt *comm_plan.PlanOpt, userRelationShip *[]md.UserRelation, pvd string, newLevel int, eg *xorm.Engine) (pvdFee, sysFee, subsidyFee float64, lvUser *comm_plan.LvUser, err error) {
func CalcCommission(uid, level, oldDiff, ownbuyReturnType int, fee, integralFee float64, isShare bool, opt *comm_plan.PlanOpt, userRelationShip *[]md.UserRelation, pvd string, newLevel int, eg *xorm.Engine, isGoods string) (pvdFee, sysFee, subsidyFee float64, lvUser *comm_plan.LvUser, err error) {
//佣金扣除抽成后
fee, pvdFee, sysFee = CommFee(fee, opt, "commission")
fee, pvdFee, sysFee = CommFee(fee, opt, "commission", isGoods)
//积分扣除抽成后
var integralSysFee float64 = 0
integralFee, _, integralSysFee = CommFee(integralFee, opt, "integral")
integralFee, _, integralSysFee = CommFee(integralFee, opt, "integral", isGoods)
// 计算自购补贴比例
subsidyFee = 0
//如果没登录,要找出权重最低的那个


Notiek ielāde…
Atcelt
Saglabāt