'person']); // 仅导出勾选的人员 $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); } $where = ['p.id IN (' . implode(',', array_fill(0, count($idList), '?')) . ')', 'p.is_active = 1']; $params = $idList; $whereSql = implode(' AND ', $where); $pdo = DB::getInstance()->getPdo(); $stmt = $pdo->prepare( "SELECT p.id, p.union_id, p.full_name, p.gender, p.nationality, p.id_type, p.id_number, p.education, p.graduated_from, p.hometown, p.work_location, p.source_channel, p.source_detail, p.created_at, (SELECT sa.account_id FROM social_accounts sa WHERE sa.owner_type='person' AND sa.owner_id=p.id AND sa.platform='phone' AND sa.is_active=1 ORDER BY sa.is_defult DESC, sa.is_primary DESC LIMIT 1) AS phone, (SELECT sa.account_id FROM social_accounts sa WHERE sa.owner_type='person' AND sa.owner_id=p.id AND sa.platform='email' AND sa.is_active=1 ORDER BY sa.is_defult DESC, sa.is_primary DESC LIMIT 1) AS email FROM persons p WHERE $whereSql ORDER BY p.id DESC" ); $stmt->execute($params); $list = $stmt->fetchAll(); logCurrent('export', 'person', 'persons', null, ['count' => count($list)]); header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename="persons_' . date('Ymd_His') . '.csv"'); echo "\xEF\xBB\xBF"; $out = fopen('php://output', 'w'); fputcsv($out, ['ID', 'union_id', '姓名', '性别', '国籍', '证件类型', '证件号', '学历', '毕业院校', '家乡', '工作所在地', '来源渠道', '来源详情', '手机', '邮箱', '创建时间']); foreach ($list as $r) { fputcsv($out, [ $r['id'], $r['union_id'], $r['full_name'], $r['gender'], $r['nationality'], $r['id_type'], $r['id_number'], $r['education'], $r['graduated_from'], $r['hometown'], $r['work_location'], $r['source_channel'], $r['source_detail'], $r['phone'], $r['email'], $r['created_at'], ]); } fclose($out); exit;