Initial commit: 心理咨询预约系统

PHP 前后端一体:首页咨询师列表、预约表单、管理后台、二维码准入与邮件通知;敏感配置与提交数据通过 .gitignore 排除。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
litianming
2026-06-04 10:17:09 +08:00
commit 08ce60344d
49 changed files with 3490 additions and 0 deletions

75
api/submit.php Normal file
View File

@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
require __DIR__ . '/bootstrap.php';
require __DIR__ . '/mailer.php';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
jsonError('方法不允许', 405);
}
$body = getRequestBody();
$doctorId = trim((string) ($body['doctorId'] ?? ''));
$doctorName = trim((string) ($body['doctorName'] ?? ''));
$nickname = trim((string) ($body['nickname'] ?? ''));
$gender = trim((string) ($body['gender'] ?? ''));
$contact = trim((string) ($body['contact'] ?? ''));
$description = trim((string) ($body['description'] ?? ''));
if ($nickname === '') {
jsonError('请填写昵称');
}
if (!in_array($gender, ['男', '女'], true)) {
jsonError('请选择性别');
}
if ($contact === '') {
jsonError('请填写联系电话');
}
if (!validatePhone($contact)) {
jsonError('请输入正确的11位手机号码');
}
if ($description === '') {
jsonError('请填写需求简述');
}
if (mb_strlen($description) > 200) {
jsonError('需求简述不能超过200字');
}
$record = [
'id' => uniqid('sub_', true),
'createdAt' => date('c'),
'doctorId' => $doctorId,
'doctorName' => $doctorName,
'nickname' => $nickname,
'gender' => $gender,
'contact' => $contact,
'description' => $description,
];
$submissions = readSubmissions();
$submissions[] = $record;
if (!saveSubmissions($submissions)) {
jsonError(getSaveSubmissionsError(), 500);
}
$response = [
'ok' => true,
'message' => '提交成功',
'id' => $record['id'],
'total' => count($submissions),
];
http_response_code(200);
header('Content-Type: application/json; charset=utf-8');
echo json_encode($response, JSON_UNESCAPED_UNICODE);
finishResponseAndContinue();
$mailSent = sendSubmissionMail($submissions);
if (!$mailSent) {
error_log('[submit] 数据已保存邮件通知未发送ID=' . $record['id']);
}
exit;