Browse Source

更新

master
huangjiajun 3 months ago
parent
commit
3765696771
2 changed files with 237 additions and 0 deletions
  1. +92
    -0
      md/double_public_platoon_relate_commission.go
  2. +145
    -0
      svc/double_public_platoon_relate_commission.go

+ 92
- 0
md/double_public_platoon_relate_commission.go View File

@@ -0,0 +1,92 @@
package md

// 公排结构
type DoubleLvGrade struct {
Lv int `json:"lv"` // 会员级别
LvName string `json:"lv_name"` // 会员名称
ReturnType []string `json:"return_type"` //返利类型
CommonWealthSystem map[string]string `json:"common_wealth_system"` //共富制度比例
SelfRateList map[string]string `json:"self_rate_list"` // 自购比例
DirectPush map[string]string `json:"direct_push"` // 直推奖励比例
}

type DoublePublicPlatoonRelateCommissionReq struct {
Pvd string `json:"pvd"` //平台供应商 (taobao/jd/pdd/mall_goods ...)
Uid string `json:"uid"`
UserLevel string `json:"user_level"` //用户等级
PendingAmount string `json:"pending_amount"` //待处理金额
Oid string `json:"oid"` //订单id
PendingIntegral string `json:"pending_integral"` //待处理金额
}

type DoublePublicPlatoonRelateCommissionResp struct {
Uid string `json:"uid"`
CommonWealthBenefitUid string `json:"common_wealth_benefit_uid"` //共富奖励给到的uid
DirectPushBenefitUid string `json:"direct_push_benefit_uid"` //直推奖励给到的uid
PendingAmount string `json:"pending_amount"` //处理金额
Oid string `json:"oid"`
SelfRateList map[string]string `json:"self_rate_list"` // 自购奖励
CommonWealthSystem map[string]string `json:"common_wealth_system"` // 共富制度奖励
DirectPush map[string]string `json:"direct_push"` // 直推奖励
PendingIntegral string `json:"pending_integral"` //待处理金额
}

type CalcDoublePublicPlatoonRelateLaXinReward struct {
Uid string `json:"uid"`
CoinId int `json:"coin_id"`
Value string `json:"value"`
}
type CalcDoublePublicPlatoonRelateLaXinLevel struct {
Id string `json:"id"`
Detail []*CalcSmallPublicPlatoonRelateLaXinDetail `json:"detail"`
}

type CalcDoublePublicPlatoonRelateLaXinDetail struct {
Key int `json:"key"`
Val interface{} `json:"val"`
}

type DoubleAddPublicPlatoonRelateCommissionReq struct {
Uid string `json:"uid"`
RecommendUid string `json:"recommend_uid"` //推荐人uid
}

type StandardDoublelPublicPlatoonRelation struct {
FatherUid1 int `json:"father_uid1"`
FatherUid2 int `json:"father_uid2"`
FatherUid3 int `json:"father_uid3"`
FatherUid4 int `json:"father_uid4"`
FatherUid5 int `json:"father_uid5"`
FatherUid6 int `json:"father_uid6"`
FatherUid7 int `json:"father_uid7"`
FatherUid8 int `json:"father_uid8"`
FatherUid9 int `json:"father_uid9"`
Pid1 int `json:"pid1"`
Pid2 int `json:"pid2"`
Pid3 int `json:"pid3"`
Pid4 int `json:"pid4"`
Pid5 int `json:"pid5"`
Pid6 int `json:"pid6"`
Pid7 int `json:"pid7"`
Pid8 int `json:"pid8"`
Pid9 int `json:"pid9"`
Position1 int `json:"position1"`
Position2 int `json:"position2"`
Position3 int `json:"position3"`
Position4 int `json:"position4"`
Position5 int `json:"position5"`
Position6 int `json:"position6"`
Position7 int `json:"position7"`
Position8 int `json:"position8"`
Position9 int `json:"position9"`
Level1 int `json:"level1"`
Level2 int `json:"level2"`
Level3 int `json:"level3"`
Level4 int `json:"level4"`
Level5 int `json:"level5"`
Level6 int `json:"level6"`
Level7 int `json:"level7"`
Level8 int `json:"level8"`
Level9 int `json:"level9"`
LevelTotal int `json:"level_total"`
}

+ 145
- 0
svc/double_public_platoon_relate_commission.go View File

@@ -0,0 +1,145 @@
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/md"
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils"
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx"
"encoding/json"
"errors"
"fmt"
"strings"
"xorm.io/xorm"
)

// BatchGetPublicPlatoonRelateCommission 批量分佣 订单显示
func BatchGetDoublePublicPlatoonRelateCommissionByOrder(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.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.SelfRateList[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100)
commonWealthSystem[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.CommonWealthSystem[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100)
directPush[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.DirectPush[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100)
}
}
nowBenefitUid, _, err := doubleBenefitUidByBig(engine, param)
if err != nil {
return nil, err
}
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: recommendUid,
PendingAmount: param.PendingAmount,
PendingIntegral: param.PendingIntegral,
Oid: param.Oid,
SelfRateList: selfRateList,
CommonWealthSystem: commonWealthSystem,
DirectPush: directPush,
}
}
return resp, nil
}
func doubleBenefitUidByBig(engine *xorm.Engine, param *md.PublicPlatoonRelateCommissionReq) (string, map[string]*md.PublicPlatoonRelateCommissionResp, error) {

//TODO::本次消费产生的共富收益给到谁
var nowBenefitUid string
userPublicPlatoonRelation, err := db.UserPublicPlatoonDoubleNetworkRelationGetOneByParams(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.UserPublicPlatoonDoubleNetworkRelationGetOneByParams(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.UserPublicPlatoonDoubleNetworkRelationUpdate(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

}

Loading…
Cancel
Save