This commit is contained in:
nanguaboss
2026-08-03 00:07:01 +08:00
commit 71c6e8d9c1
112 changed files with 7815 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
<?php
/**
* 企业导出接口(CSV) GET/POST /api/company/export.php
* 入参:ids(必填,勾选的企业ID,逗号分隔)——只导出勾选的企业
*/
require_once __DIR__ . '/../common/db.php';
require_once __DIR__ . '/../common/response.php';
require_once __DIR__ . '/../common/auth.php';
require_once __DIR__ . '/../common/logger.php';
checkPermission('company');
// 仅导出勾选的企业
$idsRaw = trim($_REQUEST['ids'] ?? '');
$idList = [];
if ($idsRaw !== '') {
foreach (explode(',', $idsRaw) as $v) {
$v = (int)trim($v);
if ($v > 0) {
$idList[] = $v;
}
}
}
$idList = array_unique($idList);
if (!$idList) {
Response::error('请先选择需要导出的企业数据', 1);
}
$pdo = DB::getInstance()->getPdo();
$in = implode(',', array_fill(0, count($idList), '?'));
$stmt = $pdo->prepare(
"SELECT id, name_zh, name_en, business_role, country, registration_number,
address, legal_representative, industry, industry_subdivision, website,
registered_capital, established_date, latest_employee_count, latest_annual_revenue,
is_listed, stock_code, created_at
FROM companies WHERE id IN ($in) AND is_active = 1 ORDER BY id DESC"
);
$stmt->execute($idList);
$list = $stmt->fetchAll();
logCurrent('export', 'company', 'companies', null, ['count' => count($list), 'ids' => $idList]);
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="companies_' . date('Ymd_His') . '.csv"');
echo "\xEF\xBB\xBF"; // UTF-8 BOM,便于 Excel 直接打开
$out = fopen('php://output', 'w');
fputcsv($out, ['ID', '公司名称', '英文名称', '业务角色', '国家/地区', '注册号', '地址', '法人', '行业', '行业细分', '官网', '注册资本', '成立日期', '员工数', '年营收', '是否上市', '股票代码', '创建时间']);
foreach ($list as $r) {
fputcsv($out, [
$r['id'], $r['name_zh'], $r['name_en'], $r['business_role'],
$r['country'], $r['registration_number'], $r['address'], $r['legal_representative'],
$r['industry'], $r['industry_subdivision'], $r['website'], $r['registered_capital'],
$r['established_date'], $r['latest_employee_count'], $r['latest_annual_revenue'],
$r['is_listed'], $r['stock_code'], date('Y-m-d', strtotime($r['created_at'])),
]);
}
fclose($out);
exit;