PHP 前后端一体:首页咨询师列表、预约表单、管理后台、二维码准入与邮件通知;敏感配置与提交数据通过 .gitignore 排除。 Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require __DIR__ . '/bootstrap.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
|
jsonError('方法不允许', 405);
|
|
}
|
|
|
|
requireAdmin();
|
|
|
|
$format = strtolower(trim((string) ($_GET['format'] ?? 'json')));
|
|
if (!in_array($format, ['json', 'csv'], true)) {
|
|
jsonError('不支持的导出格式');
|
|
}
|
|
|
|
$submissions = readSubmissions();
|
|
usort($submissions, function ($a, $b) {
|
|
return strcmp($b['createdAt'] ?? '', $a['createdAt'] ?? '');
|
|
});
|
|
|
|
$filename = 'consultations_' . date('Ymd_His');
|
|
|
|
if ($format === 'json') {
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
header('Content-Disposition: attachment; filename="' . $filename . '.json"');
|
|
echo json_encode($submissions, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
|
exit;
|
|
}
|
|
|
|
header('Content-Type: text/csv; charset=utf-8');
|
|
header('Content-Disposition: attachment; filename="' . $filename . '.csv"');
|
|
echo "\xEF\xBB\xBF";
|
|
|
|
$out = fopen('php://output', 'w');
|
|
fputcsv($out, ['ID', '提交时间', '咨询师', '咨询师ID', '昵称', '性别', '联系电话', '需求简述']);
|
|
foreach ($submissions as $row) {
|
|
fputcsv($out, [
|
|
$row['id'] ?? '',
|
|
$row['createdAt'] ?? '',
|
|
$row['doctorName'] ?? '',
|
|
$row['doctorId'] ?? '',
|
|
$row['nickname'] ?? '',
|
|
$row['gender'] ?? '',
|
|
$row['contact'] ?? '',
|
|
$row['description'] ?? ($row['topic'] ?? ''),
|
|
]);
|
|
}
|
|
fclose($out);
|
|
exit;
|