feat(vip): 添加VIP客户管理功能
- 创建vip_customers表存储VIP客户信息 - 实现VIP客户添加、查看和删除功能 - 在预约页面增加VIP客户选择功能 - 添加VIP管理页面和API接口
This commit is contained in:
@@ -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) {
|
||||
<a href="index.php" class="nav-link active">预约洗车</a>
|
||||
<a href="bookings.php" class="nav-link">预约管理</a>
|
||||
<a href="packages.php" class="nav-link">套餐管理</a>
|
||||
<a href="vip.php" class="nav-link">VIP管理</a>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
@@ -226,14 +261,33 @@ $packages_json = json_encode(array_map(function($package) {
|
||||
<div class="booking-form-section">
|
||||
<h2>📋 预约信息</h2>
|
||||
<form method="POST" class="form" id="bookingForm">
|
||||
<div class="form-group">
|
||||
<label for="customer_name">客户姓名 *</label>
|
||||
<input type="text" id="customer_name" name="customer_name" required>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="customer_type">客户类型 *</label>
|
||||
<select id="customer_type" name="customer_type" required onchange="handleCustomerTypeChange()">
|
||||
<option value="new">新客户</option>
|
||||
<option value="vip">VIP客户</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group" id="vip_select_group" style="display: none;">
|
||||
<label for="vip_id">选择VIP客户</label>
|
||||
<select id="vip_id" name="vip_id" onchange="loadVIPInfo()">
|
||||
<option value="">请选择VIP客户</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="phone">联系电话 *</label>
|
||||
<input type="tel" id="phone" name="phone" required>
|
||||
<div class="form-row" id="new_customer_fields">
|
||||
<div class="form-group">
|
||||
<label for="customer_name">客户姓名 *</label>
|
||||
<input type="text" id="customer_name" name="customer_name" placeholder="请输入客户姓名">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="phone">联系电话 *</label>
|
||||
<input type="tel" id="phone" name="phone" placeholder="请输入联系电话">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
@@ -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 = '<option value="">请选择VIP客户</option>';
|
||||
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');
|
||||
|
||||
Reference in New Issue
Block a user