UpdateChestDatabaseCommand.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Module\GameItems\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. /**
  6. * 更新宝箱数据库结构命令
  7. */
  8. class UpdateChestDatabaseCommand extends Command
  9. {
  10. /**
  11. * 命令签名
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'gameitems:update-chest-database';
  16. /**
  17. * 命令描述
  18. *
  19. * @var string
  20. */
  21. protected $description = '更新宝箱数据库结构,创建宝箱配置表';
  22. /**
  23. * 执行命令
  24. *
  25. * @return int
  26. */
  27. public function handle()
  28. {
  29. $this->info('开始创建宝箱配置表...');
  30. try {
  31. // 检查表是否已存在
  32. $tableExists = DB::select("SHOW TABLES LIKE 'kku_item_chest_configs'");
  33. if ($tableExists) {
  34. $this->info('宝箱配置表已存在,跳过创建');
  35. return 0;
  36. }
  37. // 读取并执行SQL文件
  38. $sqlFile = app_path('Module/GameItems/Databases/GenerateSql/item_items_chest_groups_update.sql');
  39. if (!file_exists($sqlFile)) {
  40. $this->error('SQL文件不存在: ' . $sqlFile);
  41. return 1;
  42. }
  43. $sql = file_get_contents($sqlFile);
  44. DB::unprepared($sql);
  45. $this->info('✓ 宝箱配置表创建成功');
  46. $this->info('宝箱数据库结构更新完成!');
  47. return 0;
  48. } catch (\Exception $e) {
  49. $this->error('更新失败: ' . $e->getMessage());
  50. return 1;
  51. }
  52. }
  53. }