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 = []; } ?>