Commit 87e3a566 authored by hujiebin's avatar hujiebin

保级续送cp头像头饰,否则删除cp头像头饰

parent 7d83fd1e
......@@ -11,7 +11,7 @@ func ClearCpExpire() {
c := cron.New()
spec := "0 0 */1 * * ?"
if !config.AppIsRelease() {
spec = "* * * * * ?"
spec = "0 * * * * ?"
}
// 1小时清理一次
_ = c.AddFunc(spec, func() {
......
......@@ -316,10 +316,11 @@ func AddCpLevelPoints(model *domain.Model, cpRelation CpRelation, points mysql.N
func ClearExpireCpPoints(model *domain.Model) error {
var cpLevels []*CpLevel
// 过期 + (积分 or level) 大于0
if err := model.DB().Model(CpLevel{}).Where("expire_at < ? AND (points > 0 or level > 0) ", time.Now()).Find(&cpLevels).Error; err != nil {
if err := model.DB().Table("cp_level l").Joins("cp_relation r ON l.cp_id = r.id").Where("l.expire_at < ? AND (l.points > 0 or l.level > 0) ", time.Now()).Find(&cpLevels).Error; err != nil {
return myerr.WrapErr(err)
}
for _, cpLevel := range cpLevels {
model.Log.Infof("ClearExpireCpPoints %v", *cpLevel)
var doubleCheck CpLevel
if err := model.DB().Model(CpLevel{}).Where("id = ?", cpLevel.ID).First(&doubleCheck).Error; err != nil {
model.Log.Errorf("double check fail:%v", err)
......@@ -375,10 +376,18 @@ func ClearExpireCpPoints(model *domain.Model) error {
// 保级续送cp头像头饰
if newLevel >= 3 {
if err := headwear_tx.SendHeadwear(model, cpLevel.UserId1, cp_e.CpHeadwearId, 30); err != nil {
return err
model.Log.Errorf("SendHeadwear fail:%v", err)
}
if err := headwear_tx.SendHeadwear(model, cpLevel.UserId2, cp_e.CpHeadwearId, 30); err != nil {
return err
model.Log.Errorf("SendHeadwear fail:%v", err)
}
} else {
// 否则删除cp头像头饰
if err := headwear_tx.DelHeadwear(model, cpLevel.UserId1, cp_e.CpHeadwearId); err != nil {
model.Log.Errorf("DelHeadwear fail:%v", err)
}
if err := headwear_tx.DelHeadwear(model, cpLevel.UserId2, cp_e.CpHeadwearId); err != nil {
model.Log.Errorf("DelHeadwear fail:%v", err)
}
}
}
......
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