feat(vip): 新增VIP客户管理功能及预约系统
- 添加VIP客户搜索功能 - 实现VIP客户信息编辑功能 - 新增VIP客户预约记录查看功能 - 添加为VIP客户快速创建预约功能 - 新增预约处理API接口 - 优化移动端交互体验
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
// 配置数据库连接参数
|
||||
$servername = "localhost";
|
||||
$username = "root";
|
||||
$password = "";
|
||||
$dbname = "car_wash_db";
|
||||
|
||||
// 检查表单提交
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// 获取表单数据
|
||||
$customer_name = $_POST['customer_name'] ?? '';
|
||||
$phone = $_POST['phone'] ?? '';
|
||||
$car_model = $_POST['car_model'] ?? '';
|
||||
$car_number = $_POST['car_number'] ?? '';
|
||||
$booking_date = $_POST['booking_date'] ?? '';
|
||||
$time_slot = $_POST['time_slot'] ?? '';
|
||||
$package_id = $_POST['package_id'] ?? '';
|
||||
$notes = $_POST['notes'] ?? '';
|
||||
$source = $_POST['source'] ?? ''; // 来源标识,用于确定返回页面
|
||||
|
||||
// 验证必填字段
|
||||
$errors = [];
|
||||
|
||||
if (empty($customer_name)) {
|
||||
$errors[] = '请输入客户姓名';
|
||||
}
|
||||
|
||||
if (empty($phone)) {
|
||||
$errors[] = '请输入手机号码';
|
||||
} elseif (!preg_match('/^1[3-9]\d{9}$/', $phone)) {
|
||||
$errors[] = '请输入正确的手机号码';
|
||||
}
|
||||
|
||||
if (empty($car_number)) {
|
||||
$errors[] = '请输入车牌号';
|
||||
}
|
||||
|
||||
if (empty($booking_date)) {
|
||||
$errors[] = '请选择预约日期';
|
||||
}
|
||||
|
||||
if (empty($time_slot)) {
|
||||
$errors[] = '请选择预约时间';
|
||||
}
|
||||
|
||||
if (empty($package_id)) {
|
||||
$errors[] = '请选择洗车套餐';
|
||||
}
|
||||
|
||||
// 验证日期是否为过去
|
||||
$current_date = date('Y-m-d');
|
||||
if ($booking_date < $current_date) {
|
||||
$errors[] = '不能选择过去的日期';
|
||||
}
|
||||
|
||||
// 如果有错误,返回错误信息
|
||||
if (!empty($errors)) {
|
||||
$error_message = implode('\n', $errors);
|
||||
echo "<script>
|
||||
alert('$error_message');
|
||||
window.history.back();
|
||||
</script>";
|
||||
exit;
|
||||
}
|
||||
|
||||
// 创建数据库连接
|
||||
$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
|
||||
// 检查连接
|
||||
if ($conn->connect_error) {
|
||||
echo "<script>
|
||||
alert('数据库连接失败,请稍后重试');
|
||||
window.history.back();
|
||||
</script>";
|
||||
exit;
|
||||
}
|
||||
|
||||
// 检查是否已经存在相同的预约(同一天、同一时间段、同一车牌号)
|
||||
$check_sql = "SELECT * FROM bookings
|
||||
WHERE booking_date = ? AND time_slot = ? AND car_number = ? AND status != '已取消'";
|
||||
$check_stmt = $conn->prepare($check_sql);
|
||||
$check_stmt->bind_param("sss", $booking_date, $time_slot, $car_number);
|
||||
$check_stmt->execute();
|
||||
$check_result = $check_stmt->get_result();
|
||||
|
||||
if ($check_result->num_rows > 0) {
|
||||
echo "<script>
|
||||
alert('该时间段已存在相同车牌号的预约');
|
||||
window.history.back();
|
||||
</script>";
|
||||
$check_stmt->close();
|
||||
$conn->close();
|
||||
exit;
|
||||
}
|
||||
$check_stmt->close();
|
||||
|
||||
// 插入预约记录
|
||||
$status = '待服务'; // 默认为待服务状态
|
||||
$create_time = date('Y-m-d H:i:s');
|
||||
|
||||
$insert_sql = "INSERT INTO bookings
|
||||
(customer_name, phone, car_model, car_number, booking_date, time_slot, package_id, notes, status, create_time)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
$stmt = $conn->prepare($insert_sql);
|
||||
$stmt->bind_param("ssssssssss", $customer_name, $phone, $car_model, $car_number, $booking_date, $time_slot, $package_id, $notes, $status, $create_time);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
// 预约成功
|
||||
$success_message = '预约添加成功!';
|
||||
|
||||
// 根据来源决定返回页面
|
||||
$redirect_url = $source === 'vip_page' ? 'vip.php' : 'index.php';
|
||||
|
||||
echo "<script>
|
||||
alert('$success_message');
|
||||
window.location.href = '$redirect_url';
|
||||
</script>";
|
||||
} else {
|
||||
// 预约失败
|
||||
echo "<script>
|
||||
alert('预约添加失败,请稍后重试');
|
||||
window.history.back();
|
||||
</script>";
|
||||
}
|
||||
|
||||
// 关闭数据库连接
|
||||
$stmt->close();
|
||||
$conn->close();
|
||||
} else {
|
||||
// 不是POST请求,重定向到首页
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
Reference in New Issue
Block a user