配置功能完善
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('home_modules', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('module_key', 80)->unique();
|
||||
$table->string('name', 120);
|
||||
$table->string('title', 160)->nullable();
|
||||
$table->string('subtitle', 255)->nullable();
|
||||
$table->boolean('enabled')->default(true);
|
||||
$table->unsignedInteger('sort_order')->default(0);
|
||||
$table->unsignedInteger('limit')->default(18);
|
||||
$table->string('more_link_type', 20)->nullable();
|
||||
$table->string('more_link_target', 255)->nullable();
|
||||
$table->json('extra')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('home_modules');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('home_module_items', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('home_module_id')->constrained('home_modules')->cascadeOnDelete();
|
||||
$table->string('item_key', 80)->nullable();
|
||||
$table->string('title', 160)->nullable();
|
||||
$table->string('subtitle', 255)->nullable();
|
||||
$table->string('image_path', 255)->nullable();
|
||||
$table->string('link_type', 20)->default('route');
|
||||
$table->string('link_target', 255)->nullable();
|
||||
$table->unsignedInteger('sort_order')->default(0);
|
||||
$table->boolean('enabled')->default(true);
|
||||
$table->json('extra')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['home_module_id', 'enabled']);
|
||||
$table->index(['home_module_id', 'sort_order']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('home_module_items');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Models\HomeModule;
|
||||
use App\Models\SiteSetting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
return new class extends Migration {
|
||||
public function up(): void
|
||||
{
|
||||
$defaults = [
|
||||
'hot_tools' => ['name' => '热门工具', 'sort' => 40, 'limit' => 18],
|
||||
'latest_tools' => ['name' => '最新收录', 'sort' => 50, 'limit' => 18],
|
||||
'category_sections' => ['name' => '分类分块', 'sort' => 60, 'limit' => 18],
|
||||
'channel_cards' => ['name' => '频道卡片', 'sort' => 20, 'limit' => 5],
|
||||
'promo_banners' => ['name' => '横幅推荐', 'sort' => 30, 'limit' => 2],
|
||||
];
|
||||
|
||||
foreach ($defaults as $key => $meta) {
|
||||
HomeModule::query()->firstOrCreate([
|
||||
'module_key' => $key,
|
||||
], [
|
||||
'name' => $meta['name'],
|
||||
'title' => $meta['name'],
|
||||
'enabled' => true,
|
||||
'sort_order' => $meta['sort'],
|
||||
'limit' => $meta['limit'],
|
||||
]);
|
||||
}
|
||||
|
||||
$legacy = SiteSetting::query()->where('setting_key', 'home_modules')->value('setting_value');
|
||||
if (!is_array($legacy)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($legacy as $module) {
|
||||
if (!is_array($module) || empty($module['key'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = (string) $module['key'];
|
||||
$existing = HomeModule::query()->where('module_key', $key)->first();
|
||||
if (! $existing instanceof HomeModule) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$existing->fill([
|
||||
'enabled' => (bool) ($module['enabled'] ?? true),
|
||||
'limit' => max(1, min(30, (int) ($module['limit'] ?? $existing->limit))),
|
||||
'name' => (string) ($module['label'] ?? $existing->name),
|
||||
'title' => (string) ($module['label'] ?? $existing->title),
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
HomeModule::query()->whereIn('module_key', [
|
||||
'hot_tools',
|
||||
'latest_tools',
|
||||
'category_sections',
|
||||
'channel_cards',
|
||||
'promo_banners',
|
||||
])->delete();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user