setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // 1. 定义 4 个新父级分类目录 $parentCategories = [ [ 'name' => 'order_manage', 'title' => '服务与调度', 'icon' => 'fa fa-tasks', 'weigh' => 190, ], [ 'name' => 'capacity_manage', 'title' => '运力与商户', 'icon' => 'fa fa-id-badge', 'weigh' => 170, ], [ 'name' => 'finance_manage', 'title' => '财务与资金', 'icon' => 'fa fa-money', 'weigh' => 150, ], [ 'name' => 'operation_manage', 'title' => '运营与营销', 'icon' => 'fa fa-bullhorn', 'weigh' => 130, ], ]; $catIds = []; $now = time(); foreach ($parentCategories as $cat) { // 检查是否已存在 $stmt = $pdo->prepare("SELECT id FROM fa_auth_rule WHERE name = ?"); $stmt->execute([$cat['name']]); $id = $stmt->fetchColumn(); if (!$id) { $insertStmt = $pdo->prepare("INSERT INTO fa_auth_rule (type, pid, name, title, icon, `condition`, remark, ismenu, createtime, updatetime, weigh, status) VALUES ('file', 0, ?, ?, ?, '', '', 1, ?, ?, ?, 'normal')"); $insertStmt->execute([$cat['name'], $cat['title'], $cat['icon'], $now, $now, $cat['weigh']]); $id = $pdo->lastInsertId(); echo "Created parent menu [{$cat['title']}] with ID: $id\n"; } else { $updateStmt = $pdo->prepare("UPDATE fa_auth_rule SET title = ?, icon = ?, weigh = ?, ismenu = 1, status = 'normal' WHERE id = ?"); $updateStmt->execute([$cat['title'], $cat['icon'], $cat['weigh'], $id]); echo "Updated parent menu [{$cat['title']}] with ID: $id\n"; } $catIds[$cat['name']] = $id; } // 2. 将子菜单调整到对应父分类下,并分配专属高辨识度图标和权重 $menuUpdates = [ // 业务与调度 (order_manage) 119 => ['pid' => $catIds['order_manage'], 'title' => '订单管理', 'icon' => 'fa fa-shopping-cart', 'weigh' => 195], 155 => ['pid' => $catIds['order_manage'], 'title' => '服务项目', 'icon' => 'fa fa-th-list', 'weigh' => 194], 185 => ['pid' => $catIds['order_manage'], 'title' => '服务类目', 'icon' => 'fa fa-cubes', 'weigh' => 193], 143 => ['pid' => $catIds['order_manage'], 'title' => '评价管理', 'icon' => 'fa fa-star', 'weigh' => 192], 161 => ['pid' => $catIds['order_manage'], 'title' => '申诉工单', 'icon' => 'fa fa-shield', 'weigh' => 191], // 运力与商户 (capacity_manage) 125 => ['pid' => $catIds['capacity_manage'], 'title' => '师傅档案', 'icon' => 'fa fa-wrench', 'weigh' => 175], 131 => ['pid' => $catIds['capacity_manage'], 'title' => '商家档案', 'icon' => 'fa fa-building', 'weigh' => 174], // 财务与资金 (finance_manage) 179 => ['pid' => $catIds['finance_manage'], 'title' => '结算账单', 'icon' => 'fa fa-calculator', 'weigh' => 155], 173 => ['pid' => $catIds['finance_manage'], 'title' => '提现申请', 'icon' => 'fa fa-credit-card', 'weigh' => 154], 167 => ['pid' => $catIds['finance_manage'], 'title' => '开票申请', 'icon' => 'fa fa-file-text-o', 'weigh' => 153], // 运营与营销 (operation_manage) 137 => ['pid' => $catIds['operation_manage'], 'title' => '优惠券管理', 'icon' => 'fa fa-ticket', 'weigh' => 135], 113 => ['pid' => $catIds['operation_manage'], 'title' => '轮播管理', 'icon' => 'fa fa-picture-o', 'weigh' => 134], 149 => ['pid' => $catIds['operation_manage'], 'title' => '消息通知', 'icon' => 'fa fa-bell', 'weigh' => 133], // 现有一级菜单权重与图标强化 1 => ['pid' => 0, 'title' => '控制台', 'icon' => 'fa fa-dashboard', 'weigh' => 200], 66 => ['pid' => 0, 'title' => '会员管理', 'icon' => 'fa fa-user-circle', 'weigh' => 110], 85 => ['pid' => 0, 'title' => '微信管理', 'icon' => 'fa fa-wechat', 'weigh' => 90], 2 => ['pid' => 0, 'title' => '常规管理', 'icon' => 'fa fa-cogs', 'weigh' => 70], 5 => ['pid' => 0, 'title' => '权限管理', 'icon' => 'fa fa-group', 'weigh' => 50], ]; foreach ($menuUpdates as $id => $u) { $stmt = $pdo->prepare("UPDATE fa_auth_rule SET pid = ?, title = ?, icon = ?, weigh = ? WHERE id = ?"); $stmt->execute([$u['pid'], $u['title'], $u['icon'], $u['weigh'], $id]); echo "Updated menu [$id] -> {$u['title']}\n"; } // 3. 在 常规管理 (general, id: 2) 下添加原控制台的迁移目标:系统监控 (general/system) $stmt = $pdo->prepare("SELECT id FROM fa_auth_rule WHERE name = 'general/system'"); $stmt->execute(); $systemId = $stmt->fetchColumn(); if (!$systemId) { $stmt = $pdo->prepare("INSERT INTO fa_auth_rule (type, pid, name, title, icon, `condition`, remark, ismenu, createtime, updatetime, weigh, status) VALUES ('file', 2, 'general/system', '系统监控', 'fa fa-server', '', '系统运维与服务器状态监控', 1, ?, ?, 65, 'normal')"); $stmt->execute([$now, $now]); $systemId = $pdo->lastInsertId(); echo "Created [系统监控] menu under general with ID: $systemId\n"; } else { $stmt = $pdo->prepare("UPDATE fa_auth_rule SET pid = 2, title = '系统监控', icon = 'fa fa-server', weigh = 65, ismenu = 1, status = 'normal' WHERE id = ?"); $stmt->execute([$systemId]); echo "Updated [系统监控] menu with ID: $systemId\n"; } echo "\nMenu reorganization completed successfully!\n";