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 {
使用此页面测试update_booking.php脚本的功能。
+ + $test_case): ?> +