From ffb7acdc21613339e957894121df981950524ba2 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Mon, 20 Mar 2023 16:05:14 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E8=A1=A5=E4=B8=8A=E7=AD=89?= =?UTF-8?q?=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv/group_power_cv/groupPower.go | 30 ++++++++++++------------- domain/model/groupPower_m/family.go | 6 ----- domain/model/groupPower_m/groupPower.go | 3 --- route/group_power_r/group_power.go | 28 ++++++++++++++++++----- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/cv/group_power_cv/groupPower.go b/cv/group_power_cv/groupPower.go index 4c9522d..ff988db 100644 --- a/cv/group_power_cv/groupPower.go +++ b/cv/group_power_cv/groupPower.go @@ -657,21 +657,21 @@ type GroupPowerInfo struct { } type GroupPower struct { - Id uint64 `json:"id"` - Name string `json:"name"` - Nameplate string `json:"nameplate"` // 铭牌 - Declaration string `json:"declaration"` // 宣言 - Icon string `json:"icon"` // 头像 - Grade mysql.Num `json:"grade" gorm:"-"` // 等级 - Exp mysql.Num `json:"exp" gorm:"-"` // 当前经验值 - NextExp mysql.Num `json:"nextExp" gorm:"-"` // 升到下一级需要的经验值 - GradeName mysql.Str `json:"gradeName"` // 等级称号 - GradeMedal mysql.Str `json:"gradeMedal"` // 等级勋章图片 - MemberNum mysql.Num `json:"memberNum" gorm:"-"` // 当前人数 - MemberMax mysql.Num `json:"memberMax" gorm:"-"` // 最大人数 - Role int `json:"role" gorm:"-"` // 我在此家族中的角色 0.路人 1.成员 2.家族长 3.管理员 - IsApply bool `json:"isApply" gorm:"-"` // 最大人数 - MonthRank int `json:"monthRank" gorm:"-"` // 家族月排名 + Id uint64 `json:"id"` + Name string `json:"name"` + Nameplate string `json:"nameplate"` // 铭牌 + Declaration string `json:"declaration"` // 宣言 + Icon string `json:"icon"` // 头像 + Grade groupPower_e.GroupPowerGrade `json:"grade" gorm:"-"` // 等级 + Exp mysql.Num `json:"exp" gorm:"-"` // 当前经验值 + NextExp mysql.Num `json:"nextExp" gorm:"-"` // 升到下一级需要的经验值 + GradeName mysql.Str `json:"gradeName"` // 等级称号 + GradeMedal mysql.Str `json:"gradeMedal"` // 等级勋章图片 + MemberNum mysql.Num `json:"memberNum" gorm:"-"` // 当前人数 + MemberMax mysql.Num `json:"memberMax" gorm:"-"` // 最大人数 + Role int `json:"role" gorm:"-"` // 我在此家族中的角色 0.路人 1.成员 2.家族长 3.管理员 + IsApply bool `json:"isApply" gorm:"-"` // 最大人数 + MonthRank int `json:"monthRank" gorm:"-"` // 家族月排名 } type GroupPowerUser struct { diff --git a/domain/model/groupPower_m/family.go b/domain/model/groupPower_m/family.go index a2a0791..4a07f1b 100644 --- a/domain/model/groupPower_m/family.go +++ b/domain/model/groupPower_m/family.go @@ -2,7 +2,6 @@ package groupPower_m import ( "git.hilo.cn/hilo-common/domain" - "git.hilo.cn/hilo-common/resource/mysql" "gorm.io/gorm" "hilo-group/_const/enum/groupPower_e" "hilo-group/common" @@ -41,11 +40,6 @@ func (this *GroupPower) Get(model *domain.Model) (*GroupPower, error) { if err != nil && err != gorm.ErrRecordNotFound { return nil, err } - if grade.GroupPowerId > 0 { - group.Grade = mysql.Num(grade.Grade) - group.Exp = mysql.Num(grade.Exp) - group.NextExp = mysql.Num(grade.Exp) - } return group, nil } diff --git a/domain/model/groupPower_m/groupPower.go b/domain/model/groupPower_m/groupPower.go index 19a4cd7..12c7f1a 100644 --- a/domain/model/groupPower_m/groupPower.go +++ b/domain/model/groupPower_m/groupPower.go @@ -29,9 +29,6 @@ type GroupPower struct { Nameplate mysql.Str // 铭牌 Declaration mysql.Str // 宣言 Icon mysql.Str // 头像 - Grade mysql.Num `gorm:"-"` // 等级 - Exp mysql.Num `gorm:"-"` // 当前经验值 - NextExp mysql.Num `gorm:"-"` // 升到下一级需要的经验值 GradeName mysql.Str // 等级称号 GradeMedal mysql.Str // 等级勋章图片 } diff --git a/route/group_power_r/group_power.go b/route/group_power_r/group_power.go index 1d11c61..84ee767 100644 --- a/route/group_power_r/group_power.go +++ b/route/group_power_r/group_power.go @@ -744,9 +744,18 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) { 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}) + if err != nil { + return myContext, err + } + grade := gradeM[gp.ID] + nextExp := mysql.Num(0) + if grade.Grade != groupPower_e.GroupPowerGradeMax { + nextExp = groupPower_e.GroupPowerGradeExp[grade.Grade+1] + } info := &group_power_cv.GroupPower{ Id: gpInfo.ID, Name: gpInfo.Name, Nameplate: gpInfo.Nameplate, Declaration: gpInfo.Declaration, Icon: gpInfo.Icon, - Grade: gpInfo.Grade, Exp: gpInfo.Exp, NextExp: gpInfo.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), } if info.Icon != "" { @@ -1399,12 +1408,12 @@ func GroupPowerSetInfo(c *gin.Context) (*mycontext.MyContext, error) { // 检查铭牌是否能够修改 if para.Nameplate != "" { // 等级检查 - gp := &groupPower_m.GroupPower{Entity: mysql.Entity{ID: myGroupPUser.GroupPowerId}} - groupPInfo, err := gp.Get(model) + gradeM, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{myGroupPUser.GroupPowerId}) if err != nil { return myContext, err } - if groupPInfo.Grade < 1 { + grade := gradeM[myGroupPUser.GroupPowerId] + if grade.Grade < 1 { return myContext, bizerr.GroupPowerChangeNameplate } // 检查铭牌长度和唯一性 @@ -1433,9 +1442,18 @@ func GroupPowerSetInfo(c *gin.Context) (*mycontext.MyContext, error) { return myContext, myerr.WrapErr(err) } groupPowerGrade, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{gp.ID}) + gradeM, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{gp.ID}) + if err != nil { + return myContext, err + } + grade := gradeM[gp.ID] + nextExp := mysql.Num(0) + if grade.Grade != groupPower_e.GroupPowerGradeMax { + nextExp = groupPower_e.GroupPowerGradeExp[grade.Grade+1] + } info := &group_power_cv.GroupPower{ Id: gpInfo.ID, Name: gpInfo.Name, Nameplate: gpInfo.Nameplate, Declaration: gpInfo.Declaration, Icon: gpInfo.Icon, - Grade: gpInfo.Grade, Exp: gpInfo.Exp, NextExp: gpInfo.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), } if info.Icon != "" { -- 2.22.0