This repository has been archived on 2026-06-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
carwash_order/test_update_booking.php
T
wsh5485 0ffb4f610b feat(预约管理): 添加付款状态功能并增强预约更新逻辑
添加付款状态字段到预约表,实现状态更新API和前端交互
新增update_booking.php处理预约状态、付款状态和时间更新
改进bookings.php前端界面,添加付款状态显示和AJAX操作
添加测试页面test_update_booking.php验证功能
2025-11-19 12:48:04 +08:00

160 lines
5.4 KiB
PHP

<?php
// test_update_booking.php - 用于测试update_booking.php功能
// 测试参数
$test_cases = [
[
'name' => '测试修改预约状态',
'booking_id' => 1, // 假设存在ID为1的预约
'action' => '已确认'
],
[
'name' => '测试更新付款状态',
'booking_id' => 1,
'action' => '已付款'
],
[
'name' => '测试更新预约时间',
'booking_id' => 1,
'action' => 'update_time',
'new_start_time' => date('Y-m-d H:i', strtotime('tomorrow 10:00')),
'new_end_time' => date('Y-m-d H:i', strtotime('tomorrow 11:30'))
]
];
?>
<!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-case {
border: 1px solid #ddd;
margin-bottom: 20px;
padding: 15px;
border-radius: 5px;
}
.test-case h3 {
margin-top: 0;
color: #2c3e50;
}
.form-group {
margin-bottom: 10px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type="text"], input[type="datetime-local"] {
width: 100%;
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
background-color: #3498db;
color: white;
border: none;
padding: 10px 15px;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #2980b9;
}
.result {
margin-top: 15px;
padding: 10px;
background-color: #f8f9fa;
border-radius: 4px;
}
.success {
color: #27ae60;
}
.error {
color: #e74c3c;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h1>测试预约更新功能</h1>
<p>使用此页面测试update_booking.php脚本的功能。</p>
<?php foreach ($test_cases as $index => $test_case): ?>
<div class="test-case">
<h3><?php echo $test_case['name']; ?></h3>
<form class="test-form" data-index="<?php echo $index; ?>">
<input type="hidden" name="test_index" value="<?php echo $index; ?>">
<div class="form-group">
<label for="booking_id_<?php echo $index; ?>">预约ID:</label>
<input type="text" id="booking_id_<?php echo $index; ?>" name="booking_id" value="<?php echo $test_case['booking_id']; ?>">
</div>
<div class="form-group">
<label for="action_<?php echo $index; ?>">操作:</label>
<input type="text" id="action_<?php echo $index; ?>" name="action" value="<?php echo $test_case['action']; ?>">
</div>
<?php if ($test_case['action'] === 'update_time'): ?>
<div class="form-group">
<label for="new_start_time_<?php echo $index; ?>">新开始时间:</label>
<input type="datetime-local" id="new_start_time_<?php echo $index; ?>" name="new_start_time" value="<?php echo date('Y-m-d\TH:i', strtotime($test_case['new_start_time'])); ?>">
</div>
<div class="form-group">
<label for="new_end_time_<?php echo $index; ?>">新结束时间:</label>
<input type="datetime-local" id="new_end_time_<?php echo $index; ?>" name="new_end_time" value="<?php echo date('Y-m-d\TH:i', strtotime($test_case['new_end_time'])); ?>">
</div>
<?php endif; ?>
<button type="submit">运行测试</button>
</form>
<div id="result_<?php echo $index; ?>" class="result"></div>
</div>
<?php endforeach; ?>
<script>
$(document).ready(function() {
$('.test-form').on('submit', function(event) {
event.preventDefault();
const form = $(this);
const index = form.data('index');
const resultDiv = $('#result_' + index);
resultDiv.text('正在测试...');
$.ajax({
url: 'update_booking.php',
type: 'POST',
data: form.serialize(),
dataType: 'json',
success: function(response) {
const statusClass = response.status === 'success' ? 'success' : 'error';
resultDiv.html('<strong class="' + statusClass + '">' +
(response.status === 'success' ? '成功' : '失败') +
'</strong>: ' + response.message);
},
error: function(xhr, status, error) {
resultDiv.html('<strong class="error">请求失败</strong>: ' + error);
}
});
});
});
</script>
</body>
</html>