getPdo(); // 公司存在性校验 $chk = $pdo->prepare("SELECT COUNT(*) FROM companies WHERE id = ?"); $chk->execute([$companyId]); if ((int)$chk->fetchColumn() === 0) { Response::error('企业不存在'); } $where = ['pwe.company_id = ?', 'pwe.is_active = 1']; $params = [$companyId]; if ($keyword !== '') { $where[] = 'p.full_name LIKE ?'; $params[] = "%$keyword%"; } if ($jobLevel !== '') { $where[] = 'pwe.job_level = ?'; $params[] = $jobLevel; } if (isset($_REQUEST['is_current']) && $_REQUEST['is_current'] !== '') { $where[] = 'pwe.is_current = ?'; $params[] = (int)$_REQUEST['is_current'] ? 1 : 0; } $whereSql = implode(' AND ', $where); // 总数 $stmt = $pdo->prepare( "SELECT COUNT(*) FROM person_work_experiences pwe INNER JOIN persons p ON p.id = pwe.person_id WHERE $whereSql" ); $stmt->execute($params); $total = (int)$stmt->fetchColumn(); // 列表 $offset = ($page - 1) * $limit; $stmt = $pdo->prepare( "SELECT p.id AS person_id, p.full_name, pwe.id AS work_id, pwe.position, pwe.department, pwe.job_level, pwe.start_date, pwe.end_date, pwe.is_current, (SELECT sa.account_id FROM social_accounts sa WHERE sa.owner_type = 'person' AND sa.owner_id = p.id AND sa.platform = 'phone' AND sa.is_active = 1 ORDER BY sa.is_primary DESC LIMIT 1) AS phone, (SELECT sa.account_id FROM social_accounts sa WHERE sa.owner_type = 'person' AND sa.owner_id = p.id AND sa.platform = 'email' AND sa.is_active = 1 ORDER BY sa.is_primary DESC LIMIT 1) AS email FROM person_work_experiences pwe INNER JOIN persons p ON p.id = pwe.person_id WHERE $whereSql ORDER BY pwe.is_current DESC, pwe.start_date DESC LIMIT $limit OFFSET $offset" ); $stmt->execute($params); $list = $stmt->fetchAll(); // 职级字典(该公司范围内,供筛选下拉) $lv = $pdo->prepare( "SELECT DISTINCT job_level FROM person_work_experiences WHERE company_id = ? AND is_active = 1 AND job_level IS NOT NULL AND job_level <> '' ORDER BY job_level" ); $lv->execute([$companyId]); $levels = $lv->fetchAll(PDO::FETCH_COLUMN); Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit, 'levels' => $levels]);