From 623b6af8b724b37425b9ff73a1e25d78c331b7ba Mon Sep 17 00:00:00 2001 From: hujiebin Date: Thu, 9 Mar 2023 18:28:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=AD=89=E7=BA=A7=E6=98=8E=E7=BB=86?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _const/enum/groupPower_e/grade.go | 23 +++-- cv/group_power_cv/group_rank.go | 92 +++++++++++++++++-- domain/model/groupPower_m/group_grade.go | 2 +- route/group_power_r/group_rank.go | 107 +++++++++++++++++++---- route/router.go | 1 + 5 files changed, 194 insertions(+), 31 deletions(-) diff --git a/_const/enum/groupPower_e/grade.go b/_const/enum/groupPower_e/grade.go index 8c0b6d9..d504b38 100644 --- a/_const/enum/groupPower_e/grade.go +++ b/_const/enum/groupPower_e/grade.go @@ -1,22 +1,35 @@ package groupPower_e +import "git.hilo.cn/hilo-common/resource/mysql" + type GroupPowerGrade int const ( GroupPowerGrade0 GroupPowerGrade = 0 - GroupPowerGrade1 GroupPowerGrade = 1 - GroupPowerGrade2 GroupPowerGrade = 2 - GroupPowerGrade3 GroupPowerGrade = 3 - GroupPowerGrade4 GroupPowerGrade = 4 + GroupPowerGrade1 GroupPowerGrade = 1 // 青铜 + GroupPowerGrade2 GroupPowerGrade = 2 // 白银 + GroupPowerGrade3 GroupPowerGrade = 3 // 黄金 + GroupPowerGrade4 GroupPowerGrade = 4 // 黑金 GroupPowerGradeMax = GroupPowerGrade4 ) var ( - GroupPowerGradeExp = map[GroupPowerGrade]int64{ + GroupPowerGradeExp = map[GroupPowerGrade]mysql.Num{ GroupPowerGrade1: 2500000, GroupPowerGrade2: 15000000, GroupPowerGrade3: 45000000, // todo GroupPowerGrade4: 60000000, } ) + +type GroupPowerPrivilege int + +const ( + GroupPowerPrivilegeMemberNum GroupPowerPrivilege = 1 // 成员数 + GroupPowerPrivilegeMgrNum GroupPowerPrivilege = 2 // 管理员数 + GroupPowerPrivilegeNameplate GroupPowerPrivilege = 3 // 家族铭牌 + GroupPowerPrivilegeMedal GroupPowerPrivilege = 4 // 家族徽章装饰 + GroupPowerPrivilegeNameplateEdit GroupPowerPrivilege = 5 // 编辑铭牌 + GroupPowerPrivilegeNameplateHeadwear GroupPowerPrivilege = 6 // 家族头饰 +) diff --git a/cv/group_power_cv/group_rank.go b/cv/group_power_cv/group_rank.go index 2987c6f..b15675f 100644 --- a/cv/group_power_cv/group_rank.go +++ b/cv/group_power_cv/group_rank.go @@ -6,20 +6,33 @@ import ( "hilo-group/cv/user_cv" ) +// 家族基本信息 +type CvGroupPowerInfo struct { + GroupPowerId mysql.ID `json:"groupPowerId"` // 家族id + Icon string `json:"icon"` // 家族图片 + Name string `json:"name"` // 家族名 + Nameplate string `json:"nameplate"` // 铭牌 +} + +// 家族等级 +type CvGroupPowerGrade struct { + Grade groupPower_e.GroupPowerGrade `json:"grade"` // 等级 0:无 1:青铜 2:白银 3:黄金 4:黑金 + Exp mysql.Num `json:"exp"` // 经验值 + NextExp mysql.Num `json:"nextExp,omitempty"` // 升级所需经验值 + ExpireAt string `json:"expireAt,omitempty"` // 有效期 + ShowExp bool `json:"showExp"` // 是否展示经验值 +} + // 家族榜单 type CvGroupPowerRank struct { - MyGroupPower CvGroupPowerRankData `json:"myGroupPower"` - Items []CvGroupPowerRankData `json:"items"` + MyGroupPower CvGroupPowerRankData `json:"myGroupPower"` // 我的家族排名 + Items []CvGroupPowerRankData `json:"items"` // 列表 } type CvGroupPowerRankData struct { - GroupPowerId mysql.ID `json:"groupPowerId"` // 家族id - Icon string `json:"icon"` // 家族图片 - Name string `json:"name"` // 家族名 - Nameplate string `json:"nameplate"` // 铭牌 - Grade groupPower_e.GroupPowerGrade `json:"grade"` // 等级 0:无 1:青铜 2:白银 3:黄金 4:黑金 - Exp mysql.Num `json:"exp"` // 经验值 - Rank int `json:"rank"` // 排名 + CvGroupPowerInfo `json:",inline"` + CvGroupPowerGrade `json:",inline"` + Rank int `json:"rank"` // 排名 } // 家族之星 @@ -27,3 +40,64 @@ type CvGroupPowerStarData struct { user_cv.CvUserTiny `json:",inline"` Score mysql.Num `json:"score"` // 对应分值 } + +// 资源等级 +type CvResGrade struct { + Grade groupPower_e.GroupPowerGrade `json:"grade"` // 等级 + Icon string `json:"icon"` // 等级icon + BigIcon string `json:"bigIcon"` // 等级大图标 +} + +// 特权信息 +type CvPrivilege struct { + Type groupPower_e.GroupPowerPrivilege `json:"type"` // 特权id 1:成员数 2:管理员数 3:家族铭牌 4:家族徽章装饰 5:编辑铭牌 6:家族头饰 + Num int `json:"num"` // 数目 +} + +// 家族等级页 +type CvGroupPowerGradeDetail struct { + GroupPowerInfo CvGroupPowerInfo `json:"groupPowerInfo"` // 家族基本信息 + GroupPowerGrade CvGroupPowerGrade `json:"groupPowerGrade"` // 家族等级信息 + ResGradeList []CvResGrade `json:"resGradeList"` // 资源等级列表,青铜、白银、黄金、黑金 + PrivilegeList []CvPrivilege `json:"privilegeList"` // 等级特权 +} + +var CvResGradeList = []CvResGrade{ + {groupPower_e.GroupPowerGrade1, "青铜icon", "青铜bigIcon"}, // todo + {groupPower_e.GroupPowerGrade2, "白银icon", "白银bigIcon"}, // todo + {groupPower_e.GroupPowerGrade3, "黄金icon", "黄金bigIcon"}, // todo + {groupPower_e.GroupPowerGrade4, "黑金icon", "黑金bigIcon"}, // todo +} + +var GroupPowerGradePrivilegeNum = map[groupPower_e.GroupPowerGrade][]CvPrivilege{ + groupPower_e.GroupPowerGrade0: {}, + groupPower_e.GroupPowerGrade1: { + {groupPower_e.GroupPowerPrivilegeMemberNum, 300}, + {groupPower_e.GroupPowerPrivilegeMgrNum, 10}, + {groupPower_e.GroupPowerPrivilegeNameplate, 1}, + {groupPower_e.GroupPowerPrivilegeMedal, 1}, + }, + groupPower_e.GroupPowerGrade2: { + {groupPower_e.GroupPowerPrivilegeMemberNum, 500}, + {groupPower_e.GroupPowerPrivilegeMgrNum, 15}, + {groupPower_e.GroupPowerPrivilegeNameplate, 1}, + {groupPower_e.GroupPowerPrivilegeMedal, 1}, + {groupPower_e.GroupPowerPrivilegeNameplateEdit, 1}, + }, + groupPower_e.GroupPowerGrade3: { + {groupPower_e.GroupPowerPrivilegeMemberNum, 800}, + {groupPower_e.GroupPowerPrivilegeMgrNum, 20}, + {groupPower_e.GroupPowerPrivilegeNameplate, 1}, + {groupPower_e.GroupPowerPrivilegeMedal, 1}, + {groupPower_e.GroupPowerPrivilegeNameplateEdit, 1}, + {groupPower_e.GroupPowerPrivilegeNameplateHeadwear, 1}, + }, + groupPower_e.GroupPowerGrade4: { + {groupPower_e.GroupPowerPrivilegeMemberNum, 1200}, + {groupPower_e.GroupPowerPrivilegeMgrNum, 25}, + {groupPower_e.GroupPowerPrivilegeNameplate, 1}, + {groupPower_e.GroupPowerPrivilegeMedal, 1}, + {groupPower_e.GroupPowerPrivilegeNameplateEdit, 1}, + {groupPower_e.GroupPowerPrivilegeNameplateHeadwear, 1}, + }, +} diff --git a/domain/model/groupPower_m/group_grade.go b/domain/model/groupPower_m/group_grade.go index 7558f5b..9979629 100644 --- a/domain/model/groupPower_m/group_grade.go +++ b/domain/model/groupPower_m/group_grade.go @@ -255,7 +255,7 @@ func ClearGroupPowerExp(model *domain.Model) error { // 清理过期家族等级 func ClearGroupPowerGrade(model *domain.Model) error { var groupPowerGrades []*GroupPowerGrade - if err := model.DB().Model(GroupPowerGrade{}).Where("expire_at > ?", time.Now()).Find(&groupPowerGrades).Error; err != nil { + if err := model.DB().Model(GroupPowerGrade{}).Where("expire_at < ?", time.Now()).Find(&groupPowerGrades).Error; err != nil { return err } return model.Transaction(func(model *domain.Model) error { diff --git a/route/group_power_r/group_rank.go b/route/group_power_r/group_rank.go index 3a184e1..13d8757 100644 --- a/route/group_power_r/group_rank.go +++ b/route/group_power_r/group_rank.go @@ -15,6 +15,7 @@ import ( "hilo-group/myerr/bizerr" "hilo-group/req" "hilo-group/resp" + "strconv" "time" ) @@ -75,24 +76,32 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) { return myContext, err } response.MyGroupPower = group_power_cv.CvGroupPowerRankData{ - GroupPowerId: myGroupPower.GroupPowerId, - Icon: groupPowers[myGroupPower.ID].Icon, - Name: groupPowers[myGroupPower.ID].Name, - Nameplate: groupPowers[myGroupPower.ID].Nameplate, - Grade: grades[myGroupPower.GroupPowerId].Grade, - Exp: myGroupPowerRank.Exp, - Rank: myGroupPowerRank.Rank, + CvGroupPowerInfo: group_power_cv.CvGroupPowerInfo{ + GroupPowerId: myGroupPower.GroupPowerId, + Icon: groupPowers[myGroupPower.GroupPowerId].Icon, + Name: groupPowers[myGroupPower.GroupPowerId].Name, + Nameplate: groupPowers[myGroupPower.GroupPowerId].Nameplate, + }, + CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{ + Grade: grades[myGroupPower.GroupPowerId].Grade, + Exp: myGroupPowerRank.Exp, + }, + Rank: myGroupPowerRank.Rank, } } - for r, v := range rank { + for _, v := range rank { response.Items = append(response.Items, group_power_cv.CvGroupPowerRankData{ - GroupPowerId: v.GroupPowerId, - Icon: groupPowers[v.GroupPowerId].Icon, - Name: groupPowers[v.GroupPowerId].Name, - Nameplate: groupPowers[v.GroupPowerId].Nameplate, - Grade: grades[v.GroupPowerId].Grade, - Exp: v.Exp, - Rank: r + 1, // 查询已做排序 + CvGroupPowerInfo: group_power_cv.CvGroupPowerInfo{ + GroupPowerId: v.GroupPowerId, + Icon: groupPowers[v.GroupPowerId].Icon, + Name: groupPowers[v.GroupPowerId].Name, + Nameplate: groupPowers[v.GroupPowerId].Nameplate, + }, + CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{ + Grade: grades[v.GroupPowerId].Grade, + Exp: v.Exp, + }, + Rank: v.Rank, }) } resp.ResponseOk(c, response) @@ -110,7 +119,7 @@ type GroupPowerStarReq struct { // @Summary 家族之星 // @Param token header string true "token" // @Param nonce header string true "随机数字" -// @Param groupPowerId query int true "分页大小 默认:10" default(10) +// @Param groupPowerId query int true "家族id" // @Param type query string true "类型 1:送礼 2:活跃 3:收礼物" // @Param pageSize query int false "分页大小 默认:10" default(10) // @Param pageIndex query int false "第几个分页,从1开始 默认:1" default(1) @@ -153,3 +162,69 @@ func GroupPowerStar(c *gin.Context) (*mycontext.MyContext, error) { resp.ResponseOk(c, response) return myContext, nil } + +// @Tags 国家势力 +// @Summary 家族等级页 +// @Param token header string true "token" +// @Param nonce header string true "随机数字" +// @Param groupPowerId query int true "家族id" +// @Success 200 {object} group_power_cv.CvGroupPowerGradeDetail +// @Router /v1/groupPower/grade/detail [get] +func GroupPowerGradeDetail(c *gin.Context) (*mycontext.MyContext, error) { + myContext := mycontext.CreateMyContext(c.Keys) + userId, err := req.GetUserId(c) + if err != nil { + return myContext, err + } + groupPowerId, err := strconv.ParseUint(c.Query("groupPowerId"), 10, 16) + if err != nil || groupPowerId <= 0 { + return myContext, bizerr.InvalidParameter + } + var model = domain.CreateModelContext(myContext) + groupPowerInfo, err := groupPower_m.MGetGroupPowerInfoMap(model, []mysql.ID{groupPowerId}) + if err != nil { + return myContext, err + } + gradeM, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{groupPowerId}) + if err != nil { + return myContext, err + } + groupPower, ok := groupPowerInfo[groupPowerId] + if !ok { + return myContext, bizerr.GroupNotFound + } + grade := gradeM[groupPowerId] + nextExp := mysql.Num(0) + if grade.Grade != groupPower_e.GroupPowerGradeMax { + nextExp = groupPower_e.GroupPowerGradeExp[grade.Grade+1] - groupPower_e.GroupPowerGradeExp[grade.Grade] + } + expireAt := "" + if grade.ExpireAt.After(time.Now()) { + expireAt = grade.ExpireAt.Format("2006-01-02") + } + showExp := false + if exits, _, err := groupPower_m.CheckGroupPowerUser(model, userId); err != nil { + return myContext, err + } else if exits { + showExp = true + } + response := group_power_cv.CvGroupPowerGradeDetail{ + GroupPowerInfo: group_power_cv.CvGroupPowerInfo{ + GroupPowerId: groupPower.ID, + Icon: groupPower.Icon, + Name: groupPower.Name, + Nameplate: groupPower.Nameplate, + }, + GroupPowerGrade: group_power_cv.CvGroupPowerGrade{ + Grade: grade.Grade, + Exp: grade.Exp, + NextExp: nextExp, + ExpireAt: expireAt, + ShowExp: showExp, + }, + ResGradeList: group_power_cv.CvResGradeList, + PrivilegeList: group_power_cv.GroupPowerGradePrivilegeNum[grade.Grade], + } + resp.ResponseOk(c, response) + return myContext, nil +} diff --git a/route/router.go b/route/router.go index c1f6c0f..f0bce1e 100644 --- a/route/router.go +++ b/route/router.go @@ -127,6 +127,7 @@ func InitRouter() *gin.Engine { groupPower.GET("/billboard/owner/week", wrapper(group_power_r.GroupPowerBillboardOwnerWeek)) groupPower.GET("/rank/:period", wrapper(group_power_r.GroupPowerRank)) groupPower.GET("/star", wrapper(group_power_r.GroupPowerStar)) + groupPower.GET("/grade/detail", wrapper(group_power_r.GroupPowerGradeDetail)) } return r } -- 2.22.0