Commit 3534f327 authored by hujiebin's avatar hujiebin

清理家族经验/等级

parent b34a7a8c
......@@ -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() // 清理家族经验/等级
}
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()
}
......@@ -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
})
}
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