@@ -1,27 +1,28 @@ | |||
package model | |||
type PlanReward struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||
Pvd string `json:"pvd" xorm:"not null comment('供应商') unique VARCHAR(255)"` | |||
PvdRate float32 `json:"pvd_rate" xorm:"not null default 0.0000 comment('供应商抽成比例') FLOAT(6,4)"` | |||
SysRate float32 `json:"sys_rate" xorm:"not null default 0.0000 comment('平台抽成比例') FLOAT(6,4)"` | |||
RegionRate float32 `json:"region_rate" xorm:"not null default 0.0000 comment('区域代理抽成比例') FLOAT(6,4)"` | |||
RegionSubRate float32 `json:"region_sub_rate" xorm:"not null default 0.0000 comment('区域代理抽成比例') FLOAT(6,4)"` | |||
GlobalRate float32 `json:"global_rate" xorm:"not null default 0.0000 comment('全球分红抽成比例') FLOAT(6,4)"` | |||
SelfBuyGlobalRate float64 `json:"self_buy_global_rate" xorm:"not null default 0.0000 comment('全球分红抽成比例') FLOAT(6,4)"` | |||
BuckleRate float64 `json:"buckle_rate_rate" xorm:"not null default 0.0000 comment('抽成比例') FLOAT(6,4)"` | |||
SettleMode int `json:"settle_mode" xorm:"not null default 1 comment('0.手动方案,1.自动方案') TINYINT(1)"` | |||
PlanCommissionId int `json:"plan_commission_id" xorm:"not null default 0 comment('佣金方案0未设置,>0对应方案') TINYINT(3)"` | |||
PlanSettleId int `json:"plan_settle_id" xorm:"not null default 0 comment('结算方案0未设置,>0对应方案') TINYINT(3)"` | |||
State int `json:"state" xorm:"not null default 1 comment('0关闭,1开启') TINYINT(1)"` | |||
SubsidyRate float32 `json:"subsidy_rate" xorm:"not null default 0.0000 comment('待删除字段') FLOAT(6,4)"` | |||
Source int `json:"source" xorm:"not null default 1 comment('佣金来源:1联盟佣金 2补贴金额') TINYINT(1)"` | |||
AppType int `json:"app_type" xorm:"not null default 1 comment('所属应用:1导购 2自营 4O2O') TINYINT(3)"` | |||
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)"` | |||
PointType int `json:"point_type" xorm:"not null default 0 comment('') TINYINT(1)"` | |||
RateList string `json:"rate_list" xorm:"not null default '' comment('') VARCHAR(3000)"` | |||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||
Pvd string `json:"pvd" xorm:"not null comment('供应商') unique VARCHAR(255)"` | |||
PvdRate float32 `json:"pvd_rate" xorm:"not null default 0.0000 comment('供应商抽成比例') FLOAT(6,4)"` | |||
SysRate float32 `json:"sys_rate" xorm:"not null default 0.0000 comment('平台抽成比例') FLOAT(6,4)"` | |||
RegionRate float32 `json:"region_rate" xorm:"not null default 0.0000 comment('区域代理抽成比例') FLOAT(6,4)"` | |||
RegionSubRate float32 `json:"region_sub_rate" xorm:"not null default 0.0000 comment('区域代理抽成比例') FLOAT(6,4)"` | |||
GlobalRate float32 `json:"global_rate" xorm:"not null default 0.0000 comment('全球分红抽成比例') FLOAT(6,4)"` | |||
SelfBuyGlobalRate float64 `json:"self_buy_global_rate" xorm:"not null default 0.0000 comment('全球分红抽成比例') FLOAT(6,4)"` | |||
BuckleRate float64 `json:"buckle_rate_rate" xorm:"not null default 0.0000 comment('抽成比例') FLOAT(6,4)"` | |||
SettleMode int `json:"settle_mode" xorm:"not null default 1 comment('0.手动方案,1.自动方案') TINYINT(1)"` | |||
PlanCommissionId int `json:"plan_commission_id" xorm:"not null default 0 comment('佣金方案0未设置,>0对应方案') TINYINT(3)"` | |||
SecondPlanCommissionId int `json:"second_plan_commission_id" xorm:"not null default 0 comment('佣金方案0未设置,>0对应方案') TINYINT(3)"` | |||
PlanSettleId int `json:"plan_settle_id" xorm:"not null default 0 comment('结算方案0未设置,>0对应方案') TINYINT(3)"` | |||
State int `json:"state" xorm:"not null default 1 comment('0关闭,1开启') TINYINT(1)"` | |||
SubsidyRate float32 `json:"subsidy_rate" xorm:"not null default 0.0000 comment('待删除字段') FLOAT(6,4)"` | |||
Source int `json:"source" xorm:"not null default 1 comment('佣金来源:1联盟佣金 2补贴金额') TINYINT(1)"` | |||
AppType int `json:"app_type" xorm:"not null default 1 comment('所属应用:1导购 2自营 4O2O') TINYINT(3)"` | |||
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)"` | |||
PointType int `json:"point_type" xorm:"not null default 0 comment('') TINYINT(1)"` | |||
RateList string `json:"rate_list" xorm:"not null default '' comment('') VARCHAR(3000)"` | |||
} |
@@ -23,10 +23,12 @@ type CommissionParam struct { | |||
IsTikTokTeamOrder string `json:"is_tik_tok_team_order"` | |||
MinLevel int `json:"min_level"` | |||
DouyinBili string `json:"douyin_bili"` | |||
ServiceUid string `json:"service_uid"` | |||
} | |||
type CommissionFirstParam struct { | |||
CommissionParam CommissionParam `json:"commission_param"` | |||
Uid string `json:"uid"` | |||
ServiceUid string `json:"service_uid"` | |||
IsShare int `json:"is_share"` | |||
OldLv string `json:"old_lv"` //升级礼包读取的是升级前的等级 | |||
NewLv string `json:"new_lv"` //升级礼包读取的是升级后的等级 | |||
@@ -18,6 +18,7 @@ type PublicPlatoonRelateCommissionReq struct { | |||
PendingAmount string `json:"pending_amount"` //待处理金额 | |||
Oid string `json:"oid"` //订单id | |||
PendingIntegral string `json:"pending_integral"` //待处理金额 | |||
ServiceUid string `json:"service_uid"` | |||
} | |||
type PublicPlatoonRelateCommissionResp struct { | |||
@@ -17,6 +17,7 @@ type SmallPublicPlatoonRelateCommissionReq struct { | |||
PendingAmount string `json:"pending_amount"` //待处理金额 | |||
Oid string `json:"oid"` //订单id | |||
PendingIntegral string `json:"pending_integral"` //待处理金额 | |||
ServiceUid string `json:"service_uid"` | |||
} | |||
type SmallPublicPlatoonRelateCommissionResp struct { | |||
@@ -304,6 +304,68 @@ func BatchGetCommissionByOrder(engine *xorm.Engine, dbName string, CommissionPar | |||
return goodsId2lvUser, nil | |||
} | |||
func BatchGetCommissionByOrderService(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 | |||
commArr := GetComm(engine) | |||
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("订单缺失") | |||
} | |||
if zhios_order_relate_utils.StrToFloat64(param.CommissionParam.GoodsPrice) > 0 { | |||
param.CommissionParam.OldPrice = param.CommissionParam.GoodsPrice | |||
} | |||
param.CommissionParam.ShowLevel = param.ShowLevel | |||
param.CommissionParam.ServiceUid = param.ServiceUid | |||
param.CommissionParam.Oid = param.Oid | |||
var mapData = map[string]string{ | |||
"old_lv": param.OldLv, | |||
"new_lv": param.NewLv, | |||
"ownbuy_return_type": zhios_order_relate_utils.IntToStr(param.OwnbuyReturnType), | |||
} | |||
profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommissionService(engine, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, mapData, commArr, 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 ( | |||
@@ -250,6 +250,162 @@ func GetPlanCfg(eg *xorm.Engine, pvd, masterId string, rewardOpts map[string]*mo | |||
return opt, nil | |||
} | |||
func GetPlanCfgService(eg *xorm.Engine, pvd, masterId string, rewardOpts map[string]*model.PlanReward, commissionOpts map[int]*model.PlanCommission, virtualCoinMoneyRate map[int]string, rmd *md.CommissionParam) (*comm_plan.PlanOpt, error) { | |||
opt := &comm_plan.PlanOpt{} | |||
// 根据供应商 | |||
rewardOpt := rewardOpts[pvd] | |||
if strings.Contains(pvd, "seFree") == false && strings.Contains(pvd, "moreFree") == false { | |||
if (pvd == "tikTok" || pvd == "csjp") && rmd.IsTikTokTeamOrder == "1" && rewardOpts["tikTokTeam"] != nil && rewardOpts["tikTokTeam"].PlanCommissionId > 0 { | |||
rewardOpt = rewardOpts["tikTokTeam"] | |||
} | |||
if pvd == "kuaishou" && rmd.IsTikTokTeamOrder == "1" && rewardOpts["kuaishouTeam"] != nil && rewardOpts["kuaishouTeam"].PlanCommissionId > 0 { | |||
rewardOpt = rewardOpts["kuaishouTeam"] | |||
} | |||
} | |||
if pvd == md.PVD_JDOwn && (rewardOpts["jd_own"] == nil || (rewardOpts["jd_own"] != nil && rewardOpts["jd_own"].PlanCommissionId == 0)) { | |||
rewardOpt = rewardOpts["jd"] | |||
} | |||
if rewardOpt == nil { | |||
return nil, zhios_order_relate_logx.Warn("找不到方案记录") | |||
} | |||
if rewardOpt.State == 0 { | |||
return nil, zhios_order_relate_logx.Warn("抽成方案未开启") | |||
} | |||
if rewardOpt.SecondPlanCommissionId == 0 { | |||
return nil, zhios_order_relate_logx.Warn("抽成方案未设置佣金方案id") | |||
} | |||
commissionOpt := commissionOpts[rewardOpt.SecondPlanCommissionId] | |||
if commissionOpt == nil || commissionOpt.Id == 0 { | |||
return nil, errors.New("佣金方案有误") | |||
} | |||
if _, ok := comm_plan.Fn[commissionOpt.Mode]; !ok && zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"public_platoon_level", "public_platoon", "extend_price", "lv_integral_release"}) == false { | |||
return nil, zhios_order_relate_logx.Warn("分佣模式不存在") | |||
} | |||
opt.Pvd = pvd | |||
opt.PointType = rewardOpt.PointType | |||
opt.Mode = commissionOpt.Mode | |||
opt.IntegralOpen = rewardOpt.IntegralOpen | |||
opt.SysRate = float64(int64(rewardOpt.SysRate*1e4)) / 1e4 | |||
opt.PvdRate = float64(int64(rewardOpt.PvdRate*1e4)) / 1e4 | |||
opt.RegionRate = float64(int64(rewardOpt.RegionRate*1e4)) / 1e4 | |||
opt.RegionSubRate = float64(int64(rewardOpt.RegionSubRate*1e4)) / 1e4 | |||
opt.GlobalRate = float64(int64(rewardOpt.GlobalRate*1e4)) / 1e4 | |||
opt.SelfBuyGlobalRate = float64(int64(rewardOpt.SelfBuyGlobalRate*1e4)) / 1e4 | |||
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.BuckleRate = float64(int64(rewardOpt.BuckleRate*1e4)) / 1e4 | |||
opt.PlanCommissionId = rewardOpt.SecondPlanCommissionId | |||
rateList := make(map[string]float64) | |||
if rewardOpt.RateList != "" { | |||
rateListMap := make(map[string]interface{}) | |||
json.Unmarshal([]byte(rewardOpt.RateList), &rateListMap) | |||
for k1, v1 := range rateListMap { | |||
rateList[k1] = zhios_order_relate_utils.AnyToFloat64(v1) | |||
} | |||
} | |||
opt.RateList = rateList | |||
// 兑换现金比例 | |||
if virtualCoinMoneyRate == nil { | |||
opt.VirtualCoinMoneyRatioList = nil | |||
} else { | |||
opt.VirtualCoinMoneyRatioList = virtualCoinMoneyRate | |||
} | |||
if zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"public_platoon_level", "public_platoon", "extend_price", "lv_integral_release"}) { //公排 | |||
return opt, nil | |||
} | |||
if opt.SysRate > 1 || opt.PvdRate > 1 || opt.RegionRate > 1 || opt.GlobalRate > 1 || opt.PvdRate+opt.SysRate+opt.RegionRate+opt.GlobalRate > 1 { | |||
return nil, zhios_order_relate_logx.Warn("分佣方案数据设置总额不能大于1") | |||
} | |||
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\":{}") | |||
commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, "\"new_team_list\":[]", "\"new_team_list\":{}") | |||
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, "\"common_wealth_system\":[\"0\"]", "\"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\":[") { //兼容旧的方案 | |||
tmp := strings.Split(commissionOpt.Data, "\"subsidy_mode_list\":[") | |||
if len(tmp) > 0 { | |||
tmp1 := strings.Split(tmp[1], "]") | |||
if len(tmp1) > 0 { | |||
str := "\"subsidy_mode_list\":[" + tmp1[0] + "]" | |||
ex := strings.Split(tmp1[0], ",") | |||
bili := "bili" | |||
if len(ex) > 0 { | |||
bili = strings.ReplaceAll(ex[0], "\"", "") | |||
} | |||
commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, str, "\"subsidy_mode_list\":{\"0\":\""+bili+"\"}") | |||
} | |||
} | |||
} | |||
if strings.Contains(commissionOpt.Data, "\"buy_deliver_list\":[") { // | |||
tmp := strings.Split(commissionOpt.Data, "\"buy_deliver_list\":[") | |||
if len(tmp) > 0 { | |||
tmp1 := strings.Split(tmp[1], "]") | |||
if len(tmp1) > 0 { | |||
str := "\"buy_deliver_list\":[" + tmp1[0] + "]" | |||
str1 := "\"buy_deliver_list\":{" + tmp1[0] + "}" | |||
commissionOpt.Data = strings.ReplaceAll(commissionOpt.Data, str, str1) | |||
} | |||
} | |||
} | |||
if zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"lv_ds_check"}) { | |||
if err := json.Unmarshal([]byte(commissionOpt.Data), &subsidyTmpDs); err != nil { | |||
if masterId == "68823769" { | |||
fmt.Println("===========================分佣方案数据设置错误", commissionOpt) | |||
fmt.Println("===========================分佣方案数据设置错误", err) | |||
} | |||
return nil, zhios_order_relate_logx.Warn(fmt.Sprintf("%s:分佣方案数据设置错误", masterId)) | |||
} | |||
copier.Copy(&subsidyTmp, &subsidyTmpDs) | |||
opt.UserRate = subsidyTmp | |||
return opt, nil | |||
} | |||
if zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"lv_price_public_platoon", "lv_commission_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" { | |||
fmt.Println("===========================分佣方案数据设置错误", commissionOpt) | |||
fmt.Println("===========================分佣方案数据设置错误", err) | |||
} | |||
return nil, zhios_order_relate_logx.Warn(fmt.Sprintf("%s:分佣方案数据设置错误", masterId)) | |||
} | |||
copier.Copy(&subsidyTmp, &subsidyTmpWineryAdv) | |||
opt.UserRate = subsidyTmp | |||
return opt, nil | |||
} | |||
if err := json.Unmarshal([]byte(commissionOpt.Data), &subsidyTmp); err != nil { | |||
fmt.Println("===========================分佣方案数据设置错误", commissionOpt) | |||
fmt.Println("===========================分佣方案数据设置错误", err) | |||
return nil, zhios_order_relate_logx.Warn(fmt.Sprintf("%s:分佣方案数据设置错误", masterId)) | |||
} | |||
opt.UserRate = subsidyTmp | |||
return opt, nil | |||
} | |||
// 获取所有供应商对应的分佣方案, 包括免单,一元购 | |||
func PlanOpts(eg *xorm.Engine) map[string]*comm_plan.PlanOpt { | |||
@@ -271,3 +271,126 @@ func BatchGetPublicPlatoonRelateCommissionByOrderLevel(engine *xorm.Engine, mast | |||
} | |||
return resp, nil | |||
} | |||
func BatchGetPublicPlatoonRelateCommissionByOrderLevelService(engine *xorm.Engine, masterId string, PublicPlatoonRelateCommissionReqList []*md.PublicPlatoonRelateCommissionReq) (map[string]*md.PublicPlatoonRelateCommissionResp, error) { | |||
var resp = make(map[string]*md.PublicPlatoonRelateCommissionResp) | |||
for _, param := range PublicPlatoonRelateCommissionReqList { | |||
// 根据供应商 | |||
rewardOpt, err := db.DbsPlanRewardByPvd(engine, param.Pvd) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if rewardOpt == nil { | |||
return nil, zhios_order_relate_logx.Warn("找不到方案记录") | |||
} | |||
if rewardOpt.State == 0 { | |||
return nil, zhios_order_relate_logx.Warn("抽成方案未开启") | |||
} | |||
if rewardOpt.PlanCommissionId == 0 { | |||
return nil, zhios_order_relate_logx.Warn("抽成方案未设置佣金方案id") | |||
} | |||
fmt.Println("抽成设置:", zhios_order_relate_utils.SerializeStr(rewardOpt)) | |||
fmt.Println("commission id:", rewardOpt.PlanCommissionId) | |||
//TODO::计算共富收益 | |||
commissionOpt, err := db.DbsPlanCommissionById(engine, rewardOpt.PlanCommissionId) | |||
if err != nil || commissionOpt == nil || commissionOpt.Id == 0 { | |||
return nil, err | |||
} | |||
var subsidyTmp = make(map[string]*md.LvGrade) | |||
var tmp map[string]*md.LvGrade | |||
if err := json.Unmarshal([]byte(commissionOpt.Data), &tmp); err != nil { | |||
return nil, zhios_order_relate_logx.Warn(fmt.Sprintf("%s:分佣方案数据设置错误", masterId)) | |||
} | |||
for _, v := range tmp { | |||
subsidyTmp[zhios_order_relate_utils.IntToStr(v.Lv)] = v | |||
} | |||
lvGrade := subsidyTmp[param.UserLevel] | |||
var directPush = make(map[string]string) | |||
var selfRateList = make(map[string]string) | |||
var commonWealthSystem = make(map[string]string) | |||
if lvGrade != nil { | |||
for _, coinId := range lvGrade.ReturnType { | |||
var pendingAmount = param.PendingAmount | |||
if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 | |||
pendingAmount = param.PendingIntegral | |||
} | |||
selfRateList[coinId] = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(lvGrade.SelfRateList[coinId])*zhios_order_relate_utils.StrToFloat64(pendingAmount)/100, 9) | |||
} | |||
} | |||
nowBenefitUid, _, err := benefitUidByBig(engine, param) | |||
if err != nil { | |||
return nil, err | |||
} | |||
recommendUid := param.ServiceUid | |||
//直推獎勵 | |||
if zhios_order_relate_utils.StrToInt(recommendUid) > 0 { | |||
parentUid, _ := db.UserFindByID(engine, recommendUid) | |||
lvGrade := subsidyTmp[zhios_order_relate_utils.IntToStr(parentUid.Level)] | |||
if lvGrade != nil { | |||
for _, coinId := range lvGrade.ReturnType { | |||
var pendingAmount = param.PendingAmount | |||
if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 | |||
pendingAmount = param.PendingIntegral | |||
} | |||
directPush[coinId] = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(lvGrade.DirectPush[coinId])*zhios_order_relate_utils.StrToFloat64(pendingAmount)/100, 9) | |||
} | |||
} | |||
} | |||
//共富简历 | |||
if zhios_order_relate_utils.StrToInt(nowBenefitUid) > 0 { | |||
parentUid, _ := db.UserFindByID(engine, nowBenefitUid) | |||
lvGrade := subsidyTmp[zhios_order_relate_utils.IntToStr(parentUid.Level)] | |||
if lvGrade != nil { | |||
//判断购买人是哪个等级 | |||
UserLvUpPublicPlatoonList := make(map[string]interface{}) | |||
if len(lvGrade.UserLvUpPublicPlatoonList) > 0 { | |||
for _, v1 := range lvGrade.UserLvUpPublicPlatoonList { | |||
v2 := v1.(map[string]interface{}) | |||
if zhios_order_relate_utils.AnyToInt64(v2["lv"]) == zhios_order_relate_utils.StrToInt64(param.UserLevel) { | |||
rateList, ok := v2["rate_list"].(map[string]interface{}) | |||
if ok { | |||
UserLvUpPublicPlatoonList = rateList | |||
} else { | |||
rateList, ok := v2["rate_list"].([]interface{}) | |||
if ok { | |||
for k, v := range rateList { | |||
UserLvUpPublicPlatoonList[zhios_order_relate_utils.AnyToString(k)] = v | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
for _, coinId := range lvGrade.ReturnType { | |||
var pendingAmount = param.PendingAmount | |||
if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 | |||
pendingAmount = param.PendingIntegral | |||
} | |||
bili := lvGrade.CommonWealthSystem[coinId] | |||
//判断购买人是哪个等级 读对应的比例 | |||
if UserLvUpPublicPlatoonList != nil { | |||
newBili, ok := UserLvUpPublicPlatoonList[coinId] | |||
if ok { | |||
bili = zhios_order_relate_utils.AnyToString(newBili) | |||
} | |||
} | |||
commonWealthSystem[coinId] = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(bili)*zhios_order_relate_utils.StrToFloat64(pendingAmount)/100, 9) | |||
} | |||
} | |||
} | |||
/// | |||
resp[param.Oid] = &md.PublicPlatoonRelateCommissionResp{ | |||
Uid: param.Uid, | |||
CommonWealthBenefitUid: nowBenefitUid, | |||
DirectPushBenefitUid: recommendUid, | |||
PendingAmount: param.PendingAmount, | |||
PendingIntegral: param.PendingIntegral, | |||
Oid: param.Oid, | |||
SelfRateList: selfRateList, | |||
CommonWealthSystem: commonWealthSystem, | |||
DirectPush: directPush, | |||
} | |||
} | |||
return resp, nil | |||
} |
@@ -268,6 +268,260 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b | |||
comm(commArr, ulink) | |||
return ulink.Profit, pvdFee, sysFee, subsidyFee, ulink, nil | |||
} | |||
func GetRewardCommissionService(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_JDOwn, md.PVD_VIP}) == false { | |||
rmd.GoodsPrice = rmd.Commission | |||
} | |||
} | |||
if rmd.Oid == "" { | |||
rmd.Oid = "1" | |||
} | |||
var ( | |||
err error | |||
uid = 0 | |||
level = 0 | |||
userLevel = 0 | |||
newLevel = 0 | |||
minLevel = 0 | |||
) | |||
user, _ := db.UserFindByID(engine, userId) | |||
if user != nil { | |||
uid = user.Uid | |||
level = user.Level | |||
newLevel = user.Level | |||
userLevel = user.Level | |||
} | |||
minLevelList, _ := db.UserLevelInIDescByWeightLowWithOne(engine) | |||
if minLevelList != nil { | |||
minLevel = minLevelList.Id | |||
if uid == 0 { | |||
level = minLevel | |||
newLevel = minLevel | |||
userLevel = minLevel | |||
} | |||
} | |||
// 获取抽成方案 | |||
newProvider := provider | |||
if newProvider == md.PVD_TM { //抽成方案只有淘宝的要替换回来 | |||
newProvider = md.PVD_TB | |||
} | |||
if newProvider == "userlvup" { | |||
newProvider = "user_level_up" | |||
} | |||
if newProvider == md.PVD_MALL_GOODS_USER_LV || newProvider == "user_level_up" { //升级礼包按升级前等级计算佣金 | |||
level = zhios_order_relate_utils.StrToInt(extraData["old_lv"]) | |||
newLevel = zhios_order_relate_utils.StrToInt(extraData["new_lv"]) | |||
} | |||
if rmd.ShowLevel != "" { | |||
level = zhios_order_relate_utils.StrToInt(rmd.ShowLevel) | |||
} | |||
if extraData["show_level"] != "" { | |||
level = zhios_order_relate_utils.StrToInt(extraData["show_level"]) | |||
} | |||
ownbuyReturnType := zhios_order_relate_utils.StrToInt(extraData["ownbuy_return_type"]) | |||
cfg, err := GetPlanCfgService(engine, newProvider, masterId, rewardOpts, commissionOpts, virtualCoinMoneyRate, rmd) | |||
if err != nil { | |||
return 0, 0, 0, 0, nil, err | |||
} | |||
if cfg == nil { | |||
return 0, 0, 0, 0, nil, errors.New("分佣方案未设置") | |||
} | |||
// 获取全部佣金 | |||
com, price := getCommission(rmd, provider) | |||
fmt.Println(com) | |||
fmt.Println(price) | |||
comf := zhios_order_relate_utils.StrToFloat64(com) | |||
if zhios_order_relate_utils.InArr(cfg.Mode, []string{"lv_price_public_platoon", "lv_price", "lv_price_other", "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" { | |||
//公排 | |||
//佣金扣除抽成后 | |||
fee, _, pvdFee, sysFee := CommFee(comf, cfg, "commission", rmd) | |||
////积分扣除抽成后 | |||
integralFee, _, _, _ := CommFee(zhios_order_relate_utils.StrToFloat64(price), cfg, "integral", rmd) | |||
//调用公排制度 | |||
userPublicPlatoonSetting, err := db.UserPublicPlatoonSettingGetOneByParams(engine, map[string]interface{}{ | |||
"key": "is_open", | |||
"value": 1, | |||
}) | |||
if err != nil || userPublicPlatoonSetting == nil { | |||
return 0, 0, 0, 0, nil, nil | |||
} | |||
var reward = &md.PublicPlatoonRelateCommissionResp{} | |||
if userPublicPlatoonSetting.IsUseSmallPublicPlatoon == 1 { //小公排 | |||
var PublicPlatoonRelateCommissionReqList = []*md.SmallPublicPlatoonRelateCommissionReq{ | |||
{ | |||
Pvd: newProvider, | |||
Uid: zhios_order_relate_utils.IntToStr(uid), | |||
ServiceUid: rmd.ServiceUid, | |||
UserLevel: zhios_order_relate_utils.IntToStr(level), | |||
PendingAmount: zhios_order_relate_utils.Float64ToStrByPrec(fee, 9), | |||
PendingIntegral: zhios_order_relate_utils.Float64ToStrByPrec(integralFee, 9), | |||
Oid: rmd.Oid, | |||
}, | |||
} | |||
var order = make(map[string]*md.SmallPublicPlatoonRelateCommissionResp) | |||
if rmd.IsGoods == "1" { | |||
order, err = BatchSmallGetPublicPlatoonRelateByGoods(engine, masterId, PublicPlatoonRelateCommissionReqList) | |||
} else { | |||
order, err = BatchSmallGetPublicPlatoonRelateCommissionLevelService(engine, masterId, PublicPlatoonRelateCommissionReqList) | |||
} | |||
if err != nil || order[rmd.Oid] == nil { | |||
return 0, 0, 0, 0, nil, nil | |||
} | |||
rewardSmall := order[rmd.Oid] | |||
err = copier.Copy(reward, &rewardSmall) | |||
if err != nil || reward == nil { | |||
return 0, 0, 0, 0, nil, nil | |||
} | |||
} else { | |||
var PublicPlatoonRelateCommissionReqList = []*md.PublicPlatoonRelateCommissionReq{ | |||
{ | |||
Pvd: newProvider, | |||
Uid: zhios_order_relate_utils.IntToStr(uid), | |||
UserLevel: zhios_order_relate_utils.IntToStr(level), | |||
PendingAmount: zhios_order_relate_utils.Float64ToStrByPrec(fee, 9), | |||
ServiceUid: rmd.ServiceUid, | |||
PendingIntegral: zhios_order_relate_utils.Float64ToStrByPrec(integralFee, 9), | |||
Oid: rmd.Oid, | |||
}, | |||
} | |||
var order = make(map[string]*md.PublicPlatoonRelateCommissionResp) | |||
if rmd.IsGoods == "1" { | |||
order, err = BatchGetPublicPlatoonRelateCommissionByGoods(engine, masterId, PublicPlatoonRelateCommissionReqList) | |||
} else { | |||
order, err = BatchGetPublicPlatoonRelateCommissionByOrderLevelService(engine, masterId, PublicPlatoonRelateCommissionReqList) | |||
} | |||
if err != nil || order[rmd.Oid] == nil { | |||
return 0, 0, 0, 0, nil, nil | |||
} | |||
reward = order[rmd.Oid] | |||
} | |||
profit := zhios_order_relate_utils.StrToFloat64(reward.SelfRateList["0"]) | |||
var ulink = &comm_plan.LvUser{} | |||
if zhios_order_relate_utils.StrToInt(reward.CommonWealthBenefitUid) != zhios_order_relate_utils.StrToInt(reward.DirectPushBenefitUid) { | |||
//共富收益处理 | |||
ulink = getRewardLink(reward.CommonWealthBenefitUid, 2, reward.CommonWealthSystem, ulink, "public_platoon", cfg) | |||
//直推收益处理 | |||
ulink = getRewardLink(reward.DirectPushBenefitUid, 1, reward.DirectPush, ulink, "extend", cfg) | |||
} else { //共富 直推都是同一个用户的处理 | |||
ulink = getRewardLinkCommWithExtend(reward.CommonWealthBenefitUid, 3, reward.CommonWealthSystem, reward.DirectPush, ulink, cfg) | |||
} | |||
//自购 | |||
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"]) | |||
} | |||
} | |||
comm(commArr, ulink) | |||
return profit, pvdFee, sysFee, 0, ulink, nil | |||
} | |||
if cfg.Mode == "lv_integral_release" { // | |||
price = rmd.OldPrice | |||
pvdFee, sysFee, _, ulink, err := IntegralRelease(engine, uid, newLevel, returnAllLevel, rmd.IsShowExtend, newProvider, user, comf, price, cfg, rmd, commArr, virtualCoinMoneyRate) | |||
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" { //自购没奖励,就不计算了 | |||
return 0, 0, 0, 0, ulink, nil | |||
} | |||
if newProvider == md.PVD_REGIONAL_AGENT_PAY { | |||
userLevel = zhios_order_relate_utils.StrToInt(extraData["agent_lv"]) | |||
} | |||
//佣金扣除抽成后 | |||
fee, _, pvdFee, sysFee := CommFee(comf, cfg, "commission", rmd) | |||
////积分扣除抽成后 | |||
integralFee, _, _, _ := CommFee(zhios_order_relate_utils.StrToFloat64(price), cfg, "integral", rmd) | |||
var param = map[string]string{ | |||
"commission": zhios_order_relate_utils.Float64ToStr(fee), | |||
"integral": zhios_order_relate_utils.Float64ToStr(integralFee), | |||
"level": zhios_order_relate_utils.IntToStr(userLevel), | |||
"uid": zhios_order_relate_utils.IntToStr(uid), | |||
"source": newProvider, | |||
} | |||
reward, parentUid := ExtendPriceReward(engine, param, cfg) | |||
for k, v := range reward { | |||
if zhios_order_relate_utils.StrToFloat64(v) < 0 { | |||
reward[k] = "0" | |||
} | |||
} | |||
//直推收益处理 | |||
if parentUid > 0 { | |||
ulink = getRewardLink(zhios_order_relate_utils.IntToStr(parentUid), 1, reward, ulink, "extend", cfg) | |||
} | |||
//自购 | |||
ulink = getRewardLink(zhios_order_relate_utils.IntToStr(uid), 0, map[string]string{}, ulink, "own", cfg) | |||
return 0, pvdFee, sysFee, 0, ulink, nil | |||
} | |||
//常规级差 | |||
var userRelationship *[]md.UserRelation | |||
if returnAllLevel { | |||
userRelationship, err = UserRelativeNetworkService(engine, uid, zhios_order_relate_utils.StrToInt(rmd.ServiceUid), 0) | |||
} else if rmd.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 cfg.Mode == "niubei_commission" || cfg.Mode == "niubei_amount" { // | |||
price = zhios_order_relate_utils.Float64ToStrByPrec(comf, 8) | |||
if cfg.Mode == "niubei_amount" { | |||
price = rmd.OldPrice | |||
} | |||
pvdFee, sysFee, subsidyFee, ulink, err := NiuBeiCalcCommission(uid, level, 0, ownbuyReturnType, comf, zhios_order_relate_utils.StrToFloat64(price), isShare, cfg, userRelationship, newProvider, newLevel, engine, rmd.IsGoods, rmd) | |||
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, subsidyFee, ulink, nil | |||
} | |||
// userRelationship == nil 是只返回第一层 即用户自己的 | |||
rmd.MinLevel = minLevel | |||
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, rmd) | |||
if err != nil { | |||
return 0, 0, 0, 0, nil, nil | |||
} | |||
if ulink == nil { | |||
return 0, 0, 0, 0, nil, nil | |||
} | |||
if cfg.Mode == "lv_price_public_platoon" || cfg.Mode == "lv_commission_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) | |||
@@ -486,3 +486,129 @@ func BatchSmallGetPublicPlatoonRelateCommissionLevel(engine *xorm.Engine, master | |||
} | |||
return resp, nil | |||
} | |||
func BatchSmallGetPublicPlatoonRelateCommissionLevelService(engine *xorm.Engine, masterId string, PublicPlatoonRelateCommissionReqList []*md.SmallPublicPlatoonRelateCommissionReq) (map[string]*md.SmallPublicPlatoonRelateCommissionResp, error) { | |||
var resp = make(map[string]*md.SmallPublicPlatoonRelateCommissionResp) | |||
for _, param := range PublicPlatoonRelateCommissionReqList { | |||
// 根据供应商 | |||
rewardOpt, err := db.DbsPlanRewardByPvd(engine, param.Pvd) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if rewardOpt == nil { | |||
return nil, zhios_order_relate_logx.Warn("找不到方案记录") | |||
} | |||
if rewardOpt.State == 0 { | |||
return nil, zhios_order_relate_logx.Warn("抽成方案未开启") | |||
} | |||
if rewardOpt.PlanCommissionId == 0 { | |||
return nil, zhios_order_relate_logx.Warn("抽成方案未设置佣金方案id") | |||
} | |||
fmt.Println("抽成设置:", zhios_order_relate_utils.SerializeStr(rewardOpt)) | |||
fmt.Println("commission id:", rewardOpt.PlanCommissionId) | |||
//TODO::计算共富收益 | |||
commissionOpt, err := db.DbsPlanCommissionById(engine, rewardOpt.PlanCommissionId) | |||
if err != nil || commissionOpt == nil || commissionOpt.Id == 0 { | |||
return nil, err | |||
} | |||
var subsidyTmp = make(map[string]*md.LvGrade) | |||
var tmp map[string]*md.LvGrade | |||
if err := json.Unmarshal([]byte(commissionOpt.Data), &tmp); err != nil { | |||
return nil, zhios_order_relate_logx.Warn(fmt.Sprintf("%s:分佣方案数据设置错误", masterId)) | |||
} | |||
for _, v := range tmp { | |||
subsidyTmp[zhios_order_relate_utils.IntToStr(v.Lv)] = v | |||
} | |||
var directPush = make(map[string]string) | |||
var selfRateList = make(map[string]string) | |||
var commonWealthSystem = make(map[string]string) | |||
lvGrade := subsidyTmp[param.UserLevel] | |||
if lvGrade != nil { | |||
for _, coinId := range lvGrade.ReturnType { | |||
var pendingAmount = param.PendingAmount | |||
if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 | |||
pendingAmount = param.PendingIntegral | |||
} | |||
selfRateList[coinId] = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(lvGrade.SelfRateList[coinId])*zhios_order_relate_utils.StrToFloat64(pendingAmount)/100, 9) | |||
} | |||
} | |||
//TODO::本次消费产生的共富收益给到谁 | |||
nowBenefitUid, _, err := benefitUid(engine, param) | |||
if err != nil { | |||
return nil, err | |||
} | |||
recommendUid := "" | |||
recommendUid = param.ServiceUid | |||
//直推獎勵 | |||
if zhios_order_relate_utils.StrToInt(recommendUid) > 0 { | |||
parentUid, _ := db.UserFindByID(engine, recommendUid) | |||
lvGrade := subsidyTmp[zhios_order_relate_utils.IntToStr(parentUid.Level)] | |||
if lvGrade != nil { | |||
for _, coinId := range lvGrade.ReturnType { | |||
var pendingAmount = param.PendingAmount | |||
if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 | |||
pendingAmount = param.PendingIntegral | |||
} | |||
directPush[coinId] = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(lvGrade.DirectPush[coinId])*zhios_order_relate_utils.StrToFloat64(pendingAmount)/100, 9) | |||
} | |||
} | |||
} | |||
//共富简历 | |||
if zhios_order_relate_utils.StrToInt(nowBenefitUid) > 0 { | |||
parentUid, _ := db.UserFindByID(engine, nowBenefitUid) | |||
if parentUid != nil { | |||
lvGrade := subsidyTmp[zhios_order_relate_utils.IntToStr(parentUid.Level)] | |||
if lvGrade != nil { | |||
//判断购买人是哪个等级 | |||
UserLvUpPublicPlatoonList := make(map[string]interface{}) | |||
if len(lvGrade.UserLvUpPublicPlatoonList) > 0 { | |||
for _, v1 := range lvGrade.UserLvUpPublicPlatoonList { | |||
v2 := v1.(map[string]interface{}) | |||
if zhios_order_relate_utils.AnyToInt64(v2["lv"]) == zhios_order_relate_utils.StrToInt64(param.UserLevel) { | |||
rateList, ok := v2["rate_list"].(map[string]interface{}) | |||
if ok { | |||
UserLvUpPublicPlatoonList = rateList | |||
} else { | |||
rateList, ok := v2["rate_list"].([]interface{}) | |||
if ok { | |||
for k, v := range rateList { | |||
UserLvUpPublicPlatoonList[zhios_order_relate_utils.AnyToString(k)] = v | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
for _, coinId := range lvGrade.ReturnType { | |||
var pendingAmount = param.PendingAmount | |||
if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 | |||
pendingAmount = param.PendingIntegral | |||
} | |||
bili := lvGrade.CommonWealthSystem[coinId] | |||
//判断购买人是哪个等级 读对应的比例 | |||
if UserLvUpPublicPlatoonList != nil { | |||
newBili, ok := UserLvUpPublicPlatoonList[coinId] | |||
if ok { | |||
bili = zhios_order_relate_utils.AnyToString(newBili) | |||
} | |||
} | |||
commonWealthSystem[coinId] = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(bili)*zhios_order_relate_utils.StrToFloat64(pendingAmount)/100, 9) | |||
} | |||
} | |||
} | |||
} | |||
resp[param.Oid] = &md.SmallPublicPlatoonRelateCommissionResp{ | |||
Uid: param.Uid, | |||
CommonWealthBenefitUid: nowBenefitUid, | |||
DirectPushBenefitUid: recommendUid, | |||
PendingAmount: param.PendingAmount, | |||
Oid: param.Oid, | |||
SelfRateList: selfRateList, | |||
CommonWealthSystem: commonWealthSystem, | |||
DirectPush: directPush, | |||
} | |||
} | |||
return resp, nil | |||
} |
@@ -44,3 +44,46 @@ func UserRelativeNetwork(eg *xorm.Engine, uid, level int) (*[]md.UserRelation, e | |||
} | |||
return &userRelation, nil | |||
} | |||
func UserRelativeNetworkService(eg *xorm.Engine, uid, serviceUid, level int) (*[]md.UserRelation, error) { | |||
var uids = []int{serviceUid} | |||
var userRelation = []md.UserRelation{ | |||
{ | |||
Uid: serviceUid, | |||
CurUid: uid, | |||
Diff: 1, | |||
Level: 0, | |||
}, | |||
} | |||
parent, _ := db.DbsUserRelate(eg, serviceUid, level) | |||
if parent != nil { | |||
for _, v := range *parent { | |||
uids = append(uids, v.ParentUid) | |||
userRelation = append(userRelation, md.UserRelation{ | |||
Uid: v.ParentUid, | |||
CurUid: uid, | |||
Diff: v.Level + 1, | |||
Level: 0, | |||
}) | |||
} | |||
} | |||
relateUsers, err := db.DbsUserFindByIds(eg, uids) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if relateUsers == nil { | |||
return nil, nil | |||
} | |||
tmp := map[int]int{} | |||
for _, v := range *relateUsers { | |||
tmp[v.Uid] = v.Level | |||
} | |||
for k, v := range userRelation { | |||
if val, ok := tmp[v.Uid]; ok { | |||
userRelation[k].Level = val | |||
} | |||
} | |||
if len(userRelation) == 0 { | |||
return nil, nil | |||
} | |||
return &userRelation, nil | |||
} |