diff --git a/_const/enum/cp_e/anniversary.go b/_const/enum/cp_e/anniversary.go new file mode 100644 index 0000000000000000000000000000000000000000..4ef8ef39039920914ee5d4097e72684e644d2589 --- /dev/null +++ b/_const/enum/cp_e/anniversary.go @@ -0,0 +1,8 @@ +package cp_e + +type AnniversaryItemType int + +const ( + AnniversaryItemTypeNormal AnniversaryItemType = 0 // 普通类型 + AnniversaryItemTypeAvatar AnniversaryItemType = 1 // 头像类型 +) diff --git a/cv/cp_cv/anniversary.go b/cv/cp_cv/anniversary.go new file mode 100644 index 0000000000000000000000000000000000000000..db80a41f9217e91e6249a2fe2273026d8ec6be45 --- /dev/null +++ b/cv/cp_cv/anniversary.go @@ -0,0 +1,22 @@ +package cp_cv + +import ( + "hilo-user/_const/enum/cp_e" + "hilo-user/cv/user_cv" +) + +// cp信息 +type CvCpBase struct { + UserInfo user_cv.UserTiny `json:"userInfo"` // 用户信息 + CpUserInfo user_cv.UserTiny `json:"cpUserInfo,omitempty"` // cp用户信息 +} + +type CvCpAnniversary struct { + Type cp_e.AnniversaryItemType `json:"type"` // 列表类型 0:普通 1:头像 + CpInfo *CvCpBase `json:"cpInfo"` // cp信息,type=1(头像)时候用到 + Id uint64 `json:"id"` // 记录id + Content string `json:"content"` // 纪念日内容 + Timestamp int64 `json:"timestamp"` // 纪念日时间戳 + IsRemind bool `json:"isRemind"` // 是否提醒 + CanDel bool `json:"canDel"` // 能否删除 +} diff --git a/cv/cp_cv/rank.go b/cv/cp_cv/rank.go index 0a5949ed32ddd616df59f04389cc1c56c5326cb5..fe57ef96ca0cefe7f54a266481a0d410dbe49fd2 100644 --- a/cv/cp_cv/rank.go +++ b/cv/cp_cv/rank.go @@ -5,7 +5,7 @@ import ( "hilo-user/cv/user_cv" ) -type CvCp struct { +type CvCpRank struct { CpId uint64 `json:"cpId"` // cpId User1 *user_cv.CvUserBase `json:"user1"` // user1 User2 *user_cv.CvUserBase `json:"user2,omitempty"` // user2 @@ -24,14 +24,7 @@ type CvCpAchievement struct { TimeUnix int64 `json:"timeUnix"` // 达成成就时间戳 } -type CvCpAnniversary struct { - Id uint64 `json:"id"` // 记录id - Content string `json:"content"` // 纪念日内容 - Timestamp int64 `json:"timestamp"` // 纪念日时间戳 - IsRemind bool `json:"isRemind"` // 是否提醒 -} - type CpTops struct { - Day []CvCp `json:"day"` - Week []CvCp `json:"week"` + Day []CvCpRank `json:"day"` + Week []CvCpRank `json:"week"` } diff --git a/domain/model/cp_m/anniversary.go b/domain/model/cp_m/anniversary.go index 2c8e91e14fc82adefd70aebdcce95e4fdceecc48..e930fbacc442448713e2aff4dd834fe84f62c92d 100644 --- a/domain/model/cp_m/anniversary.go +++ b/domain/model/cp_m/anniversary.go @@ -52,7 +52,7 @@ func GetAllCpAnniversary(model *domain.Model, userId mysql.ID) []CpAnniversary { if !exists { return res } - if err := model.DB().Model(CpAnniversary{}).Where("cp_id = ?", relation.ID).Order("id").Find(&res).Error; err != nil { + if err := model.DB().Model(CpAnniversary{}).Where("cp_id = ?", relation.ID).Order("`timestamp` DESC,id DESC").Find(&res).Error; err != nil { model.Log.Errorf("GetAllCpAnniversary fail:%v", err) } return res diff --git a/route/cp_r/anniversary.go b/route/cp_r/anniversary.go index fa270fcc8eb89e25f3563ccc6ec7702cf9fc4a60..ccd49fef7807b3da0f0a5f9d205281ebedafd2fb 100644 --- a/route/cp_r/anniversary.go +++ b/route/cp_r/anniversary.go @@ -4,8 +4,11 @@ import ( "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/mycontext" "github.com/gin-gonic/gin" + "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" @@ -79,6 +82,8 @@ func PutAnniversary(c *gin.Context) (*mycontext.MyContext, error) { // @Summary 获取纪念日 // @Param token header string true "token" // @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.CvCpAnniversary // @Router /v2/cp/anniversary [get] func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { @@ -87,15 +92,39 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { if err != nil { return myCtx, err } - model := domain.CreateModelContext(myCtx) var response = make([]cp_cv.CvCpAnniversary, 0) + model := domain.CreateModelContext(myCtx) + cpRelation, exits := cp_m.GetCpRelation(model, userId) + if exits { + userIds := []uint64{cpRelation.UserId1, cpRelation.UserId2} + users, err := user_m.GetUserMapByIds(model, userIds) + if err != nil { + return myCtx, err + } + cpUserId := cpRelation.UserId2 + if cpUserId == userId { + cpUserId = cpRelation.UserId1 + } + userInfo := user_cv.UserToTiny(users[userId]) + cpUserInfo := user_cv.UserToTiny(users[cpUserId]) + response = append(response, cp_cv.CvCpAnniversary{ + Type: cp_e.AnniversaryItemTypeAvatar, + CpInfo: &cp_cv.CvCpBase{ + UserInfo: *userInfo, + CpUserInfo: *cpUserInfo, + }, + CanDel: false, + }) + } anniversary := cp_m.GetAllCpAnniversary(model, userId) for _, v := range anniversary { response = append(response, cp_cv.CvCpAnniversary{ + Type: cp_e.AnniversaryItemTypeNormal, Id: v.ID, Content: v.Content, Timestamp: v.Timestamp, IsRemind: v.IsRemind, + CanDel: true, }) } resp.ResponsePageBaseOk(c, response, 0, false) diff --git a/route/cp_r/rank.go b/route/cp_r/rank.go index 08fda30503870eff740416e8ac6952951b32a94c..a0cd46f272568e749b24299d7118d5bf4778a891 100644 --- a/route/cp_r/rank.go +++ b/route/cp_r/rank.go @@ -25,7 +25,7 @@ import ( // @Param pageIndex query int true "偏移值 默认:1" default(1) // @Param pageSize query int true "请求数量 默认:10" default(10) // @Param queryType path string true "类型:day/week/month" -// @Success 200 {object} []cp_cv.CvCp +// @Success 200 {object} []cp_cv.CvCpRank // @Router /v2/cp/rank/{queryType} [get] func CpRank(c *gin.Context) (*mycontext.MyContext, error) { myCtx := mycontext.CreateMyContext(c.Keys) @@ -58,7 +58,7 @@ func CpRank(c *gin.Context) (*mycontext.MyContext, error) { offset, limit := (pageReq.PageIndex-1)*pageReq.PageSize, pageReq.PageSize model := domain.CreateModelContext(myCtx) ranks := cp_m.PageCpDayRank(model, beginDate, endDate, offset, limit) - var response []cp_cv.CvCp + var response []cp_cv.CvCpRank var userIds []mysql.ID var cpIds []mysql.ID for _, rank := range ranks { @@ -72,7 +72,7 @@ func CpRank(c *gin.Context) (*mycontext.MyContext, error) { } cpLevels := cp_m.MGetCpLevel(model, cpIds) for i, rank := range ranks { - response = append(response, cp_cv.CvCp{ + response = append(response, cp_cv.CvCpRank{ CpId: rank.CpId, User1: userBase[rank.UserId1], User2: userBase[rank.UserId2], @@ -104,8 +104,8 @@ func CpTop3(c *gin.Context) (*mycontext.MyContext, error) { return myCtx, err } var response = cp_cv.CpTops{ - Day: make([]cp_cv.CvCp, 0), - Week: make([]cp_cv.CvCp, 0), + Day: make([]cp_cv.CvCpRank, 0), + Week: make([]cp_cv.CvCpRank, 0), } queryTypes := []string{"day", "week"} for _, queryType := range queryTypes { @@ -134,7 +134,7 @@ func CpTop3(c *gin.Context) (*mycontext.MyContext, error) { cpLevels := cp_m.MGetCpLevel(model, cpIds) for i, rank := range ranks { if queryType == "day" { - response.Day = append(response.Day, cp_cv.CvCp{ + response.Day = append(response.Day, cp_cv.CvCpRank{ CpId: rank.CpId, User1: userBase[rank.UserId1], User2: userBase[rank.UserId2], @@ -145,7 +145,7 @@ func CpTop3(c *gin.Context) (*mycontext.MyContext, error) { }, }) } else { - response.Week = append(response.Week, cp_cv.CvCp{ + response.Week = append(response.Week, cp_cv.CvCpRank{ CpId: rank.CpId, User1: userBase[rank.UserId1], User2: userBase[rank.UserId2], @@ -167,7 +167,7 @@ func CpTop3(c *gin.Context) (*mycontext.MyContext, error) { // @Param token header string true "token" // @Param nonce header string true "随机数字" // @Param queryType path string true "类型:day/week/month" -// @Success 200 {object} cp_cv.CvCp +// @Success 200 {object} cp_cv.CvCpRank // @Router /v2/cp/my/{queryType} [get] func CpMy(c *gin.Context) (*mycontext.MyContext, error) { myCtx := mycontext.CreateMyContext(c.Keys) @@ -212,7 +212,7 @@ func CpMy(c *gin.Context) (*mycontext.MyContext, error) { if err != nil { return myCtx, err } - response := cp_cv.CvCp{ + response := cp_cv.CvCpRank{ CpId: relation.ID, Score: scores, }