UpdateChestAdminMenu.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Module\System\Models\AdminMenu;
  4. use Illuminate\Console\Command;
  5. class UpdateChestAdminMenu extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'admin:update-chest-menu';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '更新宝箱系统的后台管理菜单';
  19. /**
  20. * Execute the console command.
  21. *
  22. * @return int
  23. */
  24. public function handle()
  25. {
  26. $this->info('开始更新宝箱系统后台菜单...');
  27. // 1. 在游戏物品管理(215)下添加宝箱配置管理菜单
  28. $this->addChestConfigMenu();
  29. // 2. 更新已废弃菜单的状态
  30. $this->updateDeprecatedMenus();
  31. // 3. 添加保底机制相关菜单
  32. $this->addPityMenus();
  33. $this->info('宝箱系统后台菜单更新完成!');
  34. return 0;
  35. }
  36. /**
  37. * 添加宝箱配置管理菜单
  38. */
  39. private function addChestConfigMenu()
  40. {
  41. // 获取游戏物品管理菜单ID
  42. $gameItemsMenu = AdminMenu::where('title', '游戏物品管理')
  43. ->where('parent_id', 259)
  44. ->first();
  45. if (!$gameItemsMenu) {
  46. $this->error('未找到游戏物品管理菜单');
  47. return;
  48. }
  49. // 获取当前最大order值
  50. $maxOrder = AdminMenu::where('parent_id', $gameItemsMenu->id)->max('order');
  51. $nextOrder = $maxOrder ? $maxOrder + 1 : 35;
  52. // 创建宝箱配置管理菜单
  53. $chestConfigMenu = AdminMenu::firstOrCreate(
  54. [
  55. 'title' => '宝箱配置管理',
  56. 'parent_id' => $gameItemsMenu->id
  57. ],
  58. [
  59. 'uri' => 'game-items/chest-configs',
  60. 'icon' => 'fa-treasure-chest',
  61. 'order' => $nextOrder,
  62. 'show' => 1
  63. ]
  64. );
  65. $this->info("✓ 添加宝箱配置管理菜单: {$chestConfigMenu->title}, ID: {$chestConfigMenu->id}");
  66. }
  67. /**
  68. * 更新已废弃菜单的状态
  69. */
  70. private function updateDeprecatedMenus()
  71. {
  72. // 标记已废弃的菜单项(不删除,只是标记为不显示或添加说明)
  73. $deprecatedMenus = [
  74. '宝箱消耗配置' => 'game-items-chest-costs',
  75. '宝箱内容' => 'game-items-chest-contents'
  76. ];
  77. foreach ($deprecatedMenus as $title => $uri) {
  78. $menu = AdminMenu::where('title', $title)->where('uri', $uri)->first();
  79. if ($menu) {
  80. // 更新标题,添加废弃标记
  81. $newTitle = $title . ' (已废弃)';
  82. $menu->update([
  83. 'title' => $newTitle,
  84. 'show' => 0 // 隐藏菜单
  85. ]);
  86. $this->info("✓ 标记废弃菜单: {$title} -> {$newTitle}");
  87. }
  88. }
  89. }
  90. /**
  91. * 添加保底机制相关菜单
  92. */
  93. private function addPityMenus()
  94. {
  95. // 在游戏运营管理 -> 游戏物品管理(423)下添加保底相关菜单
  96. $gameItemsManageMenu = AdminMenu::where('id', 423)->first();
  97. if (!$gameItemsManageMenu) {
  98. $this->error('未找到游戏运营管理下的游戏物品管理菜单');
  99. return;
  100. }
  101. // 获取当前最大order值
  102. $maxOrder = AdminMenu::where('parent_id', $gameItemsManageMenu->id)->max('order');
  103. $nextOrder = $maxOrder ? $maxOrder + 1 : 73;
  104. // 创建奖励组保底计数菜单
  105. $pityCountMenu = AdminMenu::firstOrCreate(
  106. [
  107. 'title' => '奖励组保底计数',
  108. 'parent_id' => $gameItemsManageMenu->id
  109. ],
  110. [
  111. 'uri' => 'game/reward-group-pity-counts',
  112. 'icon' => 'fa-chart-line',
  113. 'order' => $nextOrder,
  114. 'show' => 1
  115. ]
  116. );
  117. $this->info("✓ 添加奖励组保底计数菜单: {$pityCountMenu->title}, ID: {$pityCountMenu->id}");
  118. // 更新原有的"用户宝箱保底计数"菜单标题
  119. $oldPityMenu = AdminMenu::where('title', '用户宝箱保底计数')->first();
  120. if ($oldPityMenu) {
  121. $oldPityMenu->update([
  122. 'title' => '用户宝箱保底计数 (旧系统)',
  123. 'show' => 0 // 隐藏旧系统菜单
  124. ]);
  125. $this->info("✓ 更新旧保底菜单: 用户宝箱保底计数 -> 用户宝箱保底计数 (旧系统)");
  126. }
  127. }
  128. }