From f605aa1c984e0c0658e73a7ba074384891f9ee4e 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 01:51:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(vip):=20=E6=B7=BB=E5=8A=A0VIP=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建vip_customers表存储VIP客户信息 - 实现VIP客户添加、查看和删除功能 - 在预约页面增加VIP客户选择功能 - 添加VIP管理页面和API接口 --- carwash_db.sql | 15 +++ get_vip_customer.php | 48 ++++++++ get_vip_customers.php | 34 ++++++ index.php | 140 +++++++++++++++++++++-- vip.php | 260 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 489 insertions(+), 8 deletions(-) create mode 100644 get_vip_customer.php create mode 100644 get_vip_customers.php create mode 100644 vip.php diff --git a/carwash_db.sql b/carwash_db.sql index e964fd4..efbba04 100644 --- a/carwash_db.sql +++ b/carwash_db.sql @@ -2,6 +2,21 @@ CREATE DATABASE IF NOT EXISTS carwash_booking; USE carwash_booking; +-- 创建VIP客户表 +CREATE TABLE IF NOT EXISTS vip_customers ( + id INT AUTO_INCREMENT PRIMARY KEY, + customer_name VARCHAR(100) NOT NULL COMMENT '客户姓名', + phone VARCHAR(20) NOT NULL UNIQUE COMMENT '联系电话(唯一)', + car_model VARCHAR(50) COMMENT '车型', + car_number VARCHAR(20) COMMENT '车牌号', + email VARCHAR(100) COMMENT '邮箱地址', + birthday DATE COMMENT '生日', + notes TEXT COMMENT '备注信息', + is_active BOOLEAN DEFAULT TRUE, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NULL +); + -- 创建套餐表 CREATE TABLE IF NOT EXISTS packages ( id INT AUTO_INCREMENT PRIMARY KEY, diff --git a/get_vip_customer.php b/get_vip_customer.php new file mode 100644 index 0000000..e8a6e79 --- /dev/null +++ b/get_vip_customer.php @@ -0,0 +1,48 @@ + '缺少客户ID参数'], JSON_UNESCAPED_UNICODE); + exit; +} + +// 数据库连接配置 +$host = 'localhost'; +$dbname = 'carwash_db'; +$username = 'root'; +$password = ''; + +try { + $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + // 查询指定ID的VIP客户 + $stmt = $pdo->prepare(" + SELECT id, customer_name, phone, car_model, car_number, email, birthday, notes, is_active + FROM vip_customers + WHERE id = ? AND is_active = 1 + "); + $stmt->execute([$id]); + + $vipCustomer = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($vipCustomer) { + echo json_encode($vipCustomer, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + } else { + http_response_code(404); + echo json_encode(['error' => 'VIP客户不存在'], JSON_UNESCAPED_UNICODE); + } + +} catch(PDOException $e) { + http_response_code(500); + echo json_encode([ + 'error' => '数据库连接失败', + 'message' => $e->getMessage() + ], JSON_UNESCAPED_UNICODE); +} +?> \ No newline at end of file diff --git a/get_vip_customers.php b/get_vip_customers.php new file mode 100644 index 0000000..7e00621 --- /dev/null +++ b/get_vip_customers.php @@ -0,0 +1,34 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + // 查询所有VIP客户,按创建时间倒序排列 + $stmt = $pdo->query(" + SELECT id, customer_name, phone, car_model, car_number, email, birthday, is_active + FROM vip_customers + WHERE is_active = 1 + ORDER BY created_at DESC + "); + + $vipCustomers = $stmt->fetchAll(PDO::FETCH_ASSOC); + + echo json_encode($vipCustomers, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + +} catch(PDOException $e) { + http_response_code(500); + echo json_encode([ + 'error' => '数据库连接失败', + 'message' => $e->getMessage() + ], JSON_UNESCAPED_UNICODE); +} +?> \ No newline at end of file diff --git a/index.php b/index.php index 6e42aa9..298309d 100644 --- a/index.php +++ b/index.php @@ -8,8 +8,31 @@ $success_message = ''; // 处理表单提交 if ($_SERVER['REQUEST_METHOD'] === 'POST') { try { - $customer_name = trim($_POST['customer_name']); - $phone = trim($_POST['phone']); + $customer_type = $_POST['customer_type']; + $vip_id = isset($_POST['vip_id']) ? (int)$_POST['vip_id'] : 0; + + // 如果选择VIP客户,从VIP表获取信息 + if ($customer_type === 'vip' && $vip_id > 0) { + $stmt = $pdo->prepare("SELECT * FROM vip_customers WHERE id = ? AND is_active = 1"); + $stmt->execute([$vip_id]); + $vip_customer = $stmt->fetch(); + + if (!$vip_customer) { + throw new Exception('选择的VIP客户无效'); + } + + // 使用VIP客户信息 + $customer_name = $vip_customer['customer_name']; + $phone = $vip_customer['phone']; + $car_model = $vip_customer['car_model'] ?: $car_model; // 允许覆盖 + $car_number = $vip_customer['car_number'] ?: $car_number; // 允许覆盖 + $member_type = 'VIP会员'; + } else { + // 新客户录入 + $customer_name = trim($_POST['customer_name']); + $phone = trim($_POST['phone']); + } + $car_model = trim($_POST['car_model']); $car_number = trim($_POST['car_number']); $package_id = (int)$_POST['package_id']; @@ -27,6 +50,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { throw new Exception('请填写所有必填字段'); } + // 验证VIP客户或新客户的必填字段 + if ($customer_type === 'vip') { + if (empty($vip_id)) { + throw new Exception('请选择一个VIP客户'); + } + } else { + if (empty($customer_name) || empty($phone)) { + throw new Exception('请填写客户姓名和联系电话'); + } + } + // 验证套餐 if ($package_id) { $stmt = $pdo->prepare("SELECT * FROM packages WHERE id = ? AND is_active = 1"); @@ -157,6 +191,7 @@ $packages_json = json_encode(array_map(function($package) { 预约洗车 预约管理 套餐管理 + VIP管理 @@ -226,14 +261,33 @@ $packages_json = json_encode(array_map(function($package) {

