This commit is contained in:
nanguaboss
2026-08-03 00:07:01 +08:00
commit 71c6e8d9c1
112 changed files with 7815 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
<?php
/**
* 人员列表接口 GET/POST /api/person/list.php
* 参数:page / limit / keyword(姓名/证件号/手机/邮箱)/ gender / nationality / work_location / is_active
* 返回:{ list, total, page, limit }
*/
require_once __DIR__ . '/../common/db.php';
require_once __DIR__ . '/../common/response.php';
require_once __DIR__ . '/../common/auth.php';
checkPermission('person');
[$page, $limit] = pageParams();
$keyword = trim($_REQUEST['keyword'] ?? '');
$gender = trim($_REQUEST['gender'] ?? '');
$nationality = trim($_REQUEST['nationality'] ?? '');
$location = trim($_REQUEST['work_location'] ?? '');
$active = isset($_REQUEST['is_active']) && $_REQUEST['is_active'] !== '' ? (int)$_REQUEST['is_active'] : null;
$where = ['p.is_active = 1'];
$params = [];
if ($active !== null) {
$where = ['p.is_active = ?'];
$params = [$active];
}
if ($keyword !== '') {
// 姓名/证件号直查;手机/邮箱通过 social_accounts 关联
$where[] = "(p.full_name LIKE ? OR p.id_number LIKE ? OR p.union_id LIKE ? OR EXISTS (
SELECT 1 FROM social_accounts sa
WHERE sa.owner_type = 'person' AND sa.owner_id = p.id AND sa.is_active = 1
AND sa.account_id LIKE ?
))";
$like = "%$keyword%";
array_push($params, $like, $like, $like, $like);
}
if ($gender !== '') { $where[] = 'p.gender = ?'; $params[] = $gender; }
if ($nationality !== '') { $where[] = 'p.nationality = ?'; $params[] = $nationality; }
if ($location !== '') { $where[] = 'p.work_location LIKE ?'; $params[] = "%$location%"; }
$whereSql = implode(' AND ', $where);
$pdo = DB::getInstance()->getPdo();
$stmt = $pdo->prepare("SELECT COUNT(*) FROM persons p WHERE $whereSql");
$stmt->execute($params);
$total = (int)$stmt->fetchColumn();
$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
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]);