Commit b9aeabdc authored by hujiebin's avatar hujiebin

feat:成就yefix

parent d0121190
...@@ -41,10 +41,11 @@ func UpdateCpAchievement(model *domain.Model, cpId, userId1, userId2 mysql.ID, T ...@@ -41,10 +41,11 @@ func UpdateCpAchievement(model *domain.Model, cpId, userId1, userId2 mysql.ID, T
return model.DB().Model(CpAchievement{}).Where("cp_id = ? AND `type` = ?", cpId, Type).Where("score < ?", score).UpdateColumn("score", score).Error return model.DB().Model(CpAchievement{}).Where("cp_id = ? AND `type` = ?", cpId, Type).Where("score < ?", score).UpdateColumn("score", score).Error
} }
// 获取用户cp成就 // 获取cp成就
func GetCpAchievements(model *domain.Model, cpId mysql.ID) []CpAchievement { func GetCpAchievements(model *domain.Model) []CpAchievement {
var achievements []CpAchievement var achievements []CpAchievement
if err := model.DB().Model(CpAchievement{}).Where("cp_id = ?", cpId).Find(&achievements).Error; err != nil { subQuery := model.DB().Table("cp_achievement a").Joins("JOIN cp_relation r ON a.cp_id = r.id").Select("type,MAX(score) AS max_score").Group("type")
if err := model.DB().Model(CpAchievement{}).Where("(type, score) IN (?)", subQuery).Find(&achievements).Error; err != nil {
model.Log.Errorf("GetAchievements fail:%v", err) model.Log.Errorf("GetAchievements fail:%v", err)
} }
return achievements return achievements
......
...@@ -2,7 +2,6 @@ package event_s ...@@ -2,7 +2,6 @@ package event_s
import ( import (
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/jinzhu/now" "github.com/jinzhu/now"
"hilo-user/_const/enum/cp_e" "hilo-user/_const/enum/cp_e"
"hilo-user/domain/event/gift_ev" "hilo-user/domain/event/gift_ev"
...@@ -31,7 +30,8 @@ func CpGiftEvent() { ...@@ -31,7 +30,8 @@ func CpGiftEvent() {
} }
// 检查最新的等级 // 检查最新的等级
if cpLevel := cp_m.GetCpLevel(model, cpRelation.ID); cpLevel.CpId >= 0 { if cpLevel := cp_m.GetCpLevel(model, cpRelation.ID); cpLevel.CpId >= 0 {
if err := cp_m.UpdateCpAchievement(model, cpLevel.CpId, cpRelation.UserId1, cpRelation.UserId2, cp_e.CpAchievementLevel, mysql.Num(cpLevel.Level)); err != nil { points := cpLevel.Points + cp_e.CpLevelPoints[cpLevel.Level]
if err := cp_m.UpdateCpAchievement(model, cpLevel.CpId, cpRelation.UserId1, cpRelation.UserId2, cp_e.CpAchievementLevel, points); err != nil {
model.Log.Errorf("UpdateCpAchievement fail:%v", err) model.Log.Errorf("UpdateCpAchievement fail:%v", err)
} }
} }
......
...@@ -231,16 +231,13 @@ func CpMy(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -231,16 +231,13 @@ func CpMy(c *gin.Context) (*mycontext.MyContext, error) {
// @Summary 成就页 // @Summary 成就页
// @Param token header string true "token" // @Param token header string true "token"
// @Param nonce header string true "随机数字" // @Param nonce header string true "随机数字"
// @Param pageIndex query int true "偏移值 默认:1" default(1)
// @Param pageSize query int true "请求数量 默认:10" default(10)
// @Success 200 {object} []cp_cv.CvCpAchievement // @Success 200 {object} []cp_cv.CvCpAchievement
// @Router /v2/cp/achievement [get] // @Router /v2/cp/achievement [get]
func CpAchievement(c *gin.Context) (*mycontext.MyContext, error) { func CpAchievement(c *gin.Context) (*mycontext.MyContext, error) {
myCtx := mycontext.CreateMyContext(c.Keys) myCtx := mycontext.CreateMyContext(c.Keys)
userId, err := req.GetUserId(c)
if err != nil {
return myCtx, err
}
model := domain.CreateModelContext(myCtx) model := domain.CreateModelContext(myCtx)
relation, exits := cp_m.GetCpRelation(model, userId)
var response = make([]cp_cv.CvCpAchievement, 0) var response = make([]cp_cv.CvCpAchievement, 0)
TypeDescMap := map[cp_e.CpAchievement]string{ // todo 翻译 TypeDescMap := map[cp_e.CpAchievement]string{ // todo 翻译
cp_e.CpAchievementLevel: "等级分值最高", cp_e.CpAchievementLevel: "等级分值最高",
...@@ -249,12 +246,16 @@ func CpAchievement(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -249,12 +246,16 @@ func CpAchievement(c *gin.Context) (*mycontext.MyContext, error) {
cp_e.CpAchievementWeekRank: "周榜最高", cp_e.CpAchievementWeekRank: "周榜最高",
cp_e.CpAchievementDayRank: "天榜最高", cp_e.CpAchievementDayRank: "天榜最高",
} }
if exits { achievements := cp_m.GetCpAchievements(model)
users, err := user_m.GetUserMapByIds(model, []mysql.ID{relation.UserId1, relation.UserId2}) var userIds []uint64
for _, v := range achievements {
userIds = append(userIds, v.UserId1)
userIds = append(userIds, v.UserId2)
}
users, err := user_m.GetUserMapByIds(model, userIds)
if err != nil { if err != nil {
return myCtx, err return myCtx, err
} }
achievements := cp_m.GetCpAchievements(model, relation.ID)
for _, a := range achievements { for _, a := range achievements {
response = append(response, cp_cv.CvCpAchievement{ response = append(response, cp_cv.CvCpAchievement{
CpId: a.CpId, CpId: a.CpId,
...@@ -266,8 +267,6 @@ func CpAchievement(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -266,8 +267,6 @@ func CpAchievement(c *gin.Context) (*mycontext.MyContext, error) {
TimeUnix: a.UpdatedTime.Unix(), TimeUnix: a.UpdatedTime.Unix(),
}) })
} }
} else {
}
resp.ResponsePageBaseOk(c, response, 0, false) resp.ResponsePageBaseOk(c, response, 0, false)
return myCtx, nil return myCtx, nil
} }
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