c86f08c325
Co-Authored-By: Claude Code <noreply@anthropic.com>
60 lines
1.9 KiB
PHP
60 lines
1.9 KiB
PHP
<?php
|
||
/**
|
||
* 人员详情接口 GET /api/person/detail.php?id=1
|
||
* v1.0.16:联系方式改为“手机”“邮箱”两字段(仅常用);另有全部账号列表 accounts 供编辑回显
|
||
*/
|
||
require_once __DIR__ . '/../common/Api.php';
|
||
$pdo = Api::boot(['module' => 'person']);
|
||
|
||
|
||
$id = (int)($_REQUEST['id'] ?? 0);
|
||
if ($id <= 0) {
|
||
Response::error('参数错误', 400);
|
||
}
|
||
|
||
$pdo = DB::getInstance()->getPdo();
|
||
|
||
$stmt = $pdo->prepare("SELECT * FROM persons WHERE id = ?");
|
||
$stmt->execute([$id]);
|
||
$person = $stmt->fetch();
|
||
if (!$person) {
|
||
Response::error('人员不存在');
|
||
}
|
||
|
||
$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,
|
||
pwe.job_level, pwe.start_date, pwe.end_date, pwe.is_current
|
||
FROM person_work_experiences pwe
|
||
LEFT JOIN companies c ON c.id = pwe.company_id
|
||
WHERE pwe.person_id = ? AND pwe.is_active = 1
|
||
ORDER BY pwe.is_current DESC, pwe.start_date DESC"
|
||
);
|
||
$experiences->execute([$id]);
|
||
|
||
Response::success([
|
||
'person' => $person,
|
||
'accounts' => $accountList,
|
||
'phone' => $phone,
|
||
'email' => $email,
|
||
'experiences' => $experiences->fetchAll(),
|
||
]);
|