This repository has been archived on 2026-06-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
carwash_order/get_vip_last_booking.php
T
wsh5485 7d81c77fac refactor: 移除测试代码并仅使用实际数据库数据
移除get_vip_last_booking.php和index.php中的测试代码和模拟数据功能,系统现在仅返回实际数据库中的预约记录数据
2025-11-19 18:42:07 +08:00

69 lines
1.9 KiB
PHP

<?php
// 获取VIP客户最近的预约记录
header('Content-Type: application/json');
// 连接数据库
require 'db_connect.php';
// 检查是否提供了VIP ID
if (!isset($_GET['vip_id']) || empty($_GET['vip_id'])) {
echo json_encode(['error' => '未提供VIP客户ID']);
exit;
}
$vipId = intval($_GET['vip_id']);
// 尝试从数据库获取数据
$lastBooking = null;
try {
// 查询该VIP客户的最近一次预约
$sql = "SELECT
b.id,
b.appointment_date,
b.appointment_time,
b.duration,
p.package_name
FROM
bookings b
LEFT JOIN
packages p ON b.package_id = p.id
WHERE
b.customer_id = :vipId
AND b.status != '已取消'
ORDER BY
b.appointment_date DESC,
b.appointment_time DESC
LIMIT 1";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':vipId', $vipId, PDO::PARAM_INT);
$stmt->execute();
$lastBooking = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// 数据库查询失败,返回错误但继续执行
echo json_encode(['error' => '数据库查询失败: ' . $e->getMessage()]);
exit;
}
// 如果没有找到记录,返回空结果
if (!$lastBooking) {
echo json_encode(['has_booking' => false]);
exit;
}
// 格式化返回数据
$response = [
'has_booking' => true,
'appointment_date' => $lastBooking['appointment_date'],
'appointment_time' => $lastBooking['appointment_time'],
'package_name' => $lastBooking['package_name'] ? $lastBooking['package_name'] : '自定义服务',
'duration' => $lastBooking['duration']
];
echo json_encode($response);
// 关闭数据库连接
$conn = null;
// 系统现在只返回实际数据库中的预约记录数据