diff --git a/domain/model/cp_m/anniversary.go b/domain/model/cp_m/anniversary.go index a85da083416c1e4a9e846d051d945cb0907955d2..002f95851e7df512d60b62a56c286d20c25e4580 100644 --- a/domain/model/cp_m/anniversary.go +++ b/domain/model/cp_m/anniversary.go @@ -140,7 +140,7 @@ func GetNeedRemindCpAnniversary(model *domain.Model) []CpAnniversary { } now := time.Now().Unix() for i, v := range rows { - ts := CalcNextAnniversary(v.Timestamp) + ts := CalcNextAnniversary(v.Timestamp, time.Local) if now > ts { res = append(res, rows[i]) } @@ -149,7 +149,7 @@ func GetNeedRemindCpAnniversary(model *domain.Model) []CpAnniversary { } // 获取cp当天需要提醒的纪念日 -func GetUserTodayCpAnniversary(model *domain.Model, cpId mysql.ID) []CpAnniversary { +func GetUserTodayCpAnniversary(model *domain.Model, cpId mysql.ID, tz *time.Location) []CpAnniversary { var rows, res []CpAnniversary if err := model.DB().Model(CpAnniversary{}). Where("`timestamp` > 0"). @@ -161,7 +161,7 @@ func GetUserTodayCpAnniversary(model *domain.Model, cpId mysql.ID) []CpAnniversa } now := time.Now().Unix() for i, v := range rows { - ts := CalcNextAnniversary(v.Timestamp) + ts := CalcNextAnniversary(v.Timestamp, tz) if now > ts { res = append(res, rows[i]) } @@ -174,11 +174,14 @@ func UpdateCpAnniversaryReminded(model *domain.Model, id mysql.ID) error { } // 计算下一个纪念日 -func CalcNextAnniversary(timestamp int64) int64 { +func CalcNextAnniversary(timestamp int64, tz *time.Location) int64 { + if tz == nil { + tz = time.Local + } now := time.Now() birthday := time.Unix(timestamp, 0) // 计算今年的生日日期 - thisYearBirthday := time.Date(now.Year(), birthday.Month(), birthday.Day(), 0, 0, 0, 0, time.Local) + thisYearBirthday := time.Date(now.Year(), birthday.Month(), birthday.Day(), 0, 0, 0, 0, tz) // 如果今年的生日还未到,则生日日期为今年的生日日期;否则为明年的生日日期 var next time.Time diff --git a/route/cp_r/anniversary.go b/route/cp_r/anniversary.go index f0c23c8e33f0ae5ad21a4cee216f1708bce91856..2ad3e997900c48d31d82f249f42176b2692de26c 100644 --- a/route/cp_r/anniversary.go +++ b/route/cp_r/anniversary.go @@ -1,6 +1,7 @@ package cp_r import ( + "git.hilo.cn/hilo-common/_const/enum/timezone_e" "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/mycontext" "github.com/gin-gonic/gin" @@ -13,6 +14,7 @@ import ( "hilo-user/req" "hilo-user/resp" "strconv" + "time" ) type PostPutAnniversaryReq struct { @@ -92,8 +94,19 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { if err != nil { return myCtx, err } - var response = make([]cp_cv.CvCpAnniversary, 0) model := domain.CreateModelContext(myCtx) + loc, err := time.LoadLocation(c.GetHeader(mycontext.TIMEZONE)) + if err != nil { + user, err := user_m.GetUser(model, userId) + if err != nil { + return myCtx, err + } + if user.Language == "ar" { + loc = timezone_e.KSATimezoneLoc + } + } + + var response = make([]cp_cv.CvCpAnniversary, 0) cpRelation, exits := cp_m.GetCpRelation(model, userId) if exits { userIds := []uint64{cpRelation.UserId1, cpRelation.UserId2} @@ -122,7 +135,7 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { for _, v := range anniversary { timestamp := v.Timestamp if v.Type == cp_e.AnniversaryItemTypeAnniversary && timestamp > 0 { - timestamp = cp_m.CalcNextAnniversary(timestamp) + timestamp = cp_m.CalcNextAnniversary(timestamp, loc) } // 客户端只认识0 1 Type := v.Type diff --git a/route/cp_r/space.go b/route/cp_r/space.go index ac0ed4a43778aaa21762ec581fadec0a666bfe01..1be7cc65fbf2885eacd4a688bb40e8ffb3e9b76b 100644 --- a/route/cp_r/space.go +++ b/route/cp_r/space.go @@ -1,6 +1,7 @@ package cp_r import ( + "git.hilo.cn/hilo-common/_const/enum/timezone_e" "git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/resource/mysql" @@ -30,15 +31,21 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) { if err != nil { return myContext, err } - externalId := c.Query("externalId") - if len(externalId) <= 0 { - return myContext, bizerr.InvalidParameter - } var model = domain.CreateModelContext(myContext) userInfo, err := user_m.GetUser(model, userId) if err != nil { return myContext, err } + loc, err := time.LoadLocation(c.GetHeader(mycontext.TIMEZONE)) + if err != nil { + if userInfo.Language == "ar" { + loc = timezone_e.KSATimezoneLoc + } + } + externalId := c.Query("externalId") + if len(externalId) <= 0 { + return myContext, bizerr.InvalidParameter + } targetUserInfo, err := user_m.GetUserByExtId(model, externalId) if err != nil { return myContext, err @@ -130,7 +137,7 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) { } // 需要提醒的纪念日 if exists && (userId == cpRelation.UserId1 || userId == cpRelation.UserId2) { - anniversary := cp_m.GetUserTodayCpAnniversary(model, cpRelation.Id) + anniversary := cp_m.GetUserTodayCpAnniversary(model, cpRelation.Id, loc) for _, a := range anniversary { response.CpAnniversary = append(response.CpAnniversary, cp_cv.CvCpAnniversary{ Id: a.ID,