Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
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
hujiebin
hilo-group
Commits
3534f327
Commit
3534f327
authored
Mar 08, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
清理家族经验/等级
parent
b34a7a8c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
3 deletions
+84
-3
cron.go
cron/cron.go
+5
-3
group_power_exp.go
cron/group_cron/group_power_exp.go
+30
-0
group_grade.go
domain/model/groupPower_m/group_grade.go
+49
-0
No files found.
cron/cron.go
View file @
3534f327
...
...
@@ -3,6 +3,7 @@ package cron
import
(
"git.hilo.cn/hilo-common/resource/config"
"hilo-group/cron/gift_cron"
"hilo-group/cron/group_cron"
"hilo-group/cron/mic_cron"
)
...
...
@@ -10,7 +11,8 @@ func Init() {
if
!
config
.
IsMaster
()
{
return
}
gift_cron
.
SendGiftEventInit
()
// 礼物消息
gift_cron
.
GiftRemark
()
// 礼物消息补偿
mic_cron
.
OnMicCheck
()
// 检查上麦
gift_cron
.
SendGiftEventInit
()
// 礼物消息
gift_cron
.
GiftRemark
()
// 礼物消息补偿
mic_cron
.
OnMicCheck
()
// 检查上麦
group_cron
.
GroupPowerExpClear
()
// 清理家族经验/等级
}
cron/group_cron/group_power_exp.go
0 → 100644
View file @
3534f327
package
group_cron
import
(
"git.hilo.cn/hilo-common/domain"
"github.com/robfig/cron"
"hilo-group/domain/model/groupPower_m"
)
// 清理家族经验和等级
func
GroupPowerExpClear
()
{
c
:=
cron
.
New
()
// 每月1号0:00经验值清零
spec
:=
"0 0 0 1 * ?"
_
=
c
.
AddFunc
(
spec
,
func
()
{
var
model
=
domain
.
CreateModelNil
()
if
err
:=
groupPower_m
.
ClearGroupPowerExp
(
model
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"ClearGroupPowerExp fail:%v"
,
err
)
}
})
// 每分钟清理过期家族等级
spec
=
"0 * * * * ?"
_
=
c
.
AddFunc
(
spec
,
func
()
{
var
model
=
domain
.
CreateModelNil
()
if
err
:=
groupPower_m
.
ClearGroupPowerGrade
(
model
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"ClearGroupPowerGrade fail:%v"
,
err
)
}
})
c
.
Start
()
}
domain/model/groupPower_m/group_grade.go
View file @
3534f327
...
...
@@ -222,3 +222,52 @@ func IncrGroupPowerExpOnMic(model *domain.Model, groupPowerId, userId mysql.ID,
return
nil
})
}
// 清理所有家族的经验
func
ClearGroupPowerExp
(
model
*
domain
.
Model
)
error
{
var
groupPowerGrades
[]
*
GroupPowerGrade
if
err
:=
model
.
DB
()
.
Model
(
GroupPowerGrade
{})
.
Where
(
"exp > 0"
)
.
Find
(
&
groupPowerGrades
)
.
Error
;
err
!=
nil
{
return
err
}
return
model
.
Transaction
(
func
(
model
*
domain
.
Model
)
error
{
for
_
,
grade
:=
range
groupPowerGrades
{
if
err
:=
model
.
DB
()
.
Model
(
GroupPowerGrade
{})
.
Where
(
"group_power_id = ?"
,
grade
.
GroupPowerId
)
.
UpdateColumn
(
"exp"
,
0
)
.
Error
;
err
!=
nil
{
return
err
}
// 记录明细
detail
:=
&
GroupPowerExpDetail
{
GroupPowerId
:
grade
.
GroupPowerId
,
UserId
:
0
,
Exp
:
0
,
AddReduce
:
mysql
.
SET
,
BefNum
:
grade
.
Exp
,
AftNum
:
0
,
Remark
:
"每月清零"
,
}
if
err
:=
model
.
DB
()
.
Model
(
GroupPowerExpDetail
{})
.
Create
(
detail
)
.
Error
;
err
!=
nil
{
return
err
}
}
return
nil
})
}
// 清理过期家族等级
func
ClearGroupPowerGrade
(
model
*
domain
.
Model
)
error
{
var
groupPowerGrades
[]
*
GroupPowerGrade
if
err
:=
model
.
DB
()
.
Model
(
GroupPowerGrade
{})
.
Where
(
"expire_at > ?"
,
time
.
Now
())
.
Find
(
&
groupPowerGrades
)
.
Error
;
err
!=
nil
{
return
err
}
return
model
.
Transaction
(
func
(
model
*
domain
.
Model
)
error
{
for
_
,
grade
:=
range
groupPowerGrades
{
updateAttrs
:=
map
[
string
]
interface
{}{
"grade"
:
0
,
"expire_at"
:
time
.
Time
{},
}
if
err
:=
model
.
DB
()
.
Model
(
GroupPowerGrade
{})
.
Where
(
"group_power_id = ?"
,
grade
.
GroupPowerId
)
.
Updates
(
updateAttrs
)
.
Error
;
err
!=
nil
{
return
err
}
}
return
nil
})
}
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