prepare("SELECT id FROM vip_customers WHERE phone = ? AND car_number = ?"); $stmt->execute([$phone, $car_number]); 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 (?, ?, ?, ?, ?, ?, ?)"); try { $stmt->execute([$customer_name, $phone, $car_model, $car_number, $email, $birthday, $notes]); $success_message = "VIP客户录入成功!"; } catch (PDOException $e) { // 捕获唯一约束错误 if ($e->errorInfo[1] == 1062) { // MySQL唯一键约束错误码 throw new Exception('该手机号和车牌号组合已经是VIP客户'); } throw $e; // 重新抛出其他类型的异常 } } elseif ($action === 'update_vip') { $id = (int)$_POST['vip_id']; $customer_name = trim($_POST['customer_name']); $phone = trim($_POST['phone']); $car_model = trim($_POST['car_model']); $car_number = trim($_POST['car_number']); $email = trim($_POST['email'] ?? ''); $birthday = $_POST['birthday'] ?? ''; $notes = trim($_POST['notes'] ?? ''); if (empty($customer_name) || empty($phone)) { throw new Exception('请填写客户姓名和联系电话'); } // 检查手机号和车牌号组合是否与其他VIP客户冲突 $stmt = $pdo->prepare("SELECT id FROM vip_customers WHERE phone = ? AND car_number = ? AND id != ?"); $stmt->execute([$phone, $car_number, $id]); if ($stmt->fetch()) { throw new Exception('该手机号和车牌号组合已经被其他VIP客户使用'); } // 更新VIP客户信息 $stmt = $pdo->prepare("UPDATE vip_customers SET customer_name = ?, phone = ?, car_model = ?, car_number = ?, email = ?, birthday = ?, notes = ?, updated_at = NOW() WHERE id = ?"); try { $stmt->execute([$customer_name, $phone, $car_model, $car_number, $email, $birthday, $notes, $id]); $success_message = "VIP客户信息更新成功!"; } catch (PDOException $e) { // 捕获唯一约束错误 if ($e->errorInfo[1] == 1062) { // MySQL唯一键约束错误码 throw new Exception('该手机号和车牌号组合已经被其他VIP客户使用'); } throw $e; // 重新抛出其他类型的异常 } } 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(); } } // 获取搜索参数 $search_phone = isset($_GET['search_phone']) ? trim($_GET['search_phone']) : ''; $search_car_number = isset($_GET['search_car_number']) ? trim($_GET['search_car_number']) : ''; // 获取所有VIP客户(支持搜索) try { // 构建查询语句 $query = "SELECT * FROM vip_customers WHERE 1=1"; $params = []; if (!empty($search_phone)) { $query .= " AND phone LIKE :phone"; $params[':phone'] = '%' . $search_phone . '%'; } if (!empty($search_car_number)) { $query .= " AND car_number LIKE :car_number"; $params[':car_number'] = '%' . $search_car_number . '%'; } $query .= " ORDER BY created_at DESC"; $stmt = $pdo->prepare($query); $stmt->execute($params); $vip_customers = $stmt->fetchAll(); } catch (Exception $e) { $error_message = '获取VIP客户列表失败:' . $e->getMessage(); $vip_customers = []; } ?> VIP管理 - 洗车预约系统

🚗 洗车预约系统 - VIP管理

🔍 VIP客户搜索

➕ 录入新VIP客户

👑 VIP客户列表 (共 位)

暂无VIP客户

👑 VIP
联系电话:
车型:
车牌号:
邮箱:
生日:
备注:
录入时间:
返回预约页面