Browse Source

更新

master
huangjiajun 1 year ago
parent
commit
b78200360c
5 changed files with 303 additions and 149 deletions
  1. +64
    -27
      lib/comm_plan/init.go
  2. +11
    -0
      svc/get_plan_cfg.go
  3. +59
    -57
      svc/public_platoon_relate_commission.go
  4. +97
    -1
      svc/reward_commission.go
  5. +72
    -64
      svc/small_public_platoon_relate_commission.go

+ 64
- 27
lib/comm_plan/init.go View File

@@ -3,16 +3,17 @@ package comm_plan
import "xorm.io/xorm"

var Fn = map[string]func(opt *PlanOpt, totalAmt, integralTotalAmt float64, userList *LvUser, pvd string, sysFee float64, integralSysFee float64, level, levelWeight int, eg *xorm.Engine) error{
"lv_all": CalcAll,
"niubei_commission": NiuBeiCalcAll,
"niubei_amount": NiuBeiCalcAll,
"lv_self": CalcSelf,
"lv_subsidy": CalcAll,
"lv_price": CalcAll,
"lv_winery": CalcWinery,
"lv_winery_adv": CalcAdv,
"lv_price_other": CalcOther,
"lv_ds_check": CalcDsCheck,
"lv_all": CalcAll,
"niubei_commission": NiuBeiCalcAll,
"niubei_amount": NiuBeiCalcAll,
"lv_self": CalcSelf,
"lv_subsidy": CalcAll,
"lv_price": CalcAll,
"lv_price_public_platoon": CalcAll,
"lv_winery": CalcWinery,
"lv_winery_adv": CalcAdv,
"lv_price_other": CalcOther,
"lv_ds_check": CalcDsCheck,
}

