v1.0.10
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* 企业列表接口 GET/POST /api/company/list.php
|
||||
* 参数:page / limit / keyword(公司名/注册号)/ industry / business_role / country / is_active
|
||||
* 返回:{ list, total, page, limit }
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
require_once __DIR__ . '/../common/auth.php';
|
||||
|
||||
checkPermission('company');
|
||||
|
||||
[$page, $limit] = pageParams();
|
||||
$keyword = trim($_REQUEST['keyword'] ?? '');
|
||||
$industry = trim($_REQUEST['industry'] ?? '');
|
||||
$role = trim($_REQUEST['business_role'] ?? '');
|
||||
$country = trim($_REQUEST['country'] ?? '');
|
||||
$active = isset($_REQUEST['is_active']) && $_REQUEST['is_active'] !== '' ? (int)$_REQUEST['is_active'] : null;
|
||||
|
||||
$where = ['is_active = 1'];
|
||||
$params = [];
|
||||
if ($active !== null) {
|
||||
$where = [];
|
||||
$params = [];
|
||||
$where[] = 'is_active = ?';
|
||||
$params[] = $active;
|
||||
}
|
||||
if ($keyword !== '') {
|
||||
$where[] = '(display_name LIKE ? OR name_zh LIKE ? OR name_en LIKE ? OR registration_number LIKE ?)';
|
||||
$like = "%$keyword%";
|
||||
array_push($params, $like, $like, $like, $like);
|
||||
}
|
||||
if ($industry !== '') {
|
||||
$where[] = 'industry = ?';
|
||||
$params[] = $industry;
|
||||
}
|
||||
if ($role !== '') {
|
||||
$where[] = 'business_role = ?';
|
||||
$params[] = $role;
|
||||
}
|
||||
if ($country !== '') {
|
||||
$where[] = 'country = ?';
|
||||
$params[] = $country;
|
||||
}
|
||||
$whereSql = implode(' AND ', $where);
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
|
||||
$stmt = $pdo->prepare("SELECT COUNT(*) FROM companies WHERE $whereSql");
|
||||
$stmt->execute($params);
|
||||
$total = (int)$stmt->fetchColumn();
|
||||
|
||||
$offset = ($page - 1) * $limit;
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT id, name_zh, name_en, display_name, business_role, country, registration_number,
|
||||
address, legal_representative, industry, industry_subdivision, website,
|
||||
latest_employee_count, latest_annual_revenue, is_listed, stock_code,
|
||||
is_active, created_at, updated_at
|
||||
FROM companies
|
||||
WHERE $whereSql
|
||||
ORDER BY id DESC
|
||||
LIMIT $limit OFFSET $offset"
|
||||
);
|
||||
$stmt->execute($params);
|
||||
$list = $stmt->fetchAll();
|
||||
|
||||
Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);
|
||||
Reference in New Issue
Block a user