@@ -15,3 +15,11 @@ func UserFindByID(Db *xorm.Engine, id interface{}) (*model.User, error) { | |||
} | |||
return &m, nil | |||
} | |||
func UserProfileFindByID(Db *xorm.Engine, id interface{}) (*model.UserProfile, error) { | |||
var m model.UserProfile | |||
if has, err := Db.Where("uid = ?", id). | |||
Get(&m); err != nil || has == false { | |||
return nil, zhios_order_relate_logx.Warn(err) | |||
} | |||
return &m, nil | |||
} |
@@ -0,0 +1,14 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type UserLvBuyList struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Lv int `json:"lv" xorm:"default 0 comment('等级id') INT(11)"` | |||
Source string `json:"source" xorm:"comment('来源') VARCHAR(255)"` | |||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | |||
Time time.Time `json:"time" xorm:"comment('创建时间') DATETIME"` | |||
Oid string `json:"oid" xorm:"comment('订单号') VARCHAR(255)"` | |||
} |
@@ -0,0 +1,9 @@ | |||
package md | |||
// 直推奖励结构 | |||
type ExtendRewardLvGrade struct { | |||
Lv int `json:"lv"` // 会员级别 | |||
LvName string `json:"lv_name"` // 会员名称 | |||
ReturnType []string `json:"return_type"` //返利类型 | |||
ExtendPriceRewardList []map[string]string `json:"extend_price_reward_list"` // 直推奖励比例 | |||
} |
@@ -0,0 +1,74 @@ | |||
package svc | |||
import ( | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/lib/comm_plan" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" | |||
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" | |||
"encoding/json" | |||
"xorm.io/xorm" | |||
) | |||
func ExtendPriceReward(eg *xorm.Engine, param map[string]string, cfg *comm_plan.PlanOpt) (map[string]string, int) { | |||
if zhios_order_relate_utils.InArr(param["source"], []string{"mall_goods_extend_price", "regional_agent_pay"}) == false { | |||
return map[string]string{"0": "0"}, 0 | |||
} | |||
commissionOpt, err := db.DbsPlanCommissionById(eg, cfg.PlanCommissionId) | |||
if err != nil || commissionOpt == nil || commissionOpt.Id == 0 { | |||
return map[string]string{"0": "0"}, 0 | |||
} | |||
var subsidyTmp = make(map[int]*md.ExtendRewardLvGrade) | |||
var tmp map[int]*md.ExtendRewardLvGrade | |||
if err := json.Unmarshal([]byte(commissionOpt.Data), &tmp); err != nil { | |||
return map[string]string{"0": "0"}, 0 | |||
} | |||
for _, v := range tmp { | |||
subsidyTmp[v.Lv] = v | |||
} | |||
userProfile, err := db.UserProfileFindByID(eg, param["uid"]) | |||
if err != nil || userProfile == nil { | |||
return map[string]string{"0": "0"}, 0 | |||
} | |||
if userProfile.ParentUid == 0 { | |||
return map[string]string{"0": "0"}, 0 | |||
} | |||
//查询用户等级 | |||
parentUser, err := db.UserFindByID(eg, userProfile.ParentUid) | |||
if err != nil || parentUser == nil { | |||
return map[string]string{"0": "0"}, 0 | |||
} | |||
lvGrade := subsidyTmp[parentUser.Level] | |||
var rewardList = make(map[string]map[string]string) | |||
for _, v := range lvGrade.ExtendPriceRewardList { | |||
rewardList[v["coin_id"]] = v | |||
} | |||
//查出当前的数量 | |||
count, _ := eg.Where("source=? and lv=?", param["source"], param["level"]).Count(&model.UserLvBuyList{}) | |||
count++ | |||
var isTrue = false | |||
//如果等级一致 或是代理费分佣 判断位置 | |||
if (zhios_order_relate_utils.StrToInt(param["level"]) == parentUser.Level && param["source"] == "mall_goods_extend_price") || param["source"] == "regional_agent_pay" { | |||
isTrue = true | |||
} | |||
var extendReward = make(map[string]string) | |||
for _, coinId := range lvGrade.ReturnType { | |||
reward := rewardList[coinId] | |||
var pendingAmount = param["commission"] | |||
if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 | |||
pendingAmount = param["integral"] | |||
} | |||
rewardAmount := reward["extend_bili"] | |||
//如果等级一致 判断位置 | |||
if isTrue { | |||
position := count % zhios_order_relate_utils.StrToInt64(param["base_val"]) | |||
if position == 0 { | |||
rewardAmount = reward["extend_position_bili"] | |||
} | |||
} | |||
extendReward[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(rewardAmount) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100) | |||
} | |||
return extendReward, userProfile.ParentUid | |||
} |
@@ -68,7 +68,7 @@ func GetPlanCfg(eg *xorm.Engine, pvd, masterId string) (*comm_plan.PlanOpt, erro | |||
} else { | |||
opt.VirtualCoinMoneyRatioList = virtualCoinMoneyRate | |||
} | |||
if commissionOpt.Mode == "public_platoon" { //公排 | |||
if zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"public_platoon", "extend_price"}) { //公排 | |||
return opt, nil | |||
} | |||
@@ -25,17 +25,20 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b | |||
rmd.Oid = "1" | |||
} | |||
var ( | |||
err error | |||
uid = 0 | |||
level = 0 | |||
newLevel = 0 | |||
err error | |||
uid = 0 | |||
level = 0 | |||
userLevel = 0 | |||
newLevel = 0 | |||
) | |||
user, _ := db.UserFindByID(engine, userId) | |||
if user != nil { | |||
uid = user.Uid | |||
level = user.Level | |||
newLevel = user.Level | |||
userLevel = user.Level | |||
} | |||
// 获取抽成方案 | |||
newProvider := provider | |||
if newProvider == md.PVD_TM { //抽成方案只有淘宝的要替换回来 | |||
@@ -65,26 +68,10 @@ 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"}) && zhios_order_relate_utils.StrToFloat64(rmd.OldPrice) > 0 { //价格为基数 | |||
if zhios_order_relate_utils.InArr(cfg.Mode, []string{"lv_price", "lv_winery", "extend_price"}) && zhios_order_relate_utils.StrToFloat64(rmd.OldPrice) > 0 { //价格为基数 | |||
comf = zhios_order_relate_utils.StrToFloat64(rmd.OldPrice) | |||
} | |||
if cfg.Mode != "public_platoon" { //公排走另一个制度 | |||
var userRelationship *[]md.UserRelation | |||
if returnAllLevel { | |||
userRelationship, err = UserRelativeNetwork(engine, uid) | |||
} else { | |||
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) | |||
if err != nil { | |||
return 0, 0, 0, 0, nil, nil | |||
} | |||
if ulink == nil { | |||
return 0, 0, 0, 0, nil, nil | |||
} | |||
return ulink.Profit, pvdFee, sysFee, subsidyFee, ulink, nil | |||
} else { //公排 | |||
if cfg.Mode == "public_platoon" { //公排 | |||
//佣金扣除抽成后 | |||
fee, pvdFee, sysFee := CommFee(comf, cfg, "commission") | |||
////积分扣除抽成后 | |||
@@ -124,6 +111,51 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b | |||
ulink = getRewardLink(reward.Uid, 0, reward.SelfRateList, ulink, "own", cfg) | |||
return 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") | |||
////积分扣除抽成后 | |||
integralFee, _, _ := CommFee(zhios_order_relate_utils.StrToFloat64(price), cfg, "integral") | |||
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) | |||
//直推收益处理 | |||
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 = UserRelativeNetwork(engine, uid) | |||
} else { | |||
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) | |||
if err != nil { | |||
return 0, 0, 0, 0, nil, nil | |||
} | |||
if ulink == nil { | |||
return 0, 0, 0, 0, nil, nil | |||
} | |||
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 { | |||
var SubsidyFee = zhios_order_relate_utils.StrToFloat64(reward["0"]) | |||