refactor: 优化预约系统代码结构并改进日期处理
- 移除packages.php中的会话检查,改为统一入口控制 - 在index.php中优化日期初始化逻辑并添加默认日期选择 - 重构bookings.php的查询逻辑,关联套餐表并改进时间显示格式
This commit is contained in:
+4
-4
@@ -20,7 +20,7 @@ if (isset($_POST['action']) && isset($_POST['booking_id'])) {
|
||||
|
||||
// 获取所有预约
|
||||
try {
|
||||
$stmt = $pdo->query("SELECT * FROM bookings ORDER BY appointment_date DESC, appointment_time DESC");
|
||||
$stmt = $pdo->query("SELECT b.*, p.package_name FROM bookings b LEFT JOIN packages p ON b.package_id = p.id ORDER BY b.start_time DESC");
|
||||
$bookings = $stmt->fetchAll();
|
||||
} catch (Exception $e) {
|
||||
$error_message = '获取预约列表失败:' . $e->getMessage();
|
||||
@@ -95,13 +95,13 @@ try {
|
||||
<strong>车牌号:</strong><?php echo htmlspecialchars($booking['car_number']); ?>
|
||||
</div>
|
||||
<div>
|
||||
<strong>服务类型:</strong><?php echo htmlspecialchars($booking['service_type']); ?>
|
||||
<strong>服务套餐:</strong><?php echo htmlspecialchars($booking['package_name'] ?? '未选择套餐'); ?>
|
||||
</div>
|
||||
<div>
|
||||
<strong>预约日期:</strong><?php echo $booking['appointment_date']; ?>
|
||||
<strong>预约日期:</strong><?php echo date('Y-m-d', strtotime($booking['start_time'])); ?>
|
||||
</div>
|
||||
<div>
|
||||
<strong>预约时间:</strong><?php echo $booking['appointment_time']; ?>
|
||||
<strong>预约时间:</strong><?php echo date('H:i', strtotime($booking['start_time'])); ?> - <?php echo date('H:i', strtotime($booking['end_time'])); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -306,8 +306,12 @@ $packages_json = json_encode(array_map(function($package) {
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const today = new Date();
|
||||
today.setDate(today.getDate());
|
||||
document.getElementById('appointment_date').value = today.toISOString().split('T')[0];
|
||||
selectedDate = today.toISOString().split('T')[0];
|
||||
const todayStr = today.toISOString().split('T')[0];
|
||||
document.getElementById('appointment_date').value = todayStr;
|
||||
selectedDate = todayStr;
|
||||
|
||||
// 默认选择今天的日期并显示时间段
|
||||
selectDate(todayStr);
|
||||
|
||||
// 移动端优化
|
||||
if (/Mobi|Android|iPhone|iPad|iPod/i.test(navigator.userAgent)) {
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db_connect.php';
|
||||
|
||||
// 检查是否已登录
|
||||
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
|
||||
header('Location: index.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
$message = '';
|
||||
|
||||
// 处理套餐操作
|
||||
|
||||
Reference in New Issue
Block a user