checkParentMenu()) { $this->error("宠物管理父菜单 (ID: {$this->petParentId}) 不存在"); return 1; } // 检查是否强制重新创建 if ($this->option('force')) { $this->deleteExistingMenu(); } // 创建宠物激活技能菜单 $this->createPetActiveSkillMenu(); $this->info('宠物激活技能菜单添加成功!'); return 0; } catch (\Exception $e) { $this->error('添加宠物激活技能菜单失败: ' . $e->getMessage()); return 1; } } /** * 检查父菜单是否存在 * * @return bool */ protected function checkParentMenu(): bool { return AdminMenu::where('id', $this->petParentId)->exists(); } /** * 删除已存在的菜单 * * @return void */ protected function deleteExistingMenu(): void { $existingMenu = AdminMenu::where('title', '宠物激活技能') ->where('parent_id', $this->petParentId) ->first(); if ($existingMenu) { $existingMenu->delete(); $this->info("✓ 删除已存在的菜单: {$existingMenu->title}, ID: {$existingMenu->id}"); } } /** * 创建宠物激活技能菜单 * * @return void */ protected function createPetActiveSkillMenu(): void { // 获取当前最大order值 $maxOrder = AdminMenu::where('parent_id', $this->petParentId)->max('order'); $nextOrder = $maxOrder ? $maxOrder + 1 : 202; // 创建宠物激活技能菜单 $activeSkillMenu = AdminMenu::firstOrCreate( [ 'title' => '宠物激活技能', 'parent_id' => $this->petParentId ], [ 'uri' => 'pet-active-skills', 'icon' => 'fa-magic', 'order' => $nextOrder, 'show' => 1, 'extension' => '', 'created_at' => now(), 'updated_at' => now() ] ); $this->info("✓ 添加宠物激活技能菜单: {$activeSkillMenu->title}, ID: {$activeSkillMenu->id}, Order: {$activeSkillMenu->order}"); } }