58 lines
3.0 KiB
PHP
58 lines
3.0 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 文件功能:创建 gifts 礼物表并填充默认鲜花数据
|
|||
|
|
*
|
|||
|
|
* 礼物系统支持后台管理多种花/礼物类型,每种有不同的金币消耗和魅力增量。
|
|||
|
|
* 图片存放在 public/images/gifts/ 目录下。
|
|||
|
|
*
|
|||
|
|
* @author ChatRoom Laravel
|
|||
|
|
*
|
|||
|
|
* @version 1.0.0
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
use Illuminate\Database\Migrations\Migration;
|
|||
|
|
use Illuminate\Database\Schema\Blueprint;
|
|||
|
|
use Illuminate\Support\Facades\DB;
|
|||
|
|
use Illuminate\Support\Facades\Schema;
|
|||
|
|
|
|||
|
|
return new class extends Migration
|
|||
|
|
{
|
|||
|
|
/**
|
|||
|
|
* 创建 gifts 表并填充默认礼物数据
|
|||
|
|
*/
|
|||
|
|
public function up(): void
|
|||
|
|
{
|
|||
|
|
Schema::create('gifts', function (Blueprint $table) {
|
|||
|
|
$table->id();
|
|||
|
|
$table->string('name', 50)->comment('礼物名称');
|
|||
|
|
$table->string('emoji', 10)->comment('显示图标/emoji');
|
|||
|
|
$table->string('image', 100)->nullable()->comment('礼物图片路径(相对 /images/gifts/)');
|
|||
|
|
$table->unsignedInteger('cost')->default(0)->comment('消耗金币数');
|
|||
|
|
$table->unsignedInteger('charm')->default(1)->comment('增加魅力值');
|
|||
|
|
$table->unsignedTinyInteger('sort_order')->default(0)->comment('排序(越小越靠前)');
|
|||
|
|
$table->boolean('is_active')->default(true)->comment('是否启用');
|
|||
|
|
$table->timestamps();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// 填充默认鲜花数据(图片文件名与 sort_order 对应)
|
|||
|
|
DB::table('gifts')->insert([
|
|||
|
|
['name' => '小雏菊', 'emoji' => '🌼', 'image' => 'daisy.png', 'cost' => 5, 'charm' => 1, 'sort_order' => 1, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()],
|
|||
|
|
['name' => '玫瑰花', 'emoji' => '🌹', 'image' => 'rose.png', 'cost' => 10, 'charm' => 2, 'sort_order' => 2, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()],
|
|||
|
|
['name' => '向日葵', 'emoji' => '🌻', 'image' => 'sunflower.png', 'cost' => 20, 'charm' => 5, 'sort_order' => 3, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()],
|
|||
|
|
['name' => '樱花束', 'emoji' => '🌸', 'image' => 'sakura.png', 'cost' => 50, 'charm' => 12, 'sort_order' => 4, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()],
|
|||
|
|
['name' => '满天星', 'emoji' => '💐', 'image' => 'bouquet.png', 'cost' => 100, 'charm' => 30, 'sort_order' => 5, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()],
|
|||
|
|
['name' => '蓝色妖姬', 'emoji' => '🪻', 'image' => 'bluerose.png', 'cost' => 200, 'charm' => 66, 'sort_order' => 6, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()],
|
|||
|
|
['name' => '钻石花冠', 'emoji' => '👑', 'image' => 'crown.png', 'cost' => 520, 'charm' => 188, 'sort_order' => 7, 'is_active' => true, 'created_at' => now(), 'updated_at' => now()],
|
|||
|
|
]);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 回滚:删除 gifts 表
|
|||
|
|
*/
|
|||
|
|
public function down(): void
|
|||
|
|
{
|
|||
|
|
Schema::dropIfExists('gifts');
|
|||
|
|
}
|
|||
|
|
};
|