From 0ffb4f610bcb515cb727f31f448508c57b437edb 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 12:48:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E9=A2=84=E7=BA=A6=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=98=E6=AC=BE=E7=8A=B6=E6=80=81=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=B9=B6=E5=A2=9E=E5=BC=BA=E9=A2=84=E7=BA=A6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加付款状态字段到预约表,实现状态更新API和前端交互 新增update_booking.php处理预约状态、付款状态和时间更新 改进bookings.php前端界面,添加付款状态显示和AJAX操作 添加测试页面test_update_booking.php验证功能 --- add_payment_status.php | 18 +++ bookings.php | 335 ++++++++++++++++++++++++++++++++++++++-- test_update_booking.php | 160 +++++++++++++++++++ update_booking.php | 77 +++++++++ 4 files changed, 577 insertions(+), 13 deletions(-) create mode 100644 add_payment_status.php create mode 100644 test_update_booking.php create mode 100644 update_booking.php diff --git a/add_payment_status.php b/add_payment_status.php new file mode 100644 index 0000000..debb0f6 --- /dev/null +++ b/add_payment_status.php @@ -0,0 +1,18 @@ +query("SHOW COLUMNS FROM bookings LIKE 'payment_status'"); + if ($checkColumn->rowCount() == 0) { + // 添加付款状态字段 + $pdo->exec("ALTER TABLE bookings ADD COLUMN payment_status ENUM('未付款', '已付款') DEFAULT '未付款' AFTER status"); + echo "付款状态字段添加成功!"; + } else { + echo "付款状态字段已存在!"; + } +} catch (Exception $e) { + echo "操作失败:" . $e->getMessage(); +} +?> \ No newline at end of file diff --git a/bookings.php b/bookings.php index d44ed52..f0ff3b1 100644 --- a/bookings.php +++ b/bookings.php @@ -5,21 +5,35 @@ require_once 'db_connect.php'; // 处理状态更新 if (isset($_POST['action']) && isset($_POST['booking_id'])) { $booking_id = $_POST['booking_id']; - $new_status = $_POST['action']; + $action = $_POST['action']; - if (in_array($new_status, ['已确认', '已完成', '已取消'])) { - try { + try { + if (in_array($action, ['已确认', '已完成', '已取消'])) { + // 更新预约状态 $stmt = $pdo->prepare("UPDATE bookings SET status = ? WHERE id = ?"); - $stmt->execute([$new_status, $booking_id]); - $success_message = '状态更新成功!'; - } catch (Exception $e) { - $error_message = '状态更新失败:' . $e->getMessage(); + $stmt->execute([$action, $booking_id]); + $success_message = '预约状态更新成功!'; + } elseif (in_array($action, ['已付款', '未付款'])) { + // 更新付款状态 + $stmt = $pdo->prepare("UPDATE bookings SET payment_status = ? WHERE id = ?"); + $stmt->execute([$action, $booking_id]); + $success_message = '付款状态更新成功!'; + } elseif ($action == 'update_time' && isset($_POST['new_start_time']) && isset($_POST['new_end_time'])) { + // 更新预约时间 + $new_start_time = $_POST['new_start_time']; + $new_end_time = $_POST['new_end_time']; + $stmt = $pdo->prepare("UPDATE bookings SET start_time = ?, end_time = ? WHERE id = ?"); + $stmt->execute([$new_start_time, $new_end_time, $booking_id]); + $success_message = '预约时间更新成功!'; } + } catch (Exception $e) { + $error_message = '更新失败:' . $e->getMessage(); } } // 获取所有预约(过滤掉已完成和已取消的订单) try { + // 确保查询包含payment_status字段 $stmt = $pdo->query("SELECT b.*, p.package_name FROM bookings b LEFT JOIN packages p ON b.package_id = p.id WHERE b.status NOT IN ('已完成', '已取消') ORDER BY b.start_time DESC"); $bookings = $stmt->fetchAll(); } catch (Exception $e) { @@ -39,6 +53,7 @@ try { 预约列表 - 洗车预约系统 + @@ -110,6 +125,14 @@ try { 预约时间: - +
+ 付款状态: + + + + + +
会员类型: @@ -151,12 +174,21 @@ try {
-
- - - - -
+ +
+ + + +
+
+ +
+ + +
+
+ +
@@ -169,7 +201,284 @@ try { + + + + + + + +

测试预约更新功能

+ +

使用此页面测试update_booking.php脚本的功能。

+ + $test_case): ?> +
+

+
+ + +
+ + +
+ +
+ + +
+ + +
+ + +
+ +
+ + +
+ + + +
+ +
+
+ + + + + \ No newline at end of file diff --git a/update_booking.php b/update_booking.php new file mode 100644 index 0000000..038f7b4 --- /dev/null +++ b/update_booking.php @@ -0,0 +1,77 @@ + 'error', 'message' => '只允许POST请求']); + exit; +} + +// 检查必要的参数 +if (!isset($_POST['booking_id']) || !isset($_POST['action'])) { + echo json_encode(['status' => 'error', 'message' => '缺少必要参数']); + exit; +} + +$booking_id = $_POST['booking_id']; +$action = $_POST['action']; +$response = ['status' => 'error', 'message' => '未知操作']; + +try { + // 验证预约ID是否存在 + $stmt = $pdo->prepare("SELECT id FROM bookings WHERE id = ?"); + $stmt->execute([$booking_id]); + if ($stmt->rowCount() === 0) { + $response['message'] = '预约不存在'; + echo json_encode($response); + exit; + } + + if (in_array($action, ['已确认', '已完成', '已取消'])) { + // 更新预约状态 + $stmt = $pdo->prepare("UPDATE bookings SET status = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?"); + $stmt->execute([$action, $booking_id]); + $response = ['status' => 'success', 'message' => '预约状态更新成功!']; + } elseif (in_array($action, ['已付款', '未付款'])) { + // 更新付款状态 + $stmt = $pdo->prepare("UPDATE bookings SET payment_status = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?"); + $stmt->execute([$action, $booking_id]); + $response = ['status' => 'success', 'message' => '付款状态更新成功!']; + } elseif ($action == 'update_time' && isset($_POST['new_start_time']) && isset($_POST['new_end_time'])) { + // 更新预约时间 + $new_start_time = $_POST['new_start_time']; + $new_end_time = $_POST['new_end_time']; + + // 验证时间有效性 + $start_dt = new DateTime($new_start_time); + $end_dt = new DateTime($new_end_time); + $now = new DateTime(); + + if ($start_dt < $now) { + $response['message'] = '开始时间不能早于当前时间'; + echo json_encode($response); + exit; + } + + if ($end_dt <= $start_dt) { + $response['message'] = '结束时间必须晚于开始时间'; + echo json_encode($response); + exit; + } + + // 计算新的持续时间(分钟) + $duration = $start_dt->diff($end_dt)->i + ($start_dt->diff($end_dt)->h * 60); + + // 更新预约时间和持续时间 + $stmt = $pdo->prepare("UPDATE bookings SET start_time = ?, end_time = ?, duration = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?"); + $stmt->execute([$new_start_time, $new_end_time, $duration, $booking_id]); + $response = ['status' => 'success', 'message' => '预约时间更新成功!']; + } +} catch (Exception $e) { + $response['message'] = '操作失败:' . $e->getMessage(); +} + +echo json_encode($response); +?> \ No newline at end of file