改为独立座驾模块

This commit is contained in:
pllx
2026-04-30 09:55:20 +08:00
parent 3c95478097
commit 181cc6a0b0
22 changed files with 886 additions and 216 deletions
@@ -1,104 +1,28 @@
<?php
/**
* 文件功能:为商店商品加入聊天室座驾类型与欢迎语字段
* 文件功能:保留旧迁移文件名但不再扩展商店表
*
* 座驾复用 shop_items user_purchases,并预置当前四个军事主题座驾
* 座驾已经改为独立 rides 模块,本迁移保持空操作以避免新环境继续污染 shop_items
*/
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
{
/**
* 方法功能:扩展商品类型、增加欢迎语字段并写入默认座驾
* 方法功能:不再向商店表添加座驾字段
*/
public function up(): void
{
Schema::table('shop_items', function (Blueprint $table) {
$table->string('welcome_message', 255)->nullable()->after('charm_bonus')->comment('座驾入场欢迎语模板');
});
if (DB::getDriverName() === 'mysql') {
DB::statement("ALTER TABLE `shop_items` MODIFY `type` ENUM('instant','duration','one_time','ring','auto_fishing','sign_repair','msg_bubble','msg_name_color','avatar_frame','msg_text_color','ride') NOT NULL COMMENT '道具类型'");
}
$rides = [
[
'name' => '歼-35隐身战机',
'slug' => 'ride_j35',
'description' => '驾驶歼-35划破长空入场,附带全屏战机掠过特效。',
'icon' => '🛩️',
'price' => 18888,
'duration_days' => 7,
'sort_order' => 80,
'welcome_message' => '【{name}】驾驶【{ride}】划破长空,震撼降临聊天室!',
],
[
'name' => '99A主战坦克',
'slug' => 'ride_99a',
'description' => '驾驶 99A 主战坦克重装入场,附带履带尘土与炮击冲击特效。',
'icon' => '🛡️',
'price' => 18888,
'duration_days' => 7,
'sort_order' => 81,
'welcome_message' => '【{name}】驾驶【{ride}】重装入场,地面都为之一震!',
],
[
'name' => '东风-5C战略导弹',
'slug' => 'ride_df5c',
'description' => '乘东风-5C 发射升空入场,附带尾焰、烟尘和雷达 HUD 特效。',
'icon' => '🚀',
'price' => 28888,
'duration_days' => 7,
'sort_order' => 82,
'welcome_message' => '【{name}】乘【{ride}】点火升空,战略级排面拉满!',
],
[
'name' => '福建舰航母',
'slug' => 'ride_fujian',
'description' => '乘福建舰破浪入场,附带海浪、舰载机和甲板 HUD 特效。',
'icon' => '⚓',
'price' => 28888,
'duration_days' => 7,
'sort_order' => 83,
'welcome_message' => '【{name}】乘【{ride}】破浪而来,全场列队欢迎!',
],
];
foreach ($rides as $ride) {
DB::table('shop_items')->updateOrInsert(
['slug' => $ride['slug']],
$ride + [
'type' => 'ride',
'duration_minutes' => 0,
'intimacy_bonus' => 0,
'charm_bonus' => 0,
'is_active' => true,
'created_at' => now(),
'updated_at' => now(),
]
);
}
//
}
/**
* 方法功能:移除座驾默认商品并回滚字段与类型
* 方法功能:空迁移无需回滚结构
*/
public function down(): void
{
DB::table('shop_items')->whereIn('slug', ['ride_j35', 'ride_99a', 'ride_df5c', 'ride_fujian'])->delete();
if (DB::getDriverName() === 'mysql') {
DB::statement("UPDATE `shop_items` SET `type` = 'one_time' WHERE `type` = 'ride'");
DB::statement("ALTER TABLE `shop_items` MODIFY `type` ENUM('instant','duration','one_time','ring','auto_fishing','sign_repair','msg_bubble','msg_name_color','avatar_frame','msg_text_color') NOT NULL COMMENT '道具类型'");
}
Schema::table('shop_items', function (Blueprint $table) {
$table->dropColumn('welcome_message');
});
//
}
};
@@ -0,0 +1,122 @@
<?php
/**
* 文件功能:创建聊天室座驾独立数据表。
*
* 座驾定义和用户座驾购买记录独立于商店模块,支持后台单独配置价格、使用天数和欢迎语。
*/
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
{
/**
* 方法功能:创建 rides user_ride_purchases 并预置默认座驾。
*/
public function up(): void
{
Schema::create('rides', function (Blueprint $table) {
$table->id();
$table->string('name', 100)->comment('座驾名称');
$table->string('slug', 100)->unique()->comment('座驾唯一标识,格式 ride_key');
$table->string('effect_key', 50)->unique()->comment('全屏特效 key');
$table->string('icon', 20)->default('🚘')->comment('座驾图标');
$table->text('description')->nullable()->comment('座驾说明');
$table->unsignedInteger('price')->default(0)->comment('购买价格');
$table->unsignedInteger('duration_days')->default(7)->comment('使用天数');
$table->string('welcome_message', 255)->nullable()->comment('入场欢迎语模板');
$table->unsignedInteger('sort_order')->default(0)->comment('排序权重');
$table->boolean('is_active')->default(true)->comment('是否上架');
$table->timestamps();
});
Schema::create('user_ride_purchases', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignId('ride_id')->constrained('rides')->cascadeOnDelete();
$table->enum('status', ['active', 'expired', 'cancelled'])->default('active')->comment('座驾状态');
$table->unsignedInteger('price_paid')->default(0)->comment('实际支付金币');
$table->timestamp('expires_at')->nullable()->comment('到期时间');
$table->timestamp('used_at')->nullable()->comment('首次使用时间');
$table->timestamps();
$table->index(['user_id', 'status', 'expires_at']);
});
$this->seedDefaultRides();
}
/**
* 方法功能:删除座驾独立数据表。
*/
public function down(): void
{
Schema::dropIfExists('user_ride_purchases');
Schema::dropIfExists('rides');
}
/**
* 方法功能:写入当前默认四个全屏座驾。
*/
private function seedDefaultRides(): void
{
$now = now();
$rides = [
[
'name' => '歼-35隐身战机',
'slug' => 'ride_j35',
'effect_key' => 'j35',
'description' => '驾驶歼-35划破长空入场,附带全屏战机掠过特效。',
'icon' => '🛩️',
'price' => 18888,
'duration_days' => 7,
'sort_order' => 80,
'welcome_message' => '【{name}】驾驶【{ride}】划破长空,震撼降临聊天室!',
],
[
'name' => '99A主战坦克',
'slug' => 'ride_99a',
'effect_key' => '99a',
'description' => '驾驶 99A 主战坦克重装入场,附带履带尘土与炮击冲击特效。',
'icon' => '🛡️',
'price' => 18888,
'duration_days' => 7,
'sort_order' => 81,
'welcome_message' => '【{name}】驾驶【{ride}】重装入场,地面都为之一震!',
],
[
'name' => '东风-5C战略导弹',
'slug' => 'ride_df5c',
'effect_key' => 'df5c',
'description' => '乘东风-5C 发射升空入场,附带尾焰、烟尘和雷达 HUD 特效。',
'icon' => '🚀',
'price' => 28888,
'duration_days' => 7,
'sort_order' => 82,
'welcome_message' => '【{name}】乘【{ride}】点火升空,战略级排面拉满!',
],
[
'name' => '福建舰航母',
'slug' => 'ride_fujian',
'effect_key' => 'fujian',
'description' => '乘福建舰破浪入场,附带海浪、舰载机和甲板 HUD 特效。',
'icon' => '⚓',
'price' => 28888,
'duration_days' => 7,
'sort_order' => 83,
'welcome_message' => '【{name}】乘【{ride}】破浪而来,全场列队欢迎!',
],
];
foreach ($rides as $ride) {
DB::table('rides')->insert($ride + [
'is_active' => true,
'created_at' => $now,
'updated_at' => $now,
]);
}
}
};
@@ -0,0 +1,52 @@
<?php
/**
* 文件功能:清理旧版商店座驾数据。
*
* 如果环境曾跑过“座驾复用商店”的旧迁移,本迁移会移除商店里的座驾字段和残留记录。
*/
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
{
/**
* 方法功能:删除 shop_items 中旧座驾记录并移除欢迎语字段。
*/
public function up(): void
{
DB::table('shop_items')->where('slug', 'like', 'ride_%')->delete();
if (DB::getDriverName() === 'mysql' && $this->shopItemTypeContainsRide()) {
DB::statement("UPDATE `shop_items` SET `type` = 'one_time' WHERE `type` = 'ride'");
DB::statement("ALTER TABLE `shop_items` MODIFY `type` ENUM('instant','duration','one_time','ring','auto_fishing','sign_repair','msg_bubble','msg_name_color','avatar_frame','msg_text_color') NOT NULL COMMENT '道具类型'");
}
if (Schema::hasColumn('shop_items', 'welcome_message')) {
Schema::table('shop_items', function (Blueprint $table) {
$table->dropColumn('welcome_message');
});
}
}
/**
* 方法功能:清理迁移不恢复旧商店座驾结构。
*/
public function down(): void
{
//
}
/**
* 方法功能:判断当前 shop_items.type 枚举是否包含旧座驾类型。
*/
private function shopItemTypeContainsRide(): bool
{
$column = DB::selectOne("SHOW COLUMNS FROM `shop_items` LIKE 'type'");
return $column && str_contains((string) $column->Type, "'ride'");
}
};