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
+9 -8
View File
@@ -2,8 +2,8 @@
/**
* 人员 CSV 导入接口 POST /api/person/import.php (multipart/form-data, 字段名 file)
* CSV 表头:union_id,full_name,gender,nationality,id_type,id_number,education,
* graduated_from,hometown,work_location,phone,email
* 仅 full_name 必填;union_id 留空自动生成;phone/email 写入 social_accounts。
* graduated_from,hometown,work_location,phone,email,source_channel,source_detail
* 仅 full_name 必填;union_id 留空自动生成;phone/email 写入 social_accounts(默认常用)。
*/
require_once __DIR__ . '/../common/db.php';
require_once __DIR__ . '/../common/response.php';
@@ -26,12 +26,12 @@ $header = str_getcsv(trim($first));
$pdo = DB::getInstance()->getPdo();
$insPerson = $pdo->prepare(
"INSERT INTO persons (union_id, full_name, gender, nationality, id_type, id_number, education, graduated_from, hometown, work_location)
VALUES (?,?,?,?,?,?,?,?,?,?)"
"INSERT INTO persons (union_id, full_name, gender, nationality, id_type, id_number, education, graduated_from, hometown, work_location, source_channel, source_detail)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"
);
$insAccount = $pdo->prepare(
"INSERT INTO social_accounts (owner_type, owner_id, platform, account_id, is_primary)
VALUES ('person', ?, ?, ?, ?)"
"INSERT INTO social_accounts (owner_type, owner_id, platform, account_id, is_defult)
VALUES ('person', ?, ?, ?, 1)"
);
$inserted = 0;
@@ -63,13 +63,14 @@ while (($row = fgetcsv($handle)) !== false) {
$unionId, $rec['full_name'], $rec['gender'] ?? '保密', $rec['nationality'] ?? null,
$rec['id_type'] ?? null, $rec['id_number'] ?? null, $rec['education'] ?? null,
$rec['graduated_from'] ?? null, $rec['hometown'] ?? null, $rec['work_location'] ?? null,
$rec['source_channel'] ?? null, $rec['source_detail'] ?? null,
]);
$newId = (int)$pdo->lastInsertId();
if (!empty($rec['phone'])) {
$insAccount->execute([$newId, 'phone', $rec['phone'], 1]);
$insAccount->execute([$newId, 'phone', $rec['phone']]);
}
if (!empty($rec['email'])) {
$insAccount->execute([$newId, 'email', $rec['email'], 0]);
$insAccount->execute([$newId, 'email', $rec['email']]);
}
$inserted++;
} catch (Exception $e) {