feat: add article and production modules

This commit is contained in:
2026-08-31 13:16:46 +08:00
parent ac3da246b2
commit 5c586a1a95
334 changed files with 34419 additions and 1 deletions
@@ -0,0 +1,94 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
if (!$schema->hasTable('article_category')) {
$schema->create('article_category', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键');
$table->string('name', 100)->comment('分类名称');
$table->string('slug', 100)->nullable()->comment('分类标识');
$table->bigInteger('parent_id')->default(0)->comment('父级分类ID');
$table->integer('sort')->default(100)->comment('排序');
$table->tinyInteger('enabled')->default(1)->comment('状态: 1启用 0禁用');
$table->longText('description')->nullable()->comment('分类描述');
$table->bigInteger('created_by')->nullable()->comment('创建者');
$table->bigInteger('updated_by')->nullable()->comment('更新者');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->index('parent_id');
$table->index('slug');
$table->index('enabled');
});
}
if (!$schema->hasTable('article_tag')) {
$schema->create('article_tag', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键');
$table->string('name', 100)->comment('标签名称');
$table->string('slug', 100)->nullable()->comment('标签标识');
$table->integer('sort')->default(100)->comment('排序');
$table->integer('heat')->default(0)->comment('热度');
$table->tinyInteger('enabled')->default(1)->comment('状态: 1启用 0禁用');
$table->longText('description')->nullable()->comment('标签描述');
$table->bigInteger('created_by')->nullable()->comment('创建者');
$table->bigInteger('updated_by')->nullable()->comment('更新者');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->index('slug');
$table->index('enabled');
$table->index('heat');
});
}
if (!$schema->hasTable('article_content')) {
$schema->create('article_content', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键');
$table->string('title', 200)->comment('文章标题');
$table->string('slug', 200)->nullable()->comment('文章标识');
$table->bigInteger('category_id')->default(0)->comment('分类ID');
$table->string('cover', 255)->nullable()->comment('封面图');
$table->string('summary', 500)->nullable()->comment('摘要');
$table->longText('content')->nullable()->comment('文章内容');
$table->tinyInteger('status')->default(1)->comment('状态: 0草稿 1发布 2下架');
$table->tinyInteger('is_top')->default(0)->comment('是否置顶');
$table->integer('sort')->default(100)->comment('排序');
$table->integer('view_count')->default(0)->comment('浏览量');
$table->bigInteger('published_at')->nullable()->comment('发布时间');
$table->bigInteger('created_by')->nullable()->comment('创建者');
$table->bigInteger('updated_by')->nullable()->comment('更新者');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->index('category_id');
$table->index('status');
$table->index('is_top');
$table->index('published_at');
});
}
if (!$schema->hasTable('article_content_tag')) {
$schema->create('article_content_tag', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键');
$table->bigInteger('content_id')->comment('文章ID');
$table->bigInteger('tag_id')->comment('标签ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->index('content_id');
$table->index('tag_id');
});
}
}
public function down(Builder $schema): void
{
$schema->dropIfExists('article_content_tag');
$schema->dropIfExists('article_content');
$schema->dropIfExists('article_tag');
$schema->dropIfExists('article_category');
}
};
@@ -0,0 +1,93 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
if (!$schema->hasTable('article_content')) {
return;
}
$schema->table('article_content', function (Blueprint $table) use ($schema) {
if (!$schema->hasColumn('article_content', 'content_type')) {
$table->string('content_type', 50)->default('article')->comment('内容类型')->after('title');
}
if (!$schema->hasColumn('article_content', 'channel')) {
$table->string('channel', 100)->default('official')->comment('所属频道')->after('category_id');
}
if (!$schema->hasColumn('article_content', 'visibility')) {
$table->tinyInteger('visibility')->default(1)->comment('可见范围: 1公开 2登录可见 3私密')->after('channel');
}
if (!$schema->hasColumn('article_content', 'author')) {
$table->string('author', 100)->nullable()->comment('作者')->after('visibility');
}
if (!$schema->hasColumn('article_content', 'source')) {
$table->string('source', 100)->default('original')->comment('内容来源')->after('author');
}
if (!$schema->hasColumn('article_content', 'offline_at')) {
$table->bigInteger('offline_at')->nullable()->comment('下线时间')->after('published_at');
}
if (!$schema->hasColumn('article_content', 'seo_keywords')) {
$table->string('seo_keywords', 255)->nullable()->comment('SEO关键词')->after('source');
}
if (!$schema->hasColumn('article_content', 'seo_title')) {
$table->string('seo_title', 200)->nullable()->comment('SEO标题')->after('seo_keywords');
}
if (!$schema->hasColumn('article_content', 'seo_description')) {
$table->string('seo_description', 500)->nullable()->comment('SEO描述')->after('seo_title');
}
if (!$schema->hasColumn('article_content', 'like_count')) {
$table->integer('like_count')->default(0)->comment('点赞量')->after('view_count');
}
if (!$schema->hasColumn('article_content', 'comment_count')) {
$table->integer('comment_count')->default(0)->comment('评论量')->after('like_count');
}
if (!$schema->hasColumn('article_content', 'favorite_count')) {
$table->integer('favorite_count')->default(0)->comment('收藏量')->after('comment_count');
}
if (!$schema->hasColumn('article_content', 'is_recommend')) {
$table->tinyInteger('is_recommend')->default(0)->comment('是否推荐')->after('is_top');
}
if (!$schema->hasColumn('article_content', 'allow_comment')) {
$table->tinyInteger('allow_comment')->default(1)->comment('是否允许评论')->after('is_recommend');
}
});
}
public function down(Builder $schema): void
{
if (!$schema->hasTable('article_content')) {
return;
}
$dropColumns = [];
foreach ([
'content_type',
'channel',
'visibility',
'author',
'source',
'offline_at',
'seo_keywords',
'seo_title',
'seo_description',
'like_count',
'comment_count',
'favorite_count',
'is_recommend',
'allow_comment',
] as $column) {
if ($schema->hasColumn('article_content', $column)) {
$dropColumns[] = $column;
}
}
if (!empty($dropColumns)) {
$schema->table('article_content', function (Blueprint $table) use ($dropColumns) {
$table->dropColumn($dropColumns);
});
}
}
};