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
+56
View File
@@ -0,0 +1,56 @@
<?php
/**
* EDM 邮箱列表导出接口(CSV) GET/POST /api/marketing/edm_export.php
* 入参同 edm.php filter:industry / province / city / keyword
*/
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('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;