diff --git a/_const/enum/cp_e/anniversary.go b/_const/enum/cp_e/anniversary.go index b09c3b75e9d76aa7c0149e77b28e56fa6fb7a494..a2011004ec33431dc9607c26c8c6b15659f686a3 100644 --- a/_const/enum/cp_e/anniversary.go +++ b/_const/enum/cp_e/anniversary.go @@ -3,7 +3,7 @@ package cp_e type AnniversaryItemType int const ( - AnniversaryItemTypeNormal AnniversaryItemType = 0 // 普通类型 - AnniversaryItemTypeAvatar AnniversaryItemType = 1 // 头像类型 - AnniversaryItemTypeBirthday AnniversaryItemType = 2 // 生日类型 + AnniversaryItemTypeNormal AnniversaryItemType = 0 // 普通类型 + AnniversaryItemTypeAvatar AnniversaryItemType = 1 // 头像类型 + AnniversaryItemTypeAnniversary AnniversaryItemType = 2 // 纪念日类型(一年一度,如生日/结婚纪念日) ) diff --git a/cv/cp_cv/anniversary.go b/cv/cp_cv/anniversary.go index f022bbeda39d19545f62d9d3f596c6230290838a..1c503a0a2f8c52ccf18b51752bbeda0b6aa855c4 100644 --- a/cv/cp_cv/anniversary.go +++ b/cv/cp_cv/anniversary.go @@ -19,4 +19,5 @@ type CvCpAnniversary struct { Timestamp int64 `json:"timestamp"` // 纪念日时间戳 IsRemind bool `json:"isRemind"` // 是否提醒 CanDel bool `json:"canDel"` // 能否删除 + IsTop bool `json:"isTop"` // 是否置顶 } diff --git a/domain/model/cp_m/anniversary.go b/domain/model/cp_m/anniversary.go index e48d66c3508ebf173fadce59e014ae7baeeb21d0..70f5305159060a73ffedccfe7a148b58aef5a27e 100644 --- a/domain/model/cp_m/anniversary.go +++ b/domain/model/cp_m/anniversary.go @@ -1,17 +1,19 @@ package cp_m import ( + "fmt" "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/resource/mysql" "hilo-user/_const/enum/cp_e" + "hilo-user/domain/model/user_m" "time" ) // CpAnniversary cp纪念日 type CpAnniversary struct { mysql.Entity - CpId mysql.ID Type cp_e.AnniversaryItemType + CpId mysql.ID UserId1 mysql.ID UserId2 mysql.ID Content string @@ -21,16 +23,47 @@ type CpAnniversary struct { Sort int } +// 初始化6个cp纪念日 +// 1)我们在一起;2)XXX的生日;3)XXX的生日;4)第一次说我爱你;5)第一次亲吻;6)结婚纪念日 +// todo 翻译 +func InitCpAnniversary(model *domain.Model, cp CpRelationTmp) error { + users, err := user_m.GetUserMapByIds(model, []uint64{cp.UserId1, cp.UserId2}) + if err != nil { + return err + } + if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, "我们在一起", time.Now().Unix(), true, 100); err != nil { + return err + } + if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, fmt.Sprintf("%s的生日", users[cp.UserId1].Nick), int64(users[cp.UserId1].Birthday), true, 0); err != nil { + return err + } + if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, fmt.Sprintf("%s的生日", users[cp.UserId2].Nick), int64(users[cp.UserId2].Birthday), true, 0); err != nil { + return err + } + if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, "第一次说我爱你", 0, false, 0); err != nil { + return err + } + if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, "第一次亲吻", 0, false, 0); err != nil { + return err + } + if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, "结婚纪念日", 0, false, 0); err != nil { + return err + } + return nil +} + // 添加cp纪念日 -func AddCpAnniversary(model *domain.Model, cp CpRelationTmp, content string, ts int64, isRemind bool) error { +func AddCpAnniversary(model *domain.Model, Type cp_e.AnniversaryItemType, cp CpRelationTmp, content string, ts int64, isRemind bool, sort int) error { return model.DB().Model(CpAnniversary{}).Create(&CpAnniversary{ CpId: cp.ID, + Type: Type, UserId1: cp.UserId1, UserId2: cp.UserId2, Content: content, Timestamp: ts, IsRemind: isRemind, Reminded: mysql.NO, + Sort: sort, }).Error } @@ -55,7 +88,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("`sort` DESC,updated_time DESC").Find(&res).Error; err != nil { + if err := model.DB().Model(CpAnniversary{}).Where("cp_id = ?", relation.ID).Order("`sort` DESC,updated_time DESC,id ASC").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 11f59e6c16469d4b73581f26acc104dff5f74e73..e2f1febc971c3db0320b25b84828aade882d2701 100644 --- a/route/cp_r/anniversary.go +++ b/route/cp_r/anniversary.go @@ -45,7 +45,7 @@ func PostAnniversary(c *gin.Context) (*mycontext.MyContext, error) { if !exits { return myCtx, bizerr.CpNotRelation } else { - if err := cp_m.AddCpAnniversary(model, relation, param.Content, param.Timestamp, param.IsRemind); err != nil { + if err := cp_m.AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, relation, param.Content, param.Timestamp, param.IsRemind, 0); err != nil { return myCtx, err } } @@ -120,12 +120,13 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { anniversary := cp_m.GetAllCpAnniversary(model, userId) for _, v := range anniversary { response = append(response, cp_cv.CvCpAnniversary{ - Type: cp_e.AnniversaryItemTypeNormal, + Type: v.Type, Id: v.ID, Content: v.Content, Timestamp: v.Timestamp, IsRemind: v.IsRemind, CanDel: true, + IsTop: v.Sort > 0, }) } resp.ResponsePageBaseOk(c, response, 0, false)