0) { return [$root]; } } if ($systemKey === 'cockpit') { $roots = Config::get('mproc.cockpit_login_group_root_ids'); if (is_array($roots) && $roots !== []) { return $roots; } } } $val = Config::get('systems.' . $systemKey . '.' . $key); if ($val !== null && $val !== '') { return $val; } if ($systemKey === 'collab') { if ($key === 'name' || $key === 'brand') { if ($key === 'brand') { $brand = Config::get('mproc.collab_system_brand'); if (!$brand) { $brand = Config::get('mproc.system_brand.collab'); } return $brand ?: '生产协同系统'; } return '生产协同系统'; } if ($key === 'allow_rule_super') { $v = Config::get('mproc.collab_allow_rule_super'); if ($v === null) { return true; } return (bool)$v; } } if ($systemKey === 'cockpit') { if ($key === 'name') { return '生产经营驾驶舱系统'; } if ($key === 'brand') { $brand = Config::get('mproc.cockpit_system_brand'); if (!$brand) { $brand = Config::get('mproc.system_brand.cockpit'); } return $brand ?: '浙江印刷集团有限公司'; } if ($key === 'allow_rule_super') { $v = Config::get('mproc.cockpit_allow_rule_super'); if ($v === null) { return true; } return (bool)$v; } } return $default; } /** * @return array */ public static function allowedGroupIds(string $systemKey): array { self::loadConfig(); $systemKey = self::normalizeKey($systemKey); $roots = self::option($systemKey, 'allowed_group_roots', []); if (!is_array($roots) || $roots === []) { return []; } $rootIds = []; foreach ($roots as $rid) { $rid = (int)$rid; if ($rid > 0) { $rootIds[$rid] = true; } } if ($rootIds === []) { return []; } static $cache = []; $cacheKey = $systemKey . ':' . implode(',', array_keys($rootIds)); if (isset($cache[$cacheKey])) { return $cache[$cacheKey]; } $groupList = AuthGroup::where('status', 'normal')->field('id,pid')->select(); $rows = []; if (is_array($groupList) || $groupList instanceof \Traversable) { foreach ($groupList as $g) { if (is_object($g) && method_exists($g, 'toArray')) { $g = $g->toArray(); } if (!is_array($g)) { continue; } $rows[] = [ 'id' => (int)($g['id'] ?? 0), 'pid' => (int)($g['pid'] ?? 0), ]; } } $allowed = []; foreach (array_keys($rootIds) as $rootId) { $allowed[$rootId] = true; $children = Tree::instance()->init($rows, 'pid')->getChildrenIds($rootId, false); if (!is_array($children)) { continue; } foreach ($children as $cid) { $cid = (int)$cid; if ($cid > 0) { $allowed[$cid] = true; } } } $cache[$cacheKey] = $allowed; return $allowed; } public static function belongsTo(Auth $auth, int $adminId, string $systemKey): bool { if ($adminId <= 0) { return false; } $systemKey = self::normalizeKey($systemKey); if (self::option($systemKey, 'allow_rule_super', false)) { $ruleIds = $auth->getRuleIds($adminId); if (is_array($ruleIds) && in_array('*', $ruleIds, true)) { return true; } } $allowed = self::allowedGroupIds($systemKey); if ($allowed === []) { return false; } $userGroupIds = $auth->getGroupIds($adminId); if ($userGroupIds === []) { return false; } foreach ($userGroupIds as $gid) { if (isset($allowed[(int)$gid])) { return true; } } return false; } /** * 按角色组识别所属系统:先生产协同,再驾驶舱 */ public static function resolveSystem(Auth $auth, int $adminId): ?string { if ($adminId <= 0) { return null; } if (self::belongsTo($auth, $adminId, 'collab')) { return 'collab'; } if (self::belongsTo($auth, $adminId, 'cockpit')) { return 'cockpit'; } return null; } /** * 会话中的系统;缺失时按角色组补全 */ public static function currentSystem(Auth $auth = null): string { $system = Session::get('login_system'); if ($system === 'collab' || $system === 'cockpit') { return $system; } if ($auth && $auth->isLogin()) { $resolved = self::resolveSystem($auth, (int)$auth->id); if ($resolved) { Session::set('login_system', $resolved); return $resolved; } } return 'collab'; } /** * 读取风格码:1=白色 2=黑色原版 */ public static function styleCode(string $systemKey): int { self::loadConfig(); $systemKey = self::normalizeKey($systemKey); // 优先:collab_system_style / cockpit_system_style(只改 1 或 2) $flatKey = $systemKey === 'cockpit' ? 'mproc.cockpit_system_style' : 'mproc.collab_system_style'; $flat = Config::get($flatKey); if ($flat === 1 || $flat === 2 || $flat === '1' || $flat === '2') { return (int)$flat === 2 ? 2 : 1; } // 兼容旧数组 / 单数字写法 $map = Config::get('mproc.system_style'); if (is_array($map) && isset($map[$systemKey])) { $code = (int)$map[$systemKey]; } elseif (!is_array($map) && ((int)$map === 1 || (int)$map === 2)) { $code = (int)$map; } else { $code = $systemKey === 'cockpit' ? 2 : 1; } return $code === 2 ? 2 : 1; } /** * 应用后台皮肤到 Config,并返回模板变量 * * @return array{login_system:string,system_style:int,adminskin:string,load_xinhua_theme:bool,system_brand:string} */ public static function applyTheme(Auth $auth = null): array { $system = self::currentSystem($auth); $style = self::styleCode($system); // 1 白色:skin-blue-light + xinhua-theme(生产协同) // 2 黑色原版:skin-black(驾驶舱;本站 skin-blue 已改成亮蓝,不能当原版用) if ($style === 2) { $skin = 'skin-black'; $loadXinhua = false; } else { $skin = 'skin-blue-light'; $loadXinhua = true; } Config::set('fastadmin.adminskin', $skin); $brand = (string)self::option($system, 'brand', ''); if ($brand === '') { $brand = (string)self::option($system, 'name', '生产协同系统'); } $flatBrand = Config::get($system === 'cockpit' ? 'mproc.cockpit_system_brand' : 'mproc.collab_system_brand'); if (is_string($flatBrand) && $flatBrand !== '') { $brand = $flatBrand; } else { $fromMproc = Config::get('mproc.system_brand.' . $system); if (is_string($fromMproc) && $fromMproc !== '') { $brand = $fromMproc; } } return [ 'login_system' => $system, 'system_style' => $style, 'adminskin' => $skin, 'load_xinhua_theme' => $loadXinhua, 'system_brand' => $brand, ]; } }