where('id', $projectId)->find(); if (!$row) { throw new \Exception('项目不存在', 404); } return [ 'projectId' => (int) $row['id'], 'companyId' => (int) $row['companyId'], 'name' => $row['name'], 'status' => (int) $row['status'], ]; } public static function resolveCompanyId(int $projectOrCompanyId): int { $ctx = self::resolveByProjectId($projectOrCompanyId); return $ctx['companyId']; } /** 支持传 project 表 id 或已是 companyId */ public static function resolveCompanyIdFlexible(int $id): int { $row = Db::name('company')->where('id', $id)->find(); if ($row) { return (int) $row['companyId']; } $exists = Db::name('company')->where('companyId', $id)->count(); if ($exists > 0) { return $id; } throw new \Exception('项目不存在', 404); } /** 项目主操盘手(MIN id · isAdmin=1),用于排除「子账号/成员」列表 */ public static function primaryMasterUserId(int $companyId): int { $id = Db::name('users') ->where('companyId', $companyId) ->where('isAdmin', UserModel::ADMIN_STP) ->where('deleteTime', 0) ->order('id asc') ->value('id'); return (int) ($id ?: 0); } }