getPdo(); $stmt = $pdo->prepare("SELECT COUNT(*) FROM persons p WHERE $whereSql"); $stmt->execute($params); $total = (int)$stmt->fetchColumn(); // 常用手机/邮箱:优先 is_defult=1,其次 is_primary=1,最后取任意一条 $phoneSql = "(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_defult DESC, sa.is_primary DESC, sa.id DESC LIMIT 1)"; $emailSql = "(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_defult DESC, sa.is_primary DESC, sa.id DESC LIMIT 1)"; $offset = ($page - 1) * $limit; $stmt = $pdo->prepare( "SELECT p.id, p.union_id, p.full_name, p.gender, p.nationality, p.id_type, p.id_number, p.education, p.graduated_from, p.hometown, p.work_location, p.is_active, p.created_at, p.source_channel, p.source_detail, $phoneSql AS phone, $emailSql AS email FROM persons p WHERE $whereSql ORDER BY p.id DESC LIMIT $limit OFFSET $offset" ); $stmt->execute($params); $list = $stmt->fetchAll(); Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);