228 lines
8.6 KiB
PHP
228 lines
8.6 KiB
PHP
<?php
|
|
session_start();
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$pdo = db();
|
|
$user_id = $_SESSION['user_id'];
|
|
|
|
$stmt = $pdo->prepare("SELECT username, balance FROM users WHERE id = ?");
|
|
$stmt->execute([$user_id]);
|
|
$user = $stmt->fetch();
|
|
|
|
// Messages will be loaded via AJAX
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>客服中心 - 全球接码</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
|
|
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
|
|
<style>
|
|
:root {
|
|
--primary: #3b82f6;
|
|
--primary-gradient: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
|
|
--bg-body: #f1f5f9;
|
|
--surface: #ffffff;
|
|
--text-main: #1e293b;
|
|
--text-muted: #64748b;
|
|
--border-color: #e2e8f0;
|
|
--sidebar-width: 280px;
|
|
--radius-xl: 24px;
|
|
}
|
|
body {
|
|
font-family: 'Plus Jakarta Sans', sans-serif;
|
|
background-color: var(--bg-body);
|
|
color: var(--text-main);
|
|
overflow: hidden;
|
|
letter-spacing: -0.01em;
|
|
}
|
|
|
|
.main-content {
|
|
margin-left: var(--sidebar-width);
|
|
padding: 2.5rem;
|
|
height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.chat-container {
|
|
background: white;
|
|
border: 1px solid var(--border-color);
|
|
border-radius: var(--radius-xl);
|
|
display: flex;
|
|
flex-direction: column;
|
|
flex: 1;
|
|
overflow: hidden;
|
|
box-shadow: 0 1px 3px rgba(0,0,0,0.05);
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.chat-body {
|
|
flex: 1;
|
|
padding: 2.5rem;
|
|
overflow-y: auto;
|
|
background-color: #fff;
|
|
scroll-behavior: smooth;
|
|
}
|
|
|
|
.chat-footer {
|
|
padding: 1.5rem 2.5rem;
|
|
border-top: 1px solid var(--border-color);
|
|
background: #fff;
|
|
}
|
|
|
|
.message { margin-bottom: 1.5rem; max-width: 75%; display: flex; flex-direction: column; }
|
|
.message-content { padding: 1rem 1.25rem; border-radius: 18px; font-size: 14px; font-weight: 500; line-height: 1.6; position: relative; }
|
|
.message-user { margin-left: auto; align-items: flex-end; }
|
|
.message-user .message-content { background: var(--primary-gradient); color: white; border-bottom-right-radius: 4px; box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2); }
|
|
.message-admin { align-items: flex-start; }
|
|
.message-admin .message-content { background: #f1f5f9; color: #334155; border-bottom-left-radius: 4px; }
|
|
|
|
.btn-send { background: var(--primary-gradient); border: none; border-radius: 14px; width: 52px; height: 52px; color: white; transition: all 0.2s; }
|
|
.btn-send:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3); }
|
|
.form-control { border: 1.5px solid var(--border-color); border-radius: 14px; padding: 14px 20px; background: #f8fafc; font-weight: 500; }
|
|
.form-control:focus { background: white; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1); }
|
|
|
|
.online-indicator {
|
|
background: #dcfce7;
|
|
color: #15803d;
|
|
padding: 6px 14px;
|
|
border-radius: 100px;
|
|
font-size: 10px;
|
|
font-weight: 800;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
letter-spacing: 0.5px;
|
|
}
|
|
|
|
@media (max-width: 992px) {
|
|
.main-content { margin-left: 0; padding: 1.5rem; }
|
|
.sidebar { display: none; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<?php include 'includes/sidebar.php'; ?>
|
|
|
|
<div class="main-content">
|
|
<div class="mb-4 d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<h1 class="fw-bold mb-1" style="font-size: 1.5rem;">客服中心 <span class="text-muted fw-medium ms-2 fs-6">SUPPORT CENTER</span></h1>
|
|
<p class="text-muted small mb-0 fw-medium">专业团队在线为您解答充值、收码与账户相关疑问</p>
|
|
</div>
|
|
<div class="online-indicator">
|
|
<i class="fas fa-circle" style="font-size: 6px; animation: pulse 2s infinite;"></i> AGENT ONLINE
|
|
</div>
|
|
</div>
|
|
|
|
<div class="chat-container">
|
|
<div class="chat-body" id="chatBody">
|
|
<div class="message message-admin">
|
|
<div class="message-content">您好,<?= htmlspecialchars($user['username']) ?>!我是您的专属技术支持。如果您遇到任何关于充值未到账、号码收不到码或其他系统问题,请随时在这里留言,我们会尽快回复您。</div>
|
|
</div>
|
|
<!-- Messages loaded via JS -->
|
|
</div>
|
|
<div class="chat-footer">
|
|
<form id="chatForm" class="d-flex gap-3">
|
|
<input type="text" id="msgInput" class="form-control" placeholder="在此输入您的问题或反馈..." required autocomplete="off">
|
|
<button type="submit" class="btn btn-send"><i class="fas fa-paper-plane"></i></button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<audio id="notifSound" src="https://assets.mixkit.co/active_storage/sfx/2354/2354-preview.mp3" preload="auto"></audio>
|
|
|
|
<script>
|
|
const chatBody = document.getElementById('chatBody');
|
|
const chatForm = document.getElementById('chatForm');
|
|
const msgInput = document.getElementById('msgInput');
|
|
const notifSound = document.getElementById('notifSound');
|
|
let lastMsgCount = 0;
|
|
|
|
async function loadMessages() {
|
|
try {
|
|
const res = await fetch('ajax_handler.php?action=get_messages');
|
|
const data = await res.json();
|
|
if (data.code === 0) {
|
|
if (data.data.length === lastMsgCount) return;
|
|
|
|
// Keep the first welcome message
|
|
const welcomeMsg = chatBody.firstElementChild.outerHTML;
|
|
chatBody.innerHTML = welcomeMsg;
|
|
|
|
data.data.forEach(msg => {
|
|
const div = document.createElement('div');
|
|
div.className = `message ${msg.sender === 'user' ? 'message-user' : 'message-admin'}`;
|
|
div.innerHTML = `
|
|
<div class="message-content">${escapeHtml(msg.message)}</div>
|
|
<div class="small text-muted mt-2 px-1" style="font-size: 10px; font-weight: 600;">${new Date(msg.created_at).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})}</div>
|
|
`;
|
|
chatBody.appendChild(div);
|
|
});
|
|
|
|
if (lastMsgCount > 0 && data.data.length > lastMsgCount) {
|
|
const lastMsg = data.data[data.data.length - 1];
|
|
if (lastMsg.sender === 'admin') {
|
|
try { notifSound.play().catch(e => console.log('Audio play failed')); } catch(e) {}
|
|
}
|
|
}
|
|
|
|
lastMsgCount = data.data.length;
|
|
chatBody.scrollTop = chatBody.scrollHeight;
|
|
}
|
|
} catch (e) {
|
|
console.error('Failed to load messages');
|
|
}
|
|
}
|
|
|
|
chatForm.addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
const msg = msgInput.value.trim();
|
|
if (!msg) return;
|
|
|
|
const formData = new FormData();
|
|
formData.append('message', msg);
|
|
|
|
try {
|
|
const res = await fetch('ajax_handler.php?action=send_message', {
|
|
method: 'POST',
|
|
body: formData
|
|
});
|
|
const data = await res.json();
|
|
if (data.code === 0) {
|
|
msgInput.value = '';
|
|
loadMessages();
|
|
}
|
|
} catch (e) {
|
|
alert('发送失败,请检查网络');
|
|
}
|
|
});
|
|
|
|
function escapeHtml(text) {
|
|
const div = document.createElement('div');
|
|
div.textContent = text;
|
|
return div.innerHTML;
|
|
}
|
|
|
|
setInterval(loadMessages, 3000);
|
|
loadMessages();
|
|
</script>
|
|
<style>
|
|
@keyframes pulse {
|
|
0% { transform: scale(0.95); opacity: 0.5; }
|
|
70% { transform: scale(1); opacity: 1; }
|
|
100% { transform: scale(0.95); opacity: 0.5; }
|
|
}
|
|
</style>
|
|
</body>
|
|
</html>
|