Commit 48f22c89 authored by hujiebin's avatar hujiebin

CpLevel CvCpLevel `json:"cpLevel"` // cp等级

parent 0b17c301
......@@ -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"` // 排名
}
......
......@@ -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
......
......@@ -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)
......
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