package task import ( "git.echol.cn/loser/lckt/global" "git.echol.cn/loser/lckt/model/article" "go.uber.org/zap" "gorm.io/gorm" "time" ) // PublishArticles 定时发布文章 func PublishArticles(db *gorm.DB) error { global.GVA_LOG.Info("开始执行定时发布文章任务") now := time.Now() result := db.Model(&article.Article{}). Where("publish_time <= ? AND status != 1", now). Updates(map[string]interface{}{"status": 1}) if result.Error != nil { global.GVA_LOG.Error("定时发布文章失败", zap.Error(result.Error)) return result.Error } global.GVA_LOG.Info("定时发布文章成功", zap.Int64("处理文章数", result.RowsAffected)) return nil }