Commit 303c41b0 authored by hujiebin's avatar hujiebin

初始化纪念日

parent a4a24136
......@@ -5,5 +5,5 @@ type AnniversaryItemType int
const (
AnniversaryItemTypeNormal AnniversaryItemType = 0 // 普通类型
AnniversaryItemTypeAvatar AnniversaryItemType = 1 // 头像类型
AnniversaryItemTypeBirthday AnniversaryItemType = 2 // 生日类型
AnniversaryItemTypeAnniversary AnniversaryItemType = 2 // 纪念日类型(一年一度,如生日/结婚纪念日)
)
......@@ -19,4 +19,5 @@ type CvCpAnniversary struct {
Timestamp int64 `json:"timestamp"` // 纪念日时间戳
IsRemind bool `json:"isRemind"` // 是否提醒
CanDel bool `json:"canDel"` // 能否删除
IsTop bool `json:"isTop"` // 是否置顶
}
package cp_m
import (
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"hilo-user/_const/enum/cp_e"
"hilo-user/domain/model/user_m"
"time"
)
// CpAnniversary cp纪念日
type CpAnniversary struct {
mysql.Entity
CpId mysql.ID
Type cp_e.AnniversaryItemType
CpId mysql.ID
UserId1 mysql.ID
UserId2 mysql.ID
Content string
......@@ -21,16 +23,47 @@ type CpAnniversary struct {
Sort int
}
// 初始化6个cp纪念日
// 1)我们在一起;2)XXX的生日;3)XXX的生日;4)第一次说我爱你;5)第一次亲吻;6)结婚纪念日
// todo 翻译
func InitCpAnniversary(model *domain.Model, cp CpRelationTmp) error {
users, err := user_m.GetUserMapByIds(model, []uint64{cp.UserId1, cp.UserId2})
if err != nil {
return err
}
if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, "我们在一起", time.Now().Unix(), true, 100); err != nil {
return err
}
if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, fmt.Sprintf("%s的生日", users[cp.UserId1].Nick), int64(users[cp.UserId1].Birthday), true, 0); err != nil {
return err
}
if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, fmt.Sprintf("%s的生日", users[cp.UserId2].Nick), int64(users[cp.UserId2].Birthday), true, 0); err != nil {
return err
}
if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, "第一次说我爱你", 0, false, 0); err != nil {
return err
}
if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, cp, "第一次亲吻", 0, false, 0); err != nil {
return err
}
if err := AddCpAnniversary(model, cp_e.AnniversaryItemTypeAnniversary, cp, "结婚纪念日", 0, false, 0); err != nil {
return err
}
return nil
}
// 添加cp纪念日
func AddCpAnniversary(model *domain.Model, cp CpRelationTmp, content string, ts int64, isRemind bool) error {
func AddCpAnniversary(model *domain.Model, Type cp_e.AnniversaryItemType, cp CpRelationTmp, content string, ts int64, isRemind bool, sort int) error {
return model.DB().Model(CpAnniversary{}).Create(&CpAnniversary{
CpId: cp.ID,
Type: Type,
UserId1: cp.UserId1,
UserId2: cp.UserId2,
Content: content,
Timestamp: ts,
IsRemind: isRemind,
Reminded: mysql.NO,
Sort: sort,
}).Error
}
......@@ -55,7 +88,7 @@ func GetAllCpAnniversary(model *domain.Model, userId mysql.ID) []CpAnniversary {
if !exists {
return res
}
if err := model.DB().Model(CpAnniversary{}).Where("cp_id = ?", relation.ID).Order("`sort` DESC,updated_time DESC").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)
}
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, relation, param.Content, param.Timestamp, param.IsRemind); err != nil {
if err := cp_m.AddCpAnniversary(model, cp_e.AnniversaryItemTypeNormal, relation, param.Content, param.Timestamp, param.IsRemind, 0); err != nil {
return myCtx, err
}
}
......@@ -120,12 +120,13 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
anniversary := cp_m.GetAllCpAnniversary(model, userId)
for _, v := range anniversary {
response = append(response, cp_cv.CvCpAnniversary{
Type: cp_e.AnniversaryItemTypeNormal,
Type: v.Type,
Id: v.ID,
Content: v.Content,
Timestamp: v.Timestamp,
IsRemind: v.IsRemind,
CanDel: true,
IsTop: v.Sort > 0,
})
}
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