diff --git a/cv/group_power_cv/group_rank.go b/cv/group_power_cv/group_rank.go index ce427664d2b308ffc7bb0c57853bc04ab39ae151..03312007b0e642cf75cbf4d0c0a3703543f39671 100644 --- a/cv/group_power_cv/group_rank.go +++ b/cv/group_power_cv/group_rank.go @@ -6,14 +6,26 @@ import ( "hilo-group/cv/user_cv" ) -// 家族基本信息 +// 家族信息 type CvGroupPowerInfo struct { + CvGroupPowerBase `json:",inline"` + CvGroupPowerMember `json:",inline"` +} + +// 家族基本信息 +type CvGroupPowerBase struct { GroupPowerId mysql.ID `json:"groupPowerId"` // 家族id Icon string `json:"icon"` // 家族图片 Name string `json:"name"` // 家族名 Nameplate string `json:"nameplate"` // 铭牌 } +// 家族成员 +type CvGroupPowerMember struct { + MemberNum mysql.Num `json:"memberNum"` // 当前成员数 + MemberLimit mysql.Num `json:"memberLimit"` // 成员上限 +} + // 家族等级 type CvGroupPowerGrade struct { Grade groupPower_e.GroupPowerGrade `json:"grade"` // 等级 0:无 1:青铜 2:白银 3:黄金 4:黑金 @@ -30,7 +42,7 @@ type CvGroupPowerRank struct { } type CvGroupPowerRankData struct { - CvGroupPowerInfo `json:",inline"` + CvGroupPowerBase `json:",inline"` CvGroupPowerGrade `json:",inline"` Rank int `json:"rank"` // 排名 } @@ -56,7 +68,7 @@ type CvPrivilege struct { // 家族等级页 type CvGroupPowerGradeDetail struct { - GroupPowerInfo CvGroupPowerInfo `json:"groupPowerInfo"` // 家族基本信息 + GroupPowerBase CvGroupPowerBase `json:"groupPowerBase"` // 家族基本信息 GroupPowerGrade CvGroupPowerGrade `json:"groupPowerGrade"` // 家族等级信息 ResGradeList []CvResGrade `json:"resGradeList"` // 资源等级列表,青铜、白银、黄金、黑金 PrivilegeList []CvPrivilege `json:"privilegeList"` // 等级特权 diff --git a/domain/model/groupPower_m/group_info.go b/domain/model/groupPower_m/group_info.go index dafcd6c3fec8348a07fb3b14b5209fc0a45dc34a..2040ac8d9c80f3bdcae2a6f4b1fca2b0fbc55ff8 100644 --- a/domain/model/groupPower_m/group_info.go +++ b/domain/model/groupPower_m/group_info.go @@ -32,3 +32,17 @@ func MGetGroupPowerInfoMap(model *domain.Model, groupPowerIds []mysql.ID) (map[m } return res, nil } + +// 批量获取家族成员 +func MGetGroupPowerUsers(model *domain.Model, groupPowerIds []mysql.ID) (map[mysql.ID][]*GroupPowerUser, error) { + var users []*GroupPowerUser + res := make(map[mysql.ID][]*GroupPowerUser) + if err := model.DB().Model(GroupPowerUser{}).Where("group_power_id in ?", groupPowerIds).Find(&users).Error; err != nil { + model.Log.Errorf("MGetGroupPowerUsers fail:%v", err) + return res, err + } + for i, v := range users { + res[v.GroupPowerId] = append(res[v.GroupPowerId], users[i]) + } + return res, nil +} diff --git a/route/group_power_r/group_rank.go b/route/group_power_r/group_rank.go index 13d875783c6e308e1a7154a3765ac30c79d50c62..31541a0c69444ae222b66401c68d59073284d4c3 100644 --- a/route/group_power_r/group_rank.go +++ b/route/group_power_r/group_rank.go @@ -76,7 +76,7 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) { return myContext, err } response.MyGroupPower = group_power_cv.CvGroupPowerRankData{ - CvGroupPowerInfo: group_power_cv.CvGroupPowerInfo{ + CvGroupPowerBase: group_power_cv.CvGroupPowerBase{ GroupPowerId: myGroupPower.GroupPowerId, Icon: groupPowers[myGroupPower.GroupPowerId].Icon, Name: groupPowers[myGroupPower.GroupPowerId].Name, @@ -91,7 +91,7 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) { } for _, v := range rank { response.Items = append(response.Items, group_power_cv.CvGroupPowerRankData{ - CvGroupPowerInfo: group_power_cv.CvGroupPowerInfo{ + CvGroupPowerBase: group_power_cv.CvGroupPowerBase{ GroupPowerId: v.GroupPowerId, Icon: groupPowers[v.GroupPowerId].Icon, Name: groupPowers[v.GroupPowerId].Name, @@ -209,7 +209,7 @@ func GroupPowerGradeDetail(c *gin.Context) (*mycontext.MyContext, error) { showExp = true } response := group_power_cv.CvGroupPowerGradeDetail{ - GroupPowerInfo: group_power_cv.CvGroupPowerInfo{ + GroupPowerBase: group_power_cv.CvGroupPowerBase{ GroupPowerId: groupPower.ID, Icon: groupPower.Icon, Name: groupPower.Name, diff --git a/route/group_power_r/inner.go b/route/group_power_r/inner.go new file mode 100644 index 0000000000000000000000000000000000000000..3e6fbc680776c7a34efe3a0699c8cb8a33088f6d --- /dev/null +++ b/route/group_power_r/inner.go @@ -0,0 +1,69 @@ +package group_power_r + +import ( + "git.hilo.cn/hilo-common/domain" + "git.hilo.cn/hilo-common/mycontext" + "git.hilo.cn/hilo-common/resource/mysql" + "github.com/gin-gonic/gin" + "hilo-group/_const/enum/groupPower_e" + "hilo-group/cv/group_power_cv" + "hilo-group/domain/model/groupPower_m" + "hilo-group/resp" +) + +type MGetGroupPowerReq struct { + Ids []mysql.ID `form:"ids" binding:"required"` +} + +// @Tags 国家势力-内部 +// @Summary 批量获取国家势力信息 +// @Param ids query string true "用户id,如:ids=1&ids=2&ids=3" +// @Success 200 {object} map[mysql.ID]group_power_cv.CvGroupPowerInfo +// @Router /inner/groupPower/infos [get] +func MGetGroupPowers(c *gin.Context) (*mycontext.MyContext, error) { + myCtx := mycontext.CreateMyContext(c.Keys) + var model = domain.CreateModelContext(myCtx) + var req MGetGroupPowerReq + if err := c.ShouldBindQuery(&req); err != nil { + return myCtx, err + } + groupPowers, err := groupPower_m.MGetGroupPowerInfoMap(model, req.Ids) + if err != nil { + return myCtx, err + } + groupPowerUsers, err := groupPower_m.MGetGroupPowerUsers(model, req.Ids) + if err != nil { + return myCtx, err + } + groupPowerGrade, err := groupPower_m.MGetGroupPowerGrade(model, req.Ids) + if err != nil { + return myCtx, err + } + response := make(map[mysql.ID]group_power_cv.CvGroupPowerInfo) + for groupPowerId, info := range groupPowers { + // 成员上限 + var memberLimit mysql.Num + grade := groupPowerGrade[groupPowerId].Grade + if grade >= groupPower_e.GroupPowerGrade0 && grade <= groupPower_e.GroupPowerGradeMax { + memberLimit = mysql.Num(group_power_cv.GroupPowerGradePrivilegeNum[groupPowerGrade[groupPowerId].Grade][0].Num) + } + memberNum := mysql.Num(len(groupPowerUsers[groupPowerId])) + if memberNum > memberLimit { + memberLimit = memberNum + } + response[groupPowerId] = group_power_cv.CvGroupPowerInfo{ + CvGroupPowerBase: group_power_cv.CvGroupPowerBase{ + GroupPowerId: groupPowerId, + Icon: info.Icon, + Name: info.Name, + Nameplate: info.Nameplate, + }, + CvGroupPowerMember: group_power_cv.CvGroupPowerMember{ + MemberNum: memberNum, + MemberLimit: memberLimit, + }, + } + } + resp.ResponseOk(c, response) + return myCtx, nil +} diff --git a/route/router.go b/route/router.go index f0bce1e37069620912b28665b20b68c37af077b2..ebd2854a9d65df3270d26af46ddbe180f9c64927 100644 --- a/route/router.go +++ b/route/router.go @@ -129,6 +129,13 @@ func InitRouter() *gin.Engine { groupPower.GET("/star", wrapper(group_power_r.GroupPowerStar)) groupPower.GET("/grade/detail", wrapper(group_power_r.GroupPowerGradeDetail)) } + + // 内部接口 + inner := r.Group("/inner") + innerGroupPower := inner.Group("/groupPower") + { + innerGroupPower.GET("/infos", wrapper(group_power_r.MGetGroupPowers)) + } return r }