From 87e3a566b4e9bea1612cb1df51bb54ecd8f0d1df Mon Sep 17 00:00:00 2001 From: hujiebin Date: Fri, 16 Jun 2023 10:29:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E7=BA=A7=E7=BB=AD=E9=80=81cp=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E5=A4=B4=E9=A5=B0=EF=BC=8C=E5=90=A6=E5=88=99=E5=88=A0?= =?UTF-8?q?=E9=99=A4cp=E5=A4=B4=E5=83=8F=E5=A4=B4=E9=A5=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cron/cp_cron/clear.go | 2 +- domain/model/cp_m/level.go | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cron/cp_cron/clear.go b/cron/cp_cron/clear.go index 7343b2b..3500201 100644 --- a/cron/cp_cron/clear.go +++ b/cron/cp_cron/clear.go @@ -11,7 +11,7 @@ func ClearCpExpire() { c := cron.New() spec := "0 0 */1 * * ?" if !config.AppIsRelease() { - spec = "* * * * * ?" + spec = "0 * * * * ?" } // 1小时清理一次 _ = c.AddFunc(spec, func() { diff --git a/domain/model/cp_m/level.go b/domain/model/cp_m/level.go index 90de5cb..22bbe1e 100644 --- a/domain/model/cp_m/level.go +++ b/domain/model/cp_m/level.go @@ -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) } } } -- 2.22.0