diff --git a/go.mod b/go.mod index 1510561..f3528e3 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ go 1.15 require ( code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 - code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240805074152-3ee9fa9e2938 + code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240805085726-a0042fa1ed3c github.com/gin-gonic/gin v1.9.1 github.com/go-redis/redis v6.15.9+incompatible github.com/gomodule/redigo v1.8.9 diff --git a/go.sum b/go.sum index 84a4178..7565f90 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,7 @@ code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240723073901-849ec3e code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240723073901-849ec3e356f3/go.mod h1:nT2x13YFgrS3tS1fDyUR6q/GNIK+hPw7bdzZXz99SM0= code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240805064206-7176a3f52675 h1:CHFIwllR+HxDvhOsrW2+h/riCpAclOVbPh5xm63530w= code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240805064206-7176a3f52675/go.mod h1:nT2x13YFgrS3tS1fDyUR6q/GNIK+hPw7bdzZXz99SM0= +code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20240805074152-3ee9fa9e2938/go.mod h1:nT2x13YFgrS3tS1fDyUR6q/GNIK+hPw7bdzZXz99SM0= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s= diff --git a/rule/service_award_dividend/index.go b/rule/service_award_dividend/index.go index 4cddc96..9b222ac 100644 --- a/rule/service_award_dividend/index.go +++ b/rule/service_award_dividend/index.go @@ -60,14 +60,14 @@ func JoinServiceAwardDividendRelation(eg *xorm.Engine, masterId string, req md.J if levelMap[user.Level].LevelWeight >= levelMap[parentUser.Level].LevelWeight { for _, vv := range vipAllocationSetStruct { if vv.FromVipId == user.Level { - err = AutoAddVip(eg, user, req.ParentUid, vv) + err = AutoAddVip(eg, user, req.ParentUid, vv, req.RegionId) if err != nil { return err } } } } else { - err = AddVipToParent(eg, user, req.ParentUid) + err = AddVipToParent(eg, user, req.ParentUid, req.RegionId) if err != nil { return err } @@ -75,7 +75,7 @@ func JoinServiceAwardDividendRelation(eg *xorm.Engine, masterId string, req md.J } else { for _, vv := range vipAllocationSetStruct { if vv.FromVipId == user.Level { - err = AutoAddVip(eg, user, req.ParentUid, vv) + err = AutoAddVip(eg, user, req.ParentUid, vv, req.RegionId) if err != nil { return err } @@ -87,15 +87,21 @@ func JoinServiceAwardDividendRelation(eg *xorm.Engine, masterId string, req md.J } // AutoAddVip 自动添加会员 -func AutoAddVip(engine *xorm.Engine, user *model.User, parentUid int, vipAllocationSetStruct md.VipAllocationSetStruct) (err error) { +func AutoAddVip(engine *xorm.Engine, user *model.User, parentUid int, vipAllocationSetStruct md.VipAllocationSetStruct, regionId int) (err error) { //1、查询出当前应该分配给哪个上级会员 var serviceAwardDividendRelation models.ServiceAwardDividendRelation - has, err := engine.In("vip_level", vipAllocationSetStruct.ToVipId).Asc("allocation_nums").Get(&serviceAwardDividendRelation) - if err != nil { - return err + var hasServiceAwardDividendRelation bool + if regionId != 0 { + hasServiceAwardDividendRelation, err = engine.Where("region_id =?", regionId).In("vip_level", vipAllocationSetStruct.ToVipId).Asc("allocation_nums").Get(&serviceAwardDividendRelation) + if err != nil { + return err + } } - if has == false { - return errors.New("未查询到合适的绑定上级会员用户!") + if !hasServiceAwardDividendRelation { + hasServiceAwardDividendRelation, err = engine.In("vip_level", vipAllocationSetStruct.ToVipId).Asc("allocation_nums").Get(&serviceAwardDividendRelation) + if err != nil { + return err + } } now := time.Now() @@ -109,36 +115,59 @@ func AutoAddVip(engine *xorm.Engine, user *model.User, parentUid int, vipAllocat }() sess.Begin() - //2、新增 service_award_dividend_relation 记录 - serviceAwardDividendRelationDb := implement.NewServiceAwardDividendRelationDb(engine) - _, err = serviceAwardDividendRelationDb.InsertServiceAwardDividendRelationBySess(sess, &models.ServiceAwardDividendRelation{ - Uid: user.Uid, - ParentUid: parentUid, - BindUid: serviceAwardDividendRelation.Uid, - VipLevel: user.Level, - AllocationNums: 0, - CreateAt: now.Format("2006-01-02 15:04:05"), - UpdateAt: now.Format("2006-01-02 15:04:05"), - }) - if err != nil { - sess.Rollback() - return err - } + if hasServiceAwardDividendRelation == false { + //return errors.New("未查询到合适的绑定上级会员用户!") + //TODO::未查询到合适的绑定上级会员用户时(新增 service_award_dividend_relation 记录) + serviceAwardDividendRelationDb := implement.NewServiceAwardDividendRelationDb(engine) + _, err = serviceAwardDividendRelationDb.InsertServiceAwardDividendRelationBySess(sess, &models.ServiceAwardDividendRelation{ + Uid: user.Uid, + ParentUid: parentUid, + BindUid: 0, + VipLevel: user.Level, + AllocationNums: 0, + RegionId: regionId, + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + if err != nil { + sess.Rollback() + return err + } + return + } else { + //2、新增 service_award_dividend_relation 记录 + serviceAwardDividendRelationDb := implement.NewServiceAwardDividendRelationDb(engine) + _, err = serviceAwardDividendRelationDb.InsertServiceAwardDividendRelationBySess(sess, &models.ServiceAwardDividendRelation{ + Uid: user.Uid, + ParentUid: parentUid, + BindUid: serviceAwardDividendRelation.Uid, + VipLevel: user.Level, + AllocationNums: 0, + RegionId: regionId, + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + if err != nil { + sess.Rollback() + return err + } - //3、修改 绑定上级的 service_award_dividend_relation 记录 - serviceAwardDividendRelation.AllocationNums++ - updateRelationAfftecd, err := serviceAwardDividendRelationDb.SaveServiceAwardDividendRelation(sess, serviceAwardDividendRelation.Id, &serviceAwardDividendRelation, "allocation_nums") - if err != nil { - return err - } - if updateRelationAfftecd <= 0 { - return errors.New("更新 绑定上级的 service_award_dividend_relation 记录 失败!") + //3、修改 绑定上级的 service_award_dividend_relation 记录 + serviceAwardDividendRelation.AllocationNums++ + updateRelationAfftecd, err := serviceAwardDividendRelationDb.SaveServiceAwardDividendRelation(sess, serviceAwardDividendRelation.Id, &serviceAwardDividendRelation, "allocation_nums") + if err != nil { + return err + } + if updateRelationAfftecd <= 0 { + return errors.New("更新 绑定上级的 service_award_dividend_relation 记录 失败!") + } } + return sess.Commit() } // AddVipToParent 添加会员至父级 -func AddVipToParent(engine *xorm.Engine, user *model.User, parentUid int) (err error) { +func AddVipToParent(engine *xorm.Engine, user *model.User, parentUid int, regionId int) (err error) { //1、查询出当前应该分配给哪个上级会员 var serviceAwardDividendRelation models.ServiceAwardDividendRelation has, err := engine.Where("uid =?", parentUid).Get(&serviceAwardDividendRelation) diff --git a/rule/service_award_dividend/md/service_award_dividend.go b/rule/service_award_dividend/md/service_award_dividend.go index e72e589..af04a83 100644 --- a/rule/service_award_dividend/md/service_award_dividend.go +++ b/rule/service_award_dividend/md/service_award_dividend.go @@ -8,4 +8,5 @@ type VipAllocationSetStruct struct { type JoinServiceAwardDividendRelationReq struct { Uid int `json:"uid"` //用户id ParentUid int `json:"parent_uid"` //父级id + RegionId int `json:"region_id"` //用户区域id }