Commit d7e6e1ad authored by hujiebin's avatar hujiebin

refact: timestamp

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