完善功能
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
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('ad_slots', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('key')->unique();
|
||||
$table->string('name');
|
||||
$table->string('description')->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->unsignedSmallInteger('max_items')->default(3);
|
||||
$table->unsignedInteger('sort')->default(0);
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['is_active', 'sort']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('ad_slots');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
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('ads', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('ad_slot_id')->constrained('ad_slots')->cascadeOnDelete();
|
||||
$table->string('title');
|
||||
$table->string('image')->nullable();
|
||||
$table->text('description')->nullable();
|
||||
$table->string('link_url')->nullable();
|
||||
$table->string('link_target')->default('_blank');
|
||||
$table->foreignId('product_id')->nullable()->constrained('products')->nullOnDelete();
|
||||
$table->dateTime('starts_at')->nullable();
|
||||
$table->dateTime('ends_at')->nullable();
|
||||
$table->unsignedInteger('sort')->default(0);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->unsignedInteger('view_count')->default(0);
|
||||
$table->unsignedInteger('click_count')->default(0);
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['ad_slot_id', 'is_active', 'sort']);
|
||||
$table->index(['starts_at', 'ends_at']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('ads');
|
||||
}
|
||||
};
|
||||
43
web10/database/seeders/AdSlotSeeder.php
Normal file
43
web10/database/seeders/AdSlotSeeder.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\AdSlot;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class AdSlotSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$slots = [
|
||||
[
|
||||
'key' => 'home',
|
||||
'name' => '首页推广位',
|
||||
'description' => '首页内容区推广位',
|
||||
'max_items' => 3,
|
||||
'sort' => 0,
|
||||
],
|
||||
[
|
||||
'key' => 'list',
|
||||
'name' => '列表页推广位',
|
||||
'description' => '列表/搜索/标签页推广位',
|
||||
'max_items' => 3,
|
||||
'sort' => 10,
|
||||
],
|
||||
[
|
||||
'key' => 'detail',
|
||||
'name' => '详情页推广位',
|
||||
'description' => '产品/文章详情页推广位',
|
||||
'max_items' => 3,
|
||||
'sort' => 20,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($slots as $slot) {
|
||||
AdSlot::updateOrCreate(
|
||||
['key' => $slot['key']],
|
||||
$slot
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user