diff --git a/rule/public_platoon_relate_commission.go b/rule/public_platoon_relate_commission.go index 70f5505..56b4d9b 100644 --- a/rule/public_platoon_relate_commission.go +++ b/rule/public_platoon_relate_commission.go @@ -4,13 +4,11 @@ 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/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/svc" 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" "math" - "strconv" "strings" "time" "xorm.io/xorm" @@ -18,101 +16,10 @@ 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, - }) + resp, err := svc.BatchGetPublicPlatoonRelateCommissionByOrder(engine, masterId, PublicPlatoonRelateCommissionReqList) if err != nil { return nil, err } - 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 map[string]*md.LvGrade - if err := json.Unmarshal([]byte(commissionOpt.Data), &subsidyTmp); err != nil { - return nil, zhios_order_relate_logx.Warn(fmt.Sprintf("%s:分佣方案数据设置错误", masterId)) - } - lvGrade := subsidyTmp[param.UserLevel] - var selfRateList, commonWealthSystem, directPush map[string]string - for _, coinId := range lvGrade.ReturnType { - selfRateList[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.SelfRateList[coinId]) * zhios_order_relate_utils.StrToFloat64(param.PendingAmount) / 100) - commonWealthSystem[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.CommonWealthSystem[coinId]) * zhios_order_relate_utils.StrToFloat64(param.PendingAmount) / 100) - directPush[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.DirectPush[coinId]) * zhios_order_relate_utils.StrToFloat64(param.PendingAmount)) - } - - //TODO::本次消费产生的共富收益给到谁 - var nowBenefitUid string - userPublicPlatoonRelation, err := db.UserPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{ - "key": "uid", - "value": param.Uid, - }) - if err != nil { - return nil, err - } - if userPublicPlatoonRelation == nil { - return nil, errors.New("未查询到公排关系记录") - } - fatherPositions := strings.Split(userPublicPlatoonRelation.FatherUid, "-") - var fatherPosition string - userPublicPlatoonRelation.ReturnCommissionNum++ - remainder := (userPublicPlatoonRelation.ReturnCommissionNum) % userPublicPlatoonSetting.SeveralRows - if remainder == 0 { - fatherPosition = fatherPositions[userPublicPlatoonSetting.SeveralRows-1] - } else { - fatherPosition = fatherPositions[remainder-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("未查询到父级公排关系记录") - } - 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("更新公排关系记录失败") - } - resp[param.Oid] = &md.PublicPlatoonRelateCommissionResp{ - Uid: param.Uid, - CommonWealthBenefitUid: nowBenefitUid, - DirectPushBenefitUid: strconv.Itoa(userPublicPlatoonRelation.RecommendUid), - PendingAmount: param.PendingAmount, - Oid: param.Oid, - SelfRateList: selfRateList, - CommonWealthSystem: commonWealthSystem, - DirectPush: directPush, - } - } return resp, nil } diff --git a/svc/public_platoon_relate_commission.go b/svc/public_platoon_relate_commission.go new file mode 100644 index 0000000..2bc0e20 --- /dev/null +++ b/svc/public_platoon_relate_commission.go @@ -0,0 +1,114 @@ +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" + "strconv" + "strings" + "xorm.io/xorm" +) + +// 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) + 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 map[string]*md.LvGrade + if err := json.Unmarshal([]byte(commissionOpt.Data), &subsidyTmp); err != nil { + return nil, zhios_order_relate_logx.Warn(fmt.Sprintf("%s:分佣方案数据设置错误", masterId)) + } + lvGrade := subsidyTmp[param.UserLevel] + var selfRateList, commonWealthSystem, directPush map[string]string + for _, coinId := range lvGrade.ReturnType { + selfRateList[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.SelfRateList[coinId]) * zhios_order_relate_utils.StrToFloat64(param.PendingAmount) / 100) + commonWealthSystem[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.CommonWealthSystem[coinId]) * zhios_order_relate_utils.StrToFloat64(param.PendingAmount) / 100) + directPush[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.DirectPush[coinId]) * zhios_order_relate_utils.StrToFloat64(param.PendingAmount)) + } + + //TODO::本次消费产生的共富收益给到谁 + var nowBenefitUid string + userPublicPlatoonRelation, err := db.UserPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{ + "key": "uid", + "value": param.Uid, + }) + if err != nil { + return nil, err + } + if userPublicPlatoonRelation == nil { + return nil, errors.New("未查询到公排关系记录") + } + fatherPositions := strings.Split(userPublicPlatoonRelation.FatherUid, "-") + var fatherPosition string + userPublicPlatoonRelation.ReturnCommissionNum++ + remainder := (userPublicPlatoonRelation.ReturnCommissionNum) % userPublicPlatoonSetting.SeveralRows + if remainder == 0 { + fatherPosition = fatherPositions[userPublicPlatoonSetting.SeveralRows-1] + } else { + fatherPosition = fatherPositions[remainder-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("未查询到父级公排关系记录") + } + 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("更新公排关系记录失败") + } + resp[param.Oid] = &md.PublicPlatoonRelateCommissionResp{ + Uid: param.Uid, + CommonWealthBenefitUid: nowBenefitUid, + DirectPushBenefitUid: strconv.Itoa(userPublicPlatoonRelation.RecommendUid), + PendingAmount: param.PendingAmount, + Oid: param.Oid, + SelfRateList: selfRateList, + CommonWealthSystem: commonWealthSystem, + DirectPush: directPush, + } + } + return resp, nil +} diff --git a/svc/reward_commission.go b/svc/reward_commission.go index 2340801..d4c024d 100644 --- a/svc/reward_commission.go +++ b/svc/reward_commission.go @@ -4,7 +4,6 @@ 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/lib/comm_plan" "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" - "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule" zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" "errors" "fmt" @@ -97,7 +96,7 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b Oid: rmd.Oid, }, } - order, err := rule.BatchGetPublicPlatoonRelateCommissionByOrder(engine, masterId, PublicPlatoonRelateCommissionReqList) + order, err := BatchGetPublicPlatoonRelateCommissionByOrder(engine, masterId, PublicPlatoonRelateCommissionReqList) if err != nil || order[rmd.Oid] == nil { return 0, 0, 0, 0, nil, nil }