first commit 2
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
include_once('../_common_con.php'); // 💡 [수정] 컴포넌트용 공통 파일 포함
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
// 입력 데이터 정리
|
||||
$reservation_data = [
|
||||
'customer_name' => trim($_POST['customer_name'] ?? ''),
|
||||
'customer_phone' => trim($_POST['customer_phone'] ?? ''),
|
||||
'customer_email' => trim($_POST['customer_email'] ?? ''),
|
||||
'reservation_date' => trim($_POST['reservation_date'] ?? ''),
|
||||
'reservation_time' => trim($_POST['reservation_time'] ?? ''),
|
||||
'consultation_type' => trim($_POST['consultation_type'] ?? 'onsite'),
|
||||
'request_memo' => trim($_POST['customer_request'] ?? ''),
|
||||
'payment_amount' => (int)($_POST['payment_amount'] ?? 0),
|
||||
'status' => 'payment_pending'
|
||||
];
|
||||
|
||||
// 필수 항목 유효성 검사
|
||||
if (empty($reservation_data['customer_name']) || empty($reservation_data['customer_phone']) || empty($reservation_data['reservation_date']) || empty($reservation_data['reservation_time'])) {
|
||||
throw new Exception('필수 예약 정보가 누락되었습니다.');
|
||||
}
|
||||
|
||||
// 예약 가능 여부 재확인 (서버 측 검증)
|
||||
$sql_check = "SELECT COUNT(*) as cnt FROM consultant_schedule
|
||||
WHERE specific_date = '{$reservation_data['reservation_date']}'
|
||||
AND start_time = '{$reservation_data['reservation_time']}'
|
||||
AND is_available = 1";
|
||||
$schedule = sql_fetch($sql_check);
|
||||
|
||||
if (!$schedule || $schedule['cnt'] == 0) {
|
||||
throw new Exception('선택하신 시간은 예약이 불가능합니다. 다른 시간을 선택해주세요.');
|
||||
}
|
||||
|
||||
// 예약 생성
|
||||
$sql = "INSERT INTO consultant_reservations
|
||||
(customer_name, customer_phone, customer_email, reservation_date, reservation_time, consultation_type, request_memo, payment_amount, status, created_at, updated_at)
|
||||
VALUES
|
||||
(
|
||||
'" . sql_real_escape_string($reservation_data['customer_name']) . "',
|
||||
'" . sql_real_escape_string($reservation_data['customer_phone']) . "',
|
||||
'" . sql_real_escape_string($reservation_data['customer_email']) . "',
|
||||
'" . sql_real_escape_string($reservation_data['reservation_date']) . "',
|
||||
'" . sql_real_escape_string($reservation_data['reservation_time']) . "',
|
||||
'" . sql_real_escape_string($reservation_data['consultation_type']) . "',
|
||||
'" . sql_real_escape_string($reservation_data['request_memo']) . "',
|
||||
'{$reservation_data['payment_amount']}',
|
||||
'{$reservation_data['status']}',
|
||||
NOW(),
|
||||
NOW()
|
||||
)";
|
||||
|
||||
if (sql_query($sql)) {
|
||||
$reservation_id = sql_insert_id();
|
||||
consultant_log("새 예약 신청: ID {$reservation_id} (고객: {$reservation_data['customer_name']})");
|
||||
|
||||
// TODO: 고객 및 관리자에게 알림 발송 로직 추가
|
||||
|
||||
echo json_encode(['success' => true, 'message' => '예약 신청이 완료되었습니다.']);
|
||||
} else {
|
||||
throw new Exception('데이터베이스 저장 중 오류가 발생했습니다.');
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
consultant_log("예약 신청 오류: " . $e->getMessage(), 'error');
|
||||
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user