From 325382061571a2e0f81b4be88d696a9223618796 Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Wed, 26 Mar 2025 17:12:49 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=A4=84=E7=90=86=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E5=8F=91=E5=B8=83=E6=97=B6=E9=97=B4=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/model/v1/ArticleModel.php | 6 ++++++ app/common/model/ArticleBaseModel.php | 2 +- database/migrations/20241220062631_create_article.php | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/admin/model/v1/ArticleModel.php b/app/admin/model/v1/ArticleModel.php index e988cd9c..2fcdf20e 100644 --- a/app/admin/model/v1/ArticleModel.php +++ b/app/admin/model/v1/ArticleModel.php @@ -16,6 +16,12 @@ class ArticleModel extends ArticleBaseModel // 软删除标记数据字段 protected $deleteTime = 'deleted_at'; + // 写入前,处理发布时间为空情况 + public static function onBeforeWrite(ArticleModel $article) + { + $article->release_time = empty($article->release_time) ? null : $article->release_time; + } + // 关联分类 public function category() { diff --git a/app/common/model/ArticleBaseModel.php b/app/common/model/ArticleBaseModel.php index a3e9b216..a6b23b11 100644 --- a/app/common/model/ArticleBaseModel.php +++ b/app/common/model/ArticleBaseModel.php @@ -25,7 +25,7 @@ class ArticleBaseModel extends BaseModel 'image' => 'string', 'desc' => 'string', 'recommend' => 'int', - 'release_time' => 'int', + 'release_time' => 'datetime', 'sort' => 'int', 'link' => 'string', 'content' => 'string', diff --git a/database/migrations/20241220062631_create_article.php b/database/migrations/20241220062631_create_article.php index c0fbc5b0..39ba899c 100644 --- a/database/migrations/20241220062631_create_article.php +++ b/database/migrations/20241220062631_create_article.php @@ -45,7 +45,7 @@ class CreateArticle extends Migrator ->addColumn('seo_keywords', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => 'SEO关键字']) ->addColumn('seo_desc', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => 'SEO描述']) ->addColumn('enabled', 'boolean', ['null' => false, 'default' => 1, 'comment' => '是否启用:1是,-1否']) - ->addColumn('release_time', 'datetime', ['null' => false, 'comment' => '发布时间']) + ->addColumn('release_time', 'datetime', ['null' => true, 'default' => null, 'comment' => '发布时间']) ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间']) ->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP', 'comment' => '更新时间']) ->addColumn('deleted_at', 'timestamp', ['null' => true, 'comment' => '删除时间'])