@@ -884,7 +884,7 @@ func CalVirtualCommissionMinus(a, b []*VirtualCoinCommission) (c []*VirtualCoinC | |||||
for _, coinA := range a { | for _, coinA := range a { | ||||
for _, coinB := range b { | for _, coinB := range b { | ||||
if coinA.Cid == coinB.Cid { | if coinA.Cid == coinB.Cid { | ||||
amount = coinA.Val - coinB.Val | |||||
amount = zhios_order_relate_utils.FloatFormat(coinA.Val-coinB.Val, 8) | |||||
if amount < 0 { | if amount < 0 { | ||||
zeroList[coinA.Cid] = struct{}{} | zeroList[coinA.Cid] = struct{}{} | ||||
amount = 0 | amount = 0 | ||||
@@ -39,7 +39,7 @@ func AddOneCirclesPublicPlatoonUserRelationCommission(engine *xorm.Engine, AddOn | |||||
if err11 != nil { | if err11 != nil { | ||||
return nil, err11 | return nil, err11 | ||||
} | } | ||||
if isHasOneCirclesPublicPlatoonUserRelation == nil { | |||||
if isHasOneCirclesPublicPlatoonUserRelation != nil { | |||||
return nil, errors.New("当前用户已加入公排") | return nil, errors.New("当前用户已加入公排") | ||||
} | } | ||||
@@ -122,7 +122,7 @@ func GetPlanCfg(eg *xorm.Engine, pvd, masterId string, rewardOpts map[string]*mo | |||||
if commissionOpt == nil || commissionOpt.Id == 0 { | if commissionOpt == nil || commissionOpt.Id == 0 { | ||||
return nil, errors.New("佣金方案有误") | return nil, errors.New("佣金方案有误") | ||||
} | } | ||||
if _, ok := comm_plan.Fn[commissionOpt.Mode]; !ok && zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"public_platoon", "extend_price", "lv_integral_release"}) == false { | |||||
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("分佣模式不存在") | return nil, zhios_order_relate_logx.Warn("分佣模式不存在") | ||||
} | } | ||||
opt.Pvd = pvd | opt.Pvd = pvd | ||||
@@ -156,7 +156,7 @@ func GetPlanCfg(eg *xorm.Engine, pvd, masterId string, rewardOpts map[string]*mo | |||||
} else { | } else { | ||||
opt.VirtualCoinMoneyRatioList = virtualCoinMoneyRate | opt.VirtualCoinMoneyRatioList = virtualCoinMoneyRate | ||||
} | } | ||||
if zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"public_platoon", "extend_price", "lv_integral_release"}) { //公排 | |||||
if zhios_order_relate_utils.InArr(commissionOpt.Mode, []string{"public_platoon_level", "public_platoon", "extend_price", "lv_integral_release"}) { //公排 | |||||
return opt, nil | return opt, nil | ||||
} | } | ||||
@@ -143,3 +143,103 @@ func benefitUidByBig(engine *xorm.Engine, param *md.PublicPlatoonRelateCommissio | |||||
return nowBenefitUid, nil, nil | return nowBenefitUid, nil, nil | ||||
} | } | ||||
func BatchGetPublicPlatoonRelateCommissionByOrderLevel(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) | |||||
} | |||||
} | |||||
nowBenefitUid, _, err := benefitUidByBig(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) | |||||
} | |||||
//直推獎勵 | |||||
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.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.DirectPush[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100) | |||||
} | |||||
} | |||||
} | |||||
//共富简历 | |||||
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 { | |||||
for _, coinId := range lvGrade.ReturnType { | |||||
var pendingAmount = param.PendingAmount | |||||
if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 | |||||
pendingAmount = param.PendingIntegral | |||||
} | |||||
commonWealthSystem[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.CommonWealthSystem[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100) | |||||
} | |||||
} | |||||
} | |||||
/// | |||||
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 | |||||
} |
@@ -117,7 +117,7 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b | |||||
if rmd.IsGoods == "1" { | if rmd.IsGoods == "1" { | ||||
order, err = BatchSmallGetPublicPlatoonRelateByGoods(engine, masterId, PublicPlatoonRelateCommissionReqList) | order, err = BatchSmallGetPublicPlatoonRelateByGoods(engine, masterId, PublicPlatoonRelateCommissionReqList) | ||||
} else { | } else { | ||||
order, err = BatchSmallGetPublicPlatoonRelateCommission(engine, masterId, PublicPlatoonRelateCommissionReqList) | |||||
order, err = BatchSmallGetPublicPlatoonRelateCommissionLevel(engine, masterId, PublicPlatoonRelateCommissionReqList) | |||||
} | } | ||||
if err != nil || order[rmd.Oid] == nil { | if err != nil || order[rmd.Oid] == nil { | ||||
return 0, 0, 0, 0, nil, nil | return 0, 0, 0, 0, nil, nil | ||||
@@ -142,7 +142,7 @@ func GetRewardCommission(engine *xorm.Engine, rmd *md.CommissionParam, isShare b | |||||
if rmd.IsGoods == "1" { | if rmd.IsGoods == "1" { | ||||
order, err = BatchGetPublicPlatoonRelateCommissionByGoods(engine, masterId, PublicPlatoonRelateCommissionReqList) | order, err = BatchGetPublicPlatoonRelateCommissionByGoods(engine, masterId, PublicPlatoonRelateCommissionReqList) | ||||
} else { | } else { | ||||
order, err = BatchGetPublicPlatoonRelateCommissionByOrder(engine, masterId, PublicPlatoonRelateCommissionReqList) | |||||
order, err = BatchGetPublicPlatoonRelateCommissionByOrderLevel(engine, masterId, PublicPlatoonRelateCommissionReqList) | |||||
} | } | ||||
if err != nil || order[rmd.Oid] == nil { | if err != nil || order[rmd.Oid] == nil { | ||||
return 0, 0, 0, 0, nil, nil | return 0, 0, 0, 0, nil, nil | ||||
@@ -322,7 +322,6 @@ func public(engine *xorm.Engine, ulinkParent *comm_plan.LvUser, cfg *comm_plan.P | |||||
CommonWealthSystems, ok := grade.CommonWealthSystem.(map[string]string) | CommonWealthSystems, ok := grade.CommonWealthSystem.(map[string]string) | ||||
if ok { | if ok { | ||||
commonWealthSystem[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(CommonWealthSystems[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100) | commonWealthSystem[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(CommonWealthSystems[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100) | ||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -355,3 +355,102 @@ func BatchSmallGetPublicPlatoonRelateByGoods(engine *xorm.Engine, masterId strin | |||||
} | } | ||||
return resp, nil | return resp, nil | ||||
} | } | ||||
func BatchSmallGetPublicPlatoonRelateCommissionLevel(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.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.SelfRateList[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100) | |||||
} | |||||
} | |||||
//TODO::本次消费产生的共富收益给到谁 | |||||
nowBenefitUid, _, err := benefitUid(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) | |||||
} | |||||
//直推獎勵 | |||||
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.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.DirectPush[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100) | |||||
} | |||||
} | |||||
} | |||||
//共富简历 | |||||
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 { | |||||
for _, coinId := range lvGrade.ReturnType { | |||||
var pendingAmount = param.PendingAmount | |||||
if zhios_order_relate_utils.StrToInt(coinId) > 0 { //积分更换基数 | |||||
pendingAmount = param.PendingIntegral | |||||
} | |||||
commonWealthSystem[coinId] = zhios_order_relate_utils.Float64ToStr(zhios_order_relate_utils.StrToFloat64(lvGrade.CommonWealthSystem[coinId]) * zhios_order_relate_utils.StrToFloat64(pendingAmount) / 100) | |||||
} | |||||
} | |||||
} | |||||
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 | |||||
} |