Commit 0b17c301 authored by hujiebin's avatar hujiebin

成就页

parent 48d2038a
package cp_cv
import "hilo-user/cv/user_cv"
import (
"hilo-user/_const/enum/cp_e"
"hilo-user/cv/user_cv"
)
type CvCp struct {
CpId uint64 `json:"cpId"` // cpId
......@@ -9,3 +12,13 @@ type CvCp struct {
Score uint32 `json:"score"` // 分值
//Ranking int `json:"ranking"` // 排名
}
type CvCpAchievement struct {
CpId uint64 `json:"cpId"` // cpId
User1 user_cv.UserTiny `json:"user1"` // user1
User2 user_cv.UserTiny `json:"user2"` // user2
Type cp_e.CpAchievement `json:"type"` // 成就类型 1:等级 2:空间访问人数 3:月榜最高 4:周榜最高 5:日榜最高
TypeDesc string `json:"typeDesc"` // 成就类型翻译
Score uint32 `json:"score"` // 分值
TimeUnix int64 `json:"timeUnix"` // 达成成就时间戳
}
......@@ -40,3 +40,12 @@ func UpdateCpAchievement(model *domain.Model, cpId, userId1, userId2 mysql.ID, T
// update if less than
return model.DB().Model(CpAchievement{}).Where("cp_id = ? AND `type` = ?", cpId, Type).Where("score < ?", score).UpdateColumn("score", score).Error
}
// 获取用户cp成就
func GetCpAchievements(model *domain.Model, cpId mysql.ID) []CpAchievement {
var achievements []CpAchievement
if err := model.DB().Model(CpAchievement{}).Where("cp_id = ?", cpId).Find(&achievements).Error; err != nil {
model.Log.Errorf("GetAchievements fail:%v", err)
}
return achievements
}
......@@ -6,9 +6,11 @@ import (
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/gin-gonic/gin"
"github.com/jinzhu/now"
"hilo-user/_const/enum/cp_e"
"hilo-user/cv/cp_cv"
"hilo-user/cv/user_cv"
"hilo-user/domain/model/cp_m"
"hilo-user/domain/model/user_m"
"hilo-user/myerr/bizerr"
"hilo-user/req"
"hilo-user/resp"
......@@ -143,3 +145,48 @@ func CpMy(c *gin.Context) (*mycontext.MyContext, error) {
resp.ResponseOk(c, response)
return myCtx, nil
}
// @Tags CP v2
// @Summary 成就页
// @Param token header string true "token"
// @Param nonce header string true "随机数字"
// @Success 200 {object} []cp_cv.CvCpAchievement
// @Router /v2/cp/achievement [get]
func CpAchievement(c *gin.Context) (*mycontext.MyContext, error) {
myCtx := mycontext.CreateMyContext(c.Keys)
userId, err := req.GetUserId(c)
if err != nil {
return myCtx, err
}
model := domain.CreateModelContext(myCtx)
relation, exits := cp_m.GetCpRelation(model, userId)
var response = make([]cp_cv.CvCpAchievement, 0)
TypeDescMap := map[cp_e.CpAchievement]string{ // todo 翻译
cp_e.CpAchievementLevel: "等级分值最高",
cp_e.CpAchievementVisitors: "空间访问量最高",
cp_e.CpAchievementMonthRank: "月榜最高",
cp_e.CpAchievementWeekRank: "周榜最高",
cp_e.CpAchievementDayRank: "天榜最高",
}
if exits {
users, err := user_m.GetUserMapByIds(model, []mysql.ID{relation.UserId1, relation.UserId2})
if err != nil {
return myCtx, err
}
achievements := cp_m.GetCpAchievements(model, relation.ID)
for _, a := range achievements {
response = append(response, cp_cv.CvCpAchievement{
CpId: a.CpId,
User1: user_cv.UserToTiny(users[a.UserId1]),
User2: user_cv.UserToTiny(users[a.UserId2]),
Type: a.Type,
TypeDesc: TypeDescMap[a.Type],
Score: a.Score,
TimeUnix: a.UpdatedTime.Unix(),
})
}
} else {
}
resp.ResponseOk(c, response)
return nil, nil
}
......@@ -35,6 +35,7 @@ func InitRouter() *gin.Engine {
cp.PUT("/privilege/openClose", wrapper(cp_r.CpPrivilegeOpenClose))
cp.GET("/rank/:queryType", wrapper(cp_r.CpRank))
cp.GET("/my/:queryType", wrapper(cp_r.CpMy))
cp.GET("/achievement", wrapper(cp_r.CpAchievement))
}
inner := r.Group("/inner")
inner.Use(ExceptionHandle, LoggerHandle)
......
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