Commit f2613d0e authored by hujiebin's avatar hujiebin

CP,Top3

parent d2202b7d
......@@ -30,3 +30,8 @@ type CvCpAnniversary struct {
Date string `json:"date"` // 纪念日日期
IsRemind bool `json:"isRemind"` // 是否提醒
}
type CpTops struct {
Day []CvCp `json:"day"`
Week []CvCp `json:"week"`
}
......@@ -91,6 +91,77 @@ func CpRank(c *gin.Context) (*mycontext.MyContext, error) {
return myCtx, nil
}
// @Tags CP v2
// @Summary CP,Top3
// @Param token header string true "token"
// @Param nonce header string true "随机数字"
// @Success 200 {object} cp_cv.CpTops
// @Router /v2/cp/top3 [get]
func CpTop3(c *gin.Context) (*mycontext.MyContext, error) {
myCtx := mycontext.CreateMyContext(c.Keys)
userId, err := req.GetUserId(c)
if err != nil {
return myCtx, err
}
var response = cp_cv.CpTops{
Day: make([]cp_cv.CvCp, 0),
Week: make([]cp_cv.CvCp, 0),
}
queryTypes := []string{"day", "week"}
for _, queryType := range queryTypes {
var beginDate, endDate string
switch queryType {
case "day":
beginDate, endDate = time.Now().Format("2006-01-02"), time.Now().Format("2006-01-02")
case "week":
beginDate = now.BeginningOfWeek().Format("2006-01-02")
endDate = now.EndOfWeek().Format("2006-01-02")
}
offset, limit := 0, 3
model := domain.CreateModelContext(myCtx)
ranks := cp_m.PageCpDayRank(model, beginDate, endDate, offset, limit)
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 i, rank := range ranks {
if queryType == "day" {
response.Day = append(response.Day, cp_cv.CvCp{
CpId: rank.CpId,
User1: userBase[rank.UserId1],
User2: userBase[rank.UserId2],
Score: rank.Score,
Ranking: fmt.Sprintf("%d", i+1+offset),
CpLevel: cp_cv.CvCpLevel{
Level: cpLevels[rank.CpId].Level,
},
})
} else {
response.Week = append(response.Week, cp_cv.CvCp{
CpId: rank.CpId,
User1: userBase[rank.UserId1],
User2: userBase[rank.UserId2],
Score: rank.Score,
Ranking: fmt.Sprintf("%d", i+1+offset),
CpLevel: cp_cv.CvCpLevel{
Level: cpLevels[rank.CpId].Level,
},
})
}
}
}
resp.ResponseOk(c, response)
return myCtx, nil
}
// @Tags CP v2
// @Summary 我的cp
// @Param token header string true "token"
......
......@@ -36,6 +36,7 @@ func InitRouter() *gin.Engine {
cp.GET("/rank/:queryType", wrapper(cp_r.CpRank))
cp.GET("/my/:queryType", wrapper(cp_r.CpMy))
cp.GET("/achievement", wrapper(cp_r.CpAchievement))
cp.GET("/top3", wrapper(cp_r.CpTop3))
cp.POST("/anniversary", wrapper(cp_r.PostAnniversary))
cp.PUT("/anniversary/:id", wrapper(cp_r.PutAnniversary))
......
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