InsertShopPurchaseLimitMenu.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Module\System\Models\AdminMenu;
  4. use Illuminate\Console\Command;
  5. class InsertShopPurchaseLimitMenu extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'admin:insert-shop-purchase-limit-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. // 查找商店管理菜单
  27. $shopManageMenu = AdminMenu::where('title', '🛒 商店管理')->first();
  28. if (!$shopManageMenu) {
  29. $this->error('未找到商店管理菜单,请先运行 admin:insert-shop-menu 命令');
  30. return 1;
  31. }
  32. $this->info("找到商店管理菜单: {$shopManageMenu->title}, ID: {$shopManageMenu->id}");
  33. // 获取商店管理下的最大order值
  34. $maxOrder = AdminMenu::where('parent_id', $shopManageMenu->id)->max('order');
  35. $nextOrder = $maxOrder ? $maxOrder + 1 : 1;
  36. // 创建限购配置菜单
  37. $purchaseLimitMenu = AdminMenu::firstOrCreate(
  38. ['title' => '限购配置', 'uri' => 'shop/purchase-limits'],
  39. [
  40. 'parent_id' => $shopManageMenu->id,
  41. 'order' => $nextOrder,
  42. 'icon' => 'fa-ban',
  43. 'uri' => 'shop/purchase-limits',
  44. 'show' => 1
  45. ]
  46. );
  47. if ($purchaseLimitMenu->wasRecentlyCreated) {
  48. $this->info("创建限购配置菜单: {$purchaseLimitMenu->title}, URI: {$purchaseLimitMenu->uri}");
  49. } else {
  50. $this->info("限购配置菜单已存在: {$purchaseLimitMenu->title}, URI: {$purchaseLimitMenu->uri}");
  51. }
  52. $this->info('商店限购配置菜单添加完成!');
  53. return 0;
  54. }
  55. }