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
+29
View File
@@ -0,0 +1,29 @@
<?php
/**
* 数据定制接口(占位) GET/POST /api/marketing/data_custom.php
* 后续扩展:定制数据需求提交、报价、交付等。
*/
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');
$action = $_REQUEST['action'] ?? 'info';
if ($action === 'submit' && $_SERVER['REQUEST_METHOD'] === 'POST') {
checkAjax();
$content = [
'contact_name' => trim($_POST['contact_name'] ?? ''),
'contact_phone' => trim($_POST['contact_phone'] ?? ''),
'requirements' => trim($_POST['requirements'] ?? ''),
];
logCurrent('audit', 'marketing', null, null, $content);
Response::success(null, '需求已提交(占位实现,后续接入业务流)');
}
Response::success([
'title' => '数据定制',
'description' => '按行业/区域/规模等维度定制企业数据、人员数据,功能建设中(占位)。',
'status' => 'placeholder',
]);
+114
View File
@@ -0,0 +1,114 @@
<?php
/**
* EDM 筛选接口 GET/POST /api/marketing/edm.php
* action:
* industries 返回行业下拉数据
* regions 返回区域二级联动数据(省/州 -> 市/区,来自 persons.work_location / hometown)
* filter 按 行业 + 区域 + 关键词 筛选邮箱列表(persons.email + companies 关联联系人邮箱)
* 入参(filter):industry / province / city / keyword / page / limit
*/
require_once __DIR__ . '/../common/db.php';
require_once __DIR__ . '/../common/response.php';
require_once __DIR__ . '/../common/auth.php';
checkPermission('marketing');
$action = $_REQUEST['action'] ?? 'filter';
$pdo = DB::getInstance()->getPdo();
// ---------- 行业下拉 ----------
if ($action === 'industries') {
$rows = $pdo->query(
"SELECT DISTINCT industry FROM companies WHERE industry IS NOT NULL AND industry <> '' AND is_active = 1 ORDER BY industry"
)->fetchAll(PDO::FETCH_COLUMN);
Response::success(['industries' => $rows]);
}
// ---------- 区域二级联动 ----------
if ($action === 'regions') {
// 从 persons.work_location 与 hometown 提取 省/州 与 市/区
$rows = $pdo->query(
"SELECT work_location AS loc FROM persons WHERE work_location IS NOT NULL AND work_location <> '' AND is_active = 1
UNION SELECT hometown AS loc FROM persons WHERE hometown IS NOT NULL AND hometown <> '' AND is_active = 1"
)->fetchAll(PDO::FETCH_COLUMN);
$regions = [];
foreach ($rows as $loc) {
$parts = preg_split('/[\s\-—–\/,,]+/u', trim($loc));
$province = $parts[0] ?? $loc;
$city = isset($parts[1]) && $parts[1] !== '' ? $parts[1] : '';
if ($province === '') continue;
if (!isset($regions[$province])) {
$regions[$province] = [];
}
if ($city !== '' && !in_array($city, $regions[$province], true)) {
$regions[$province][] = $city;
}
}
Response::success(['regions' => $regions]);
}
// ---------- 筛选邮箱列表 ----------
if ($action === 'filter') {
$industry = trim($_REQUEST['industry'] ?? '');
$province = trim($_REQUEST['province'] ?? '');
$city = trim($_REQUEST['city'] ?? '');
$keyword = trim($_REQUEST['keyword'] ?? '');
// 邮箱来源:persons 的 social_accounts(platform=email),关联工作经历(company) 做行业过滤
$where = ["sa.platform = 'email'", "sa.is_active = 1", 'p.is_active = 1'];
$params = [];
if ($industry !== '') {
$where[] = "EXISTS (
SELECT 1 FROM person_work_experiences pwe
LEFT JOIN companies c ON c.id = pwe.company_id
WHERE pwe.person_id = p.id AND pwe.is_active = 1 AND c.industry = ?
)";
$params[] = $industry;
}
if ($province !== '') {
$where[] = "(p.work_location LIKE ? OR p.hometown LIKE ?)";
$params[] = "%$province%";
$params[] = "%$province%";
}
if ($city !== '') {
$where[] = "(p.work_location LIKE ? OR p.hometown LIKE ?)";
$params[] = "%$city%";
$params[] = "%$city%";
}
if ($keyword !== '') {
$where[] = '(p.full_name LIKE ? OR sa.account_id LIKE ?)';
$like = "%$keyword%";
array_push($params, $like, $like);
}
$whereSql = implode(' AND ', $where);
$stmt = $pdo->prepare(
"SELECT COUNT(*) FROM social_accounts sa
LEFT JOIN persons p ON p.id = sa.owner_id
WHERE $whereSql"
);
$stmt->execute($params);
$total = (int)$stmt->fetchColumn();
[$page, $limit] = pageParams(20);
$offset = ($page - 1) * $limit;
$stmt = $pdo->prepare(
"SELECT sa.id, sa.account_id AS email, p.id AS person_id, p.full_name, p.work_location, p.hometown,
(SELECT c.display_name FROM person_work_experiences pwe
LEFT JOIN companies c ON c.id = pwe.company_id
WHERE pwe.person_id = p.id AND pwe.is_current = 1 LIMIT 1) AS company_name
FROM social_accounts sa
LEFT JOIN persons p ON p.id = sa.owner_id
WHERE $whereSql
ORDER BY sa.id DESC
LIMIT $limit OFFSET $offset"
);
$stmt->execute($params);
$list = $stmt->fetchAll();
Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);
}
Response::error('未知操作', 400);
+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;
+28
View File
@@ -0,0 +1,28 @@
<?php
/**
* 媒体批发接口(占位) GET/POST /api/marketing/media_wholesale.php
* 后续扩展:媒体资源批量询价、下单等。
*/
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');
$action = $_REQUEST['action'] ?? 'info';
if ($action === 'inquiry' && $_SERVER['REQUEST_METHOD'] === 'POST') {
checkAjax();
$content = [
'media_ids' => trim($_POST['media_ids'] ?? ''),
'remark' => trim($_POST['remark'] ?? ''),
];
logCurrent('audit', 'marketing', 'social_accounts', null, $content);
Response::success(null, '询价已提交(占位实现,后续接入业务流)');
}
Response::success([
'title' => '媒体批发',
'description' => '媒体账号资源批量采购/询价,功能建设中(占位)。',
'status' => 'placeholder',
]);