Commit 78403c9e authored by hujiebin's avatar hujiebin

feat:增加msgId

parent 6295f1dc
...@@ -23,6 +23,7 @@ type CpAnniversary struct { ...@@ -23,6 +23,7 @@ type CpAnniversary struct {
IsRemind bool IsRemind bool
LastRemindTime int64 LastRemindTime int64
Sort int Sort int
MsgId uint
} }
// 初始化6个cp纪念日 // 初始化6个cp纪念日
...@@ -32,22 +33,22 @@ func InitCpAnniversary(model *domain.Model, cp CpRelation, lang string) error { ...@@ -32,22 +33,22 @@ func InitCpAnniversary(model *domain.Model, cp CpRelation, lang string) error {
if err != nil { if err != nil {
return err return err
} }
if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, GetTranslate(259, lang), time.Now().Unix(), true, 100); err != nil { if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, GetTranslate(259, lang), time.Now().Unix(), true, 100, 259); err != nil {
return err return err
} }
if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, fmt.Sprintf(GetTranslate(260, lang), users[cp.UserId1].Nick), 0, true, 0); err != nil { if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, fmt.Sprintf(GetTranslate(260, lang), users[cp.UserId1].Nick), 0, true, 0, 260); err != nil {
return err return err
} }
if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, fmt.Sprintf(GetTranslate(260, lang), users[cp.UserId2].Nick), 0, true, 0); err != nil { if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, fmt.Sprintf(GetTranslate(260, lang), users[cp.UserId2].Nick), 0, true, 0, 260); err != nil {
return err return err
} }
if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, GetTranslate(261, lang), 0, true, 0); err != nil { if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, GetTranslate(261, lang), 0, true, 0, 261); err != nil {
return err return err
} }
if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, GetTranslate(262, lang), 0, true, 0); err != nil { if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, GetTranslate(262, lang), 0, true, 0, 262); err != nil {
return err return err
} }
if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, GetTranslate(263, lang), 0, true, 0); err != nil { if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, GetTranslate(263, lang), 0, true, 0, 263); err != nil {
return err return err
} }
return nil return nil
...@@ -68,7 +69,7 @@ func GetTranslate(msgId uint, lang string) string { ...@@ -68,7 +69,7 @@ func GetTranslate(msgId uint, lang string) string {
} }
// 添加cp纪念日 // 添加cp纪念日
func AddCpAnniversary(model *domain.Model, Type cp_e.AnniversaryItemType, cp CpRelation, content string, ts int64, isRemind bool, sort int) error { func AddCpAnniversary(model *domain.Model, Type cp_e.AnniversaryItemType, cp CpRelation, content string, ts int64, isRemind bool, sort int, msgId uint) error {
return model.DB().Model(CpAnniversary{}).Create(&CpAnniversary{ return model.DB().Model(CpAnniversary{}).Create(&CpAnniversary{
CpId: cp.Id, CpId: cp.Id,
Type: Type, Type: Type,
...@@ -79,6 +80,7 @@ func AddCpAnniversary(model *domain.Model, Type cp_e.AnniversaryItemType, cp CpR ...@@ -79,6 +80,7 @@ func AddCpAnniversary(model *domain.Model, Type cp_e.AnniversaryItemType, cp CpR
IsRemind: isRemind, IsRemind: isRemind,
LastRemindTime: 0, LastRemindTime: 0,
Sort: sort, Sort: sort,
MsgId: msgId,
}).Error }).Error
} }
...@@ -97,7 +99,7 @@ func DelCpAnniversary(model *domain.Model, id mysql.ID) error { ...@@ -97,7 +99,7 @@ func DelCpAnniversary(model *domain.Model, id mysql.ID) error {
} }
// 根据用户id获取所有纪念日 // 根据用户id获取所有纪念日
func GetAllCpAnniversary(model *domain.Model, userId mysql.ID) []CpAnniversary { func GetAllCpAnniversary(model *domain.Model, userId mysql.ID, lang string) []CpAnniversary {
var res []CpAnniversary var res []CpAnniversary
relation, exists := GetCpRelation(model, userId) relation, exists := GetCpRelation(model, userId)
if !exists { if !exists {
...@@ -106,6 +108,11 @@ func GetAllCpAnniversary(model *domain.Model, userId mysql.ID) []CpAnniversary { ...@@ -106,6 +108,11 @@ func GetAllCpAnniversary(model *domain.Model, userId mysql.ID) []CpAnniversary {
if err := model.DB().Model(CpAnniversary{}).Where("cp_id = ?", relation.Id).Order("`sort` DESC,updated_time DESC,id ASC").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)
} }
for i, v := range res {
if v.CreatedTime.Equal(v.UpdatedTime) && v.MsgId > 0 {
res[i].Content = GetTranslate(v.MsgId, lang)
}
}
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, cp_e.AnniversaryItemTypeNormal, relation, param.Content, param.Timestamp, param.IsRemind, 0); err != nil { if err := cp_m.AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, relation, param.Content, param.Timestamp, param.IsRemind, 0, 0); err != nil {
return myCtx, err return myCtx, err
} }
} }
...@@ -88,7 +88,7 @@ func PutAnniversary(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -88,7 +88,7 @@ func PutAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
// @Router /v2/cp/anniversary [get] // @Router /v2/cp/anniversary [get]
func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
myCtx := mycontext.CreateMyContext(c.Keys) myCtx := mycontext.CreateMyContext(c.Keys)
userId, err := req.GetUserId(c) userId, lang, err := req.GetUserIdLang(c, myCtx)
if err != nil { if err != nil {
return myCtx, err return myCtx, err
} }
...@@ -118,7 +118,7 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -118,7 +118,7 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
CanDel: false, CanDel: false,
}) })
} }
anniversary := cp_m.GetAllCpAnniversary(model, userId) anniversary := cp_m.GetAllCpAnniversary(model, userId, lang)
for _, v := range anniversary { for _, v := range anniversary {
timestamp := v.Timestamp timestamp := v.Timestamp
if v.Type == cp_e.AnniversaryItemTypeAnniversary && timestamp > 0 { if v.Type == cp_e.AnniversaryItemTypeAnniversary && timestamp > 0 {
......
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