'marketing']); // 仅导出勾选的邮箱(emails 逗号分隔) $emailsRaw = trim($_REQUEST['emails'] ?? ''); $emailList = []; if ($emailsRaw !== '') { foreach (explode(',', $emailsRaw) as $v) { $v = trim($v); if ($v !== '') { $emailList[] = $v; } } } $emailList = array_unique($emailList); if (!$emailList) { Response::error('请先选择需要导出的邮箱', 1); } $in = implode(',', array_fill(0, count($emailList), '?')); $where = ["sa.platform = 'email'", 'sa.is_active = 1', 'p.is_active = 1', "sa.account_id IN ($in)"]; $params = $emailList; $whereSql = implode(' AND ', $where); $pdo = DB::getInstance()->getPdo(); $stmt = $pdo->prepare( "SELECT sa.account_id AS email, p.full_name, p.work_location, p.hometown FROM social_accounts sa LEFT JOIN persons p ON p.id = sa.owner_id WHERE $whereSql ORDER BY sa.id DESC" ); $stmt->execute($params); $list = $stmt->fetchAll(); logCurrent('export', 'marketing', 'social_accounts', null, ['count' => count($list), 'emails' => $emailList]); header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename="edm_emails_' . date('Ymd_His') . '.csv"'); echo "\xEF\xBB\xBF"; $out = fopen('php://output', 'w'); fputcsv($out, ['邮箱', '姓名', '工作所在地', '家乡']); foreach ($list as $r) { fputcsv($out, [$r['email'], $r['full_name'], $r['work_location'], $r['hometown']]); } fclose($out); exit;