Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-user
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenweijian
hilo-user
Commits
b4589560
Commit
b4589560
authored
Jun 17, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:用上客户端的timezone
parent
7f3f8a49
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
12 deletions
+35
-12
anniversary.go
domain/model/cp_m/anniversary.go
+8
-5
anniversary.go
route/cp_r/anniversary.go
+15
-2
space.go
route/cp_r/space.go
+12
-5
No files found.
domain/model/cp_m/anniversary.go
View file @
b4589560
...
...
@@ -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
,
t
ime
.
Local
)
thisYearBirthday
:=
time
.
Date
(
now
.
Year
(),
birthday
.
Month
(),
birthday
.
Day
(),
0
,
0
,
0
,
0
,
t
z
)
// 如果今年的生日还未到,则生日日期为今年的生日日期;否则为明年的生日日期
var
next
time
.
Time
...
...
route/cp_r/anniversary.go
View file @
b4589560
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
...
...
route/cp_r/space.go
View file @
b4589560
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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment