'Transfer模块', 'icon' => 'fa-exchange', 'order' => 30, 'children' => [ [ 'title' => '应用管理', 'icon' => 'fa-cogs', 'uri' => 'transfer/apps', 'order' => 10, ], [ 'title' => '订单管理', 'icon' => 'fa-list-alt', 'uri' => 'transfer/orders', 'order' => 20, ], [ 'title' => '统计图表', 'icon' => 'fa-line-chart', 'uri' => 'transfer-metrics', 'order' => 30, ], [ 'title' => '手续费统计', 'icon' => 'fa-money', 'uri' => 'transfer/fee-statistics', 'order' => 40, ], ], ]; /** * 执行命令 */ public function handle() { $this->info('开始配置Transfer模块后台管理菜单...'); // 检查父菜单是否存在 if (!$this->checkParentMenu()) { $this->error("外接管理父菜单 (ID: {$this->externalManagementParentId}) 不存在"); return 1; } // 检查是否强制重新创建 $force = $this->option('force'); // 检查菜单是否已存在 $existingMenu = DB::table('admin_menu') ->where('title', $this->menuStructure['title']) ->where('parent_id', $this->externalManagementParentId) ->first(); if ($existingMenu && !$force) { $this->warn('Transfer模块菜单已存在,使用 --force 参数强制重新创建'); return 0; } if ($existingMenu && $force) { $this->info('删除现有菜单...'); $this->deleteExistingMenus(); } // 创建菜单 $this->createMenus(); $this->info('Transfer模块后台管理菜单配置完成!'); return 0; } /** * 检查父菜单是否存在 */ protected function checkParentMenu(): bool { return DB::table('admin_menu') ->where('id', $this->externalManagementParentId) ->exists(); } /** * 删除现有菜单 */ protected function deleteExistingMenus(): void { // 查找现有的Transfer模块菜单 $transferMenu = DB::table('admin_menu') ->where('title', $this->menuStructure['title']) ->where('parent_id', $this->externalManagementParentId) ->first(); if ($transferMenu) { // 删除子菜单 $deletedChildren = DB::table('admin_menu') ->where('parent_id', $transferMenu->id) ->delete(); // 删除主菜单 DB::table('admin_menu') ->where('id', $transferMenu->id) ->delete(); $this->info("删除了Transfer模块菜单及其 {$deletedChildren} 个子菜单"); } } /** * 创建菜单 */ protected function createMenus(): void { DB::transaction(function () { // 创建Transfer模块主菜单 $transferMenuId = DB::table('admin_menu')->insertGetId([ 'parent_id' => $this->externalManagementParentId, 'order' => $this->menuStructure['order'], 'title' => $this->menuStructure['title'], 'icon' => $this->menuStructure['icon'], 'uri' => '', 'show' => 1, 'created_at' => now(), 'updated_at' => now(), ]); $this->info("✓ 创建模块菜单: {$this->menuStructure['title']} (ID: {$transferMenuId})"); // 创建子菜单 foreach ($this->menuStructure['children'] as $child) { $childMenuId = DB::table('admin_menu')->insertGetId([ 'parent_id' => $transferMenuId, 'order' => $child['order'], 'title' => $child['title'], 'icon' => $child['icon'], 'uri' => $child['uri'], 'show' => 1, 'created_at' => now(), 'updated_at' => now(), ]); $this->info(" ├── 创建子菜单: {$child['title']} (ID: {$childMenuId}) -> {$child['uri']}"); } }); } /** * 显示当前菜单结构 */ protected function showCurrentStructure(): void { $this->info('当前外接管理菜单结构:'); $parentMenu = DB::table('admin_menu') ->where('id', $this->externalManagementParentId) ->first(); if ($parentMenu) { $this->line("├── {$parentMenu->title} (ID: {$parentMenu->id})"); $children = DB::table('admin_menu') ->where('parent_id', $this->externalManagementParentId) ->orderBy('order') ->get(); foreach ($children as $child) { $this->line("│ ├── {$child->title} (ID: {$child->id}) -> {$child->uri}"); $grandChildren = DB::table('admin_menu') ->where('parent_id', $child->id) ->orderBy('order') ->get(); foreach ($grandChildren as $grandChild) { $this->line("│ │ ├── {$grandChild->title} (ID: {$grandChild->id}) -> {$grandChild->uri}"); } } } } }