Commit d625196e authored by hujiebin's avatar hujiebin

Merge branch 'feature/cp-new' into feature/3.9.0

parents d24606f3 d7e6e1ad
...@@ -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)
......
...@@ -25,10 +25,10 @@ type CvCpAchievement struct { ...@@ -25,10 +25,10 @@ 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"` // 是否提醒
} }
type CpTops struct { type CpTops struct {
......
...@@ -9,36 +9,33 @@ import ( ...@@ -9,36 +9,33 @@ import (
// CpAnniversary cp纪念日 // CpAnniversary cp纪念日
type CpAnniversary struct { type CpAnniversary struct {
mysql.Entity mysql.Entity
CpId mysql.ID CpId mysql.ID
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 {
......
...@@ -13,18 +13,17 @@ import ( ...@@ -13,18 +13,17 @@ 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"`
} }
// @Tags CP v2 // @Tags CP v2
// @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, "")
...@@ -96,10 +92,10 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -96,10 +92,10 @@ 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{
Id: v.ID, Id: v.ID,
Content: v.Content, Content: v.Content,
Date: v.Date, Timestamp: v.Timestamp,
IsRemind: v.IsRemind, IsRemind: v.IsRemind,
}) })
} }
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