33 lines
1.0 KiB
PHP
33 lines
1.0 KiB
PHP
<?php
|
|
/**
|
|
* 任职公司选项接口 GET /api/person/company_options.php
|
|
* 返回启用中的企业(id + 显示名称),供人员「工作履历」行内公司下拉使用
|
|
* 入参:keyword(可选,模糊匹配企业名称)/ limit(默认 500)
|
|
*/
|
|
require_once __DIR__ . '/../common/db.php';
|
|
require_once __DIR__ . '/../common/response.php';
|
|
require_once __DIR__ . '/../common/auth.php';
|
|
|
|
checkPermission('person');
|
|
|
|
$keyword = trim($_REQUEST['keyword'] ?? '');
|
|
$limit = min(1000, max(1, (int)($_REQUEST['limit'] ?? 500)));
|
|
|
|
$pdo = DB::getInstance()->getPdo();
|
|
|
|
$where = 'is_active = 1';
|
|
$params = [];
|
|
if ($keyword !== '') {
|
|
$where .= ' AND (name_zh LIKE ? OR name_en LIKE ? OR display_name LIKE ?)';
|
|
$like = "%$keyword%";
|
|
array_push($params, $like, $like, $like);
|
|
}
|
|
|
|
$stmt = $pdo->prepare(
|
|
"SELECT id, COALESCE(NULLIF(display_name,''), name_zh, name_en) AS name
|
|
FROM companies WHERE $where ORDER BY id ASC LIMIT $limit"
|
|
);
|
|
$stmt->execute($params);
|
|
|
|
Response::success(['list' => $stmt->fetchAll()]);
|