MexAddAdminMenuCommand.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. namespace App\Module\Mex\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. /**
  6. * Mex模块后台菜单添加命令
  7. *
  8. * 为Mex模块添加完整的后台管理菜单
  9. */
  10. class MexAddAdminMenuCommand extends Command
  11. {
  12. /**
  13. * 命令签名
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'mex:add-admin-menu';
  18. /**
  19. * 命令描述
  20. *
  21. * @var string
  22. */
  23. protected $description = '为Mex模块添加后台管理菜单';
  24. /**
  25. * 执行命令
  26. *
  27. * @return int
  28. */
  29. public function handle(): int
  30. {
  31. $this->info('开始添加Mex模块后台菜单...');
  32. try {
  33. DB::transaction(function () {
  34. $this->addMexMenus();
  35. });
  36. $this->info('✅ Mex模块后台菜单添加成功!');
  37. return Command::SUCCESS;
  38. } catch (\Exception $e) {
  39. $this->error('❌ 添加菜单失败:' . $e->getMessage());
  40. return Command::FAILURE;
  41. }
  42. }
  43. /**
  44. * 添加Mex模块菜单
  45. */
  46. private function addMexMenus(): void
  47. {
  48. // 1. 查找或创建"游戏运营管理"父菜单
  49. $gameManageParent = DB::table('admin_menu')
  50. ->where('title', '游戏运营管理')
  51. ->where('parent_id', 0)
  52. ->first();
  53. if (!$gameManageParent) {
  54. $this->info('创建"游戏运营管理"父菜单...');
  55. $gameManageParentId = DB::table('admin_menu')->insertGetId([
  56. 'parent_id' => 0,
  57. 'order' => 400,
  58. 'title' => '游戏运营管理',
  59. 'icon' => 'fa-gamepad',
  60. 'uri' => '',
  61. 'show' => 1,
  62. 'created_at' => now(),
  63. 'updated_at' => now(),
  64. ]);
  65. } else {
  66. $gameManageParentId = $gameManageParent->id;
  67. $this->info('找到现有"游戏运营管理"父菜单 (ID: ' . $gameManageParentId . ')');
  68. }
  69. // 2. 创建"农贸市场管理"子菜单
  70. $mexParentExists = DB::table('admin_menu')
  71. ->where('title', '农贸市场管理')
  72. ->where('parent_id', $gameManageParentId)
  73. ->exists();
  74. if ($mexParentExists) {
  75. $this->warn('⚠️ "农贸市场管理"菜单已存在,跳过创建');
  76. return;
  77. }
  78. $this->info('创建"农贸市场管理"子菜单...');
  79. $mexParentId = DB::table('admin_menu')->insertGetId([
  80. 'parent_id' => $gameManageParentId,
  81. 'order' => 50,
  82. 'title' => '农贸市场管理',
  83. 'icon' => 'fa-store',
  84. 'uri' => '',
  85. 'show' => 1,
  86. 'created_at' => now(),
  87. 'updated_at' => now(),
  88. ]);
  89. // 3. 添加Mex模块的具体功能菜单
  90. $mexMenus = [
  91. [
  92. 'title' => '📋 订单管理',
  93. 'icon' => 'fa-list-alt',
  94. 'uri' => 'mex-orders',
  95. 'order' => 10,
  96. 'description' => '管理用户买入和卖出订单'
  97. ],
  98. [
  99. 'title' => '💰 价格配置',
  100. 'icon' => 'fa-tags',
  101. 'uri' => 'mex-price-configs',
  102. 'order' => 20,
  103. 'description' => '配置商品价格范围和保护阈值'
  104. ],
  105. [
  106. 'title' => '📊 成交记录',
  107. 'icon' => 'fa-chart-line',
  108. 'uri' => 'mex-transactions',
  109. 'order' => 30,
  110. 'description' => '查看撮合成交记录'
  111. ],
  112. [
  113. 'title' => '🏪 仓库管理',
  114. 'icon' => 'fa-warehouse',
  115. 'uri' => 'mex-warehouse',
  116. 'order' => 40,
  117. 'description' => '管理仓库库存和统计'
  118. ],
  119. [
  120. 'title' => '👨‍💼 管理员操作',
  121. 'icon' => 'fa-user-shield',
  122. 'uri' => 'mex-admin-operations',
  123. 'order' => 50,
  124. 'description' => '查看管理员操作记录'
  125. ],
  126. ];
  127. foreach ($mexMenus as $menu) {
  128. $this->info("添加菜单:{$menu['title']}");
  129. DB::table('admin_menu')->insert([
  130. 'parent_id' => $mexParentId,
  131. 'order' => $menu['order'],
  132. 'title' => $menu['title'],
  133. 'icon' => $menu['icon'],
  134. 'uri' => $menu['uri'],
  135. 'show' => 1,
  136. 'created_at' => now(),
  137. 'updated_at' => now(),
  138. ]);
  139. }
  140. $this->info('✅ 所有Mex模块菜单添加完成');
  141. // 4. 显示菜单结构
  142. $this->showMenuStructure($gameManageParentId, $mexParentId);
  143. }
  144. /**
  145. * 显示菜单结构
  146. */
  147. private function showMenuStructure(int $gameManageParentId, int $mexParentId): void
  148. {
  149. $this->info('');
  150. $this->info('📋 菜单结构:');
  151. $gameManageMenu = DB::table('admin_menu')->find($gameManageParentId);
  152. $this->line("├── {$gameManageMenu->title} (ID: {$gameManageMenu->id})");
  153. $mexParentMenu = DB::table('admin_menu')->find($mexParentId);
  154. $this->line(" ├── {$mexParentMenu->title} (ID: {$mexParentMenu->id})");
  155. $mexSubMenus = DB::table('admin_menu')
  156. ->where('parent_id', $mexParentId)
  157. ->orderBy('order')
  158. ->get();
  159. foreach ($mexSubMenus as $index => $menu) {
  160. $isLast = $index === count($mexSubMenus) - 1;
  161. $prefix = $isLast ? ' └──' : ' ├──';
  162. $this->line("{$prefix} {$menu->title} (/{$menu->uri})");
  163. }
  164. $this->info('');
  165. $this->info('🔗 访问路径:');
  166. foreach ($mexSubMenus as $menu) {
  167. $this->line(" - {$menu->title}: /admin/{$menu->uri}");
  168. }
  169. }
  170. }