InsertShopAdminMenu.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Module\System\Models\AdminMenu;
  4. use Illuminate\Console\Command;
  5. class InsertShopAdminMenu extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'admin:insert-shop-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. // 获取最大的order值
  27. $maxOrder = AdminMenu::max('order');
  28. $nextOrder = $maxOrder + 1;
  29. // 1. 创建商店管理菜单(在游戏运营管理下)
  30. $shopManageMenu = AdminMenu::firstOrCreate(
  31. ['title' => '🛒 商店管理', 'uri' => ''],
  32. [
  33. 'parent_id' => 260, // 游戏运营管理
  34. 'order' => $nextOrder++,
  35. 'icon' => 'fa-shopping-cart',
  36. 'uri' => '',
  37. 'show' => 1
  38. ]
  39. );
  40. $this->info("创建商店管理菜单: {$shopManageMenu->title}, ID: {$shopManageMenu->id}");
  41. // 2. 创建商店管理子菜单
  42. $shopSubMenus = [
  43. [
  44. 'title' => '商店分类',
  45. 'uri' => 'shop/categories',
  46. 'icon' => 'fa-tags'
  47. ],
  48. [
  49. 'title' => '商店商品',
  50. 'uri' => 'shop/items',
  51. 'icon' => 'fa-cube'
  52. ],
  53. [
  54. 'title' => '促销活动',
  55. 'uri' => 'shop/promotions',
  56. 'icon' => 'fa-percent'
  57. ],
  58. [
  59. 'title' => '购买记录',
  60. 'uri' => 'shop/purchase-logs',
  61. 'icon' => 'fa-list-alt'
  62. ]
  63. ];
  64. foreach ($shopSubMenus as $subMenu) {
  65. $menu = AdminMenu::firstOrCreate(
  66. ['title' => $subMenu['title'], 'uri' => $subMenu['uri']],
  67. [
  68. 'parent_id' => $shopManageMenu->id,
  69. 'order' => $nextOrder++,
  70. 'icon' => $subMenu['icon'],
  71. 'uri' => $subMenu['uri'],
  72. 'show' => 1
  73. ]
  74. );
  75. $this->info("创建商店管理子菜单: {$menu->title}, URI: {$menu->uri}");
  76. }
  77. $this->info('商店模块菜单添加完成!');
  78. return 0;
  79. }
  80. }