From c701ed25b06169996fd0c6e752c3b247b4488b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=B1=95=E9=B9=8F?= Date: Wed, 19 Nov 2025 18:49:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dvip=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E9=A2=84=E7=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- get_vip_last_booking.php | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/get_vip_last_booking.php b/get_vip_last_booking.php index ae07ebb..ac315be 100644 --- a/get_vip_last_booking.php +++ b/get_vip_last_booking.php @@ -16,11 +16,24 @@ $vipId = intval($_GET['vip_id']); // 尝试从数据库获取数据 $lastBooking = null; try { + // 首先获取VIP客户的电话号码 + $getVipPhone = "SELECT phone FROM vip_customers WHERE id = :vipId"; + $stmtPhone = $pdo->prepare($getVipPhone); + $stmtPhone->bindParam(':vipId', $vipId, PDO::PARAM_INT); + $stmtPhone->execute(); + $vipInfo = $stmtPhone->fetch(PDO::FETCH_ASSOC); + + if (!$vipInfo || !$vipInfo['phone']) { + echo json_encode(['has_booking' => false]); + exit; + } + + $vipPhone = $vipInfo['phone']; + // 查询该VIP客户的最近一次预约 $sql = "SELECT b.id, - b.appointment_date, - b.appointment_time, + b.start_time, b.duration, p.package_name FROM @@ -28,15 +41,14 @@ try { LEFT JOIN packages p ON b.package_id = p.id WHERE - b.customer_id = :vipId + b.phone = :vipPhone AND b.status != '已取消' ORDER BY - b.appointment_date DESC, - b.appointment_time DESC + b.start_time DESC LIMIT 1"; $stmt = $pdo->prepare($sql); - $stmt->bindParam(':vipId', $vipId, PDO::PARAM_INT); + $stmt->bindParam(':vipPhone', $vipPhone, PDO::PARAM_STR); $stmt->execute(); $lastBooking = $stmt->fetch(PDO::FETCH_ASSOC); @@ -53,10 +65,12 @@ if (!$lastBooking) { } // 格式化返回数据 +// 从start_time中提取日期和时间 +$startTime = new DateTime($lastBooking['start_time']); $response = [ 'has_booking' => true, - 'appointment_date' => $lastBooking['appointment_date'], - 'appointment_time' => $lastBooking['appointment_time'], + 'appointment_date' => $startTime->format('Y-m-d'), + 'appointment_time' => $startTime->format('H:i'), 'package_name' => $lastBooking['package_name'] ? $lastBooking['package_name'] : '自定义服务', 'duration' => $lastBooking['duration'] ];