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
484d82ff
Commit
484d82ff
authored
May 31, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: im 通知
parent
f3e6d072
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
1 deletion
+88
-1
anniversary.go
cron/cp_cron/anniversary.go
+56
-0
cron.go
cron/cron.go
+1
-0
anniversary.go
domain/model/cp_m/anniversary.go
+22
-1
go.mod
go.mod
+3
-0
go.sum
go.sum
+6
-0
No files found.
cron/cp_cron/anniversary.go
0 → 100644
View file @
484d82ff
package
cp_cron
import
(
"encoding/json"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/sdk/tencentyun"
"github.com/robfig/cron"
"hilo-user/domain/model/cp_m"
"hilo-user/domain/model/user_m"
)
// 纪念日
type
CpAnniversaryNoticeMsg
struct
{
Identifier
string
`json:"identifier"`
Content
string
`json:"content"`
Date
string
`json:"date"`
}
func
CpAnniversaryNotice
()
{
c
:=
cron
.
New
()
// 1小时操作一次
spec
:=
"0 0 */1 * * ?"
if
!
config
.
AppIsRelease
()
{
// 测服1分钟
spec
=
"0 * * * * ?"
}
_
=
c
.
AddFunc
(
spec
,
func
()
{
var
model
=
domain
.
CreateModelNil
()
anniversary
:=
cp_m
.
GetNeedRemindCpAnniversary
(
model
)
for
_
,
v
:=
range
anniversary
{
var
userIds
[]
uint64
userIds
=
append
(
userIds
,
v
.
UserId1
,
v
.
UserId2
)
users
,
err
:=
user_m
.
GetUserMapByIds
(
model
,
userIds
)
if
err
!=
nil
||
len
(
users
)
<
2
{
model
.
Log
.
Errorf
(
"GetUserMapByIds fail:%v"
,
err
)
continue
}
data
,
_
:=
json
.
Marshal
(
CpAnniversaryNoticeMsg
{
Identifier
:
"CpAnniversaryNotice"
,
Content
:
v
.
Content
,
Date
:
v
.
Date
,
})
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
)
}
if
err
:=
tencentyun
.
BatchSendCustomMsg
(
model
,
1
,
users
[
1
]
.
ExternalId
,
[]
string
{
users
[
0
]
.
ExternalId
},
string
(
data
),
"cp纪念日"
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"BatchSendCustomMsg fail:%v"
,
err
)
}
if
err
:=
cp_m
.
UpdateCpAnniversaryReminded
(
model
,
v
.
ID
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"UpdateCpAnniversaryReminded fail:%v"
,
err
)
}
}
})
c
.
Start
()
}
cron/cron.go
View file @
484d82ff
...
...
@@ -13,4 +13,5 @@ func Init() {
gift_cron
.
SendGiftEventInit
()
// 礼物消息
gift_cron
.
GiftRemark
()
// 礼物消息补偿
cp_cron
.
ClearCpExpire
()
// 清理过期cp
cp_cron
.
CpAnniversaryNotice
()
// cp纪念日
}
domain/model/cp_m/anniversary.go
View file @
484d82ff
...
...
@@ -3,6 +3,7 @@ package cp_m
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"time"
)
// CpAnniversary cp纪念日
...
...
@@ -15,6 +16,7 @@ type CpAnniversary struct {
Date
string
Timezone
string
IsRemind
bool
Reminded
mysql
.
YesNo
}
// 添加cp纪念日
...
...
@@ -27,6 +29,7 @@ func AddCpAnniversary(model *domain.Model, cp CpRelationTmp, content, date, tz s
Date
:
date
,
Timezone
:
tz
,
IsRemind
:
isRemind
,
Reminded
:
mysql
.
NO
,
})
.
Error
}
...
...
@@ -35,7 +38,7 @@ func UpdateCpAnniversary(model *domain.Model, id mysql.ID, content, date, tz str
updates
:=
map
[
string
]
interface
{}{
"content"
:
content
,
"date"
:
date
,
"timezone"
:
tz
,
"timezone"
:
tz
,
"is_remind"
:
isRemind
,
}
return
model
.
DB
()
.
Model
(
CpAnniversary
{})
.
Where
(
"id = ?"
,
id
)
.
Updates
(
updates
)
.
Error
...
...
@@ -57,3 +60,21 @@ func GetAllCpAnniversary(model *domain.Model, userId mysql.ID) []CpAnniversary {
}
return
res
}
// 获取所有需要提醒的纪念日
func
GetNeedRemindCpAnniversary
(
model
*
domain
.
Model
)
[]
CpAnniversary
{
var
res
[]
CpAnniversary
date
:=
time
.
Now
()
.
Format
(
"2006-01-02"
)
if
err
:=
model
.
DB
()
.
Model
(
CpAnniversary
{})
.
Where
(
"`date` = ?"
,
date
)
.
Where
(
"is_remind = 1"
)
.
Where
(
"reminded = ?"
,
mysql
.
NO
)
.
Find
(
&
res
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetNeedRemindCpAnniversary fail:%v"
,
err
)
}
return
res
}
func
UpdateCpAnniversaryReminded
(
model
*
domain
.
Model
,
id
mysql
.
ID
)
error
{
return
model
.
DB
()
.
Model
(
CpAnniversary
{})
.
Where
(
"id = ?"
,
id
)
.
Update
(
"reminded"
,
mysql
.
YES
)
.
Error
}
go.mod
View file @
484d82ff
...
...
@@ -65,6 +65,9 @@ require (
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 // indirect
github.com/robfig/cron v1.2.0 // indirect
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.479 // indirect
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ims v1.0.479 // indirect
github.com/tencentyun/tls-sig-api-v2-golang v1.0.0 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
...
...
go.sum
View file @
484d82ff
...
...
@@ -267,6 +267,12 @@ github.com/swaggo/gin-swagger v1.2.0/go.mod h1:qlH2+W7zXGZkczuL+r2nEBR2JTT+/lX05
github.com/swaggo/swag v1.5.1/go.mod h1:1Bl9F/ZBpVWh22nY0zmYyASPO1lI/zIwRDrpZU+tv8Y=
github.com/swaggo/swag v1.6.7 h1:e8GC2xDllJZr3omJkm9YfmK0Y56+rMO3cg0JBKNz09s=
github.com/swaggo/swag v1.6.7/go.mod h1:xDhTyuFIujYiN3DKWC/H/83xcfHp+UE/IzWWampG7Zc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.479 h1:3kwDb6p1J3LxmwnNgSSEheemPffo+vMewoDzKysYdig=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.479/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ims v1.0.479 h1:xDmo1rBmSJ7Hw3iOa6DQ/++z1d7pgsEVKrZno35zR7w=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ims v1.0.479/go.mod h1:3YlJ1g/Ko/iFgyBJdok+dRPTH6zRB6BBopAcFkbujPc=
github.com/tencentyun/tls-sig-api-v2-golang v1.0.0 h1:NavMw9XO2iCLv8hTKaJW2kTaGR2SdNljMABbe39yu6Q=
github.com/tencentyun/tls-sig-api-v2-golang v1.0.0/go.mod h1:u7WiArmCTXTaQAHJwAOaLgpJ5e2xdY5/cgMEy3ubL60=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/ugorji/go v1.1.5-pre/go.mod h1:FwP/aQVg39TXzItUBMwnWp9T9gPQnXw4Poh4/oBQZ/0=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
...
...
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