59 lines
2.1 KiB
PHP
59 lines
2.1 KiB
PHP
<?php
|
|
include_once('../../_common.php');
|
|
// 💡 [추가] 알림 헬퍼 포함
|
|
include_once('../lib/notification_helper.php');
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
if (!$is_member) {
|
|
die(json_encode(['success' => false, 'message' => '로그인이 필요합니다.']));
|
|
}
|
|
|
|
$action = $_POST['action'] ?? '';
|
|
$reservation_id = (int)($_POST['id'] ?? 0);
|
|
|
|
try {
|
|
if ($action === 'cancel') {
|
|
if (!$reservation_id) {
|
|
throw new Exception('예약 ID가 없습니다.');
|
|
}
|
|
|
|
// 본인의 예약인지 확인
|
|
$sql = "SELECT * FROM expert_visit_reservations WHERE id = '{$reservation_id}' AND (customer_id = '{$member['mb_id']}' OR customer_phone = '{$member['mb_hp']}')";
|
|
$reservation = sql_fetch($sql);
|
|
|
|
if (!$reservation) {
|
|
throw new Exception('취소할 수 있는 예약 정보가 없거나 권한이 없습니다.');
|
|
}
|
|
|
|
// 이미 취소되었거나 완료된 예약은 변경 불가
|
|
if ($reservation['status'] === 'cancelled' || $reservation['status'] === 'completed') {
|
|
throw new Exception('이미 취소되었거나 완료된 예약입니다.');
|
|
}
|
|
|
|
// 예약 취소 처리
|
|
$sql_update = "UPDATE expert_visit_reservations
|
|
SET status = 'cancelled',
|
|
updated_at = NOW(),
|
|
updated_by = '{$member['mb_id']}'
|
|
WHERE id = '{$reservation_id}'";
|
|
|
|
if (sql_query($sql_update)) {
|
|
// 💡 [수정] 예약 취소 알림 발송
|
|
if (function_exists('notify_for_expert_visit')) {
|
|
notify_for_expert_visit($reservation_id, '예약취소');
|
|
}
|
|
|
|
echo json_encode(['success' => true, 'message' => '예약이 정상적으로 취소되었습니다.']);
|
|
} else {
|
|
throw new Exception('예약 취소 중 오류가 발생했습니다.');
|
|
}
|
|
|
|
} else {
|
|
throw new Exception('잘못된 요청입니다.');
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
|
}
|
|
?>
|