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/vip.php
T
wsh5485 f173149e28 feat(数据库): 修改VIP客户表索引为手机号和车牌号组合唯一
移除phone字段的唯一约束,添加phone和car_number的复合唯一索引
更新相关SQL脚本和PHP代码以支持新的索引规则
2025-11-20 10:55:59 +08:00

267 lines
12 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
session_start();
require_once 'db_connect.php';
$message = '';
$success_message = '';
// 处理表单提交
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
if (isset($_POST['action'])) {
$action = $_POST['action'];
if ($action === 'add_vip') {
$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 = ?");
$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 === '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 = [];
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="format-detection" content="telephone=no">
<meta name="description" content="VIP客户管理,录入和管理VIP客户信息">
<meta name="keywords" content="VIP管理,客户管理,会员管理">
<title>VIP管理 - 洗车预约系统</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<header class="header">
<h1>👑 VIP客户管理</h1>
<nav class="nav">
<a href="index.php" class="nav-link">预约洗车</a>
<a href="bookings.php" class="nav-link">预约管理</a>
<a href="packages.php" class="nav-link">套餐管理</a>
<a href="vip.php" class="nav-link active">VIP管理</a>
</nav>
</header>
<?php if (isset($success_message)): ?>
<div class="success-message"><?php echo $success_message; ?></div>
<?php endif; ?>
<?php if (isset($error_message)): ?>
<div class="error-message"><?php echo $error_message; ?></div>
<?php endif; ?>
<?php if ($message): ?>
<div class="message error-message" style="background-color: #fee; color: #c33; border-color: #fcc;">
<?= htmlspecialchars($message) ?>
</div>
<?php endif; ?>
<div class="vip-management">
<!-- VIP录入表单 -->
<div class="card">
<h2> 录入新VIP客户</h2>
<form method="POST" class="form">
<input type="hidden" name="action" value="add_vip">
<div class="form-row">
<div class="form-group">
<label for="customer_name">客户姓名 *</label>
<input type="text" id="customer_name" name="customer_name" required>
</div>
<div class="form-group">
<label for="phone">联系电话 *</label>
<input type="tel" id="phone" name="phone" required>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="car_model">车型</label>
<input type="text" id="car_model" name="car_model" placeholder="如:宝马X5">
</div>
<div class="form-group">
<label for="car_number">车牌号</label>
<input type="text" id="car_number" name="car_number" placeholder="如:京A88888">
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="email">邮箱</label>
<input type="email" id="email" name="email" placeholder="可选">
</div>
<div class="form-group">
<label for="birthday">生日</label>
<input type="date" id="birthday" name="birthday">
</div>
</div>
<div class="form-group">
<label for="notes">备注</label>
<textarea id="notes" name="notes" rows="3" placeholder="VIP客户特殊需求或备注信息..."></textarea>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">录入VIP客户</button>
<button type="reset" class="btn">重置</button>
</div>
</form>
</div>
<!-- VIP客户列表 -->
<div class="card">
<h2>👑 VIP客户列表 (共 <?php echo count($vip_customers); ?> 位)</h2>
<?php if (empty($vip_customers)): ?>
<div class="empty-message">暂无VIP客户</div>
<?php else: ?>
<div class="vip-grid">
<?php foreach ($vip_customers as $vip): ?>
<div class="vip-card">
<div class="vip-header">
<h3><?php echo htmlspecialchars($vip['customer_name']); ?></h3>
<div class="vip-status">👑 VIP</div>
</div>
<div class="vip-details">
<div class="detail-item">
<span class="detail-label">联系电话:</span>
<span class="detail-value"><?php echo htmlspecialchars($vip['phone']); ?></span>
</div>
<?php if ($vip['car_model']): ?>
<div class="detail-item">
<span class="detail-label">车型:</span>
<span class="detail-value"><?php echo htmlspecialchars($vip['car_model']); ?></span>
</div>
<?php endif; ?>
<?php if ($vip['car_number']): ?>
<div class="detail-item">
<span class="detail-label">车牌号:</span>
<span class="detail-value"><?php echo htmlspecialchars($vip['car_number']); ?></span>
</div>
<?php endif; ?>
<?php if ($vip['email']): ?>
<div class="detail-item">
<span class="detail-label">邮箱:</span>
<span class="detail-value"><?php echo htmlspecialchars($vip['email']); ?></span>
</div>
<?php endif; ?>
<?php if ($vip['birthday']): ?>
<div class="detail-item">
<span class="detail-label">生日:</span>
<span class="detail-value"><?php echo date('Y-m-d', strtotime($vip['birthday'])); ?></span>
</div>
<?php endif; ?>
</div>
<?php if ($vip['notes']): ?>
<div class="vip-notes">
<span class="detail-label">备注:</span>
<span><?php echo htmlspecialchars($vip['notes']); ?></span>
</div>
<?php endif; ?>
<div class="vip-meta">
<span>录入时间:<?php echo $vip['created_at']; ?></span>
</div>
<div class="vip-actions">
<form method="POST" style="display: inline;">
<input type="hidden" name="vip_id" value="<?php echo $vip['id']; ?>">
<button type="submit" name="action" value="delete_vip"
class="btn btn-sm btn-danger"
onclick="return confirm('确定要删除这个VIP客户吗?')">删除</button>
</form>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
<div style="text-align: center; margin-top: 2rem;">
<a href="index.php" class="btn">返回预约页面</a>
</div>
</div>
<script>
// 移动端优化脚本
document.addEventListener('DOMContentLoaded', function() {
// 为按钮添加触摸反馈
const buttons = document.querySelectorAll('.btn');
buttons.forEach(btn => {
btn.addEventListener('touchstart', function() {
this.style.transform = 'translateY(1px)';
});
btn.addEventListener('touchend', function() {
this.style.transform = 'translateY(-2px)';
});
});
// 检测设备类型
const isMobile = /Mobi|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
if (isMobile) {
document.body.classList.add('mobile-device');
}
});
</script>
</body>
</html>