From b8155052a4c46d5b3ac4d648fe68eb949a6a3d7e Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Fri, 28 Oct 2022 14:10:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?add=20reverse:for=20v3.6.1=20=E4=BD=A3?= =?UTF-8?q?=E9=87=91=E6=8A=BD=E6=88=90=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/model/plan_reward.go | 1 + lib/comm_plan/init.go | 1 + rule/relate_commission.go | 180 +++++++++++++++++++------------------- svc/get_plan_cfg.go | 1 + svc/reward_commission.go | 25 +++--- 5 files changed, 108 insertions(+), 100 deletions(-) diff --git a/db/model/plan_reward.go b/db/model/plan_reward.go index 493fe2b..0d3e560 100644 --- a/db/model/plan_reward.go +++ b/db/model/plan_reward.go @@ -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)"` } diff --git a/lib/comm_plan/init.go b/lib/comm_plan/init.go index ab3592c..f570179 100644 --- a/lib/comm_plan/init.go +++ b/lib/comm_plan/init.go @@ -24,6 +24,7 @@ type PlanOpt struct { GlobalRate float64 // 全球分红占佣比例 MerchantRate float64 //商家占佣比例 NewAgentRate float64 //代理分红占佣比例 + OrderBeforeRate float64 PushHandRate float64 //推手占佣比例 //IntegralBili float64 // 积分兑换比例 //BlockIconsBili float64 // 区块币兑换比例 diff --git a/rule/relate_commission.go b/rule/relate_commission.go index 04dd203..0956db8 100644 --- a/rule/relate_commission.go +++ b/rule/relate_commission.go @@ -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, ¶m.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, ¶m.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, ¶m.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 +} diff --git a/svc/get_plan_cfg.go b/svc/get_plan_cfg.go index 5505f1e..c1c5071 100644 --- a/svc/get_plan_cfg.go +++ b/svc/get_plan_cfg.go @@ -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 { diff --git a/svc/reward_commission.go b/svc/reward_commission.go index 65685f6..5abd19d 100644 --- a/svc/reward_commission.go +++ b/svc/reward_commission.go @@ -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 //如果没登录,要找出权重最低的那个 From 407bf9027a71f896111d0169346fe09e7212cb75 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Mon, 31 Oct 2022 14:40:05 +0800 Subject: [PATCH 2/3] =?UTF-8?q?add=20reverse:for=20v3.6.2=20=E5=85=AC?= =?UTF-8?q?=E6=8E=92=E6=8E=A8=E8=8D=90=E4=BA=BA=E8=AF=BB=E5=8F=96=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- svc/public_platoon_relate_commission.go | 8 ++++++-- svc/small_public_platoon_relate_commission.go | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/svc/public_platoon_relate_commission.go b/svc/public_platoon_relate_commission.go index 87048b5..6661d8c 100644 --- a/svc/public_platoon_relate_commission.go +++ b/svc/public_platoon_relate_commission.go @@ -8,7 +8,6 @@ import ( "encoding/json" "errors" "fmt" - "strconv" "strings" "xorm.io/xorm" ) @@ -120,11 +119,16 @@ func BatchGetPublicPlatoonRelateCommissionByOrder(engine *xorm.Engine, masterId return nil, errors.New("更新公排关系记录失败") } } + recommendUid := "" + userProfile, _ := db.UserProfileFindByID(engine, param.Uid) + if userProfile != nil && userProfile.ParentUid > 0 { + recommendUid = zhios_order_relate_utils.IntToStr(userProfile.ParentUid) + } /// resp[param.Oid] = &md.PublicPlatoonRelateCommissionResp{ Uid: param.Uid, CommonWealthBenefitUid: nowBenefitUid, - DirectPushBenefitUid: strconv.Itoa(userPublicPlatoonRelation.RecommendUid), + DirectPushBenefitUid: recommendUid, PendingAmount: param.PendingAmount, PendingIntegral: param.PendingIntegral, Oid: param.Oid, diff --git a/svc/small_public_platoon_relate_commission.go b/svc/small_public_platoon_relate_commission.go index 86e0996..bfac21e 100644 --- a/svc/small_public_platoon_relate_commission.go +++ b/svc/small_public_platoon_relate_commission.go @@ -8,7 +8,6 @@ import ( "encoding/json" "errors" "fmt" - "strconv" "strings" "xorm.io/xorm" ) @@ -122,11 +121,15 @@ func BatchSmallGetPublicPlatoonRelateCommission(engine *xorm.Engine, masterId st return nil, errors.New("更新公排关系记录失败") } } - + recommendUid := "" + userProfile, _ := db.UserProfileFindByID(engine, param.Uid) + if userProfile != nil && userProfile.ParentUid > 0 { + recommendUid = zhios_order_relate_utils.IntToStr(userProfile.ParentUid) + } resp[param.Oid] = &md.SmallPublicPlatoonRelateCommissionResp{ Uid: param.Uid, CommonWealthBenefitUid: nowBenefitUid, - DirectPushBenefitUid: strconv.Itoa(userPublicPlatoonRelation.RecommendUid), + DirectPushBenefitUid: recommendUid, PendingAmount: param.PendingAmount, Oid: param.Oid, SelfRateList: selfRateList, From 00d7ee02e65cd88c446d39977d8afe0c50e6999f Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Sat, 5 Nov 2022 16:18:11 +0800 Subject: [PATCH 3/3] =?UTF-8?q?add=20reverse:for=20v3.6.3=20=E5=88=B6?= =?UTF-8?q?=E5=BA=A6=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/db_block_green.go | 15 +++++++ db/model/block_green_chain.go | 32 ++++++++++++++ rule/relate_commission.go | 79 +++++++++++++++++------------------ svc/reward_commission.go | 21 +++++++++- 4 files changed, 104 insertions(+), 43 deletions(-) create mode 100644 db/db_block_green.go create mode 100644 db/model/block_green_chain.go diff --git a/db/db_block_green.go b/db/db_block_green.go new file mode 100644 index 0000000..4f4ef67 --- /dev/null +++ b/db/db_block_green.go @@ -0,0 +1,15 @@ +package db + +import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" + "xorm.io/xorm" +) + +func GetGreenChain(eg *xorm.Engine) *model.BlockGreenChain { + var data model.BlockGreenChain + get, err := eg.Where("is_use=1").Get(&data) + if get == false || err != nil { + return nil + } + return &data +} diff --git a/db/model/block_green_chain.go b/db/model/block_green_chain.go new file mode 100644 index 0000000..606e967 --- /dev/null +++ b/db/model/block_green_chain.go @@ -0,0 +1,32 @@ +package model + +import ( + "time" +) + +type BlockGreenChain 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)"` + InitialEverydayPublishCoin string `json:"initial_everyday_publish_coin" xorm:"not null default 0.0000000000 comment('初始每日区块币发行数量') DECIMAL(28,10)"` + NowEverydayPublishCoin string `json:"now_everyday_publish_coin" xorm:"not null default 0.0000000000 comment('当前每日区块币发行数量') DECIMAL(28,10)"` + TodayPublishCoin string `json:"today_publish_coin" xorm:"not null default 0.0000000000 comment('今日区块币发行数量(若为0,则按当前每日区块币发行数量)') DECIMAL(28,10)"` + EveryThirtyDaysReduceRate string `json:"every_thirty_days_reduce_rate" xorm:"not null default 5.00 comment('每三十日递减发行百分比') DECIMAL(5,2)"` + TotalNowCoin string `json:"total_now_coin" xorm:"not null default 0.0000000000 comment('当前区块币总量') DECIMAL(28,10)"` + TotalPublishCoin string `json:"total_publish_coin" xorm:"not null default 0.0000000000 comment('累计区块币发行总量') DECIMAL(28,10)"` + TotalDestroyCoin string `json:"total_destroy_coin" xorm:"not null default 0.0000000000 comment('累计区块币销毁总量') DECIMAL(28,10)"` + TotalRemainderCoin string `json:"total_remainder_coin" xorm:"not null default 0.0000000000 comment('累计区块币剩余总量') DECIMAL(28,10)"` + InitialCoinTotal string `json:"initial_coin_total" xorm:"not null default 0.0000000000 comment('初始区块币总量') DECIMAL(28,10)"` + PlatformGuidePriceForCoin string `json:"platform_guide_price_for_coin" xorm:"not null default 0.0000000000 comment('平台区块币指导价') DECIMAL(22,10)"` + PlatformBusinessDiscountRate string `json:"platform_business_discount_rate" xorm:"not null default 10.00 comment('平台商家让利百分比') DECIMAL(5,2)"` + ChemicalsForDailyRate string `json:"chemicals_for_daily_rate" xorm:"not null default 100.00 comment('日化率') DECIMAL(5,2)"` + PublishCoinConsumeRate string `json:"publish_coin_consume_rate" xorm:"not null default 45.00 comment('区块币发行消费占比') DECIMAL(5,2)"` + PublishCoinAirdropRate string `json:"publish_coin_airdrop_rate" xorm:"not null default 45.00 comment('区块币发行空投占比') DECIMAL(5,2)"` + RewardSettings string `json:"reward_settings" xorm:"comment('奖励设置') TEXT"` + StartAt string `json:"start_at" xorm:"not null default '0000-00' comment('起始时间(0000-00)') CHAR(50)"` + SettlementDate string `json:"settlement_date" xorm:"not null default '0000-00' comment('结算日期(0000-00)') CHAR(50)"` + 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"` + IntegralRewardMultiple int `json:"integral_reward_multiple" xorm:"default 0 comment('自购积分奖励倍数') INT(11)"` +} diff --git a/rule/relate_commission.go b/rule/relate_commission.go index 0956db8..25d074e 100644 --- a/rule/relate_commission.go +++ b/rule/relate_commission.go @@ -13,6 +13,23 @@ import ( "xorm.io/xorm" ) +func GetComm(eg *xorm.Engine) map[string]string { + virCfg, _ := db.SysCfgGetOne(eg, "virtual_coin_rebate_type") + var virType = "price" + if virCfg != nil && virCfg.Val != "" { + virType = virCfg.Val + } + var arg = map[string]string{ + "virType": virType, + "integralRewardMultiple": "0", + } + chain := db.GetGreenChain(eg) + if chain != nil { + arg["integralRewardMultiple"] = zhios_order_relate_utils.IntToStr(chain.IntegralRewardMultiple) + } + return arg +} + // BatchGetCommission 批量分佣 商品显示 func BatchGetCommissionByGoods(eg *xorm.Engine, dbName string, commissionParamList []*md.CommissionFirstParam) (map[string]*comm_plan.LvUser, error) { var ( @@ -26,11 +43,7 @@ func BatchGetCommissionByGoods(eg *xorm.Engine, dbName string, commissionParamLi group, _ := errgroup.WithContext(context.Background()) var mu sync.Mutex - virCfg, _ := db.SysCfgGetOne(eg, "virtual_coin_rebate_type") - var virType = "price" - if virCfg != nil && virCfg.Val != "" { - virType = virCfg.Val - } + commArr := GetComm(eg) plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(eg, dbName) for _, param := range commissionParamList { param := param // 为下面的闭包创建局部变量 @@ -47,7 +60,7 @@ 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, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, virType, plan, commission, virtualCoinMoneyRate) + _, _, _, _, lvUser, err := svc.GetRewardCommission(eg, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, commArr, plan, commission, virtualCoinMoneyRate) if err != nil { return err } @@ -78,11 +91,8 @@ func BatchGetCommissionByGoodsExtend(eg *xorm.Engine, dbName string, commissionP group, _ := errgroup.WithContext(context.Background()) var mu sync.Mutex - virCfg, _ := db.SysCfgGetOne(eg, "virtual_coin_rebate_type") - var virType = "price" - if virCfg != nil && virCfg.Val != "" { - virType = virCfg.Val - } + commArr := GetComm(eg) + plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(eg, dbName) for _, param := range commissionParamList { @@ -101,7 +111,7 @@ func BatchGetCommissionByGoodsExtend(eg *xorm.Engine, dbName string, commissionP param.CommissionParam.IsGoods = "1" param.CommissionParam.IsShowExtend = param.IsShowExtend - _, _, _, _, lvUser, err := svc.GetRewardCommission(eg, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, virType, plan, commission, virtualCoinMoneyRate) + _, _, _, _, lvUser, err := svc.GetRewardCommission(eg, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, commArr, plan, commission, virtualCoinMoneyRate) if err != nil { return err } @@ -137,17 +147,14 @@ func SettleCommWithGoodsDetail(eg *xorm.Engine, dbName string, CommissionParam m "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 - } + commArr := GetComm(eg) + CommissionParam.CommissionParam.Oid = CommissionParam.GoodsId CommissionParam.CommissionParam.IsGoods = "1" CommissionParam.CommissionParam.ShowLevel = CommissionParam.ShowLevel 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) + profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, commArr, plan, commission, virtualCoinMoneyRate) return profit, pvdFee, sysFee, subsidyFee, lvUser, err } @@ -169,17 +176,14 @@ func SettleCommWithGoodsDetailExtend(eg *xorm.Engine, dbName string, CommissionP "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 - } + commArr := GetComm(eg) + CommissionParam.CommissionParam.Oid = CommissionParam.GoodsId CommissionParam.CommissionParam.IsGoods = "1" CommissionParam.CommissionParam.IsShowExtend = CommissionParam.IsShowExtend 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) + profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, commArr, plan, commission, virtualCoinMoneyRate) return profit, pvdFee, sysFee, subsidyFee, lvUser, err } @@ -204,17 +208,17 @@ func GetRewardCommission(eg *xorm.Engine, dbName, mode string, CommissionParam m CommissionParam.CommissionParam.IsGoods = "1" CommissionParam.CommissionParam.ShowLevel = CommissionParam.ShowLevel plan, commissions, virtualCoinMoneyRate := svc.GetAllPlan(eg, dbName) - + commArr := GetComm(eg) var lvUser = &comm_plan.LvUser{} var mapsDta = map[string]string{"show_level": CommissionParam.ShowLevel} if isAll { - shareCommission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, true, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, mode, plan, commissions, virtualCoinMoneyRate) - commission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, false, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, mode, plan, commissions, virtualCoinMoneyRate) + shareCommission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, true, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, commArr, plan, commissions, virtualCoinMoneyRate) + commission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, false, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, commArr, plan, commissions, virtualCoinMoneyRate) } else { if isShare { - shareCommission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, mode, plan, commissions, virtualCoinMoneyRate) + shareCommission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, commArr, plan, commissions, virtualCoinMoneyRate) } else { - commission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, mode, plan, commissions, virtualCoinMoneyRate) + commission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, commArr, plan, commissions, virtualCoinMoneyRate) } } return commission, shareCommission, lvUser, nil @@ -233,11 +237,7 @@ func BatchGetCommissionByOrder(engine *xorm.Engine, dbName string, CommissionPar 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 - } + commArr := GetComm(engine) plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(engine, dbName) for _, param := range CommissionParamList { @@ -258,7 +258,7 @@ func BatchGetCommissionByOrder(engine *xorm.Engine, dbName string, CommissionPar param.CommissionParam.OldPrice = param.CommissionParam.GoodsPrice param.CommissionParam.Oid = param.Oid - profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(engine, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, virType, plan, commission, virtualCoinMoneyRate) + profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(engine, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, commArr, plan, commission, virtualCoinMoneyRate) if err != nil { return err } @@ -297,14 +297,11 @@ func SettleCommWithOrder(eg *xorm.Engine, dbName string, CommissionParam md.Comm "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 - } + commArr := GetComm(eg) + 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) + profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, commArr, plan, commission, virtualCoinMoneyRate) return profit, pvdFee, sysFee, subsidyFee, lvUser, err } diff --git a/svc/reward_commission.go b/svc/reward_commission.go index 5abd19d..5f4be39 100644 --- a/svc/reward_commission.go +++ b/svc/reward_commission.go @@ -15,8 +15,8 @@ import ( // getRewardCommission is 获取制度后的佣金 // 返回:单个佣金、层级佣金、错误 -func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare bool, userId, provider, masterId string, returnAllLevel bool, extraData map[string]string, virType string, rewardOpts map[string]*model.PlanReward, commissionOpts map[int]*model.PlanCommission, virtualCoinMoneyRate map[int]string) (float64, float64, float64, float64, *comm_plan.LvUser, error) { - +func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare bool, userId, provider, masterId string, returnAllLevel bool, extraData map[string]string, commArr map[string]string, rewardOpts map[string]*model.PlanReward, commissionOpts map[int]*model.PlanCommission, virtualCoinMoneyRate map[int]string) (float64, float64, float64, float64, *comm_plan.LvUser, error) { + virType := commArr["virType"] if virType == "commission" { rmd.PaidPrice = rmd.Commission if zhios_order_relate_utils.InArr(provider, []string{md.PVD_TB, md.PVD_TM, md.PVD_PDD, md.PVD_SN, md.PVD_KL, md.PVD_JD, md.PVD_VIP}) == false { @@ -150,6 +150,14 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b } //自购 ulink = getRewardLink(reward.Uid, 0, reward.SelfRateList, ulink, "own", cfg) + if zhios_order_relate_utils.StrToFloat64(commArr["integralRewardMultiple"]) > 0 { + for k, v := range ulink.OwnSubsidyFeeList { + ulink.OwnSubsidyFeeList[k] = v * zhios_order_relate_utils.StrToFloat64(commArr["integralRewardMultiple"]) + } + for k, v := range ulink.ProfitList { + ulink.ProfitList[k].Val = v.Val * zhios_order_relate_utils.StrToFloat64(commArr["integralRewardMultiple"]) + } + } return profit, pvdFee, sysFee, 0, ulink, nil } if cfg.Mode == "extend_price" { //直推奖励 @@ -212,6 +220,15 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b if ulink == nil { return 0, 0, 0, 0, nil, nil } + if zhios_order_relate_utils.StrToFloat64(commArr["integralRewardMultiple"]) > 0 { + for k, v := range ulink.OwnSubsidyFeeList { + ulink.OwnSubsidyFeeList[k] = v * zhios_order_relate_utils.StrToFloat64(commArr["integralRewardMultiple"]) + } + for k, v := range ulink.ProfitList { + ulink.ProfitList[k].Val = v.Val * zhios_order_relate_utils.StrToFloat64(commArr["integralRewardMultiple"]) + } + } + return ulink.Profit, pvdFee, sysFee, subsidyFee, ulink, nil } func getRewardLink(uid string, diff int, reward map[string]string, ulinkParent *comm_plan.LvUser, types string, cfg *comm_plan.PlanOpt) *comm_plan.LvUser {