Files
superlink/api/common/dicts.php
T
nanguaboss 2cb688ed46 0806
2026-08-06 00:50:23 +08:00

46 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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);