v1.0.10
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* 人员任职公司列表接口 GET /api/person/companies.php
|
||||
* 入参:person_id(必填)/ page / limit
|
||||
* 返回:该人员任职的公司列表(公司名称/部门/岗位/职级/入职日期/是否在岗)
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
|
||||
checkPermission('person');
|
||||
|
||||
$personId = (int)($_REQUEST['person_id'] ?? 0);
|
||||
if ($personId <= 0) {
|
||||
Response::error('参数错误', 400);
|
||||
}
|
||||
|
||||
[$page, $limit] = pageParams(5);
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
|
||||
$chk = $pdo->prepare("SELECT COUNT(*) FROM persons WHERE id = ?");
|
||||
$chk->execute([$personId]);
|
||||
if ((int)$chk->fetchColumn() === 0) {
|
||||
Response::error('人员不存在');
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT COUNT(*) FROM person_work_experiences pwe
|
||||
INNER JOIN companies c ON c.id = pwe.company_id
|
||||
WHERE pwe.person_id = ? AND pwe.is_active = 1"
|
||||
);
|
||||
$stmt->execute([$personId]);
|
||||
$total = (int)$stmt->fetchColumn();
|
||||
|
||||
$offset = ($page - 1) * $limit;
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT pwe.id AS work_id, pwe.company_id,
|
||||
CASE WHEN c.name_zh IS NOT NULL AND c.name_zh <> '' THEN c.name_zh
|
||||
ELSE COALESCE(c.name_en, c.display_name) END AS company_name,
|
||||
c.industry, pwe.department, pwe.position, pwe.job_level,
|
||||
pwe.start_date, pwe.end_date, pwe.is_current
|
||||
FROM person_work_experiences pwe
|
||||
INNER 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
|
||||
LIMIT $limit OFFSET $offset"
|
||||
);
|
||||
$stmt->execute([$personId]);
|
||||
$list = $stmt->fetchAll();
|
||||
|
||||
Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);
|
||||
Reference in New Issue
Block a user