diff --git a/cron/cp_cron/clear.go b/cron/cp_cron/clear.go index 7343b2bc3539d6146a89ca031917bd81bdaf1ad6..3500201a9e525433c373b7d1d296bdef21b346e8 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 90de5cb54b36fe6cebf8f961f4991b339c6574b7..22bbe1ed98f9a800d2a0a8ec9c6c12ff99b7e28f 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) } } }