Commit 7bb301e5 authored by hujiebin's avatar hujiebin

内部接口

parent 8a6ea690
......@@ -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"` // 等级特权
......
......@@ -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
}
......@@ -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,
......
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
}
......@@ -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
}
......
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