From 581123146cfa455894757bdf7852691e733e0696 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Wed, 13 Sep 2023 18:28:50 +0800 Subject: [PATCH] update --- ...ser_public_platoon_laxin_reward_setting.go | 13 +++ md/small_public_platoon_relate_commission.go | 11 +++ .../small_public_platoon_relate_commission.go | 9 ++ svc/small_public_platoon_relate_commission.go | 86 +++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 db/model/user_public_platoon_laxin_reward_setting.go diff --git a/db/model/user_public_platoon_laxin_reward_setting.go b/db/model/user_public_platoon_laxin_reward_setting.go new file mode 100644 index 0000000..35692b6 --- /dev/null +++ b/db/model/user_public_platoon_laxin_reward_setting.go @@ -0,0 +1,13 @@ +package model + +import "time" + +type UserPublicPlatoonLaxinRewardSetting struct { + Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` + IsUse int `json:"is_use" xorm:"default 0 comment('是否在使用,1:是,0,否') TINYINT(1)"` + IsUseRewardLimit int `json:"is_use_reward_limit" xorm:"default 0 comment('是否开启奖励限制(奖励积分只能获取等级与自己一样或等级低的人的奖励积分) ') TINYINT(1)"` + CoinId int `json:"coin_id" xorm:"INT(11)"` + Detail string `json:"detail" xorm:"TEXT"` + CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') TIMESTAMP"` + UpdateAt time.Time `json:"update_at" xorm:"default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"` +} diff --git a/md/small_public_platoon_relate_commission.go b/md/small_public_platoon_relate_commission.go index a7db17f..3092a08 100644 --- a/md/small_public_platoon_relate_commission.go +++ b/md/small_public_platoon_relate_commission.go @@ -31,6 +31,17 @@ type SmallPublicPlatoonRelateCommissionResp struct { PendingIntegral string `json:"pending_integral"` //待处理金额 } +type CalcSmallPublicPlatoonRelateLaXinReward struct { + Uid string `json:"uid"` + CoinId int `json:"coin_id"` + Value string `json:"value"` +} + +type CalcSmallPublicPlatoonRelateLaXinDetail struct { + Key int `json:"key"` + Val interface{} `json:"val"` +} + type SmallAddPublicPlatoonRelateCommissionReq struct { Uid string `json:"uid"` RecommendUid string `json:"recommend_uid"` //推荐人uid diff --git a/rule/small_public_platoon_relate_commission.go b/rule/small_public_platoon_relate_commission.go index fc6de21..53b11cd 100644 --- a/rule/small_public_platoon_relate_commission.go +++ b/rule/small_public_platoon_relate_commission.go @@ -25,6 +25,15 @@ func BatchGetSmallPublicPlatoonRelateCommissionByOrder(engine *xorm.Engine, mast return resp, nil } +// CalcSmallPublicPlatoonRelateLaXinReward 计算拉新奖励 +func CalcSmallPublicPlatoonRelateLaXinReward(engine *xorm.Engine, masterId string, rewardUid int) ([]*md.CalcSmallPublicPlatoonRelateLaXinReward, error) { + resp, err := svc.CalcSmallPublicPlatoonRelateLaXinReward(engine, masterId, rewardUid) + if err != nil { + return nil, err + } + return resp, nil +} + // AddSmallPublicPlatoonRelateCommission 新增小公排用户关系记录 func AddSmallPublicPlatoonRelateCommission(engine *xorm.Engine, AddSmallPublicPlatoonRelateCommissionReqList []*md.SmallAddPublicPlatoonRelateCommissionReq) (map[string]*model.UserSmallPublicPlatoonRelation, error) { var resp = map[string]*model.UserSmallPublicPlatoonRelation{} diff --git a/svc/small_public_platoon_relate_commission.go b/svc/small_public_platoon_relate_commission.go index 0ee2cb3..6e7d4ac 100644 --- a/svc/small_public_platoon_relate_commission.go +++ b/svc/small_public_platoon_relate_commission.go @@ -2,6 +2,7 @@ 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/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" @@ -145,6 +146,91 @@ func BatchSmallGetPublicPlatoonRelateCommission(engine *xorm.Engine, masterId st return resp, nil } +func CalcSmallPublicPlatoonRelateLaXinReward(engine *xorm.Engine, masterId string, rewardUid int) (resp []*md.CalcSmallPublicPlatoonRelateLaXinReward, err error) { + userPublicPlatoonRelation, err := db.UserSmallPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{ + "key": "uid", + "value": rewardUid, + }) + if err != nil { + return nil, err + } + if userPublicPlatoonRelation == nil { + return nil, errors.New("未查询到公排关系记录") + } + if userPublicPlatoonRelation.FatherUid == "" { + //TODO::原始创始人 + return + } else { + //1、查询 user_public_platoon_laxin_reward_setting + var m model.UserPublicPlatoonLaxinRewardSetting + has, err1 := engine.Where("id >= 1").Get(&m) + if err1 != nil { + return nil, zhios_order_relate_logx.Error(err1) + } + if has == false { + return + } + if m.IsUse == 0 { + return + } + + //2、解析 detail + var detail []*md.CalcSmallPublicPlatoonRelateLaXinDetail + if err2 := json.Unmarshal([]byte(m.Detail), &detail); err != nil { + return nil, err2 + } + + fatherPositions := strings.Split(userPublicPlatoonRelation.FatherUid, "-") + var rewardUserLevelWeight int + if m.IsUseRewardLimit == 1 { + //3、判断是否开启奖励限制 + rewardUser, err3 := db.UserFindByID(engine, rewardUid) + if err3 != nil { + return nil, err3 + } + + rewardUserLevel, err4 := db.UserLevelByID(engine, rewardUser.Level) + if err4 != nil { + return nil, err4 + } + if rewardUserLevel == nil { + return nil, errors.New("未查询到对应等级") + } + rewardUserLevelWeight = rewardUserLevel.LevelWeight + } + + for k, v := range fatherPositions { + if m.IsUseRewardLimit == 1 { + //查询对应用户的等级 + tmpUser, err3 := db.UserFindByID(engine, v) + if err3 != nil { + return nil, err3 + } + + tmpUserLevel, err4 := db.UserLevelByID(engine, tmpUser.Level) + if err4 != nil { + return nil, err4 + } + if tmpUserLevel == nil { + return nil, errors.New("未查询到奖励用户对应等级") + } + if tmpUserLevel.LevelWeight < rewardUserLevelWeight { + //奖励人等级小于 + continue + } + } + value, _ := zhios_order_relate_utils.InterfaceToString(detail[k].Val) + tmp := md.CalcSmallPublicPlatoonRelateLaXinReward{ + Uid: v, + CoinId: m.CoinId, + Value: value, + } + resp = append(resp, &tmp) + } + } + return resp, nil +} + func BatchSmallGetPublicPlatoonRelateByGoods(engine *xorm.Engine, masterId string, PublicPlatoonRelateCommissionReqList []*md.SmallPublicPlatoonRelateCommissionReq) (map[string]*md.SmallPublicPlatoonRelateCommissionResp, error) { var resp = make(map[string]*md.SmallPublicPlatoonRelateCommissionResp) for _, param := range PublicPlatoonRelateCommissionReqList {