|
|
@@ -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 |
|
|
|
|
|
|
|
} |