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
6701cffc
Commit
6701cffc
authored
Jun 01, 2023
by
chenweijian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cp自动清算
parent
f4b0553f
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
321 additions
and
11 deletions
+321
-11
cp.go
corn/cp_corn/cp.go
+93
-0
cron.go
corn/cron.go
+7
-0
cp_relation.go
domain/model/cp_m/cp_relation.go
+21
-0
go.mod
go.mod
+14
-3
go.sum
go.sum
+184
-7
main.go
main.go
+2
-1
No files found.
corn/cp_corn/cp.go
0 → 100644
View file @
6701cffc
package
cp_corn
import
(
"git.hilo.cn/hilo-common/_const/enum/diamond_e"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/utils"
"github.com/robfig/cron"
"hilo-user/_const/enum/cp_e"
"hilo-user/domain/model/cp_m"
"hilo-user/domain/model/diamond_m"
"time"
)
// cp邀请、解除到期结算
func
CpInviteCancelInit
()
{
if
!
config
.
IsMaster
()
{
return
}
mylogrus
.
MyLog
.
Infof
(
"CpInviteCancelInit"
)
// 每2min监测一次
c
:=
cron
.
New
()
spec
:=
"0 */2 * * * *"
if
!
config
.
AppIsRelease
()
{
spec
=
"0 */1 * * * ?"
// 测服每1分钟
}
_
=
c
.
AddFunc
(
spec
,
func
()
{
defer
utils
.
CheckGoPanic
()
model
:=
domain
.
CreateModelNil
()
// 获取超过24小时没被处理的cp邀请
inviteList
,
err
:=
cp_m
.
GetCpInviteByTime
(
model
,
time
.
Now
()
.
AddDate
(
0
,
0
,
-
1
))
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CpInviteCancelInit err:%v"
,
err
)
return
}
for
_
,
v
:=
range
inviteList
{
model
.
Log
.
Infof
(
"CpInviteCancelInit invite:%+v"
,
v
)
err
=
model
.
Transaction
(
func
(
model
*
domain
.
Model
)
error
{
// 更新邀请记录
err
=
cp_m
.
UpdateStatusCpInvite
(
model
,
v
.
Id
,
cp_e
.
CpInviteExpired
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CpInviteCancelInit Id:%d, err:%v"
,
v
.
Id
,
err
)
return
err
}
// 退费
err
=
diamond_m
.
ChangeDiamondAccountDetail
(
model
,
diamond_e
.
CpInviteRefund
,
v
.
Id
,
v
.
UserId
,
v
.
DiamondNum
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CpInviteCancelInit Id:%d, err:%v"
,
v
.
Id
,
err
)
return
err
}
return
nil
})
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CpInviteCancelInit invite:%+v, err:%v"
,
v
,
err
)
return
}
time
.
Sleep
(
time
.
Millisecond
*
10
)
}
// 获取超过24小时没被处理的cp解除申请
cancelList
,
err
:=
cp_m
.
GetCpCancelByTime
(
model
,
time
.
Now
()
.
AddDate
(
0
,
0
,
-
1
))
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CpInviteCancelInit err:%v"
,
err
)
return
}
for
_
,
v
:=
range
cancelList
{
model
.
Log
.
Infof
(
"CpInviteCancelInit cancel:%+v"
,
v
)
err
=
model
.
Transaction
(
func
(
model
*
domain
.
Model
)
error
{
// 更新解除记录
err
=
cp_m
.
UpdateStatusCpCancel
(
model
,
v
.
Id
,
cp_e
.
CpCancelAcceptAuto
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CpInviteCancelInit Id:%d, err:%v"
,
v
.
Id
,
err
)
return
err
}
// 删除cp关系表的记录
err
=
cp_m
.
DelCpRelation
(
model
,
v
.
UserId
,
v
.
RecUserId
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CpInviteCancelInit Id:%d, err:%v"
,
v
.
Id
,
err
)
return
err
}
return
nil
})
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CpInviteCancelInit cancel:%+v, err:%v"
,
v
,
err
)
return
}
time
.
Sleep
(
time
.
Millisecond
*
10
)
}
})
c
.
Start
()
}
corn/cron.go
0 → 100644
View file @
6701cffc
package
cron
import
"hilo-user/corn/cp_corn"
func
Init
()
{
cp_corn
.
CpInviteCancelInit
()
}
domain/model/cp_m/cp_relation.go
View file @
6701cffc
...
...
@@ -2,6 +2,7 @@ package cp_m
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/utils"
"gorm.io/gorm"
"hilo-user/_const/enum/cp_e"
"hilo-user/myerr/bizerr"
...
...
@@ -172,3 +173,23 @@ func DelCpRelation(model *domain.Model, userId1, userId2 uint64) error {
}
return
nil
}
func
GetCpInviteByTime
(
model
*
domain
.
Model
,
expTime
time
.
Time
)
([]
*
CpInvite
,
error
)
{
res
:=
make
([]
*
CpInvite
,
0
)
err
:=
model
.
DB
()
.
Model
(
CpInvite
{})
.
Where
(
"status = ? and created_time <= ?"
,
cp_e
.
CpInvite
,
expTime
.
Format
(
utils
.
DATETIME_FORMAT
))
.
Find
(
&
res
)
.
Error
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetCpInviteByTime err:%v"
,
err
)
return
nil
,
err
}
return
res
,
nil
}
func
GetCpCancelByTime
(
model
*
domain
.
Model
,
expTime
time
.
Time
)
([]
*
CpCancel
,
error
)
{
res
:=
make
([]
*
CpCancel
,
0
)
err
:=
model
.
DB
()
.
Model
(
CpCancel
{})
.
Where
(
"status = ? and created_time <= ?"
,
cp_e
.
CpCancel
,
expTime
.
Format
(
utils
.
DATETIME_FORMAT
))
.
Find
(
&
res
)
.
Error
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetCpCancelByTime err:%v"
,
err
)
return
nil
,
err
}
return
res
,
nil
}
go.mod
View file @
6701cffc
...
...
@@ -19,6 +19,11 @@ require (
gorm.io/gorm v1.23.8
)
require (
github.com/jonboulle/clockwork v0.3.0 // indirect
github.com/robfig/cron v1.2.0
)
require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
...
...
@@ -37,7 +42,8 @@ require (
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator/v10 v10.2.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/golang/protobuf v1.5.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/hashicorp/consul/api v1.7.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-hclog v0.12.0 // indirect
...
...
@@ -50,8 +56,8 @@ require (
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/joho/godotenv v1.3.0 // indirect
github.com/jonboulle/clockwork v0.3.0 // indirect
github.com/json-iterator/go v1.1.9 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect
github.com/lestrrat-go/strftime v1.0.6 // indirect
...
...
@@ -63,11 +69,16 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 // 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
golang.org/x/text v0.3.6 // indirect
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18 // indirect
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/grpc v1.42.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.63.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
...
...
go.sum
View file @
6701cffc
This diff is collapsed.
Click to expand it.
main.go
View file @
6701cffc
...
...
@@ -3,6 +3,7 @@ package main
import
(
"fmt"
"git.hilo.cn/hilo-common/resource/consul"
cron
"hilo-user/corn"
"hilo-user/domain/service/event_s"
"hilo-user/route"
)
...
...
@@ -14,7 +15,7 @@ const (
)
func
main
()
{
//cron.Init()
// 开启定时任务
cron
.
Init
()
// 开启定时任务
event_s
.
EventInit
()
// 注册事件(内部事件+mysql拟kafka)
r
:=
route
.
InitRouter
()
// 注册路由
consul
.
RegisterToConsul
(
PORT
,
RegisterName
,
RegisterTag
)
// 服务注册
...
...
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