feat(bookings): 添加订单筛选和搜索功能
实现按状态筛选订单和按手机号/车牌号搜索功能 添加测试页面验证筛选和搜索功能 优化默认查询逻辑,当有搜索条件时显示所有订单
This commit is contained in:
+122
-3
@@ -31,10 +31,33 @@ if (isset($_POST['action']) && isset($_POST['booking_id'])) {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取所有预约(过滤掉已完成和已取消的订单)
|
||||
// 获取所有预约,支持状态筛选和搜索功能
|
||||
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");
|
||||
// 构建查询,支持筛选和搜索
|
||||
$query = "SELECT b.*, p.package_name FROM bookings b LEFT JOIN packages p ON b.package_id = p.id WHERE 1=1 ";
|
||||
$params = [];
|
||||
|
||||
// 状态筛选
|
||||
if (isset($_GET['status']) && !empty($_GET['status'])) {
|
||||
$query .= " AND b.status = ?";
|
||||
$params[] = $_GET['status'];
|
||||
} else if (!isset($_GET['search']) || empty($_GET['search'])) {
|
||||
// 默认为只显示未完成订单,但如果有搜索条件则显示所有订单
|
||||
$query .= " AND b.status NOT IN ('已完成', '已取消')";
|
||||
}
|
||||
|
||||
// 搜索功能
|
||||
if (isset($_GET['search']) && !empty($_GET['search'])) {
|
||||
$searchTerm = '%' . $_GET['search'] . '%';
|
||||
$query .= " AND (b.phone LIKE ? OR b.car_number LIKE ?)";
|
||||
$params[] = $searchTerm;
|
||||
$params[] = $searchTerm;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY b.start_time DESC";
|
||||
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->execute($params);
|
||||
$bookings = $stmt->fetchAll();
|
||||
} catch (Exception $e) {
|
||||
$error_message = '获取预约列表失败:' . $e->getMessage();
|
||||
@@ -82,6 +105,31 @@ try {
|
||||
<div class="card">
|
||||
<h2>所有预约 (共 <?php echo count($bookings); ?> 条)</h2>
|
||||
|
||||
<!-- 筛选和搜索区域 -->
|
||||
<div class="filter-search-area">
|
||||
<form method="GET" class="filter-form">
|
||||
<div class="filter-group">
|
||||
<label for="status_filter">状态筛选:</label>
|
||||
<select id="status_filter" name="status" class="filter-select">
|
||||
<option value="">显示所有订单</option>
|
||||
<option value="待确认" <?php echo isset($_GET['status']) && $_GET['status'] == '待确认' ? 'selected' : ''; ?>>待确认</option>
|
||||
<option value="已确认" <?php echo isset($_GET['status']) && $_GET['status'] == '已确认' ? 'selected' : ''; ?>>已确认</option>
|
||||
<option value="已完成" <?php echo isset($_GET['status']) && $_GET['status'] == '已完成' ? 'selected' : ''; ?>>已完成</option>
|
||||
<option value="已取消" <?php echo isset($_GET['status']) && $_GET['status'] == '已取消' ? 'selected' : ''; ?>>已取消</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="search-group">
|
||||
<label for="search_term">搜索:</label>
|
||||
<input type="text" id="search_term" name="search" placeholder="手机号或车牌号"
|
||||
value="<?php echo isset($_GET['search']) ? htmlspecialchars($_GET['search']) : ''; ?>">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-sm btn-primary filter-submit">应用筛选</button>
|
||||
<a href="bookings.php" class="btn btn-sm btn-secondary">重置筛选</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php if (empty($bookings)): ?>
|
||||
<div class="empty-message">暂无预约记录</div>
|
||||
<?php else: ?>
|
||||
@@ -233,6 +281,77 @@ try {
|
||||
</div>
|
||||
|
||||
<style>
|
||||
/* 筛选和搜索区域样式 */
|
||||
.filter-search-area {
|
||||
background-color: #f8f9fa;
|
||||
padding: 16px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
border: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.filter-form {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
align-items: end;
|
||||
}
|
||||
|
||||
.filter-group,
|
||||
.search-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.filter-group label,
|
||||
.search-group label {
|
||||
font-weight: 500;
|
||||
color: #495057;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.filter-select,
|
||||
#search_term {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #ced4da;
|
||||
border-radius: 4px;
|
||||
font-size: 0.9rem;
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
#search_term {
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.filter-submit {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* 响应式调整 */
|
||||
@media (max-width: 768px) {
|
||||
/* 筛选表单响应式 */
|
||||
.filter-form {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.filter-group,
|
||||
.search-group {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#search_term {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.filter-form button,
|
||||
.filter-form a {
|
||||
width: 100%;
|
||||
margin-top: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
/* 付款状态样式 */
|
||||
.payment-status {
|
||||
padding: 3px 8px;
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
// 测试筛选和搜索功能
|
||||
|
||||
// 测试步骤:
|
||||
// 1. 访问 bookings.php?status=待确认 - 应该只显示待确认的订单
|
||||
// 2. 访问 bookings.php?status=已完成 - 应该只显示已完成的订单
|
||||
// 3. 访问 bookings.php?status= - 应该显示所有非已完成和已取消的订单
|
||||
// 4. 访问 bookings.php?search=138 - 应该显示手机号包含138的所有订单(包括已完成和已取消)
|
||||
// 5. 访问 bookings.php?search=京A - 应该显示车牌号包含京A的所有订单
|
||||
// 6. 访问 bookings.php?status=已确认&search=139 - 应该显示已确认且手机号包含139的订单
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>筛选和搜索功能测试</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
}
|
||||
.test-cases {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.test-case {
|
||||
background-color: #f5f5f5;
|
||||
border-radius: 8px;
|
||||
padding: 15px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.test-case h3 {
|
||||
margin-top: 0;
|
||||
color: #2c3e50;
|
||||
}
|
||||
.test-case p {
|
||||
margin-bottom: 10px;
|
||||
color: #555;
|
||||
}
|
||||
.test-links {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
a {
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
padding: 8px 16px;
|
||||
text-decoration: none;
|
||||
border-radius: 4px;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
a:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>订单筛选和搜索功能测试</h1>
|
||||
|
||||
<div class="test-cases">
|
||||
<div class="test-case">
|
||||
<h3>状态筛选测试</h3>
|
||||
<p>测试不同状态的订单筛选功能:</p>
|
||||
<div class="test-links">
|
||||
<a href="bookings.php?status=待确认">待确认订单</a>
|
||||
<a href="bookings.php?status=已确认">已确认订单</a>
|
||||
<a href="bookings.php?status=已完成">已完成订单</a>
|
||||
<a href="bookings.php?status=已取消">已取消订单</a>
|
||||
<a href="bookings.php?status=" target="_blank">所有状态订单</a>
|
||||
<a href="bookings.php">默认状态(非已完成和已取消)</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-case">
|
||||
<h3>搜索功能测试</h3>
|
||||
<p>测试手机号和车牌号搜索:</p>
|
||||
<div class="test-links">
|
||||
<a href="bookings.php?search=138">搜索手机号包含138</a>
|
||||
<a href="bookings.php?search=139">搜索手机号包含139</a>
|
||||
<a href="bookings.php?search=京A">搜索车牌号包含京A</a>
|
||||
<a href="bookings.php?search=粤B">搜索车牌号包含粤B</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-case">
|
||||
<h3>组合筛选测试</h3>
|
||||
<p>测试状态筛选和搜索的组合功能:</p>
|
||||
<div class="test-links">
|
||||
<a href="bookings.php?status=已确认&search=138">已确认且手机号包含138</a>
|
||||
<a href="bookings.php?status=待确认&search=京A">待确认且车牌号包含京A</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-case">
|
||||
<h3>重置功能</h3>
|
||||
<p>点击重置按钮应该清除所有筛选条件:</p>
|
||||
<a href="bookings.php">重置所有筛选条件</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 40px; padding: 20px; background-color: #e8f4f8; border-radius: 8px;">
|
||||
<h3>测试注意事项</h3>
|
||||
<ul>
|
||||
<li>请根据实际数据库中的数据调整搜索关键词</li>
|
||||
<li>默认状态下应该只显示待确认和已确认的订单</li>
|
||||
<li>当有搜索条件时,应该显示所有匹配的订单(包括已完成和已取消)</li>
|
||||
<li>当有状态筛选时,应该只显示对应状态的订单</li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user