This commit is contained in:
nanguaboss
2026-08-06 00:50:23 +08:00
parent 595520822a
commit 2cb688ed46
29 changed files with 5227 additions and 186 deletions
+12 -2
View File
@@ -3,6 +3,7 @@
* 人员列表接口 GET/POST /api/person/list.php
* 参数:page / limit / keyword(姓名/证件号/手机/邮箱)/ gender / nationality / work_location / is_active
* 返回:{ list, total, page, limit }
* v1.0.16:联系方式列改为“手机”“邮箱”两个字段(仅返回常用:is_defult=1 优先,其次 is_primary=1)
*/
require_once __DIR__ . '/../common/db.php';
require_once __DIR__ . '/../common/response.php';
@@ -44,12 +45,21 @@ $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,
(SELECT GROUP_CONCAT(CONCAT(sa.platform, ':', sa.account_id) SEPARATOR ' | ')
FROM social_accounts sa WHERE sa.owner_type = 'person' AND sa.owner_id = p.id AND sa.is_active = 1) AS contacts
p.source_channel, p.source_detail,
$phoneSql AS phone,
$emailSql AS email
FROM persons p
WHERE $whereSql
ORDER BY p.id DESC