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, source_channel, source_detail, 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'], $r['source_channel'], $r['source_detail'], date('Y-m-d', strtotime($r['created_at'])), ]); } fclose($out); exit;