diff --git a/cv/cp_cv/rank.go b/cv/cp_cv/rank.go index fe3cfac29ab109cbfd9993d1f673bc68bcd59c52..c3e6af4e3c96e5c5a6c3fc2da92db4cb0add7608 100644 --- a/cv/cp_cv/rank.go +++ b/cv/cp_cv/rank.go @@ -6,10 +6,11 @@ import ( ) type CvCp struct { - CpId uint64 `json:"cpId"` // cpId - User1 *user_cv.CvUserBase `json:"user1"` // user1 - User2 *user_cv.CvUserBase `json:"user2"` // user2 - Score uint32 `json:"score"` // 分值 + CpId uint64 `json:"cpId"` // cpId + User1 *user_cv.CvUserBase `json:"user1"` // user1 + User2 *user_cv.CvUserBase `json:"user2"` // user2 + Score uint32 `json:"score"` // 分值 + CpLevel CvCpLevel `json:"cpLevel"` // cp等级 //Ranking int `json:"ranking"` // 排名 } diff --git a/domain/model/cp_m/level.go b/domain/model/cp_m/level.go index 1be2c8e70a39b3c16fecdeff608d0ea95bdf0f4f..376361667b91e3c4be376c9619dca75d911f74a3 100644 --- a/domain/model/cp_m/level.go +++ b/domain/model/cp_m/level.go @@ -53,6 +53,19 @@ func GetCpLevel(model *domain.Model, cpId mysql.ID) CpLevel { return level } +// 批量获取cp等级 +func MGetCpLevel(model *domain.Model, cpIds []mysql.ID) map[mysql.ID]CpLevel { + var res = make(map[mysql.ID]CpLevel) + var level []CpLevel + if err := model.DB().Model(CpLevel{}).Where("cp_id in ?", cpIds).Find(&level).Error; err != nil { + model.Log.Errorf("MGetCpLevel fail:%v", err) + } + for i, v := range level { + res[v.CpId] = level[i] + } + return res +} + // 添加cp等级积分增减明细 func AddCpLevelDetail(model *domain.Model, detail CpLevelDetail) error { return model.DB().Create(&detail).Error diff --git a/route/cp_r/rank.go b/route/cp_r/rank.go index d5a95992562abfcb8635580efb28468540f25f7d..0b5226edd1d3c35fee67164bfed718e5afa2ee1e 100644 --- a/route/cp_r/rank.go +++ b/route/cp_r/rank.go @@ -59,14 +59,17 @@ func CpRank(c *gin.Context) (*mycontext.MyContext, error) { ranks := cp_m.PageCpDayRank(model, beginDate, endDate, offset, limit) var response []cp_cv.CvCp var userIds []mysql.ID + var cpIds []mysql.ID for _, rank := range ranks { userIds = append(userIds, rank.UserId1) userIds = append(userIds, rank.UserId2) + cpIds = append(cpIds, rank.CpId) } userBase, err := user_cv.GetUserBaseMap(userIds, userId) if err != nil { return myCtx, err } + cpLevels := cp_m.MGetCpLevel(model, cpIds) for _, rank := range ranks { response = append(response, cp_cv.CvCp{ CpId: rank.CpId, @@ -74,6 +77,13 @@ func CpRank(c *gin.Context) (*mycontext.MyContext, error) { User2: userBase[rank.UserId2], Score: rank.Score, //Ranking: i + 1 + offset, + CpLevel: cp_cv.CvCpLevel{ + Level: cpLevels[rank.CpId].Level, + //Points: cp_e.CpLevelPoints[cpLevel] + curPoints, + //NextPoints: nextPoints, + //RemainPoints: remainPoints, + //ExpireAtUnix: expireAtUnix, + }, }) } resp.ResponsePageBaseOk(c, response, pageReq.PageIndex+1, len(ranks) >= pageReq.PageSize)