checkParentMenu()) { $this->error("农场配置父菜单 (ID: {$this->farmConfigParentId}) 不存在"); return 1; } // 检查是否强制重新创建 if ($this->option('force')) { $this->deleteExistingMenu(); } // 创建农场配置管理菜单 $this->createFarmConfigMenu(); $this->info('农场配置管理菜单添加成功!'); return 0; } catch (\Exception $e) { $this->error('添加农场配置管理菜单失败: ' . $e->getMessage()); return 1; } } /** * 检查父菜单是否存在 * * @return bool */ protected function checkParentMenu(): bool { $parentMenu = DB::table('kku_admin_menu') ->where('id', $this->farmConfigParentId) ->first(); if ($parentMenu) { $this->info("找到农场配置父菜单: {$parentMenu->title} (ID: {$parentMenu->id})"); return true; } return false; } /** * 删除已存在的菜单 * * @return void */ protected function deleteExistingMenu(): void { $existingMenu = DB::table('kku_admin_menu') ->where('parent_id', $this->farmConfigParentId) ->where('uri', 'farm-configs') ->first(); if ($existingMenu) { DB::table('kku_admin_menu')->where('id', $existingMenu->id)->delete(); $this->info("删除已存在的农场配置管理菜单 (ID: {$existingMenu->id})"); } } /** * 创建农场配置管理菜单 * * @return void */ protected function createFarmConfigMenu(): void { // 检查菜单是否已存在 $existingMenu = DB::table('kku_admin_menu') ->where('parent_id', $this->farmConfigParentId) ->where('uri', 'farm-configs') ->first(); if ($existingMenu && !$this->option('force')) { $this->info("农场配置管理菜单已存在 (ID: {$existingMenu->id})"); return; } // 获取农场配置菜单下的最大order值 $maxOrder = DB::table('kku_admin_menu') ->where('parent_id', $this->farmConfigParentId) ->max('order'); $nextOrder = $maxOrder ? $maxOrder + 1 : 1; // 创建农场配置管理菜单 $menuId = DB::table('kku_admin_menu')->insertGetId([ 'parent_id' => $this->farmConfigParentId, 'order' => $nextOrder, 'title' => '农场配置管理', 'icon' => 'fa-cogs', 'uri' => 'farm-configs', 'show' => 1, 'extension' => '', 'created_at' => now(), 'updated_at' => now(), ]); $this->info("创建农场配置管理菜单成功 (ID: {$menuId})"); $this->info("菜单标题: 农场配置管理"); $this->info("菜单URI: farm-configs"); $this->info("菜单图标: fa-cogs"); $this->info("菜单顺序: {$nextOrder}"); } }