Commit b4589560 authored by hujiebin's avatar hujiebin

fix:用上客户端的timezone

parent 7f3f8a49
...@@ -140,7 +140,7 @@ func GetNeedRemindCpAnniversary(model *domain.Model) []CpAnniversary { ...@@ -140,7 +140,7 @@ func GetNeedRemindCpAnniversary(model *domain.Model) []CpAnniversary {
} }
now := time.Now().Unix() now := time.Now().Unix()
for i, v := range rows { for i, v := range rows {
ts := CalcNextAnniversary(v.Timestamp) ts := CalcNextAnniversary(v.Timestamp, time.Local)
if now > ts { if now > ts {
res = append(res, rows[i]) res = append(res, rows[i])
} }
...@@ -149,7 +149,7 @@ func GetNeedRemindCpAnniversary(model *domain.Model) []CpAnniversary { ...@@ -149,7 +149,7 @@ func GetNeedRemindCpAnniversary(model *domain.Model) []CpAnniversary {
} }
// 获取cp当天需要提醒的纪念日 // 获取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 var rows, res []CpAnniversary
if err := model.DB().Model(CpAnniversary{}). if err := model.DB().Model(CpAnniversary{}).
Where("`timestamp` > 0"). Where("`timestamp` > 0").
...@@ -161,7 +161,7 @@ func GetUserTodayCpAnniversary(model *domain.Model, cpId mysql.ID) []CpAnniversa ...@@ -161,7 +161,7 @@ func GetUserTodayCpAnniversary(model *domain.Model, cpId mysql.ID) []CpAnniversa
} }
now := time.Now().Unix() now := time.Now().Unix()
for i, v := range rows { for i, v := range rows {
ts := CalcNextAnniversary(v.Timestamp) ts := CalcNextAnniversary(v.Timestamp, tz)
if now > ts { if now > ts {
res = append(res, rows[i]) res = append(res, rows[i])
} }
...@@ -174,11 +174,14 @@ func UpdateCpAnniversaryReminded(model *domain.Model, id mysql.ID) error { ...@@ -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() now := time.Now()
birthday := time.Unix(timestamp, 0) 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 var next time.Time
......
package cp_r package cp_r
import ( import (
"git.hilo.cn/hilo-common/_const/enum/timezone_e"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/mycontext"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
...@@ -13,6 +14,7 @@ import ( ...@@ -13,6 +14,7 @@ import (
"hilo-user/req" "hilo-user/req"
"hilo-user/resp" "hilo-user/resp"
"strconv" "strconv"
"time"
) )
type PostPutAnniversaryReq struct { type PostPutAnniversaryReq struct {
...@@ -92,8 +94,19 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -92,8 +94,19 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
if err != nil { if err != nil {
return myCtx, err return myCtx, err
} }
var response = make([]cp_cv.CvCpAnniversary, 0)
model := domain.CreateModelContext(myCtx) 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) cpRelation, exits := cp_m.GetCpRelation(model, userId)
if exits { if exits {
userIds := []uint64{cpRelation.UserId1, cpRelation.UserId2} userIds := []uint64{cpRelation.UserId1, cpRelation.UserId2}
...@@ -122,7 +135,7 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -122,7 +135,7 @@ func PageAnniversary(c *gin.Context) (*mycontext.MyContext, error) {
for _, v := range anniversary { for _, v := range anniversary {
timestamp := v.Timestamp timestamp := v.Timestamp
if v.Type == cp_e.AnniversaryItemTypeAnniversary && timestamp > 0 { if v.Type == cp_e.AnniversaryItemTypeAnniversary && timestamp > 0 {
timestamp = cp_m.CalcNextAnniversary(timestamp) timestamp = cp_m.CalcNextAnniversary(timestamp, loc)
} }
// 客户端只认识0 1 // 客户端只认识0 1
Type := v.Type Type := v.Type
......
package cp_r package cp_r
import ( import (
"git.hilo.cn/hilo-common/_const/enum/timezone_e"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
...@@ -30,15 +31,21 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -30,15 +31,21 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) {
if err != nil { if err != nil {
return myContext, err return myContext, err
} }
externalId := c.Query("externalId")
if len(externalId) <= 0 {
return myContext, bizerr.InvalidParameter
}
var model = domain.CreateModelContext(myContext) var model = domain.CreateModelContext(myContext)
userInfo, err := user_m.GetUser(model, userId) userInfo, err := user_m.GetUser(model, userId)
if err != nil { if err != nil {
return myContext, err 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) targetUserInfo, err := user_m.GetUserByExtId(model, externalId)
if err != nil { if err != nil {
return myContext, err return myContext, err
...@@ -130,7 +137,7 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -130,7 +137,7 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) {
} }
// 需要提醒的纪念日 // 需要提醒的纪念日
if exists && (userId == cpRelation.UserId1 || userId == cpRelation.UserId2) { 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 { for _, a := range anniversary {
response.CpAnniversary = append(response.CpAnniversary, cp_cv.CvCpAnniversary{ response.CpAnniversary = append(response.CpAnniversary, cp_cv.CvCpAnniversary{
Id: a.ID, Id: a.ID,
......
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