type NiuBeiIntegralReleaseO2oRatio struct {
@@ -83,9 +84,49 @@ type LvGrade struct {
SubsidyOwnBiliList []map[string]string `json:"subsidy_own_bili_list"`
TikTokTeamSubsidyOwnBiliType []string `json:"tik_tok_team_subsidy_own_bili_type"` //分销 返利类型
TikTokTeamSubsidyList []map[string]string `json:"tik_tok_team_subsidy_list"`
ToExtendList map[string]string `json:"to_extend_list"` //
ToExtendList map[string]string `json:"to_extend_list"` //
CommonWealthSystem map[string]string `json:"common_wealth_system"` //共富制度比例

}
type LvGradePricePublic struct {
Lv int `json:"lv"` // 级别
SubsidyMode int `json:"subsidy_mode"` // 补贴计算方式, 0按佣金计算,1按平台利润计算
SubsidyEnable int `json:"subsidy_enable"` // 是否开启补贴计算方式 0关闭, 1开启
TikTokTeamSubsidyEnable int `json:"tik_tok_team_subsidy_enable"` // 是否开启补贴计算方式 0关闭, 1开启
SubsidySelfRate float64 `json:"subsidy_self_rate"` // 自购补贴比例
SubsidyShareRate float64 `json:"subsidy_share_rate"` // 分享补贴比例
PayMode int `json:"pay_mode"` // 0团队内部支出, 1平台系统支出
SelfRate float64 `json:"self_rate"` // 自购比例
TeamRate float64 `json:"team_rate"` // 团队分成比例
PeerRate []float64 `json:"peer_rate"` // 同级分成比例
UserLvUpSubsidyEnable int `json:"user_lv_up_subsidy_enable"` //分销补贴开关
UserLvUpSubsidyMode int `json:"user_lv_up_subsidy_mode"` //补贴方式 0比例 1固定金额
UserSubsidyType string `json:"user_subsidy_type"` // 补贴模式 up_lv 推荐会员补贴 buy_goods 购买商品
UserSubsidyBaseCoinId string `json:"user_subsidy_base_coin_id"` // 补贴计算基数
UserLvUpSubsidyList []interface{} `json:"user_lv_up_subsidy_list"` //会员费分销补贴相应方式的列表
PeerRateList []map[string]string `json:"peer_rate_list"` //同级比例
NewPeerList []map[string]string `json:"new_peer_list"` //同级比例
BuyDeliverList map[string]string `json:"buy_deliver_list"` //酒庄制度
ReturnType []string `json:"return_type"` //返利类型
SelfRateList map[string]string `json:"self_rate_list"` // 自购比例
TeamRateList map[string]string `json:"team_rate_list"` // 团队最高比例
NewTeamList map[string]string `json:"new_team_list"` // 新团队比例
NewExtendList map[string]string `json:"new_extend_list"` // 直推比例
SecondExtendList map[string]string `json:"second_extend_list"` // 直推比例
ToTeamList map[string]string `json:"to_team_list"` // 直推比例
SameUserCount string `json:"same_user_count"`
SameExtend []map[string]string `json:"same_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 固定金额
//SubsidyIntegralMode string `json:"subsidy_integral_mode"` //分销 积分返利类型 bili 比例 money 固定金额
SubsidyReturnType []string `json:"subsidy_return_type"` //分销 返利类型
SubsidyOwnBiliList []map[string]string `json:"subsidy_own_bili_list"`
TikTokTeamSubsidyOwnBiliType []string `json:"tik_tok_team_subsidy_own_bili_type"` //分销 返利类型
TikTokTeamSubsidyList []map[string]string `json:"tik_tok_team_subsidy_list"`
ToExtendList map[string]string `json:"to_extend_list"` //
CommonWealthSystem map[string]string `json:"common_wealth_system"` //共富制度比例
}
type LvGradeWineryAdv struct {
Lv int `json:"lv"` // 级别
PayMode int `json:"pay_mode"` // 0团队内部支出, 1平台系统支出
@@ -176,21 +217,17 @@ type SettleCommissionToRelationList struct {
Name string `json:"name"`
}
type LvUser struct {
FirstFee float64
IntegralFirstFee float64
ProfitBili float64
Uid int // 用户ID
Lv int // 等级
NewLv int // 升级后等级 针对会员费分佣
LevelWeight int // 权重
Profit float64 // 利润(金额)
SubsidyFee float64 // 补贴(金额)
MinLevel int
IsFreeze int
//IntegralProfit float64 // 积分利润
//IntegralSubsidyFee float64 // 积分补贴
//BlockIconsProfit float64 // 区块币利润
//BlockIconsSubsidyFee float64 // 区块币补贴
FirstFee float64
IntegralFirstFee float64
ProfitBili float64
Uid int // 用户ID
Lv int // 等级
NewLv int // 升级后等级 针对会员费分佣
LevelWeight int // 权重
Profit float64 // 利润(金额)
SubsidyFee float64 // 补贴(金额)
MinLevel int
IsFreeze int
MinProfit float64 // 利润(金额)
MinProfitList []*VirtualCoinCommission // 各币种对用的数量
ProfitList []*VirtualCoinCommission // 各币种对用的数量
@@ -203,7 +240,7 @@ type LvUser struct {
ParentUser *LvUser // 父用户
LastProfit float64
LastProfitList []*VirtualCoinCommission // 各币种对用的数量
ExtendType int
}

// 虚拟币分佣结构体


+ 11
- 0
svc/get_plan_cfg.go View File

@@ -106,6 +106,7 @@ func GetPlanCfg(eg *xorm.Engine, pvd, masterId string, rewardOpts map[string]*mo

var subsidyTmp map[int]*comm_plan.LvGrade
var subsidyTmpDs map[int]*comm_plan.LvGradeDs
var subsidyTmpPricePublic map[int]*comm_plan.LvGradePricePublic
var subsidyTmpWineryAdv map[int]*comm_plan.LvGradeWineryAdv
commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"bili\":0", "\"bili\":\"0\"")
commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"buy_deliver_list\":[]", "\"buy_deliver_list\":{}")
@@ -113,6 +114,7 @@ func GetPlanCfg(eg *xorm.Engine, pvd, masterId string, rewardOpts map[string]*mo
commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"new_extend_list\":[]", "\"new_extend_list\":{}")
commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"second_extend_list\":[]", "\"second_extend_list\":{}")
commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"to_extend_list\":[]", "\"to_extend_list\":{}")
commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"common_wealth_system\":[]", "\"common_wealth_system\":{}")
commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"to_team_list\":[]", "\"to_team_list\":{}")
commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"same_extend\":[[]]", "\"same_extend\":[]")
if strings.Contains(commissionOpt.Data, "\"subsidy_mode_list\":[") { //兼容旧的方案
@@ -155,6 +157,15 @@ func GetPlanCfg(eg *xorm.Engine, pvd, masterId string, rewardOpts map[string]*mo

return opt, nil
}
if zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"lv_price_public_platoon"}) {
if err := json.Unmarshal([]byte(commissionOpt.Data), &subsidyTmpPricePublic); err != nil {
return nil, zhios_order_relate_logx.Warn(fmt.Sprintf("%s:分佣方案数据设置错误", masterId))
}
copier.Copy(&subsidyTmp, &subsidyTmpPricePublic)
opt.UserRate = subsidyTmp

return opt, nil
}
if zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"lv_winery_adv"}) {
if err := json.Unmarshal([]byte(commissionOpt.Data), &subsidyTmpWineryAdv); err != nil {
if masterId == "68823769" {


+ 59
- 57
svc/public_platoon_relate_commission.go View File

@@ -15,13 +15,6 @@ import (
// BatchGetPublicPlatoonRelateCommission 批量分佣 订单显示
func BatchGetPublicPlatoonRelateCommissionByOrder(engine *xorm.Engine, masterId string, PublicPlatoonRelateCommissionReqList []*md.PublicPlatoonRelateCommissionReq) (map[string]*md.PublicPlatoonRelateCommissionResp, error) {
var resp = make(map[string]*md.PublicPlatoonRelateCommissionResp)
//userPublicPlatoonSetting, err := db.UserPublicPlatoonSettingGetOneByParams(engine, map[string]interface{}{
// "key": "is_open",
// "value": 1,
//})
//if err != nil {
// return nil, err
//}
for _, param := range PublicPlatoonRelateCommissionReqList {
// 根据供应商
rewardOpt, err := db.DbsPlanRewardByPvd(engine, param.Pvd)
@@ -68,59 +61,10 @@ func BatchGetPublicPlatoonRelateCommissionByOrder(engine *xorm.Engine, masterId
directPush[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.DirectPush[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100)
}
}
//TODO::本次消费产生的共富收益给到谁
var nowBenefitUid string
userPublicPlatoonRelation, err := db.UserPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{
"key": "uid",
"value": param.Uid,
})
nowBenefitUid, _, err := benefitUidByBig(engine, param)
if err != nil {
return nil, err
}
if userPublicPlatoonRelation == nil {
return nil, errors.New("未查询到公排关系记录")
}
if userPublicPlatoonRelation.FatherUid == "" {
//TODO::原始创始人
nowBenefitUid = ""
} else {
fatherPositions := strings.Split(userPublicPlatoonRelation.FatherUid, "-")
var fatherPosition string
userPublicPlatoonRelation.ReturnCommissionNum++

remainder1 := (userPublicPlatoonRelation.ReturnCommissionNum) % len(fatherPositions)
if remainder1 == 0 {
fatherPosition = fatherPositions[len(fatherPositions)-1]
} else {
fatherPosition = fatherPositions[remainder1-1]
}

nowBenefitUsers, err := db.UserPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{
"key": "position",
"value": fatherPosition,
})
if err != nil {
return nil, err
}
if nowBenefitUsers == nil {
return nil, errors.New("未查询到父级公排关系记录")
}
if nowBenefitUsers.Uid == -1 {
//则为待填充空位用户
nowBenefitUid = ""
} else {
nowBenefitUid = zhios_order_relate_utils.AnyToString(nowBenefitUsers.Uid)
}

//TODO::更新 公排关系记录 中 `return_commission_num`
affected, err := db.UserPublicPlatoonRelationUpdate(engine.NewSession(), userPublicPlatoonRelation.Id, userPublicPlatoonRelation, "return_commission_num")
if err != nil {
return nil, err
}
if affected == 0 {
return nil, errors.New("更新公排关系记录失败")
}
}
recommendUid := ""
userProfile, _ := db.UserProfileFindByID(engine, param.Uid)
if userProfile != nil && userProfile.ParentUid > 0 {
@@ -141,3 +85,61 @@ func BatchGetPublicPlatoonRelateCommissionByOrder(engine *xorm.Engine, masterId
}
return resp, nil
}
func benefitUidByBig(engine *xorm.Engine, param *md.PublicPlatoonRelateCommissionReq) (string, map[string]*md.PublicPlatoonRelateCommissionResp, error) {

//TODO::本次消费产生的共富收益给到谁
var nowBenefitUid string
userPublicPlatoonRelation, err := db.UserPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{
"key": "uid",
"value": param.Uid,
})
if err != nil {
return nowBenefitUid, nil, err
}
if userPublicPlatoonRelation == nil {
return nowBenefitUid, nil, errors.New("未查询到公排关系记录")
}
if userPublicPlatoonRelation.FatherUid == "" {
//TODO::原始创始人
nowBenefitUid = ""
} else {
fatherPositions := strings.Split(userPublicPlatoonRelation.FatherUid, "-")
var fatherPosition string
userPublicPlatoonRelation.ReturnCommissionNum++

remainder1 := (userPublicPlatoonRelation.ReturnCommissionNum) % len(fatherPositions)
if remainder1 == 0 {
fatherPosition = fatherPositions[len(fatherPositions)-1]
} else {
fatherPosition = fatherPositions[remainder1-1]
}

nowBenefitUsers, err := db.UserPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{
"key": "position",
"value": fatherPosition,
})
if err != nil {
return nowBenefitUid, nil, err
}
if nowBenefitUsers == nil {
return nowBenefitUid, nil, errors.New("未查询到父级公排关系记录")
}
if nowBenefitUsers.Uid == -1 {
//则为待填充空位用户
nowBenefitUid = ""
} else {
nowBenefitUid = zhios_order_relate_utils.AnyToString(nowBenefitUsers.Uid)
}

//TODO::更新 公排关系记录 中 `return_commission_num`
affected, err := db.UserPublicPlatoonRelationUpdate(engine.NewSession(), userPublicPlatoonRelation.Id, userPublicPlatoonRelation, "return_commission_num")
if err != nil {
return nowBenefitUid, nil, err
}
if affected == 0 {
return nowBenefitUid, nil, errors.New("更新公排关系记录失败")
}
}
return nowBenefitUid, nil, nil

}

+ 97
- 1
svc/reward_commission.go View File

@@ -84,7 +84,7 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b
fmt.Println(com)
fmt.Println(price)
comf := zhios_order_relate_utils.StrToFloat64(com)
if zhios_order_relate_utils.InArr(cfg.Mode, []string{"lv_price", "lv_winery", "extend_price", "niubei_amount"}) && zhios_order_relate_utils.StrToFloat64(rmd.OldPrice) > 0 { //价格为基数
if zhios_order_relate_utils.InArr(cfg.Mode, []string{"lv_price_public_platoon", "lv_price", "lv_winery", "extend_price", "niubei_amount"}) && zhios_order_relate_utils.StrToFloat64(rmd.OldPrice) > 0 { //价格为基数
comf = zhios_order_relate_utils.StrToFloat64(rmd.OldPrice)
}
if cfg.Mode == "public_platoon" {
@@ -262,9 +262,71 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b
if ulink == nil {
return 0, 0, 0, 0, nil, nil
}
if cfg.Mode == "lv_price_public_platoon" {
ulink = public(engine, ulink, cfg, newProvider, uid, comf, price, rmd)
}
comm(commArr, ulink)
return ulink.Profit, pvdFee, sysFee, subsidyFee, ulink, nil
}
func public(engine *xorm.Engine, ulinkParent *comm_plan.LvUser, cfg *comm_plan.PlanOpt, newProvider string, uid int, comf float64, price string, rmd *md.CommissionParam) *comm_plan.LvUser {
//佣金扣除抽成后
fee, _, _, _ := CommFee(comf, cfg, "commission", rmd.IsGoods)
////积分扣除抽成后
integralFee, _, _, _ := CommFee(zhios_order_relate_utils.StrToFloat64(price), cfg, "integral", rmd.IsGoods)
//调用公排制度

userPublicPlatoonSetting, err := db.UserPublicPlatoonSettingGetOneByParams(engine, map[string]interface{}{
"key": "is_open",
"value": 1,
})
if err != nil || userPublicPlatoonSetting == nil {
return ulinkParent
}
var nowBenefitUid string
if userPublicPlatoonSetting.IsUseSmallPublicPlatoon == 1 { //小公排
var PublicPlatoonRelateCommissionReqList = &md.SmallPublicPlatoonRelateCommissionReq{
Pvd: newProvider,
Uid: zhios_order_relate_utils.IntToStr(uid),
PendingAmount: zhios_order_relate_utils.Float64ToStr(fee),
PendingIntegral: zhios_order_relate_utils.Float64ToStr(integralFee),
Oid: rmd.Oid,
}
if rmd.IsGoods != "1" {
nowBenefitUid, _, err = benefitUid(engine, PublicPlatoonRelateCommissionReqList)

}
} else {
var PublicPlatoonRelateCommissionReqList = &md.PublicPlatoonRelateCommissionReq{
Pvd: newProvider,
Uid: zhios_order_relate_utils.IntToStr(uid),
PendingAmount: zhios_order_relate_utils.Float64ToStr(fee),
PendingIntegral: zhios_order_relate_utils.Float64ToStr(integralFee),
Oid: rmd.Oid,
}
if rmd.IsGoods != "1" {
nowBenefitUid, _, err = benefitUidByBig(engine, PublicPlatoonRelateCommissionReqList)
}
}
if err == nil && nowBenefitUid != "" {
user, _ := db.UserFindByID(engine, nowBenefitUid)
var commonWealthSystem = make(map[string]string)
grade := cfg.UserRate[user.Level]
if grade != nil {
for _, coinId := range grade.ReturnType {
var pendingAmount = zhios_order_relate_utils.Float64ToStr(fee)
if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数
pendingAmount = zhios_order_relate_utils.Float64ToStr(integralFee)
}
commonWealthSystem[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(grade.CommonWealthSystem[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100)
}
}
//共富收益处理
ulink := getRewardLinkNew(nowBenefitUid, 2, commonWealthSystem, &comm_plan.LvUser{}, "public_platoon", cfg)
return commMax(ulinkParent, ulink)
}
return ulinkParent

}
func comm(commArr map[string]string, ulink *comm_plan.LvUser) *comm_plan.LvUser {
if zhios_order_relate_utils.StrToFloat64(commArr["integralRewardMultiple"]) > 0 {
for k, v := range ulink.OwnSubsidyFeeList {
@@ -283,6 +345,14 @@ func comm(commArr map[string]string, ulink *comm_plan.LvUser) *comm_plan.LvUser
}
return ulink
}
func commMax(ulinkParent, ulink *comm_plan.LvUser) *comm_plan.LvUser {
if ulinkParent.ParentUser != nil {
ulinkParent.ParentUser = commMax(ulinkParent.ParentUser, ulink)
} else {
ulinkParent.ParentUser = ulink
}
return ulinkParent
}

func getRewardLink(uid string, diff int, reward map[string]string, ulinkParent *comm_plan.LvUser, types string, cfg *comm_plan.PlanOpt) *comm_plan.LvUser {
var SubsidyFee = zhios_order_relate_utils.StrToFloat64(reward["0"])
@@ -297,6 +367,7 @@ func getRewardLink(uid string, diff int, reward map[string]string, ulinkParent *
}
SubsidyFeeList = append(SubsidyFeeList, tmp)
}

//组装数据
var ulink = &comm_plan.LvUser{
Uid: zhios_order_relate_utils.StrToInt(uid),
@@ -312,6 +383,31 @@ func getRewardLink(uid string, diff int, reward map[string]string, ulinkParent *
}
return ulink
}
func getRewardLinkNew(uid string, diff int, reward map[string]string, ulinkParent *comm_plan.LvUser, types string, cfg *comm_plan.PlanOpt) *comm_plan.LvUser {
var SubsidyFee = zhios_order_relate_utils.StrToFloat64(reward["0"])
var SubsidyFeeList = make([]*comm_plan.VirtualCoinCommission, 0)
for k, v := range reward {
coinId := zhios_order_relate_utils.StrToInt(k)
ratio := cfg.VirtualCoinMoneyRatioList[coinId]
rate := zhios_order_relate_utils.StrToFloat64(ratio)
var tmp = &comm_plan.VirtualCoinCommission{
Cid: k,
Val: zhios_order_relate_utils.StrToFloat64(v) * rate,
}
SubsidyFeeList = append(SubsidyFeeList, tmp)
}

//组装数据
var ulink = &comm_plan.LvUser{
Uid: zhios_order_relate_utils.StrToInt(uid),
Diff: diff,
ParentUser: ulinkParent,
ExtendType: 5,
}
ulink.Profit = SubsidyFee
ulink.ProfitList = SubsidyFeeList
return ulink
}

func getRewardLinkCommWithExtend(uid string, diff int, reward map[string]string, rewardExtend map[string]string, ulinkParent *comm_plan.LvUser, cfg *comm_plan.PlanOpt) *comm_plan.LvUser {
var SubsidyFee = zhios_order_relate_utils.StrToFloat64(reward["0"])


+ 72
- 64
svc/small_public_platoon_relate_commission.go View File

@@ -61,73 +61,10 @@ func BatchSmallGetPublicPlatoonRelateCommission(engine *xorm.Engine, masterId st
}

//TODO::本次消费产生的共富收益给到谁
var nowBenefitUid string
userPublicPlatoonRelation, err := db.UserSmallPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{
"key": "uid",
"value": param.Uid,
})
nowBenefitUid, _, err := benefitUid(engine, param)
if err != nil {
return nil, err
}
if userPublicPlatoonRelation == nil {
return nil, errors.New("未查询到公排关系记录")
}
if userPublicPlatoonRelation.FatherUid == "" {
//TODO::原始创始人
nowBenefitUid = ""
} else {
fatherPositions := strings.Split(userPublicPlatoonRelation.FatherUid, "-")
var fatherPosition string
userPublicPlatoonRelation.ReturnCommissionNum++
userPublicPlatoonSetting, err := db.UserPublicPlatoonSettingGetOneByParams(engine, map[string]interface{}{
"key": "is_open",
"value": 1,
})
if len(fatherPositions) > userPublicPlatoonSetting.SeveralRows {
remainder1 := (userPublicPlatoonRelation.ReturnCommissionNum) % userPublicPlatoonSetting.SeveralRows
if remainder1 == 0 {
fatherPosition = fatherPositions[userPublicPlatoonSetting.SeveralRows-1]
} else {
fatherPosition = fatherPositions[remainder1-1]
}
} else {
remainder1 := (userPublicPlatoonRelation.ReturnCommissionNum) % len(fatherPositions)
if remainder1 == 0 {
fatherPosition = fatherPositions[len(fatherPositions)-1]
} else {
fatherPosition = fatherPositions[remainder1-1]
}
}

nowBenefitUsers, err := db.UserSmallPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{
"key": "id",
"value": fatherPosition,
})
if err != nil {
return nil, err
}
if nowBenefitUsers == nil {
//未查询到父级公排关系记录
nowBenefitUid = ""
//return nil, errors.New("未查询到父级公排关系记录")
} else {
if nowBenefitUsers.Uid == -1 || nowBenefitUsers.Uid == -2 {
//则为待填充空位用户
nowBenefitUid = ""
} else {
nowBenefitUid = zhios_order_relate_utils.AnyToString(nowBenefitUsers.Uid)
}
}

//TODO::更新 公排关系记录 中 `return_commission_num`
affected, err := db.UserSmallPublicPlatoonRelationUpdate(engine.NewSession(), userPublicPlatoonRelation.Id, userPublicPlatoonRelation, "return_commission_num")
if err != nil {
return nil, err
}
if affected == 0 {
return nil, errors.New("更新公排关系记录失败")
}
}
recommendUid := ""
userProfile, _ := db.UserProfileFindByID(engine, param.Uid)
if userProfile != nil && userProfile.ParentUid > 0 {
@@ -146,6 +83,77 @@ func BatchSmallGetPublicPlatoonRelateCommission(engine *xorm.Engine, masterId st
}
return resp, nil
}
func benefitUid(engine *xorm.Engine, param *md.SmallPublicPlatoonRelateCommissionReq) (string, map[string]*md.SmallPublicPlatoonRelateCommissionResp, error) {
var nowBenefitUid string
userPublicPlatoonRelation, err := db.UserSmallPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{
"key": "uid",
"value": param.Uid,
})
if err != nil {
return nowBenefitUid, nil, err
}
if userPublicPlatoonRelation == nil {
return nowBenefitUid, nil, errors.New("未查询到公排关系记录")
}
if userPublicPlatoonRelation.FatherUid == "" {
//TODO::原始创始人
nowBenefitUid = ""
} else {
fatherPositions := strings.Split(userPublicPlatoonRelation.FatherUid, "-")
var fatherPosition string
userPublicPlatoonRelation.ReturnCommissionNum++
userPublicPlatoonSetting, err := db.UserPublicPlatoonSettingGetOneByParams(engine, map[string]interface{}{
"key": "is_open",
"value": 1,
})
if len(fatherPositions) > userPublicPlatoonSetting.SeveralRows {
remainder1 := (userPublicPlatoonRelation.ReturnCommissionNum) % userPublicPlatoonSetting.SeveralRows
if remainder1 == 0 {
fatherPosition = fatherPositions[userPublicPlatoonSetting.SeveralRows-1]
} else {
fatherPosition = fatherPositions[remainder1-1]
}
} else {
remainder1 := (userPublicPlatoonRelation.ReturnCommissionNum) % len(fatherPositions)
if remainder1 == 0 {
fatherPosition = fatherPositions[len(fatherPositions)-1]
} else {
fatherPosition = fatherPositions[remainder1-1]
}
}

nowBenefitUsers, err := db.UserSmallPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{
"key": "id",
"value": fatherPosition,
})
if err != nil {
return nowBenefitUid, nil, err
}
if nowBenefitUsers == nil {
//未查询到父级公排关系记录
nowBenefitUid = ""
//return nil, errors.New("未查询到父级公排关系记录")
} else {
if nowBenefitUsers.Uid == -1 || nowBenefitUsers.Uid == -2 {
//则为待填充空位用户
nowBenefitUid = ""
} else {
nowBenefitUid = zhios_order_relate_utils.AnyToString(nowBenefitUsers.Uid)
}
}

//TODO::更新 公排关系记录 中 `return_commission_num`
affected, err := db.UserSmallPublicPlatoonRelationUpdate(engine.NewSession(), userPublicPlatoonRelation.Id, userPublicPlatoonRelation, "return_commission_num")
if err != nil {
return nowBenefitUid, nil, err
}
if affected == 0 {
return nowBenefitUid, nil, errors.New("更新公排关系记录失败")
}
}
return nowBenefitUid, nil, nil

}

func CalcSmallPublicPlatoonRelateLaXinReward(engine *xorm.Engine, masterId string, rewardUid int) (resp []*md.CalcSmallPublicPlatoonRelateLaXinReward, err error) {
userPublicPlatoonRelation, err := db.UserSmallPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{


Loading…
Cancel
Save