fix(chat): 修复五子棋配置 Seeder 的字段报错,撤销错误的表结构修改
This commit is contained in:
@@ -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');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -11,31 +11,36 @@ class GomokuConfigSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$configs = [
|
||||
$params = [
|
||||
// PvP 配置
|
||||
['type' => 'gomoku', 'key' => 'pvp_reward', 'value' => '80'],
|
||||
['type' => 'gomoku', 'key' => 'pvp_invite_timeout', 'value' => '60'],
|
||||
['type' => 'gomoku', 'key' => 'pvp_move_timeout', 'value' => '60'],
|
||||
['type' => 'gomoku', 'key' => 'pvp_ready_timeout', 'value' => '30'],
|
||||
'pvp_reward' => 80,
|
||||
'pvp_invite_timeout' => 60,
|
||||
'pvp_move_timeout' => 60,
|
||||
'pvp_ready_timeout' => 30,
|
||||
|
||||
// PvE AI 难度入口费
|
||||
['type' => 'gomoku', 'key' => 'pve_fee_level_1', 'value' => '0'],
|
||||
['type' => 'gomoku', 'key' => 'pve_fee_level_2', 'value' => '10'],
|
||||
['type' => 'gomoku', 'key' => 'pve_fee_level_3', 'value' => '30'],
|
||||
['type' => 'gomoku', 'key' => 'pve_fee_level_4', 'value' => '80'],
|
||||
'pve_fee_level_1' => 0,
|
||||
'pve_fee_level_2' => 10,
|
||||
'pve_fee_level_3' => 30,
|
||||
'pve_fee_level_4' => 80,
|
||||
|
||||
// PvE AI 难度胜利奖励
|
||||
['type' => 'gomoku', 'key' => 'pve_reward_level_1', 'value' => '20'],
|
||||
['type' => 'gomoku', 'key' => 'pve_reward_level_2', 'value' => '50'],
|
||||
['type' => 'gomoku', 'key' => 'pve_reward_level_3', 'value' => '120'],
|
||||
['type' => 'gomoku', 'key' => 'pve_reward_level_4', 'value' => '300'],
|
||||
'pve_reward_level_1' => 20,
|
||||
'pve_reward_level_2' => 50,
|
||||
'pve_reward_level_3' => 120,
|
||||
'pve_reward_level_4' => 300,
|
||||
];
|
||||
|
||||
foreach ($configs as $config) {
|
||||
\App\Models\GameConfig::updateOrCreate(
|
||||
['type' => $config['type'], 'key' => $config['key']],
|
||||
['value' => $config['value']]
|
||||
);
|
||||
}
|
||||
$config = \App\Models\GameConfig::firstOrNew(['game_key' => 'gomoku']);
|
||||
$config->name = '五子棋';
|
||||
$config->icon = '♟️';
|
||||
$config->description = '支持 PvP 玩家对战与 PvE 多难度人机对战,支持断线重连。';
|
||||
$config->enabled = true;
|
||||
|
||||
// 合并已有配置,避免覆盖管理员在后台修改过的其他选项
|
||||
$existingParams = $config->params ?? [];
|
||||
$config->params = array_merge($existingParams, $params);
|
||||
|
||||
$config->save();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user