Commit 303c41b0 authored by hujiebin's avatar hujiebin

初始化纪念日

parent a4a24136
...@@ -3,7 +3,7 @@ package cp_e ...@@ -3,7 +3,7 @@ package cp_e
type AnniversaryItemType int type AnniversaryItemType int
const ( const (
AnniversaryItemTypeNormal AnniversaryItemType = 0 // 普通类型 AnniversaryItemTypeNormal AnniversaryItemType = 0 // 普通类型
AnniversaryItemTypeAvatar AnniversaryItemType = 1 // 头像类型 AnniversaryItemTypeAvatar AnniversaryItemType = 1 // 头像类型
AnniversaryItemTypeBirthday AnniversaryItemType = 2 // 生日类型 AnniversaryItemTypeAnniversary AnniversaryItemType = 2 // 纪念日类型(一年一度,如生日/结婚纪念日)
) )
...@@ -19,4 +19,5 @@ type CvCpAnniversary struct { ...@@ -19,4 +19,5 @@ type CvCpAnniversary struct {
Timestamp int64 `json:"timestamp"` // 纪念日时间戳 Timestamp int64 `json:"timestamp"` // 纪念日时间戳
IsRemind bool `json:"isRemind"` // 是否提醒 IsRemind bool `json:"isRemind"` // 是否提醒
CanDel bool `json:"canDel"` // 能否删除 CanDel bool `json:"canDel"` // 能否删除
IsTop bool `json:"isTop"` // 是否置顶
} }
package cp_m package cp_m
import ( import (
"fmt"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"hilo-user/_const/enum/cp_e" "hilo-user/_const/enum/cp_e"
"hilo-user/domain/model/user_m"
"time" "time"
) )
// CpAnniversary cp纪念日 // CpAnniversary cp纪念日
type CpAnniversary struct { type CpAnniversary struct {
mysql.Entity mysql.Entity
CpId mysql.ID
Type cp_e.AnniversaryItemType Type cp_e.AnniversaryItemType
CpId mysql.ID
UserId1 mysql.ID UserId1 mysql.ID
UserId2 mysql.ID UserId2 mysql.ID
Content string Content string
...@@ -21,16 +23,47 @@ type CpAnniversary struct { ...@@ -21,16 +23,47 @@ type CpAnniversary struct {
Sort int 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纪念日 // 添加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{ return model.DB().Model(CpAnniversary{}).Create(&CpAnniversary{
CpId: cp.ID, CpId: cp.ID,
Type: Type,
UserId1: cp.UserId1, UserId1: cp.UserId1,
UserId2: cp.UserId2, UserId2: cp.UserId2,
Content: content, Content: content,
Timestamp: ts, Timestamp: ts,
IsRemind: isRemind, IsRemind: isRemind,
Reminded: mysql.NO, Reminded: mysql.NO,
Sort: sort,
}).Error }).Error
} }
...@@ -55,7 +88,7 @@ func GetAllCpAnniversary(model *domain.Model, userId mysql.ID) []CpAnniversary { ...@@ -55,7 +88,7 @@ func GetAllCpAnniversary(model *domain.Model, userId mysql.ID) []CpAnniversary {
if !exists { if !exists {
return res 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) model.Log.Errorf("GetAllCpAnniversary fail:%v", err)
} }
return res return res
......
...@@ -45,7 +45,7 @@ func PostAnniversary(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -45,7 +45,7 @@ func PostAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
if !exits { if !exits {
return myCtx, bizerr.CpNotRelation return myCtx, bizerr.CpNotRelation
} else { } 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 return myCtx, err
} }
} }
...@@ -120,12 +120,13 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -120,12 +120,13 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
anniversary := cp_m.GetAllCpAnniversary(model, userId) anniversary := cp_m.GetAllCpAnniversary(model, userId)
for _, v := range anniversary { for _, v := range anniversary {
response = append(response, cp_cv.CvCpAnniversary{ response = append(response, cp_cv.CvCpAnniversary{
Type: cp_e.AnniversaryItemTypeNormal, Type: v.Type,
Id: v.ID, Id: v.ID,
Content: v.Content, Content: v.Content,
Timestamp: v.Timestamp, Timestamp: v.Timestamp,
IsRemind: v.IsRemind, IsRemind: v.IsRemind,
CanDel: true, CanDel: true,
IsTop: v.Sort > 0,
}) })
} }
resp.ResponsePageBaseOk(c, response, 0, false) resp.ResponsePageBaseOk(c, response, 0, false)
......
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