| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Module\GameItems\Console\Commands;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- /**
- * 更新宝箱数据库结构命令
- */
- class UpdateChestDatabaseCommand extends Command
- {
- /**
- * 命令签名
- *
- * @var string
- */
- protected $signature = 'gameitems:update-chest-database';
- /**
- * 命令描述
- *
- * @var string
- */
- protected $description = '更新宝箱数据库结构,创建宝箱配置表';
- /**
- * 执行命令
- *
- * @return int
- */
- public function handle()
- {
- $this->info('开始创建宝箱配置表...');
- try {
- // 检查表是否已存在
- $tableExists = DB::select("SHOW TABLES LIKE 'kku_item_chest_configs'");
- if ($tableExists) {
- $this->info('宝箱配置表已存在,跳过创建');
- return 0;
- }
- // 读取并执行SQL文件
- $sqlFile = app_path('Module/GameItems/Databases/GenerateSql/item_items_chest_groups_update.sql');
- if (!file_exists($sqlFile)) {
- $this->error('SQL文件不存在: ' . $sqlFile);
- return 1;
- }
- $sql = file_get_contents($sqlFile);
- DB::unprepared($sql);
- $this->info('✓ 宝箱配置表创建成功');
- $this->info('宝箱数据库结构更新完成!');
- return 0;
- } catch (\Exception $e) {
- $this->error('更新失败: ' . $e->getMessage());
- return 1;
- }
- }
- }
|