Commit 78403c9e authored by hujiebin's avatar hujiebin

feat:增加msgId

parent 6295f1dc
......@@ -23,6 +23,7 @@ type CpAnniversary struct {
IsRemind bool
LastRemindTime int64
Sort int
MsgId uint
}
// 初始化6个cp纪念日
......@@ -32,22 +33,22 @@ func InitCpAnniversary(model *domain.Model, cp CpRelation, lang string) error {
if err != nil {
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
}
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
}
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
}
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
}
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
}
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 nil
......@@ -68,7 +69,7 @@ func GetTranslate(msgId uint, lang string) string {
}
// 添加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{
CpId: cp.Id,
Type: Type,
......@@ -79,6 +80,7 @@ func AddCpAnniversary(model *domain.Model, Type cp_e.AnniversaryItemType, cp CpR
IsRemind: isRemind,
LastRemindTime: 0,
Sort: sort,
MsgId: msgId,
}).Error
}
......@@ -97,7 +99,7 @@ func DelCpAnniversary(model *domain.Model, id mysql.ID) error {
}
// 根据用户id获取所有纪念日
func GetAllCpAnniversary(model *domain.Model, userId mysql.ID) []CpAnniversary {
func GetAllCpAnniversary(model *domain.Model, userId mysql.ID, lang string) []CpAnniversary {
var res []CpAnniversary
relation, exists := GetCpRelation(model, userId)
if !exists {
......@@ -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 {
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
}
......
......@@ -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, 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
}
}
......@@ -88,7 +88,7 @@ func PutAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
// @Router /v2/cp/anniversary [get]
func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
myCtx := mycontext.CreateMyContext(c.Keys)
userId, err := req.GetUserId(c)
userId, lang, err := req.GetUserIdLang(c, myCtx)
if err != nil {
return myCtx, err
}
......@@ -118,7 +118,7 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
CanDel: false,
})
}
anniversary := cp_m.GetAllCpAnniversary(model, userId)
anniversary := cp_m.GetAllCpAnniversary(model, userId, lang)
for _, v := range anniversary {
timestamp := v.Timestamp
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