feat(预约系统): 添加跨天预约支持并增加12小时预约选项
- 修改预约数据处理逻辑以支持跨天预约情况 - 在时间选择界面添加12小时预约按钮 - 增加自定义时长上限为12小时的验证 - 优化预约详情显示,标记跨天预约延续时段
This commit is contained in:
@@ -157,10 +157,28 @@ $stmt2 = $pdo->prepare("SELECT DATE(start_time) as date,
|
||||
$stmt2->execute([$start_date, $end_date]);
|
||||
$all_bookings = $stmt2->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// 按日期组织预约数据
|
||||
// 按日期组织预约数据,处理跨天预约情况
|
||||
$bookings_by_date = [];
|
||||
foreach ($all_bookings as $booking) {
|
||||
$bookings_by_date[$booking['date']][] = $booking;
|
||||
$start_date = $booking['date'];
|
||||
$start_time = $booking['start_time'];
|
||||
$end_time = $booking['end_time'];
|
||||
|
||||
// 将预约添加到开始日期
|
||||
$bookings_by_date[$start_date][] = $booking;
|
||||
|
||||
// 检查是否是跨天预约(结束时间早于开始时间)
|
||||
if (strtotime($end_time) < strtotime($start_time)) {
|
||||
// 计算第二天的日期
|
||||
$next_date = date('Y-m-d', strtotime($start_date . ' +1 day'));
|
||||
|
||||
// 创建第二天的预约记录副本
|
||||
$next_day_booking = $booking;
|
||||
$next_day_booking['is_cross_day'] = true; // 标记为跨天预约
|
||||
|
||||
// 将预约添加到第二天
|
||||
$bookings_by_date[$next_date][] = $next_day_booking;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取套餐信息用于JavaScript
|
||||
@@ -349,6 +367,7 @@ $packages_json = json_encode(array_map(function($package) {
|
||||
<button type="button" class="duration-btn" onclick="selectDuration(120)">2小时</button>
|
||||
<button type="button" class="duration-btn" onclick="selectDuration(180)">3小时</button>
|
||||
<button type="button" class="duration-btn" onclick="selectDuration(240)">4小时</button>
|
||||
<button type="button" class="duration-btn" onclick="selectDuration(720)">12小时</button>
|
||||
<input type="number" id="customDuration" min="30" step="30" value="60" style="width: 80px; margin-left: 10px;">
|
||||
<button type="button" class="btn btn-sm" onclick="applyCustomDuration()">确定</button>
|
||||
</div>
|
||||
@@ -1061,9 +1080,17 @@ $packages_json = json_encode(array_map(function($package) {
|
||||
const bookingStart = booking.start_time;
|
||||
const bookingEnd = booking.end_time;
|
||||
|
||||
// 检查当前时间段是否与已有预约重叠
|
||||
if (time >= bookingStart && time < bookingEnd) {
|
||||
return true; // 该时间段已被预约
|
||||
// 处理跨天预约的情况
|
||||
if (booking.is_cross_day) {
|
||||
// 如果是跨天预约的第二天记录,所有时间都应该是已被预约的(从00:00到结束时间)
|
||||
if (time < bookingEnd) {
|
||||
return true; // 该时间段已被预约
|
||||
}
|
||||
} else {
|
||||
// 正常预约检查
|
||||
if (time >= bookingStart && time < bookingEnd) {
|
||||
return true; // 该时间段已被预约
|
||||
}
|
||||
}
|
||||
}
|
||||
return false; // 该时间段可用
|
||||
@@ -1080,9 +1107,20 @@ $packages_json = json_encode(array_map(function($package) {
|
||||
|
||||
details += `<h4>当日预约情况 (共${bookings.length}个预约):</h4>`;
|
||||
bookings.forEach((booking, index) => {
|
||||
// 处理跨天预约的显示
|
||||
let displayStartTime = booking.start_time;
|
||||
let displayEndTime = booking.end_time;
|
||||
let crossDayLabel = '';
|
||||
|
||||
if (booking.is_cross_day) {
|
||||
// 对于跨天预约的第二天记录,显示为从00:00开始
|
||||
displayStartTime = '00:00';
|
||||
crossDayLabel = ' <small style="color: #ff6b6b;">(跨天预约延续)</small>';
|
||||
}
|
||||
|
||||
details += `
|
||||
<div class="booking-detail-item">
|
||||
<div class="booking-time">${booking.start_time} - ${booking.end_time}</div>
|
||||
<div class="booking-time">${displayStartTime} - ${displayEndTime}${crossDayLabel}</div>
|
||||
<div class="booking-info">
|
||||
<strong>客户:</strong> ${booking.customer_name} |
|
||||
<strong>车辆:</strong> ${booking.car_model} (${booking.car_number}) |
|
||||
@@ -1129,10 +1167,13 @@ $packages_json = json_encode(array_map(function($package) {
|
||||
|
||||
function applyCustomDuration() {
|
||||
const customDuration = parseInt(document.getElementById('customDuration').value);
|
||||
if (customDuration >= 30) {
|
||||
selectDuration(customDuration);
|
||||
} else {
|
||||
const maxDuration = 720; // 最大时长为12小时(720分钟)
|
||||
if (customDuration < 30) {
|
||||
alert('自定义时长不能少于30分钟');
|
||||
} else if (customDuration > maxDuration) {
|
||||
alert('自定义时长不能超过12小时');
|
||||
} else {
|
||||
selectDuration(customDuration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user