Browse Source

update

master
dengbiao 2 months ago
parent
commit
22904c7f93
4 changed files with 65 additions and 34 deletions
  1. +1
    -1
      go.mod
  2. +1
    -0
      go.sum
  3. +62
    -33
      rule/service_award_dividend/index.go
  4. +1
    -0
      rule/service_award_dividend/md/service_award_dividend.go

+ 1
- 1
go.mod View File

@@ -7,7 +7,7 @@ go 1.15


require ( require (
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 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/gin-gonic/gin v1.9.1
github.com/go-redis/redis v6.15.9+incompatible github.com/go-redis/redis v6.15.9+incompatible
github.com/gomodule/redigo v1.8.9 github.com/gomodule/redigo v1.8.9


+ 1
- 0
go.sum View File

@@ -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.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 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.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 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s= gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=


+ 62
- 33
rule/service_award_dividend/index.go View File

@@ -60,14 +60,14 @@ func JoinServiceAwardDividendRelation(eg *xorm.Engine, masterId string, req md.J
if levelMap[user.Level].LevelWeight >= levelMap[parentUser.Level].LevelWeight { if levelMap[user.Level].LevelWeight >= levelMap[parentUser.Level].LevelWeight {
for _, vv := range vipAllocationSetStruct { for _, vv := range vipAllocationSetStruct {
if vv.FromVipId == user.Level { if vv.FromVipId == user.Level {
err = AutoAddVip(eg, user, req.ParentUid, vv)
err = AutoAddVip(eg, user, req.ParentUid, vv, req.RegionId)
if err != nil { if err != nil {
return err return err
} }
} }
} }
} else { } else {
err = AddVipToParent(eg, user, req.ParentUid)
err = AddVipToParent(eg, user, req.ParentUid, req.RegionId)
if err != nil { if err != nil {
return err return err
} }
@@ -75,7 +75,7 @@ func JoinServiceAwardDividendRelation(eg *xorm.Engine, masterId string, req md.J
} else { } else {
for _, vv := range vipAllocationSetStruct { for _, vv := range vipAllocationSetStruct {
if vv.FromVipId == user.Level { if vv.FromVipId == user.Level {
err = AutoAddVip(eg, user, req.ParentUid, vv)
err = AutoAddVip(eg, user, req.ParentUid, vv, req.RegionId)
if err != nil { if err != nil {
return err return err
} }
@@ -87,15 +87,21 @@ func JoinServiceAwardDividendRelation(eg *xorm.Engine, masterId string, req md.J
} }


// AutoAddVip 自动添加会员 // 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、查询出当前应该分配给哪个上级会员 //1、查询出当前应该分配给哪个上级会员
var serviceAwardDividendRelation models.ServiceAwardDividendRelation 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() now := time.Now()
@@ -109,36 +115,59 @@ func AutoAddVip(engine *xorm.Engine, user *model.User, parentUid int, vipAllocat
}() }()
sess.Begin() 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() return sess.Commit()
} }


// AddVipToParent 添加会员至父级 // 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、查询出当前应该分配给哪个上级会员 //1、查询出当前应该分配给哪个上级会员
var serviceAwardDividendRelation models.ServiceAwardDividendRelation var serviceAwardDividendRelation models.ServiceAwardDividendRelation
has, err := engine.Where("uid =?", parentUid).Get(&serviceAwardDividendRelation) has, err := engine.Where("uid =?", parentUid).Get(&serviceAwardDividendRelation)


+ 1
- 0
rule/service_award_dividend/md/service_award_dividend.go View File

@@ -8,4 +8,5 @@ type VipAllocationSetStruct struct {
type JoinServiceAwardDividendRelationReq struct { type JoinServiceAwardDividendRelationReq struct {
Uid int `json:"uid"` //用户id Uid int `json:"uid"` //用户id
ParentUid int `json:"parent_uid"` //父级id ParentUid int `json:"parent_uid"` //父级id
RegionId int `json:"region_id"` //用户区域id
} }

Loading…
Cancel
Save