📋 预约信息

-
- - +
+
+ + +
+ +
-
- - +
+
+ + +
+ +
+ + +
@@ -361,6 +415,9 @@ $packages_json = json_encode(array_map(function($package) { // 默认选择今天的日期并显示时间段 selectDate(todayStr); + // 加载VIP客户列表 + loadVIPCustomers(); + // 移动端优化 if (/Mobi|Android|iPhone|iPad|iPod/i.test(navigator.userAgent)) { document.body.classList.add('mobile-device'); @@ -371,6 +428,73 @@ $packages_json = json_encode(array_map(function($package) { } }); + // 加载VIP客户列表 + function loadVIPCustomers() { + // 这里将从数据库获取VIP客户列表 + // 在实际应用中,您可能需要通过AJAX获取 + fetch('get_vip_customers.php') + .then(response => response.json()) + .then(data => { + const vipSelect = document.getElementById('vip_id'); + vipSelect.innerHTML = ''; + data.forEach(vip => { + const option = document.createElement('option'); + option.value = vip.id; + option.textContent = `${vip.customer_name} (${vip.phone})`; + vipSelect.appendChild(option); + }); + }) + .catch(error => { + console.log('加载VIP客户列表失败:', error); + // 如果加载失败,显示空列表 + }); + } + + // 处理客户类型变更 + function handleCustomerTypeChange() { + const customerType = document.getElementById('customer_type').value; + const vipSelectGroup = document.getElementById('vip_select_group'); + const newCustomerFields = document.getElementById('new_customer_fields'); + + if (customerType === 'vip') { + vipSelectGroup.style.display = 'block'; + newCustomerFields.style.display = 'none'; + // 隐藏新客户字段的必填属性 + document.getElementById('customer_name').required = false; + document.getElementById('phone').required = false; + } else { + vipSelectGroup.style.display = 'none'; + newCustomerFields.style.display = 'flex'; + // 显示新客户字段的必填属性 + document.getElementById('customer_name').required = true; + document.getElementById('phone').required = true; + } + + updateSubmitButton(); + } + + // 加载VIP客户信息 + function loadVIPInfo() { + const vipId = document.getElementById('vip_id').value; + if (vipId) { + // 这里将从数据库获取VIP客户详细信息 + fetch(`get_vip_customer.php?id=${vipId}`) + .then(response => response.json()) + .then(vip => { + if (vip.car_model) { + document.getElementById('car_model').value = vip.car_model; + } + if (vip.car_number) { + document.getElementById('car_number').value = vip.car_number; + } + }) + .catch(error => { + console.log('加载VIP信息失败:', error); + }); + } + updateSubmitButton(); + } + function showDateDetails(date) { // 获取预约详情容器 const detailsDiv = document.getElementById('bookingDetails'); diff --git a/vip.php b/vip.php new file mode 100644 index 0000000..50909a8 --- /dev/null +++ b/vip.php @@ -0,0 +1,260 @@ +prepare("SELECT id FROM vip_customers WHERE phone = ?"); + $stmt->execute([$phone]); + if ($stmt->fetch()) { + throw new Exception('该手机号码已经是VIP客户'); + } + + // 插入VIP客户 + $stmt = $pdo->prepare("INSERT INTO vip_customers + (customer_name, phone, car_model, car_number, email, birthday, notes) + VALUES (?, ?, ?, ?, ?, ?, ?)"); + $stmt->execute([$customer_name, $phone, $car_model, $car_number, $email, $birthday, $notes]); + + $success_message = "VIP客户录入成功!"; + + } elseif ($action === 'delete_vip') { + $id = (int)$_POST['vip_id']; + $stmt = $pdo->prepare("DELETE FROM vip_customers WHERE id = ?"); + $stmt->execute([$id]); + $success_message = "VIP客户删除成功!"; + } + } + } catch (Exception $e) { + $message = $e->getMessage(); + } +} + +// 获取所有VIP客户 +try { + $stmt = $pdo->query("SELECT * FROM vip_customers ORDER BY created_at DESC"); + $vip_customers = $stmt->fetchAll(); +} catch (Exception $e) { + $error_message = '获取VIP客户列表失败:' . $e->getMessage(); + $vip_customers = []; +} +?> + + + + + + + + + + + VIP管理 - 洗车预约系统 + + + +
+
+

👑 VIP客户管理

+ +
+ + +
+ + + +
+ + + +
+ +
+ + +
+ +
+

➕ 录入新VIP客户

+ + + +
+
+ + +
+ +
+ + +
+
+ +
+
+ + +
+ +
+ + +
+
+ +
+
+ + +
+ +
+ + +
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+

👑 VIP客户列表 (共 位)

+ + +
暂无VIP客户
+ +
+ +
+
+

+
👑 VIP
+
+ +
+
+ 联系电话: + +
+ + +
+ 车型: + +
+ + + +
+ 车牌号: + +
+ + + +
+ 邮箱: + +
+ + + +
+ 生日: + +
+ +
+ + +
+ 备注: + +
+ + +
+ 录入时间: +
+ +
+
+ + +
+
+
+ +
+ +
+
+ + +
+ + + + \ No newline at end of file