905bbc5934
- 在多个文件中添加调试日志记录功能 - 将数据库连接统一迁移到db_connect.php - 改进预约时间冲突检测逻辑 - 优化VIP客户数据处理 - 增强套餐查询的健壮性 - 更新预约状态处理流程
99 lines
2.8 KiB
PHP
99 lines
2.8 KiB
PHP
<?php
|
|
// 加载数据库配置
|
|
require_once 'db_connect.php';
|
|
|
|
// 设置响应头为JSON
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
// 获取请求参数
|
|
$phone = $_GET['phone'] ?? '';
|
|
|
|
// 验证参数
|
|
if (empty($phone)) {
|
|
echo json_encode([
|
|
'success' => false,
|
|
'message' => '缺少必要的参数',
|
|
'total' => 0,
|
|
'pending' => 0,
|
|
'completed' => 0,
|
|
'bookings' => []
|
|
], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
// 准备SQL查询 - 查询用户的预约记录(使用新的数据库结构)
|
|
$sql = "SELECT b.*, p.package_name
|
|
FROM bookings b
|
|
LEFT JOIN packages p ON b.package_id = p.id
|
|
WHERE b.phone = ?
|
|
ORDER BY b.start_time DESC, b.id DESC";
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([$phone]);
|
|
$results = $stmt->fetchAll();
|
|
|
|
$bookings = [];
|
|
$pending = 0;
|
|
$completed = 0;
|
|
|
|
// 处理查询结果
|
|
foreach ($results as $row) {
|
|
// 格式化日期和时间
|
|
$booking_date = $row['start_time'] ? date('Y-m-d', strtotime($row['start_time'])) : '';
|
|
$time_slot = '';
|
|
if ($row['start_time'] && $row['end_time']) {
|
|
$start_time = date('H:i', strtotime($row['start_time']));
|
|
$end_time = date('H:i', strtotime($row['end_time']));
|
|
$time_slot = $start_time . '-' . $end_time;
|
|
}
|
|
|
|
$booking = [
|
|
'id' => $row['id'],
|
|
'booking_date' => $booking_date,
|
|
'phone' => $row['phone'],
|
|
'car_number' => $row['car_number'] ?? '',
|
|
'car_model' => $row['car_model'] ?? '',
|
|
'time_slot' => $time_slot,
|
|
'status' => $row['status'] ?? '未知',
|
|
'package_name' => $row['package_name'] ?? '',
|
|
'notes' => $row['notes'] ?? ''
|
|
];
|
|
|
|
// 统计不同状态的预约数量
|
|
if ($booking['status'] === '待确认' || $booking['status'] === '已确认' || $booking['status'] === '进行中') {
|
|
$pending++;
|
|
} elseif ($booking['status'] === '已完成') {
|
|
$completed++;
|
|
}
|
|
|
|
$bookings[] = $booking;
|
|
}
|
|
|
|
// 计算总预约数
|
|
$total = count($bookings);
|
|
|
|
// 构建响应数据
|
|
$response = [
|
|
'success' => true,
|
|
'total' => $total,
|
|
'pending' => $pending,
|
|
'completed' => $completed,
|
|
'bookings' => $bookings
|
|
];
|
|
|
|
// 返回JSON数据
|
|
echo json_encode($response, JSON_UNESCAPED_UNICODE);
|
|
|
|
} catch (Exception $e) {
|
|
echo json_encode([
|
|
'success' => false,
|
|
'message' => '查询失败:' . $e->getMessage(),
|
|
'total' => 0,
|
|
'pending' => 0,
|
|
'completed' => 0,
|
|
'bookings' => []
|
|
], JSON_UNESCAPED_UNICODE);
|
|
}
|
|
?>
|