0806
This commit is contained in:
+4
-4
@@ -34,18 +34,18 @@ if ((int)$chk->fetchColumn() > 0) {
|
||||
$pdo->prepare("INSERT INTO persons $sql")->execute($params);
|
||||
$newId = (int)$pdo->lastInsertId();
|
||||
|
||||
// 写入联系方式
|
||||
// 写入联系方式(v1.0.16:支持 is_defult 字段,1常用/0备用)
|
||||
$contacts = json_decode($_POST['contacts'] ?? '[]', true);
|
||||
if (is_array($contacts)) {
|
||||
$ins = $pdo->prepare(
|
||||
"INSERT INTO social_accounts (owner_type, owner_id, platform, account_id, profile_url, remark, is_primary)
|
||||
VALUES ('person', ?, ?, ?, ?, ?, ?)"
|
||||
"INSERT INTO social_accounts (owner_type, owner_id, platform, account_id, profile_url, remark, is_primary, is_defult)
|
||||
VALUES ('person', ?, ?, ?, ?, ?, ?, ?)"
|
||||
);
|
||||
foreach ($contacts as $c) {
|
||||
$platform = trim($c['platform'] ?? '');
|
||||
$accountId = trim($c['account_id'] ?? '');
|
||||
if ($platform === '' || $accountId === '') continue;
|
||||
$ins->execute([$newId, $platform, $accountId, $c['profile_url'] ?? null, $c['remark'] ?? null, !empty($c['is_primary']) ? 1 : 0]);
|
||||
$ins->execute([$newId, $platform, $accountId, $c['profile_url'] ?? null, $c['remark'] ?? null, !empty($c['is_primary']) ? 1 : 0, !empty($c['is_defult']) ? 1 : 0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+25
-2
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* 人员详情接口 GET /api/person/detail.php?id=1
|
||||
* v1.0.16:联系方式改为“手机”“邮箱”两字段(仅常用);另有全部账号列表 accounts 供编辑回显
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
@@ -22,8 +23,24 @@ if (!$person) {
|
||||
Response::error('人员不存在');
|
||||
}
|
||||
|
||||
$accounts = $pdo->prepare("SELECT id, platform, account_id, profile_url, remark, is_primary, is_active FROM social_accounts WHERE owner_type = 'person' AND owner_id = ? ORDER BY is_primary DESC, id DESC");
|
||||
$accounts = $pdo->prepare("SELECT id, platform, account_id, profile_url, remark, is_primary, is_defult, is_active FROM social_accounts WHERE owner_type = 'person' AND owner_id = ? ORDER BY is_defult DESC, is_primary DESC, id DESC");
|
||||
$accounts->execute([$id]);
|
||||
$accountList = $accounts->fetchAll();
|
||||
|
||||
// 常用手机/邮箱(优先 is_defult=1,其次 is_primary=1)
|
||||
$phone = '';
|
||||
$email = '';
|
||||
foreach ($accountList as $a) {
|
||||
if ($phone === '' && $a['platform'] === 'phone') {
|
||||
$phone = $a['account_id'];
|
||||
}
|
||||
if ($email === '' && $a['platform'] === 'email') {
|
||||
$email = $a['account_id'];
|
||||
}
|
||||
if ($phone !== '' && $email !== '') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$experiences = $pdo->prepare(
|
||||
"SELECT pwe.id, pwe.company_id, c.display_name, c.industry, pwe.position, pwe.department,
|
||||
@@ -35,4 +52,10 @@ $experiences = $pdo->prepare(
|
||||
);
|
||||
$experiences->execute([$id]);
|
||||
|
||||
Response::success(['person' => $person, 'accounts' => $accounts->fetchAll(), 'experiences' => $experiences->fetchAll()]);
|
||||
Response::success([
|
||||
'person' => $person,
|
||||
'accounts' => $accountList,
|
||||
'phone' => $phone,
|
||||
'email' => $email,
|
||||
'experiences' => $experiences->fetchAll(),
|
||||
]);
|
||||
|
||||
@@ -33,9 +33,9 @@ $whereSql = implode(' AND ', $where);
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
$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.created_at,
|
||||
(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 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 LIMIT 1) AS email
|
||||
p.education, p.graduated_from, p.hometown, p.work_location, p.source_channel, p.source_detail, p.created_at,
|
||||
(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 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_defult DESC, sa.is_primary DESC LIMIT 1) AS email
|
||||
FROM persons p WHERE $whereSql ORDER BY p.id DESC"
|
||||
);
|
||||
$stmt->execute($params);
|
||||
@@ -47,12 +47,12 @@ header('Content-Type: text/csv; charset=utf-8');
|
||||
header('Content-Disposition: attachment; filename="persons_' . date('Ymd_His') . '.csv"');
|
||||
echo "\xEF\xBB\xBF";
|
||||
$out = fopen('php://output', 'w');
|
||||
fputcsv($out, ['ID', 'union_id', '姓名', '性别', '国籍', '证件类型', '证件号', '学历', '毕业院校', '家乡', '工作所在地', '手机', '邮箱', '创建时间']);
|
||||
fputcsv($out, ['ID', 'union_id', '姓名', '性别', '国籍', '证件类型', '证件号', '学历', '毕业院校', '家乡', '工作所在地', '来源渠道', '来源详情', '手机', '邮箱', '创建时间']);
|
||||
foreach ($list as $r) {
|
||||
fputcsv($out, [
|
||||
$r['id'], $r['union_id'], $r['full_name'], $r['gender'], $r['nationality'],
|
||||
$r['id_type'], $r['id_number'], $r['education'], $r['graduated_from'],
|
||||
$r['hometown'], $r['work_location'], $r['phone'], $r['email'], $r['created_at'],
|
||||
$r['hometown'], $r['work_location'], $r['source_channel'], $r['source_detail'], $r['phone'], $r['email'], $r['created_at'],
|
||||
]);
|
||||
}
|
||||
fclose($out);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+12
-2
@@ -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
|
||||
|
||||
@@ -36,14 +36,14 @@ if (isset($_POST['contacts'])) {
|
||||
$contacts = json_decode($_POST['contacts'], true);
|
||||
if (is_array($contacts)) {
|
||||
$ins = $pdo->prepare(
|
||||
"INSERT INTO social_accounts (owner_type, owner_id, platform, account_id, profile_url, remark, is_primary)
|
||||
VALUES ('person', ?, ?, ?, ?, ?, ?)"
|
||||
"INSERT INTO social_accounts (owner_type, owner_id, platform, account_id, profile_url, remark, is_primary, is_defult)
|
||||
VALUES ('person', ?, ?, ?, ?, ?, ?, ?)"
|
||||
);
|
||||
foreach ($contacts as $c) {
|
||||
$platform = trim($c['platform'] ?? '');
|
||||
$accountId = trim($c['account_id'] ?? '');
|
||||
if ($platform === '' || $accountId === '') continue;
|
||||
$ins->execute([$id, $platform, $accountId, $c['profile_url'] ?? null, $c['remark'] ?? null, !empty($c['is_primary']) ? 1 : 0]);
|
||||
$ins->execute([$id, $platform, $accountId, $c['profile_url'] ?? null, $c['remark'] ?? null, !empty($c['is_primary']) ? 1 : 0, !empty($c['is_defult']) ? 1 : 0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user