Commit ea79ac0e authored by chenweijian's avatar chenweijian

家族成员增加判断上限

parent 47229384
...@@ -40,6 +40,9 @@ func (this *GroupPower) Get(model *domain.Model) (*GroupPower, error) { ...@@ -40,6 +40,9 @@ func (this *GroupPower) Get(model *domain.Model) (*GroupPower, error) {
if err != nil && err != gorm.ErrRecordNotFound { if err != nil && err != gorm.ErrRecordNotFound {
return nil, err return nil, err
} }
if grade.GroupPowerId > 0 {
group.Grade = grade.Grade
}
return group, nil return group, nil
} }
...@@ -159,3 +162,12 @@ func IsExistsNameplate(model *domain.Model, nameplate string) bool { ...@@ -159,3 +162,12 @@ func IsExistsNameplate(model *domain.Model, nameplate string) bool {
} }
return false return false
} }
func GetMemberNum(model *domain.Model, familyId uint64) (int64, error) {
var count int64
err := model.Db.Model(GroupPowerUser{}).Where("group_power_id=?", familyId).Count(&count).Error
if err != nil {
return 0, err
}
return count, nil
}
...@@ -31,6 +31,7 @@ type GroupPower struct { ...@@ -31,6 +31,7 @@ type GroupPower struct {
Icon mysql.Str // 头像 Icon mysql.Str // 头像
GradeName mysql.Str // 等级称号 GradeName mysql.Str // 等级称号
GradeMedal mysql.Str // 等级勋章图片 GradeMedal mysql.Str // 等级勋章图片
Grade groupPower_e.GroupPowerGrade `gorm:"-"`
} }
type GroupPowerUser struct { type GroupPowerUser struct {
......
...@@ -92,6 +92,7 @@ var ( ...@@ -92,6 +92,7 @@ var (
GroupPowerCannotQuit = myerr.NewBusinessCode(15019, "Cannot quit", myerr.BusinessData{}) // 不能退出 GroupPowerCannotQuit = myerr.NewBusinessCode(15019, "Cannot quit", myerr.BusinessData{}) // 不能退出
GroupPowerUserHaveNoJoin = myerr.NewBusinessCode(15020, "User have no joined power", myerr.BusinessData{}) // 还未加入国家势力 GroupPowerUserHaveNoJoin = myerr.NewBusinessCode(15020, "User have no joined power", myerr.BusinessData{}) // 还未加入国家势力
GroupPowerChangeNameplate = myerr.NewBusinessCode(15021, "Can only be modified at the silver level", myerr.BusinessData{}) // 修改铭牌不够等级 GroupPowerChangeNameplate = myerr.NewBusinessCode(15021, "Can only be modified at the silver level", myerr.BusinessData{}) // 修改铭牌不够等级
GroupPowerMemberMax = myerr.NewBusinessCode(15022, "The family size has reached the upper limit", myerr.BusinessData{}) // 家族人数达到上限
TaskHasAward = myerr.NewBusinessCode(19001, "task has award", myerr.BusinessData{}) TaskHasAward = myerr.NewBusinessCode(19001, "task has award", myerr.BusinessData{})
......
...@@ -743,7 +743,6 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -743,7 +743,6 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) {
for _, v := range members { for _, v := range members {
resMembers = append(resMembers, &group_power_cv.GroupPowerUser{User: userMap[v.UserId], Role: v.Role}) resMembers = append(resMembers, &group_power_cv.GroupPowerUser{User: userMap[v.UserId], Role: v.Role})
} }
groupPowerGrade, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{gp.ID})
gradeM, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{gp.ID}) gradeM, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{gp.ID})
if err != nil { if err != nil {
return myContext, err return myContext, err
...@@ -756,7 +755,7 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -756,7 +755,7 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) {
info := &group_power_cv.GroupPower{ info := &group_power_cv.GroupPower{
Id: gpInfo.ID, Name: gpInfo.Name, Nameplate: gpInfo.Nameplate, Declaration: gpInfo.Declaration, Icon: gpInfo.Icon, Id: gpInfo.ID, Name: gpInfo.Name, Nameplate: gpInfo.Nameplate, Declaration: gpInfo.Declaration, Icon: gpInfo.Icon,
Grade: grade.Grade, Exp: grade.Exp, NextExp: nextExp, GradeName: gpInfo.GradeName, GradeMedal: gpInfo.GradeMedal, Grade: grade.Grade, Exp: grade.Exp, NextExp: nextExp, GradeName: gpInfo.GradeName, GradeMedal: gpInfo.GradeMedal,
MemberNum: mysql.Num(total), MemberMax: mysql.Num(group_power_cv.GroupPowerGradePrivilegeNum[groupPowerGrade[gp.ID].Grade][0].Num), MemberNum: mysql.Num(total), MemberMax: mysql.Num(group_power_cv.GroupPowerGradePrivilegeNum[grade.Grade][0].Num),
} }
if info.Icon != "" { if info.Icon != "" {
info.Icon = common.MakeFullUrl(info.Icon) info.Icon = common.MakeFullUrl(info.Icon)
...@@ -975,6 +974,15 @@ func GroupPowerApplyJoin(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -975,6 +974,15 @@ func GroupPowerApplyJoin(c *gin.Context) (*mycontext.MyContext, error) {
if len(uList) > 0 { if len(uList) > 0 {
return myContext, bizerr.GroupPowerHasJoinOther return myContext, bizerr.GroupPowerHasJoinOther
} }
// 判断家族是否满人了
nowNum, err := groupPower_m.GetMemberNum(model, familyId)
if err != nil {
return myContext, myerr.WrapErr(err)
}
maxNum := group_power_cv.GroupPowerGradePrivilegeNum[gpInfo.Grade][0].Num
if nowNum+1 > int64(maxNum) {
return myContext, bizerr.GroupPowerMemberMax
}
// 插入申请表 // 插入申请表
err = groupPower_m.InsertGroupPowerApplyJoin(model, userId, gpInfo.ID) err = groupPower_m.InsertGroupPowerApplyJoin(model, userId, gpInfo.ID)
...@@ -1046,6 +1054,20 @@ func GroupPowerApplyPass(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -1046,6 +1054,20 @@ func GroupPowerApplyPass(c *gin.Context) (*mycontext.MyContext, error) {
resp.ResponseOk(c, nil) resp.ResponseOk(c, nil)
return myContext, nil return myContext, nil
} }
// 判断家族是否满人了
nowNum, err := groupPower_m.GetMemberNum(model, apply.GroupPowerId)
if err != nil {
return myContext, myerr.WrapErr(err)
}
gradeM, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{apply.GroupPowerId})
if err != nil {
return myContext, err
}
grade := gradeM[apply.GroupPowerId]
maxNum := group_power_cv.GroupPowerGradePrivilegeNum[grade.Grade][0].Num
if int(nowNum+1) > maxNum {
return myContext, bizerr.GroupPowerMemberMax
}
err = model.Transaction(func(model *domain.Model) error { err = model.Transaction(func(model *domain.Model) error {
txModel := domain.CreateModel(model.CtxAndDb) txModel := domain.CreateModel(model.CtxAndDb)
...@@ -1056,6 +1078,15 @@ func GroupPowerApplyPass(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -1056,6 +1078,15 @@ func GroupPowerApplyPass(c *gin.Context) (*mycontext.MyContext, error) {
txModel.Log.Errorf("GroupPowerApplyPass err:%v, info:%v", err, gpU) txModel.Log.Errorf("GroupPowerApplyPass err:%v, info:%v", err, gpU)
return err return err
} }
newNum, err := groupPower_m.GetMemberNum(txModel, apply.GroupPowerId)
if err != nil {
txModel.Log.Errorf("GroupPowerApplyPass err:%v, info:%v", err, gpU)
return err
}
if int(newNum) > maxNum {
txModel.Log.Errorf("GroupPowerApplyPass err:%v, info:%v", bizerr.GroupPowerMemberMax, gpU)
return bizerr.GroupPowerMemberMax
}
// 更改申请表状态 // 更改申请表状态
err = groupPower_m.OptGroupPowerApplyJoinById(model, apply.Id, userId, optType) err = groupPower_m.OptGroupPowerApplyJoinById(model, apply.Id, userId, optType)
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment