fix(chat): 修复五子棋配置 Seeder 的字段报错,撤销错误的表结构修改

This commit is contained in:
2026-03-12 08:39:02 +08:00
parent b7f2dae847
commit 246d89fef6
2 changed files with 24 additions and 50 deletions
@@ -1,31 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('game_configs', function (Blueprint $table) {
$table->string('type', 20)->default('general')->after('id')->comment('配置分类:gomoku/general等');
// 为了保证加速查询
$table->index(['type', 'key']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('game_configs', function (Blueprint $table) {
$table->dropIndex(['type', 'key']);
$table->dropColumn('type');
});
}
};
+24 -19
View File
@@ -11,31 +11,36 @@ class GomokuConfigSeeder extends Seeder
*/ */
public function run(): void public function run(): void
{ {
$configs = [ $params = [
// PvP 配置 // PvP 配置
['type' => 'gomoku', 'key' => 'pvp_reward', 'value' => '80'], 'pvp_reward' => 80,
['type' => 'gomoku', 'key' => 'pvp_invite_timeout', 'value' => '60'], 'pvp_invite_timeout' => 60,
['type' => 'gomoku', 'key' => 'pvp_move_timeout', 'value' => '60'], 'pvp_move_timeout' => 60,
['type' => 'gomoku', 'key' => 'pvp_ready_timeout', 'value' => '30'], 'pvp_ready_timeout' => 30,
// PvE AI 难度入口费 // PvE AI 难度入口费
['type' => 'gomoku', 'key' => 'pve_fee_level_1', 'value' => '0'], 'pve_fee_level_1' => 0,
['type' => 'gomoku', 'key' => 'pve_fee_level_2', 'value' => '10'], 'pve_fee_level_2' => 10,
['type' => 'gomoku', 'key' => 'pve_fee_level_3', 'value' => '30'], 'pve_fee_level_3' => 30,
['type' => 'gomoku', 'key' => 'pve_fee_level_4', 'value' => '80'], 'pve_fee_level_4' => 80,
// PvE AI 难度胜利奖励 // PvE AI 难度胜利奖励
['type' => 'gomoku', 'key' => 'pve_reward_level_1', 'value' => '20'], 'pve_reward_level_1' => 20,
['type' => 'gomoku', 'key' => 'pve_reward_level_2', 'value' => '50'], 'pve_reward_level_2' => 50,
['type' => 'gomoku', 'key' => 'pve_reward_level_3', 'value' => '120'], 'pve_reward_level_3' => 120,
['type' => 'gomoku', 'key' => 'pve_reward_level_4', 'value' => '300'], 'pve_reward_level_4' => 300,
]; ];
foreach ($configs as $config) { $config = \App\Models\GameConfig::firstOrNew(['game_key' => 'gomoku']);
\App\Models\GameConfig::updateOrCreate( $config->name = '五子棋';
['type' => $config['type'], 'key' => $config['key']], $config->icon = '♟️';
['value' => $config['value']] $config->description = '支持 PvP 玩家对战与 PvE 多难度人机对战,支持断线重连。';
); $config->enabled = true;
}
// 合并已有配置,避免覆盖管理员在后台修改过的其他选项
$existingParams = $config->params ?? [];
$config->params = array_merge($existingParams, $params);
$config->save();
} }
} }