Commit 440edccb authored by hujiebin's avatar hujiebin

feat:调整cp纪念日

parent d7e6e1ad
package cp_e
type AnniversaryItemType int
const (
AnniversaryItemTypeNormal AnniversaryItemType = 0 // 普通类型
AnniversaryItemTypeAvatar AnniversaryItemType = 1 // 头像类型
)
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"` // 能否删除
}
......@@ -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"`
}
......@@ -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
......
......@@ -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)
......
......@@ -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,
}
......
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