diff --git a/cv/cp_cv/rank.go b/cv/cp_cv/rank.go index f03c1f38ece55d78b679367f4bccf57a4539f24f..0e13eed96206b5f23b742932433d46901c3bc382 100644 --- a/cv/cp_cv/rank.go +++ b/cv/cp_cv/rank.go @@ -6,12 +6,12 @@ import ( ) type CvCpRank struct { - CpId uint64 `json:"cpId"` // cpId - User1 *user_cv.CvUserBase `json:"user1"` // user1 - User2 *user_cv.CvUserBase `json:"user2,omitempty"` // user2 - Score uint32 `json:"score"` // 分值 - CpLevel CvCpLevel `json:"cpLevel"` // cp等级 - Ranking string `json:"ranking"` // 排名 + CpId uint64 `json:"cpId"` // cpId + User1 *user_cv.CvUserLittle `json:"user1"` // user1 + User2 *user_cv.CvUserLittle `json:"user2,omitempty"` // user2 + Score uint32 `json:"score"` // 分值 + CpLevel CvCpLevel `json:"cpLevel"` // cp等级 + Ranking string `json:"ranking"` // 排名 } type CvCpAchievement struct { diff --git a/cv/user_cv/user.go b/cv/user_cv/user.go index 82e053d1963ad14ed7b1d33f16bc7cfdb50e3a26..6dc23788b092919aebc68c361d6c8695170fd39a 100644 --- a/cv/user_cv/user.go +++ b/cv/user_cv/user.go @@ -111,6 +111,17 @@ type CvUserBase struct { GroupRole common.GroupRoleType `json:"groupRole"` // 在群组的角色 } +type CvUserLittle struct { + //不会有返回值 + Id *mysql.ID `json:"id,omitempty"` + //头像,不存在为nil + Avatar *string `json:"avatar"` + //用户对外ID + ExternalId *string `json:"externalId"` + //昵称,不存在为nil + Nick *string `json:"nick"` +} + //批量获取用户基本信息 func GetUserBases(userIds []mysql.ID, myUserId mysql.ID) ([]*CvUserBase, error) { if len(userIds) == 0 { @@ -516,3 +527,12 @@ type CvCpLevel struct { type CvPrivilege struct { Type cp_e.CpPrivilege `json:"type"` // 特权id 1:空间 2:横幅 3:等级勋章 4:证书 5:进场特效 6:头像头饰 7:动态资料卡 8:麦位特效 } + +func UserBaseToUserLittle(base *CvUserBase) *CvUserLittle { + return &CvUserLittle{ + Id: base.Id, + Avatar: base.Avatar, + ExternalId: base.ExternalId, + Nick: base.Nick, + } +} diff --git a/route/cp_r/rank.go b/route/cp_r/rank.go index 22fdc1994f2c9aa853620870b008866662858e7d..2a2caafd3e810315f7eda178c5cca5f7a00867a0 100644 --- a/route/cp_r/rank.go +++ b/route/cp_r/rank.go @@ -81,8 +81,8 @@ func CpRank(c *gin.Context) (*mycontext.MyContext, error) { for i, rank := range ranks { response = append(response, cp_cv.CvCpRank{ CpId: rank.CpId, - User1: userBase[rank.UserId1], - User2: userBase[rank.UserId2], + User1: user_cv.UserBaseToUserLittle(userBase[rank.UserId1]), + User2: user_cv.UserBaseToUserLittle(userBase[rank.UserId2]), Score: rank.Score, Ranking: fmt.Sprintf("%d", i+1+offset), CpLevel: cp_cv.CvCpLevel{ @@ -143,8 +143,8 @@ func CpTop3(c *gin.Context) (*mycontext.MyContext, error) { if queryType == "day" { response.Day = append(response.Day, cp_cv.CvCpRank{ CpId: rank.CpId, - User1: userBase[rank.UserId1], - User2: userBase[rank.UserId2], + User1: user_cv.UserBaseToUserLittle(userBase[rank.UserId1]), + User2: user_cv.UserBaseToUserLittle(userBase[rank.UserId2]), Score: rank.Score, Ranking: fmt.Sprintf("%d", i+1+offset), CpLevel: cp_cv.CvCpLevel{ @@ -154,8 +154,8 @@ func CpTop3(c *gin.Context) (*mycontext.MyContext, error) { } else { response.Week = append(response.Week, cp_cv.CvCpRank{ CpId: rank.CpId, - User1: userBase[rank.UserId1], - User2: userBase[rank.UserId2], + User1: user_cv.UserBaseToUserLittle(userBase[rank.UserId1]), + User2: user_cv.UserBaseToUserLittle(userBase[rank.UserId2]), Score: rank.Score, Ranking: fmt.Sprintf("%d", i+1+offset), CpLevel: cp_cv.CvCpLevel{ @@ -224,10 +224,10 @@ func CpMy(c *gin.Context) (*mycontext.MyContext, error) { Score: scores, } if relation.UserId1 > 0 { - response.User1 = userBases[relation.UserId1] + response.User1 = user_cv.UserBaseToUserLittle(userBases[relation.UserId1]) } if relation.UserId2 > 0 { - response.User2 = userBases[relation.UserId2] + response.User2 = user_cv.UserBaseToUserLittle(userBases[relation.UserId2]) response.Ranking = "30+" ranks := cp_m.PageCpDayRank(model, beginDate, endDate, 0, 30) for i, rank := range ranks {