Commit d7e6e1ad authored by hujiebin's avatar hujiebin

refact: timestamp

parent b9aeabdc
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
type CpAnniversaryNoticeMsg struct { type CpAnniversaryNoticeMsg struct {
Identifier string `json:"identifier"` Identifier string `json:"identifier"`
Content string `json:"content"` Content string `json:"content"`
Date string `json:"date"` Timestamp int64 `json:"timestamp"`
} }
func CpAnniversaryNotice() { func CpAnniversaryNotice() {
...@@ -39,7 +39,7 @@ func CpAnniversaryNotice() { ...@@ -39,7 +39,7 @@ func CpAnniversaryNotice() {
data, _ := json.Marshal(CpAnniversaryNoticeMsg{ data, _ := json.Marshal(CpAnniversaryNoticeMsg{
Identifier: "CpAnniversaryNotice", Identifier: "CpAnniversaryNotice",
Content: v.Content, Content: v.Content,
Date: v.Date, Timestamp: v.Timestamp,
}) })
if err := tencentyun.BatchSendCustomMsg(model, 1, users[0].ExternalId, []string{users[1].ExternalId}, string(data), "cp纪念日"); err != nil { if err := tencentyun.BatchSendCustomMsg(model, 1, users[0].ExternalId, []string{users[1].ExternalId}, string(data), "cp纪念日"); err != nil {
model.Log.Errorf("BatchSendCustomMsg fail:%v", err) model.Log.Errorf("BatchSendCustomMsg fail:%v", err)
......
...@@ -27,7 +27,7 @@ type CvCpAchievement struct { ...@@ -27,7 +27,7 @@ type CvCpAchievement struct {
type CvCpAnniversary struct { type CvCpAnniversary struct {
Id uint64 `json:"id"` // 记录id Id uint64 `json:"id"` // 记录id
Content string `json:"content"` // 纪念日内容 Content string `json:"content"` // 纪念日内容
Date string `json:"date"` // 纪念日日期 Timestamp int64 `json:"timestamp"` // 纪念日时间戳
IsRemind bool `json:"isRemind"` // 是否提醒 IsRemind bool `json:"isRemind"` // 是否提醒
} }
......
...@@ -13,32 +13,29 @@ type CpAnniversary struct { ...@@ -13,32 +13,29 @@ type CpAnniversary struct {
UserId1 mysql.ID UserId1 mysql.ID
UserId2 mysql.ID UserId2 mysql.ID
Content string Content string
Date string Timestamp int64
Timezone string
IsRemind bool IsRemind bool
Reminded mysql.YesNo Reminded mysql.YesNo
} }
// 添加cp纪念日 // 添加cp纪念日
func AddCpAnniversary(model *domain.Model, cp CpRelationTmp, content, date, tz string, isRemind bool) error { func AddCpAnniversary(model *domain.Model, cp CpRelationTmp, content string, ts int64, isRemind bool) error {
return model.DB().Model(CpAnniversary{}).Create(&CpAnniversary{ return model.DB().Model(CpAnniversary{}).Create(&CpAnniversary{
CpId: cp.ID, CpId: cp.ID,
UserId1: cp.UserId1, UserId1: cp.UserId1,
UserId2: cp.UserId2, UserId2: cp.UserId2,
Content: content, Content: content,
Date: date, Timestamp: ts,
Timezone: tz,
IsRemind: isRemind, IsRemind: isRemind,
Reminded: mysql.NO, Reminded: mysql.NO,
}).Error }).Error
} }
// 更新cp纪念日 // 更新cp纪念日
func UpdateCpAnniversary(model *domain.Model, id mysql.ID, content, date, tz string, isRemind bool) error { func UpdateCpAnniversary(model *domain.Model, id mysql.ID, content string, ts int64, isRemind bool) error {
updates := map[string]interface{}{ updates := map[string]interface{}{
"content": content, "content": content,
"date": date, "timestamp": ts,
"timezone": tz,
"is_remind": isRemind, "is_remind": isRemind,
} }
return model.DB().Model(CpAnniversary{}).Where("id = ?", id).Updates(updates).Error return model.DB().Model(CpAnniversary{}).Where("id = ?", id).Updates(updates).Error
...@@ -64,9 +61,8 @@ func GetAllCpAnniversary(model *domain.Model, userId mysql.ID) []CpAnniversary { ...@@ -64,9 +61,8 @@ func GetAllCpAnniversary(model *domain.Model, userId mysql.ID) []CpAnniversary {
// 获取所有需要提醒的纪念日 // 获取所有需要提醒的纪念日
func GetNeedRemindCpAnniversary(model *domain.Model) []CpAnniversary { func GetNeedRemindCpAnniversary(model *domain.Model) []CpAnniversary {
var res []CpAnniversary var res []CpAnniversary
date := time.Now().Format("2006-01-02")
if err := model.DB().Model(CpAnniversary{}). if err := model.DB().Model(CpAnniversary{}).
Where("`date` = ?", date). Where("`timestamp` > ?", time.Now().Unix()).
Where("is_remind = 1"). Where("is_remind = 1").
Where("reminded = ?", mysql.NO). Where("reminded = ?", mysql.NO).
Find(&res).Error; err != nil { Find(&res).Error; err != nil {
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
type PostPutAnniversaryReq struct { type PostPutAnniversaryReq struct {
Content string `form:"content" binding:"required"` Content string `form:"content" binding:"required"`
Date string `form:"date" binding:"required"` Timestamp int64 `form:"timestamp" binding:"required"`
IsRemind bool `form:"isRemind"` IsRemind bool `form:"isRemind"`
} }
...@@ -22,9 +22,8 @@ type PostPutAnniversaryReq struct { ...@@ -22,9 +22,8 @@ type PostPutAnniversaryReq struct {
// @Summary 发布纪念日 // @Summary 发布纪念日
// @Param token header string true "token" // @Param token header string true "token"
// @Param nonce header string true "随机数字" // @Param nonce header string true "随机数字"
// @Param timezone header string true "时区"
// @Param content formData string true "纪念日名称" // @Param content formData string true "纪念日名称"
// @Param date formData string true "纪念日时间(年月日)" // @Param timestamp formData int true "时间戳"
// @Param isRemind formData bool false "是否提醒" // @Param isRemind formData bool false "是否提醒"
// @Success 200 // @Success 200
// @Router /v2/cp/anniversary [post] // @Router /v2/cp/anniversary [post]
...@@ -43,8 +42,7 @@ func PostAnniversary(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -43,8 +42,7 @@ func PostAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
if !exits { if !exits {
return myCtx, bizerr.CpNotRelation return myCtx, bizerr.CpNotRelation
} else { } else {
tz := c.GetHeader(mycontext.TIMEZONE) if err := cp_m.AddCpAnniversary(model, relation, param.Content, param.Timestamp, param.IsRemind); err != nil {
if err := cp_m.AddCpAnniversary(model, relation, param.Content, param.Date, tz, param.IsRemind); err != nil {
return myCtx, err return myCtx, err
} }
} }
...@@ -56,9 +54,8 @@ func PostAnniversary(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -56,9 +54,8 @@ func PostAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
// @Summary 修改纪念日 // @Summary 修改纪念日
// @Param token header string true "token" // @Param token header string true "token"
// @Param nonce header string true "随机数字" // @Param nonce header string true "随机数字"
// @Param timezone header string true "时区"
// @Param content formData string true "纪念日名称" // @Param content formData string true "纪念日名称"
// @Param date formData string true "纪念日时间(年月日)" // @Param timestamp formData int true "时间戳"
// @Param isRemind formData bool false "是否提醒" // @Param isRemind formData bool false "是否提醒"
// @Param id path int true "更新的记录id" // @Param id path int true "更新的记录id"
// @Success 200 // @Success 200
...@@ -71,8 +68,7 @@ func PutAnniversary(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -71,8 +68,7 @@ func PutAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
} }
id, _ := strconv.ParseUint(c.Param("id"), 10, 64) id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
model := domain.CreateModelContext(myCtx) model := domain.CreateModelContext(myCtx)
tz := c.GetHeader(mycontext.TIMEZONE) if err := cp_m.UpdateCpAnniversary(model, id, param.Content, param.Timestamp, param.IsRemind); err != nil {
if err := cp_m.UpdateCpAnniversary(model, id, param.Content, param.Date, tz, param.IsRemind); err != nil {
return myCtx, err return myCtx, err
} }
resp.ResponseOk(c, "") resp.ResponseOk(c, "")
...@@ -98,7 +94,7 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -98,7 +94,7 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
response = append(response, cp_cv.CvCpAnniversary{ response = append(response, cp_cv.CvCpAnniversary{
Id: v.ID, Id: v.ID,
Content: v.Content, Content: v.Content,
Date: v.Date, Timestamp: v.Timestamp,
IsRemind: v.IsRemind, IsRemind: v.IsRemind,
}) })
} }
......
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