0806
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* 数据字典接口 GET /api/common/dicts.php
|
||||
* 参数:type=country|area|industry|certificate|source_channel|all(默认 all)
|
||||
* 返回各字典表启用中的数据,供前端下拉/联动使用。
|
||||
* 数据来源:官方 Excel 生成的种子数据(见 sql/dict_seed.sql),不依赖任何第三方接口。
|
||||
*/
|
||||
require_once __DIR__ . '/db.php';
|
||||
require_once __DIR__ . '/response.php';
|
||||
require_once __DIR__ . '/auth.php';
|
||||
|
||||
requireLogin();
|
||||
|
||||
$type = trim($_REQUEST['type'] ?? 'all');
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
|
||||
$data = [];
|
||||
|
||||
if ($type === 'all' || $type === 'country') {
|
||||
$data['countries'] = $pdo->query(
|
||||
"SELECT id, code, name FROM date_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 date_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 date_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 date_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();
|
||||
}
|
||||
|
||||
Response::success($data);
|
||||
Reference in New Issue
Block a user