c86f08c325
Co-Authored-By: Claude Code <noreply@anthropic.com>
49 lines
1.7 KiB
PHP
49 lines
1.7 KiB
PHP
<?php
|
||
/**
|
||
* 数据字典接口 GET /api/common/dicts.php
|
||
* 参数:type=country|area|industry|certificate|source_channel|all(默认 all)
|
||
* 返回各字典表启用中的数据,供前端下拉/联动使用。
|
||
* 数据来源:官方 Excel 生成的种子数据(见 sql/dict_seed.sql),不依赖任何第三方接口。
|
||
*/
|
||
require_once __DIR__ . '/Api.php';
|
||
$pdo = Api::boot();
|
||
|
||
|
||
$type = trim($_REQUEST['type'] ?? 'all');
|
||
$pdo = DB::getInstance()->getPdo();
|
||
|
||
$data = [];
|
||
|
||
if ($type === 'all' || $type === 'country') {
|
||
$data['countries'] = $pdo->query(
|
||
"SELECT id, code, name FROM data_dict_country WHERE is_active = 1 ORDER BY sort_order, id"
|
||
)->fetchAll();
|
||
}
|
||
if ($type === 'all' || $type === 'area') {
|
||
$data['areas'] = $pdo->query(
|
||
"SELECT id, code, name, parent_code FROM data_dict_area WHERE is_active = 1 ORDER BY sort_order, id"
|
||
)->fetchAll();
|
||
}
|
||
if ($type === 'all' || $type === 'industry') {
|
||
$data['industries'] = $pdo->query(
|
||
"SELECT id, code, name, parent_code FROM data_dict_industry WHERE is_active = 1 ORDER BY sort_order, id"
|
||
)->fetchAll();
|
||
}
|
||
if ($type === 'all' || $type === 'certificate') {
|
||
$data['certificates'] = $pdo->query(
|
||
"SELECT id, code, name FROM data_dict_certificate WHERE is_active = 1 ORDER BY sort_order, id"
|
||
)->fetchAll();
|
||
}
|
||
if ($type === 'all' || $type === 'source_channel') {
|
||
$data['source_channels'] = $pdo->query(
|
||
"SELECT id, name FROM source_channels WHERE is_active = 1 ORDER BY sort_order, id"
|
||
)->fetchAll();
|
||
}
|
||
if ($type === 'all' || $type === 'company_type') {
|
||
$data['company_types'] = $pdo->query(
|
||
"SELECT id, code, name FROM data_dict_company_type WHERE is_active = 1 ORDER BY sort_order, id"
|
||
)->fetchAll();
|
||
}
|
||
|
||
Response::success($data);
|