Commit e4ce8b28 authored by chenweijian's avatar chenweijian

接口优化

parent 359f4833
......@@ -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 {
......
......@@ -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,
}
}
......@@ -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 {
......
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