| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace App\Console\Commands;
- use App\Module\System\Models\AdminMenu;
- use Illuminate\Console\Command;
- class InsertShopPurchaseLimitMenu extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'admin:insert-shop-purchase-limit-menu';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '添加商店限购配置的后台管理菜单';
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- // 查找商店管理菜单
- $shopManageMenu = AdminMenu::where('title', '🛒 商店管理')->first();
-
- if (!$shopManageMenu) {
- $this->error('未找到商店管理菜单,请先运行 admin:insert-shop-menu 命令');
- return 1;
- }
-
- $this->info("找到商店管理菜单: {$shopManageMenu->title}, ID: {$shopManageMenu->id}");
-
- // 获取商店管理下的最大order值
- $maxOrder = AdminMenu::where('parent_id', $shopManageMenu->id)->max('order');
- $nextOrder = $maxOrder ? $maxOrder + 1 : 1;
-
- // 创建限购配置菜单
- $purchaseLimitMenu = AdminMenu::firstOrCreate(
- ['title' => '限购配置', 'uri' => 'shop/purchase-limits'],
- [
- 'parent_id' => $shopManageMenu->id,
- 'order' => $nextOrder,
- 'icon' => 'fa-ban',
- 'uri' => 'shop/purchase-limits',
- 'show' => 1
- ]
- );
-
- if ($purchaseLimitMenu->wasRecentlyCreated) {
- $this->info("创建限购配置菜单: {$purchaseLimitMenu->title}, URI: {$purchaseLimitMenu->uri}");
- } else {
- $this->info("限购配置菜单已存在: {$purchaseLimitMenu->title}, URI: {$purchaseLimitMenu->uri}");
- }
-
- $this->info('商店限购配置菜单添加完成!');
-
- return 0;
- }
- }
|