Files
jwxt/app/templates/admin_dashboard-copy.html
T

2475 lines
137 KiB
HTML
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.
{% extends "base_tailwind.html" %}
{% block title %}管理后台 - {{ brand_name }}{% endblock %}
{% block content %}
<div class="space-y-6">
<!-- 页面标题 -->
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4 list-item-enter" style="animation-delay: 0ms;">
<div>
<h1 class="text-2xl md:text-3xl font-bold text-neutral-900 dark:text-white">管理后台</h1>
<p class="text-neutral-500 dark:text-neutral-400 mt-1">用户管理、系统监控和注册码管理</p>
</div>
<div class="flex gap-3 flex-wrap">
<button onclick="openCreateUserModal()" class="btn-primary px-5 py-2.5 rounded-full text-sm font-bold">
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
</svg>
添加用户
</button>
<button onclick="openCreateTicketModal()" class="btn-primary px-5 py-2.5 rounded-full text-sm font-bold">
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 5v2m0 4v2m0 4v2M5 5a2 2 0 00-2 2v3a2 2 0 110 4v3a2 2 0 002 2h14a2 2 0 002-2v-3a2 2 0 110-4V7a2 2 0 00-2-2H5z"></path>
</svg>
生成注册码
</button>
</div>
</div>
<!-- 统计卡片 -->
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 50ms;">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-neutral-500 dark:text-neutral-400">总用户数</p>
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="statTotalUsers">-</p>
</div>
<div class="w-10 h-10 rounded-xl bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center">
<svg class="w-5 h-5 text-blue-600 dark:text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"></path>
</svg>
</div>
</div>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 100ms;">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-neutral-500 dark:text-neutral-400">总任务数</p>
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="statTotalTasks">-</p>
</div>
<div class="w-10 h-10 rounded-xl bg-amber-100 dark:bg-amber-900/30 flex items-center justify-center">
<svg class="w-5 h-5 text-amber-600 dark:text-amber-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"></path>
</svg>
</div>
</div>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 150ms;">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-neutral-500 dark:text-neutral-400">运行中</p>
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="statRunningTasks">-</p>
</div>
<div class="w-10 h-10 rounded-xl bg-green-100 dark:bg-green-900/30 flex items-center justify-center">
<svg class="w-5 h-5 text-green-600 dark:text-green-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"></path>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</div>
</div>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 200ms;">
<div class="flex items-center justify-between">
<div>
<p class="text-sm text-neutral-500 dark:text-neutral-400">成功任务</p>
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="statSuccessTasks">-</p>
</div>
<div class="w-10 h-10 rounded-xl bg-purple-100 dark:bg-purple-900/30 flex items-center justify-center">
<svg class="w-5 h-5 text-purple-600 dark:text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</div>
</div>
</div>
</div>
<!-- Session 状态和管理 -->
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay: 250ms;">
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
<div>
<h3 class="text-lg font-bold text-neutral-900 dark:text-white flex items-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"></path>
</svg>
Session 状态
</h3>
<div class="flex gap-4 mt-2 text-sm">
<span class="text-green-600 dark:text-green-400">
<span class="w-2 h-2 bg-green-500 rounded-full inline-block mr-1"></span>
有效: <strong id="sessionValid">-</strong>
</span>
<span class="text-red-600 dark:text-red-400">
<span class="w-2 h-2 bg-red-500 rounded-full inline-block mr-1"></span>
过期: <strong id="sessionInvalid">-</strong>
</span>
<span class="text-neutral-500 dark:text-neutral-400">
<span class="w-2 h-2 bg-neutral-400 rounded-full inline-block mr-1"></span>
未知: <strong id="sessionUnknown">-</strong>
</span>
</div>
</div>
<div class="flex gap-3">
<button onclick="batchCheckSession()" class="px-4 py-2 bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 rounded-full text-sm font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
</svg>
批量检查
</button>
<button onclick="showBatchRefreshModal()" class="px-4 py-2 bg-neutral-900 dark:bg-white text-white dark:text-black rounded-full text-sm font-medium hover:shadow-lg transition">
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
</svg>
批量刷新
</button>
</div>
</div>
</div>
<!-- 标签页切换 -->
<div class="border-b border-neutral-200 dark:border-neutral-800 list-item-enter" style="animation-delay: 300ms;">
<nav class="flex gap-6">
<button onclick="switchTab('users')" id="tab-users" class="pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors">
用户管理
</button>
<button onclick="switchTab('tickets')" id="tab-tickets" class="pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors">
注册码管理
</button>
<button onclick="switchTab('affiliates')" id="tab-affiliates" class="pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors">
推广码管理
</button>
<button onclick="switchTab('payments')" id="tab-payments" class="pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors">
支付管理
</button>
<button onclick="switchTab('ip')" id="tab-ip" class="pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors">
IP管理
</button>
</nav>
</div>
<!-- 用户列表 -->
<div id="panel-users" class="space-y-4">
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay: 350ms;">
<div class="flex items-center justify-between mb-4">
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">用户列表</h3>
<button onclick="loadUsers()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
<svg class="w-5 h-5 text-neutral-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
</svg>
</button>
</div>
<div id="usersLoading" class="text-center py-8">
<div class="inline-block w-8 h-8 border-2 border-neutral-300 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white rounded-full animate-spin"></div>
<p class="text-neutral-500 mt-2 text-sm">加载中...</p>
</div>
<div id="usersEmpty" class="hidden text-center py-8">
<svg class="w-12 h-12 text-neutral-300 dark:text-neutral-700 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"></path>
</svg>
<p class="text-neutral-500">暂无用户</p>
</div>
<div id="usersTable" class="hidden overflow-x-auto">
<table class="data-table">
<thead>
<tr>
<th>ID</th>
<th>用户名</th>
<th>学号</th>
<th>Session</th>
<th>角色</th>
<th>状态</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody id="usersTableBody">
</tbody>
</table>
</div>
<!-- 分页 -->
<div id="usersPagination" class="hidden mt-4 flex justify-center gap-2">
</div>
</div>
</div>
<!-- 注册码列表 -->
<div id="panel-tickets" class="hidden space-y-4">
<div class="glass rounded-2xl p-6 layer-2 list-item-enter">
<div class="flex items-center justify-between mb-4">
<div>
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">注册码列表</h3>
<p class="text-sm text-neutral-500 mt-1">
总计: <span id="ticketTotal">-</span> |
已使用: <span id="ticketUsed">-</span> |
可用: <span id="ticketAvailable">-</span>
</p>
</div>
<button onclick="loadTickets()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
<svg class="w-5 h-5 text-neutral-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
</svg>
</button>
</div>
<div id="ticketsLoading" class="text-center py-8">
<div class="inline-block w-8 h-8 border-2 border-neutral-300 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white rounded-full animate-spin"></div>
<p class="text-neutral-500 mt-2 text-sm">加载中...</p>
</div>
<div id="ticketsEmpty" class="hidden text-center py-8">
<svg class="w-12 h-12 text-neutral-300 dark:text-neutral-700 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 5v2m0 4v2m0 4v2M5 5a2 2 0 00-2 2v3a2 2 0 110 4v3a2 2 0 002 2h14a2 2 0 002-2v-3a2 2 0 110-4V7a2 2 0 00-2-2H5z"></path>
</svg>
<p class="text-neutral-500">暂无注册码</p>
</div>
<div id="ticketsTable" class="hidden overflow-x-auto">
<table class="data-table">
<thead>
<tr>
<th>注册码</th>
<th>使用次数</th>
<th>已用/上限</th>
<th>状态</th>
<th>过期时间</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody id="ticketsTableBody">
</tbody>
</table>
</div>
</div>
</div>
<!-- 推广码列表 -->
<div id="panel-affiliates" class="hidden space-y-4">
<div class="glass rounded-2xl p-6 layer-2 list-item-enter">
<div class="flex items-center justify-between mb-4">
<div>
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">推广码列表</h3>
<p class="text-sm text-neutral-500 mt-1">
管理推广人、佣金比例和优惠金额
</p>
</div>
<div class="flex gap-2">
<button onclick="openCreateAffiliateModal()" class="px-4 py-2 bg-neutral-900 dark:bg-white text-white dark:text-black rounded-full text-sm font-medium hover:shadow-lg transition">
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
</svg>
添加推广人
</button>
<button onclick="loadAffiliates()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
<svg class="w-5 h-5 text-neutral-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
</svg>
</button>
</div>
</div>
<div id="affiliatesLoading" class="text-center py-8">
<div class="inline-block w-8 h-8 border-2 border-neutral-300 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white rounded-full animate-spin"></div>
<p class="text-neutral-500 mt-2 text-sm">加载中...</p>
</div>
<div id="affiliatesEmpty" class="hidden text-center py-8">
<svg class="w-12 h-12 text-neutral-300 dark:text-neutral-700 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path>
</svg>
<p class="text-neutral-500">暂无推广人</p>
</div>
<div id="affiliatesTable" class="hidden overflow-x-auto">
<table class="data-table">
<thead>
<tr>
<th>推广码</th>
<th>推广人</th>
<th>佣金比例</th>
<th>优惠金额</th>
<th>创建时间</th>
<th>操作</th>
</tr>
</thead>
<tbody id="affiliatesTableBody">
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- 创建用户模态框 -->
<div id="createUserModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeCreateUserModal()"></div>
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md p-4">
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
<div class="flex justify-between items-center mb-6">
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">添加用户</h3>
<button onclick="closeCreateUserModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
<form id="createUserForm" onsubmit="submitCreateUser(event)">
<div class="space-y-4">
<div>
<label class="input-label">用户名(学号)</label>
<input type="text" id="newUsername" class="input-field" placeholder="请输入用户名" required>
</div>
<div>
<label class="input-label">密码</label>
<input type="password" id="newPassword" class="input-field" placeholder="请输入密码" required>
</div>
<div class="flex items-center gap-2">
<input type="checkbox" id="newIsAdmin" class="w-4 h-4 rounded border-neutral-300">
<label for="newIsAdmin" class="text-sm text-neutral-700 dark:text-neutral-300">设为管理员</label>
</div>
</div>
<div class="flex gap-3 mt-6">
<button type="button" onclick="closeCreateUserModal()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
取消
</button>
<button type="submit" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition">
创建
</button>
</div>
</form>
</div>
</div>
</div>
<!-- 创建注册码模态框 -->
<div id="createTicketModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeCreateTicketModal()"></div>
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md p-4">
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
<div class="flex justify-between items-center mb-6">
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">生成注册码</h3>
<button onclick="closeCreateTicketModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
<form id="createTicketForm" onsubmit="submitCreateTicket(event)">
<div class="space-y-4">
<div>
<label class="input-label">生成数量</label>
<input type="number" id="ticketCount" class="input-field" value="1" min="1" max="100" required>
</div>
<div>
<label class="input-label">使用次数限制</label>
<input type="number" id="ticketMaxUses" class="input-field" value="1" min="1" max="100" required>
</div>
<div>
<label class="input-label">有效期(天)</label>
<input type="number" id="ticketExpiryDays" class="input-field" value="365" min="1" max="3650" required>
</div>
</div>
<div class="flex gap-3 mt-6">
<button type="button" onclick="closeCreateTicketModal()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
取消
</button>
<button type="submit" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition">
生成
</button>
</div>
</form>
</div>
</div>
</div>
<!-- 批量刷新 Session 模态框 -->
<div id="batchRefreshModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeBatchRefreshModal()"></div>
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-2xl p-4">
<div class="glass rounded-2xl p-6 layer-4 modal-animate max-h-[80vh] overflow-y-auto">
<div class="flex justify-between items-center mb-6">
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">批量刷新 Session</h3>
<button onclick="closeBatchRefreshModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
<div class="bg-blue-50 dark:bg-blue-900/20 border border-blue-100 dark:border-blue-800 rounded-xl p-4 mb-4">
<p class="text-sm text-blue-800 dark:text-blue-200">
系统会自动从 accounts.json 读取账号密码进行刷新。强制刷新会忽略当前有效的 session,重新登录所有账号。
</p>
</div>
<div class="flex items-center gap-2 mb-4">
<input type="checkbox" id="batchForceRefresh" class="w-4 h-4 rounded border-neutral-300">
<label for="batchForceRefresh" class="text-sm text-neutral-700 dark:text-neutral-300">
<strong>强制刷新</strong>(即使 session 有效也重新登录)
</label>
</div>
<div id="batchRefreshResult" class="hidden mb-4">
<div class="border-t border-neutral-200 dark:border-neutral-700 pt-4">
<h4 class="font-bold mb-2">刷新结果</h4>
<div class="flex gap-4 mb-3 text-sm">
<span class="text-green-600">未过期: <strong id="resultValid">0</strong></span>
<span class="text-blue-600">刷新成功: <strong id="resultRefreshed">0</strong></span>
<span class="text-red-600">登录失败: <strong id="resultFailed">0</strong></span>
</div>
<div class="overflow-x-auto max-h-60">
<table class="data-table text-sm">
<thead>
<tr>
<th>用户</th>
<th>状态</th>
<th>消息</th>
</tr>
</thead>
<tbody id="batchRefreshDetails"></tbody>
</table>
</div>
</div>
</div>
<div class="flex gap-3">
<button type="button" onclick="closeBatchRefreshModal()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
关闭
</button>
<button type="button" onclick="batchCheckOnly()" class="flex-1 py-3 rounded-xl bg-neutral-200 dark:bg-neutral-700 text-neutral-800 dark:text-neutral-200 font-medium hover:bg-neutral-300 dark:hover:bg-neutral-600 transition">
仅检查
</button>
<button type="button" onclick="doBatchRefresh()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition">
开始刷新
</button>
</div>
</div>
</div>
</div>
<!-- 单用户刷新 Session 模态框 -->
<div id="singleRefreshModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeSingleRefreshModal()"></div>
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md p-4">
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
<div class="flex justify-between items-center mb-6">
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">刷新用户 Session</h3>
<button onclick="closeSingleRefreshModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
<div class="space-y-4">
<div>
<label class="input-label">用户</label>
<input type="text" id="singleRefreshUsername" class="input-field bg-neutral-100 dark:bg-neutral-800" readonly>
<input type="hidden" id="singleRefreshUserId">
</div>
<div>
<label class="input-label">教务系统密码</label>
<input type="password" id="singleRefreshPassword" class="input-field" placeholder="请输入密码">
</div>
<div class="flex items-center gap-2">
<input type="checkbox" id="singleForceRefresh" class="w-4 h-4 rounded border-neutral-300">
<label for="singleForceRefresh" class="text-sm text-neutral-700 dark:text-neutral-300">强制刷新(即使 session 有效)</label>
</div>
<div id="singleRefreshResult"></div>
</div>
<div class="flex gap-3 mt-6">
<button type="button" onclick="closeSingleRefreshModal()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
取消
</button>
<button type="button" onclick="doSingleRefresh()" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition">
刷新
</button>
</div>
</div>
</div>
</div>
<!-- 创建推广人模态框 -->
<div id="createAffiliateModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeCreateAffiliateModal()"></div>
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md p-4">
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
<div class="flex justify-between items-center mb-6">
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">添加推广人</h3>
<button onclick="closeCreateAffiliateModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
<form id="createAffiliateForm" onsubmit="submitCreateAffiliate(event)">
<div class="space-y-4">
<div>
<label class="input-label">推广码</label>
<input type="text" id="affiliateCode" class="input-field" placeholder="如: WH, ZZY" required maxlength="10">
<p class="text-xs text-neutral-500 mt-1">推广码将自动转为大写</p>
</div>
<div>
<label class="input-label">推广人姓名</label>
<input type="text" id="affiliateName" class="input-field" placeholder="请输入推广人姓名" required>
</div>
<div>
<label class="input-label">佣金比例 (%)</label>
<input type="number" id="affiliateCommission" class="input-field" value="30" min="0" max="100" required>
<p class="text-xs text-neutral-500 mt-1">用户支付金额的百分比作为佣金</p>
</div>
<div>
<label class="input-label">优惠金额 (元/人)</label>
<input type="number" id="affiliateDiscount" class="input-field" value="2" min="0" max="20" required>
<p class="text-xs text-neutral-500 mt-1">用户使用此推广码每人减免的金额</p>
</div>
</div>
<div class="flex gap-3 mt-6">
<button type="button" onclick="closeCreateAffiliateModal()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
取消
</button>
<button type="submit" class="flex-1 py-3 rounded-xl bg-neutral-900 dark:bg-white text-white dark:text-black font-bold hover:shadow-lg transition">
创建
</button>
</div>
</form>
</div>
</div>
</div>
<!-- 推广人详情模态框 -->
<div id="affiliateDetailModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeAffiliateDetailModal()"></div>
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-2xl p-4 max-h-[90vh] overflow-y-auto">
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
<div class="flex justify-between items-center mb-6">
<div>
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">推广人详情</h3>
<p class="text-sm text-neutral-500 mt-1" id="detailAffiliateCode"></p>
</div>
<button onclick="closeAffiliateDetailModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
<!-- 统计卡片 -->
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
<div class="bg-blue-50 dark:bg-blue-900/20 rounded-xl p-4">
<p class="text-xs text-blue-600 dark:text-blue-400">总订单数</p>
<p class="text-2xl font-bold text-blue-900 dark:text-blue-200" id="statTotalOrders">-</p>
</div>
<div class="bg-green-50 dark:bg-green-900/20 rounded-xl p-4">
<p class="text-xs text-green-600 dark:text-green-400">已支付订单</p>
<p class="text-2xl font-bold text-green-900 dark:text-green-200" id="statPaidOrders">-</p>
</div>
<div class="bg-purple-50 dark:bg-purple-900/20 rounded-xl p-4">
<p class="text-xs text-purple-600 dark:text-purple-400">总销售额</p>
<p class="text-2xl font-bold text-purple-900 dark:text-purple-200" id="statTotalSales">-</p>
</div>
<div class="bg-orange-50 dark:bg-orange-900/20 rounded-xl p-4">
<p class="text-xs text-orange-600 dark:text-orange-400">总佣金</p>
<p class="text-2xl font-bold text-orange-900 dark:text-orange-200" id="statTotalCommission">-</p>
</div>
</div>
<!-- 结算信息卡片 -->
<div class="grid grid-cols-2 md:grid-cols-3 gap-4 mb-6">
<div class="bg-red-50 dark:bg-red-900/20 rounded-xl p-4">
<p class="text-xs text-red-600 dark:text-red-400">待结佣金</p>
<p class="text-2xl font-bold text-red-900 dark:text-red-200" id="statPendingCommission">-</p>
</div>
<div class="bg-gray-50 dark:bg-gray-900/20 rounded-xl p-4">
<p class="text-xs text-gray-600 dark:text-gray-400">已结佣金</p>
<p class="text-2xl font-bold text-gray-900 dark:text-gray-200" id="statTotalSettled">-</p>
</div>
<div class="flex items-center justify-center">
<button onclick="openSettleAffiliateModal()" id="btnSettleAffiliate" class="w-full h-full px-4 py-3 bg-red-600 hover:bg-red-700 text-white rounded-xl text-sm font-bold transition shadow-lg hover:shadow-xl">
<svg class="w-5 h-5 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
结清佣金
</button>
</div>
</div>
<!-- 推广信息 -->
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-4 mb-6">
<div class="grid grid-cols-2 gap-4">
<div>
<p class="text-xs text-neutral-500">推广人姓名</p>
<p class="font-medium text-neutral-900 dark:text-white" id="detailAffiliateName">-</p>
</div>
<div>
<p class="text-xs text-neutral-500">佣金比例</p>
<p class="font-medium text-neutral-900 dark:text-white" id="detailCommissionRate">-</p>
</div>
<div>
<p class="text-xs text-neutral-500">优惠金额</p>
<p class="font-medium text-neutral-900 dark:text-white" id="detailDiscountAmount">-</p>
</div>
<div>
<p class="text-xs text-neutral-500">创建时间</p>
<p class="font-medium text-neutral-900 dark:text-white" id="detailCreatedAt">-</p>
</div>
</div>
</div>
<!-- 推广链接 -->
<div class="mb-6">
<label class="text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-2 block">推广链接</label>
<div class="flex gap-2">
<input type="text" id="affiliateLink" class="input-field flex-1 text-sm" readonly>
<button onclick="copyAffiliateLink()" class="px-4 py-2 bg-neutral-900 dark:bg-white text-white dark:text-black rounded-xl text-sm font-medium hover:shadow-lg transition">
复制
</button>
</div>
</div>
<!-- 最近订单 -->
<div>
<h4 class="font-bold text-neutral-900 dark:text-white mb-3">最近订单</h4>
<div id="recentOrdersLoading" class="text-center py-4">
<div class="inline-block w-6 h-6 border-2 border-neutral-300 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white rounded-full animate-spin"></div>
</div>
<div id="recentOrdersEmpty" class="hidden text-center py-4 text-neutral-500">
暂无订单
</div>
<div id="recentOrdersList" class="hidden space-y-2 max-h-60 overflow-y-auto">
<!-- 订单列表将在这里渲染 -->
</div>
</div>
</div>
</div>
</div>
<!-- 结清佣金模态框 -->
<div id="settleAffiliateModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeSettleAffiliateModal()"></div>
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md p-4">
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
<div class="flex justify-between items-center mb-6">
<div>
<h3 class="text-xl font-bold text-neutral-900 dark:text-white">结清佣金</h3>
<p class="text-sm text-neutral-500 mt-1" id="settleAffiliateCode"></p>
</div>
<button onclick="closeSettleAffiliateModal()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
<form id="settleAffiliateForm" onsubmit="submitSettleAffiliate(event)">
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">待结佣金</label>
<p class="text-2xl font-bold text-red-600" id="settlePendingAmount">-</p>
</div>
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">结算金额 <span class="text-red-500">*</span></label>
<div class="relative">
<span class="absolute left-3 top-1/2 -translate-y-1/2 text-neutral-500">¥</span>
<input type="number" id="settleAmount" step="0.01" min="0.01" required class="input-field w-full pl-8" placeholder="输入结算金额">
</div>
</div>
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">备注</label>
<textarea id="settleNote" rows="2" class="input-field w-full" placeholder="可选:添加结算备注"></textarea>
</div>
</div>
<div class="flex gap-3 mt-6">
<button type="button" onclick="closeSettleAffiliateModal()" class="flex-1 px-4 py-2.5 border border-neutral-300 dark:border-neutral-600 rounded-xl text-sm font-medium hover:bg-neutral-50 dark:hover:bg-neutral-800 transition">
取消
</button>
<button type="submit" class="flex-1 px-4 py-2.5 bg-red-600 hover:bg-red-700 text-white rounded-xl text-sm font-bold transition">
确认结清
</button>
</div>
</form>
</div>
</div>
</div>
<!-- IP管理 -->
<div id="panel-ip" class="hidden space-y-4 mt-4">
<!-- 统计卡片 -->
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 350ms;">
<p class="text-sm text-neutral-500 dark:text-neutral-400">今日访问</p>
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="ipStatTotal">-</p>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 400ms;">
<p class="text-sm text-neutral-500 dark:text-neutral-400">独立IP</p>
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="ipStatUnique">-</p>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 450ms;">
<p class="text-sm text-neutral-500 dark:text-neutral-400">被拦截</p>
<p class="text-2xl font-bold text-red-500 mt-1" id="ipStatBlocked">-</p>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 500ms;">
<p class="text-sm text-neutral-500 dark:text-neutral-400">封禁规则</p>
<p class="text-2xl font-bold text-neutral-900 dark:text-white mt-1" id="ipStatBans">-</p>
</div>
</div>
<!-- 快捷操作 -->
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay: 550ms;">
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
<div>
<h3 class="text-lg font-bold text-neutral-900 dark:text-white flex items-center gap-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"></path>
</svg>
IP访问控制
</h3>
<p class="text-sm text-neutral-500 dark:text-neutral-400 mt-1">封禁管理、访问日志、登录频率限制、邮件解封</p>
</div>
<div class="flex gap-3 flex-wrap">
<button onclick="openIpBanModal()" class="px-5 py-2.5 rounded-full text-sm font-bold bg-red-500 text-white hover:bg-red-600 transition-colors">
<svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"/>
</svg>
添加封禁
</button>
<button onclick="openIpConfigModal()" class="px-4 py-2 bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 rounded-full text-sm font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
频率设置
</button>
<a href="{{ url_for('main.admin_ip') }}" class="px-4 py-2 bg-neutral-900 dark:bg-white text-white dark:text-black rounded-full text-sm font-medium hover:shadow-lg transition flex items-center gap-1.5">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
</svg>
完整页面 →
</a>
</div>
</div>
</div>
<!-- 访问统计图表 -->
<div class="grid md:grid-cols-2 gap-4">
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 600ms;">
<div class="flex items-center justify-between mb-3">
<h3 class="text-sm font-semibold text-neutral-700 dark:text-neutral-300">访问时段分布</h3>
<select id="ipStatsHours" onchange="loadIpStats()" class="text-xs rounded-lg border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-900 px-2 py-1 text-neutral-700 dark:text-neutral-300">
<option value="1">1小时</option>
<option value="6">6小时</option>
<option value="24" selected>24小时</option>
<option value="72">3天</option>
</select>
</div>
<div id="chartIpHour" class="w-full h-48"></div>
</div>
<div class="glass rounded-2xl p-5 layer-2 list-item-enter" style="animation-delay: 650ms;">
<div class="flex items-center justify-between mb-3">
<h3 class="text-sm font-semibold text-neutral-700 dark:text-neutral-300">来源省份 Top10</h3>
</div>
<div id="chartIpRegion" class="w-full h-48"></div>
</div>
</div>
<!-- 封禁列表预览 -->
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay: 700ms;">
<div class="flex items-center justify-between mb-4">
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">封禁列表</h3>
<a href="{{ url_for('main.admin_ip') }}" class="text-sm text-blue-500 hover:text-blue-700">查看全部 →</a>
</div>
<div id="ipBansPreview" class="overflow-x-auto">
<div class="text-center text-neutral-400 py-4">加载中...</div>
</div>
</div>
</div>
<div id="panel-payments" class="hidden space-y-4 mt-4">
<!-- 统计卡片 -->
<div class="grid grid-cols-2 md:grid-cols-5 gap-4">
<div class="glass rounded-2xl p-4 layer-2 list-item-enter" style="animation-delay: 350ms;">
<p class="text-xs text-neutral-500">总订单数</p>
<p class="text-2xl font-bold text-neutral-900 dark:text-white" id="paymentStatTotal">-</p>
</div>
<div class="glass rounded-2xl p-4 layer-2 list-item-enter" style="animation-delay: 400ms;">
<p class="text-xs text-neutral-500">待支付</p>
<p class="text-2xl font-bold text-yellow-600" id="paymentStatPending">-</p>
</div>
<div class="glass rounded-2xl p-4 layer-2 list-item-enter" style="animation-delay: 450ms;">
<p class="text-xs text-neutral-500">已支付</p>
<p class="text-2xl font-bold text-green-600" id="paymentStatPaid">-</p>
</div>
<div class="glass rounded-2xl p-4 layer-2 list-item-enter" style="animation-delay: 500ms;">
<p class="text-xs text-neutral-500">已处理</p>
<p class="text-2xl font-bold text-blue-600" id="paymentStatProcessed">-</p>
</div>
<div class="glass rounded-2xl p-4 layer-2 list-item-enter" style="animation-delay: 550ms;">
<p class="text-xs text-neutral-500">总收入</p>
<p class="text-2xl font-bold text-purple-600" id="paymentStatRevenue">-</p>
</div>
</div>
<!-- 筛选和搜索 -->
<div class="glass rounded-2xl p-6 layer-2 list-item-enter" style="animation-delay: 600ms;">
<div class="flex flex-wrap gap-4 items-center">
<div class="flex items-center space-x-2">
<label class="text-sm font-medium text-neutral-700 dark:text-neutral-300">状态:</label>
<select id="paymentFilterStatus" class="px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-sm">
<option value="all">全部</option>
<option value="pending">待支付</option>
<option value="paid">已支付</option>
<option value="processed">已处理</option>
<option value="failed">支付失败</option>
<option value="cancelled">已取消</option>
<option value="expired">已过期</option>
<option value="refunded">已退款</option>
</select>
</div>
<div class="flex items-center space-x-2">
<label class="text-sm font-medium text-neutral-700 dark:text-neutral-300">搜索:</label>
<input type="text" id="paymentSearchInput" placeholder="订单号/邮箱/推广码"
class="px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-lg bg-white dark:bg-neutral-800 text-sm w-64">
</div>
<button onclick="loadPaymentOrders()" class="px-4 py-2 bg-neutral-900 dark:bg-white text-white dark:text-black rounded-full hover:shadow-lg transition text-sm font-medium">
查询
</button>
<button onclick="refreshPaymentData()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
<svg class="w-5 h-5 text-neutral-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
</svg>
</button>
</div>
</div>
<!-- 订单列表 -->
<div class="glass rounded-2xl overflow-hidden layer-2 list-item-enter" style="animation-delay: 650ms;">
<div class="overflow-x-auto">
<table class="data-table">
<thead>
<tr>
<th>订单号</th>
<th>邮箱</th>
<th>数量</th>
<th>金额</th>
<th>优惠</th>
<th>实付</th>
<th>推广码</th>
<th>状态</th>
<th>创建时间</th>
<th>支付时间</th>
<th>操作</th>
</tr>
</thead>
<tbody id="paymentOrdersTableBody">
<!-- 订单数据将在这里渲染 -->
</tbody>
</table>
</div>
<div id="paymentLoadingState" class="text-center py-8">
<div class="inline-block w-8 h-8 border-2 border-neutral-300 dark:border-neutral-700 border-t-neutral-900 dark:border-t-white rounded-full animate-spin"></div>
<p class="text-neutral-500 mt-2">加载中...</p>
</div>
<div id="paymentEmptyState" class="hidden text-center py-8">
<svg class="w-12 h-12 text-neutral-300 dark:text-neutral-700 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4"></path>
</svg>
<p class="text-neutral-500">暂无订单</p>
</div>
</div>
</div>
</div>
<!-- 确认支付模态框 -->
<div id="confirmPaymentModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeConfirmPayment()"></div>
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md p-4">
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
<h3 class="text-lg font-bold text-neutral-900 dark:text-white mb-4">手动确认支付</h3>
<p class="text-neutral-600 dark:text-neutral-400 mb-4">
确认要将订单 <span id="confirmOrderId" class="font-mono font-bold"></span> 标记为已支付吗?
</p>
<div class="bg-yellow-50 dark:bg-yellow-900/20 rounded-xl p-3 mb-4">
<p class="text-sm text-yellow-800 dark:text-yellow-300">
<i class="fas fa-exclamation-triangle mr-1"></i>
此操作将生成注册码并发送邮件给用户
</p>
</div>
<div class="flex gap-3">
<button onclick="closeConfirmPayment()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
取消
</button>
<button onclick="submitConfirmPayment()" class="flex-1 py-3 rounded-xl bg-green-600 text-white font-bold hover:bg-green-700 transition">
确认支付
</button>
</div>
</div>
</div>
</div>
<!-- 拒绝订单模态框 -->
<div id="rejectOrderModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closeRejectOrder()"></div>
<div class="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-full max-w-md p-4">
<div class="glass rounded-2xl p-6 layer-4 modal-animate">
<h3 class="text-lg font-bold text-neutral-900 dark:text-white mb-4">拒绝订单</h3>
<p class="text-neutral-600 dark:text-neutral-400 mb-4">
确定要拒绝订单 <span id="rejectOrderId" class="font-mono font-bold"></span> 吗?
</p>
<div class="mb-4">
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-2">拒绝原因</label>
<textarea id="rejectReason" rows="3" class="w-full px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-xl bg-white dark:bg-neutral-800 text-sm" placeholder="请输入拒绝原因(可选)"></textarea>
</div>
<div class="flex gap-3">
<button onclick="closeRejectOrder()" class="flex-1 py-3 rounded-xl bg-neutral-100 dark:bg-neutral-800 text-neutral-700 dark:text-neutral-300 font-medium hover:bg-neutral-200 dark:hover:bg-neutral-700 transition">
取消
</button>
<button onclick="submitRejectOrder()" class="flex-1 py-3 rounded-xl bg-red-600 text-white font-bold hover:bg-red-700 transition">
确认拒绝
</button>
</div>
</div>
</div>
</div>
<!-- 订单详情模态框 -->
<div id="paymentOrderDetailModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="closePaymentOrderDetail()"></div>
<div class="absolute right-0 top-0 h-full w-full max-w-lg bg-white dark:bg-neutral-900 shadow-xl overflow-y-auto">
<div class="p-6">
<div class="flex justify-between items-center mb-6">
<h3 class="text-lg font-bold text-neutral-900 dark:text-white">订单详情</h3>
<button onclick="closePaymentOrderDetail()" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-full transition">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
<div id="paymentOrderDetailContent">
<!-- 详情内容 -->
</div>
</div>
</div>
</div>
<!-- IP管理:添加封禁 Modal -->
<div id="ipBanModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="document.getElementById('ipBanModal').classList.add('hidden')"></div>
<div class="absolute inset-0 flex items-center justify-center p-4 pointer-events-none">
<div class="bg-white dark:bg-neutral-900 rounded-2xl shadow-xl w-full max-w-md pointer-events-auto">
<div class="p-6">
<h3 class="text-lg font-bold text-neutral-900 dark:text-white mb-5">添加封禁规则</h3>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">封禁类型</label>
<select id="ipBanType" class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
<option value="ip">单个IP</option>
<option value="cidr">IP段 (CIDR,如 1.2.3.0/24)</option>
<option value="country">国家/地区代码 (如 US)</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">封禁值</label>
<input id="ipBanValue" type="text" placeholder="IP / CIDR / 国家代码"
class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
</div>
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">封禁时长</label>
<select id="ipBanDuration" class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
<option value="">永久封禁</option>
<option value="1h">1小时</option>
<option value="6h">6小时</option>
<option value="1d">1天</option>
<option value="3d">3天</option>
<option value="1w">1周</option>
<option value="1m">1个月</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">封禁原因</label>
<input id="ipBanReason" type="text" placeholder="可选"
class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
</div>
</div>
<div class="flex gap-3 mt-6">
<button onclick="submitIpBan()" class="flex-1 bg-red-500 text-white px-4 py-2.5 rounded-xl text-sm font-bold hover:bg-red-600 transition-colors">确认封禁</button>
<button onclick="document.getElementById('ipBanModal').classList.add('hidden')" class="flex-1 px-4 py-2.5 rounded-xl text-sm font-bold border border-neutral-200 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors">取消</button>
</div>
</div>
</div>
</div>
</div>
<!-- IP管理:频率限制配置 Modal -->
<div id="ipConfigModal" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" onclick="document.getElementById('ipConfigModal').classList.add('hidden')"></div>
<div class="absolute inset-0 flex items-center justify-center p-4 pointer-events-none">
<div class="bg-white dark:bg-neutral-900 rounded-2xl shadow-xl w-full max-w-md pointer-events-auto">
<div class="p-6">
<h3 class="text-lg font-bold text-neutral-900 dark:text-white mb-5">登录频率限制设置</h3>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">统计时间窗口(分钟)</label>
<input id="ipCfgWindow" type="number" min="1" max="60"
class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
<p class="text-xs text-neutral-400 mt-1">在此时间窗口内统计失败次数</p>
</div>
<div>
<label class="block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-1">最大失败次数</label>
<input id="ipCfgMax" type="number" min="1" max="100"
class="w-full rounded-xl border border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 text-sm px-3 py-2.5 text-neutral-700 dark:text-neutral-300">
<p class="text-xs text-neutral-400 mt-1">超过此次数自动封禁1小时</p>
</div>
<div class="flex items-center gap-3">
<input id="ipCfgChinaOnly" type="checkbox" class="w-4 h-4 rounded">
<label class="text-sm font-medium text-neutral-700 dark:text-neutral-300">启用中国IP限制</label>
</div>
</div>
<div class="flex gap-3 mt-6">
<button onclick="submitIpConfig()" class="flex-1 btn-primary py-2.5 rounded-xl text-sm font-bold">保存配置</button>
<button onclick="document.getElementById('ipConfigModal').classList.add('hidden')" class="flex-1 px-4 py-2.5 rounded-xl text-sm font-bold border border-neutral-200 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-800 transition-colors">取消</button>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script src="{{ url_for('static', filename='echarts.min.js') }}"></script>
<script>
let currentPage = 1;
let currentTab = 'users';
let currentPaymentOrders = [];
let currentPaymentOrderId = null;
// 初始化
document.addEventListener('DOMContentLoaded', function() {
// 将所有弹窗移到 body 直接子级,确保 fixed 定位基于视口
['createUserModal', 'createTicketModal', 'createAffiliateModal', 'affiliateDetailModal', 'settleAffiliateModal', 'batchRefreshModal', 'singleRefreshModal'].forEach(id => {
const el = document.getElementById(id);
if (el) document.body.appendChild(el);
});
loadStats();
loadUsers();
});
// 切换标签页
function switchTab(tab) {
currentTab = tab;
document.getElementById('tab-users').className = tab === 'users'
? 'pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors'
: 'pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors';
document.getElementById('tab-tickets').className = tab === 'tickets'
? 'pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors'
: 'pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors';
document.getElementById('tab-affiliates').className = tab === 'affiliates'
? 'pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors'
: 'pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors';
document.getElementById('tab-payments').className = tab === 'payments'
? 'pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors'
: 'pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors';
document.getElementById('tab-ip').className = tab === 'ip'
? 'pb-3 text-sm font-medium border-b-2 border-neutral-900 dark:border-white text-neutral-900 dark:text-white transition-colors'
: 'pb-3 text-sm font-medium border-b-2 border-transparent text-neutral-500 dark:text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200 transition-colors';
const panels = ['panel-users', 'panel-tickets', 'panel-affiliates', 'panel-payments', 'panel-ip'];
const targetPanel = 'panel-' + tab;
panels.forEach(panelId => {
const panel = document.getElementById(panelId);
if (panel) {
if (panelId === targetPanel) {
panel.classList.remove('hidden');
panel.classList.remove('tab-panel-enter');
void panel.offsetWidth;
panel.classList.add('tab-panel-enter');
} else {
panel.classList.add('hidden');
}
}
});
if (tab === 'tickets') {
loadTickets();
} else if (tab === 'affiliates') {
loadAffiliates();
} else if (tab === 'payments') {
loadPaymentOrders();
} else if (tab === 'ip') {
loadIpStats();
loadIpBansPreview();
}
}
// 加载统计数据
async function loadStats() {
try {
const data = await apiRequest('/api/admin/stats');
if (data.success) {
document.getElementById('statTotalUsers').textContent = data.stats.total_users;
document.getElementById('statTotalTasks').textContent = data.stats.total_tasks;
document.getElementById('statRunningTasks').textContent = data.stats.running_tasks;
document.getElementById('statSuccessTasks').textContent = data.stats.success_tasks;
if (data.stats.session_stats) {
document.getElementById('sessionValid').textContent = data.stats.session_stats.valid || 0;
document.getElementById('sessionInvalid').textContent = data.stats.session_stats.invalid || 0;
document.getElementById('sessionUnknown').textContent = data.stats.session_stats.unknown || 0;
}
}
} catch (error) {
console.error('加载统计失败:', error);
}
}
// 加载用户列表
async function loadUsers(page = 1) {
currentPage = page;
document.getElementById('usersLoading').classList.remove('hidden');
document.getElementById('usersEmpty').classList.add('hidden');
document.getElementById('usersTable').classList.add('hidden');
document.getElementById('usersPagination').classList.add('hidden');
try {
const data = await apiRequest(`/api/admin/users/list?page=${page}&per_page=20`);
document.getElementById('usersLoading').classList.add('hidden');
if (!data.success || !data.users || data.users.length === 0) {
document.getElementById('usersEmpty').classList.remove('hidden');
return;
}
renderUsersTable(data.users);
renderPagination(data.total, data.pages, page);
document.getElementById('usersTable').classList.remove('hidden');
document.getElementById('usersPagination').classList.remove('hidden');
} catch (error) {
document.getElementById('usersLoading').classList.add('hidden');
showToast('加载失败', 'error');
}
}
// 渲染用户表格
function renderUsersTable(users) {
const tbody = document.getElementById('usersTableBody');
tbody.innerHTML = users.map((user, index) => {
const delay = 50 * index;
return `
<tr class="list-item-enter" style="animation-delay: ${delay}ms;">
<td class="font-mono text-sm">${user.id}</td>
<td class="font-medium">${escapeHtml(user.username)}</td>
<td>${user.jwxt_username ? escapeHtml(user.jwxt_username) : '<span class="text-neutral-400">-</span>'}</td>
<td>
${user.session_status === 'valid'
? '<span class="status-badge status-success">有效</span>'
: user.session_status === 'invalid'
? '<span class="status-badge status-danger">过期</span>'
: '<span class="status-badge status-info">未知</span>'}
</td>
<td>
${user.is_admin
? '<span class="status-badge status-danger">管理员</span>'
: '<span class="status-badge" style="background: #f3f4f6; color: #6b7280;">普通用户</span>'}
</td>
<td>
${user.is_active
? '<span class="status-badge status-success">激活</span>'
: '<span class="status-badge status-warning">禁用</span>'}
</td>
<td class="text-sm text-neutral-500">${formatTime(user.created_at)}</td>
<td>
<div class="flex gap-2">
<button onclick="viewUserTasks(${user.id})" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition" title="查看任务">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"></path>
</svg>
</button>
<button onclick="refreshUserSession(${user.id}, '${user.jwxt_username || user.username}')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition" title="刷新 Session">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
</svg>
</button>
<button onclick="deleteUser(${user.id}, '${escapeHtml(user.username)}')" class="p-2 hover:bg-red-100 dark:hover:bg-red-900/30 text-red-600 dark:text-red-400 rounded-lg transition" title="删除用户">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
</svg>
</button>
</div>
</td>
</tr>
`}).join('');
}
// 渲染分页
function renderPagination(total, pages, current) {
const container = document.getElementById('usersPagination');
let html = '';
html += `<button onclick="loadUsers(${current - 1})" ${current === 1 ? 'disabled' : ''} class="px-3 py-1 rounded-lg bg-neutral-100 dark:bg-neutral-800 text-sm disabled:opacity-50">上一页</button>`;
for (let i = 1; i <= pages; i++) {
if (i === 1 || i === pages || (i >= current - 2 && i <= current + 2)) {
html += `<button onclick="loadUsers(${i})" class="px-3 py-1 rounded-lg text-sm ${i === current ? 'bg-neutral-900 dark:bg-white text-white dark:text-black' : 'bg-neutral-100 dark:bg-neutral-800'}">${i}</button>`;
} else if (i === current - 3 || i === current + 3) {
html += `<span class="px-2">...</span>`;
}
}
html += `<button onclick="loadUsers(${current + 1})" ${current === pages ? 'disabled' : ''} class="px-3 py-1 rounded-lg bg-neutral-100 dark:bg-neutral-800 text-sm disabled:opacity-50">下一页</button>`;
container.innerHTML = html;
}
// 加载注册码列表
async function loadTickets() {
document.getElementById('ticketsLoading').classList.remove('hidden');
document.getElementById('ticketsEmpty').classList.add('hidden');
document.getElementById('ticketsTable').classList.add('hidden');
try {
const data = await apiRequest('/api/admin/tickets/list');
document.getElementById('ticketsLoading').classList.add('hidden');
if (!data.success || !data.tickets || data.tickets.length === 0) {
document.getElementById('ticketsEmpty').classList.remove('hidden');
return;
}
// 更新统计
if (data.stats) {
document.getElementById('ticketTotal').textContent = data.stats.total || 0;
document.getElementById('ticketUsed').textContent = data.stats.used || 0;
document.getElementById('ticketAvailable').textContent = data.stats.available || 0;
}
renderTicketsTable(data.tickets);
document.getElementById('ticketsTable').classList.remove('hidden');
} catch (error) {
document.getElementById('ticketsLoading').classList.add('hidden');
showToast('加载失败', 'error');
}
}
// 渲染注册码表格
function renderTicketsTable(tickets) {
const tbody = document.getElementById('ticketsTableBody');
tbody.innerHTML = tickets.map((ticket, index) => {
const isExpired = new Date(ticket.expires_at) < new Date();
const isFullyUsed = ticket.uses >= ticket.max_uses;
const delay = 50 * index;
return `
<tr class="list-item-enter" style="animation-delay: ${delay}ms;">
<td class="font-mono text-sm font-medium">${ticket.code}</td>
<td>${ticket.used_by.length > 0 ? ticket.used_by.join(', ') : '<span class="text-neutral-400">-</span>'}</td>
<td>${ticket.uses} / ${ticket.max_uses}</td>
<td>
${!ticket.enabled ? '<span class="status-badge status-warning">已禁用</span>' :
isExpired ? '<span class="status-badge status-danger">已过期</span>' :
isFullyUsed ? '<span class="status-badge status-info">已用完</span>' :
'<span class="status-badge status-success">可用</span>'}
</td>
<td class="text-sm text-neutral-500">${new Date(ticket.expires_at).toLocaleDateString('zh-CN')}</td>
<td class="text-sm text-neutral-500">${new Date(ticket.created_at).toLocaleDateString('zh-CN')}</td>
<td>
<div class="flex gap-2">
${ticket.enabled ? `
<button onclick="disableTicket('${ticket.code}')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition text-amber-600" title="禁用">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"></path>
</svg>
</button>
` : `
<button onclick="enableTicket('${ticket.code}')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition text-green-600" title="启用">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</button>
`}
<button onclick="deleteTicket('${ticket.code}')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition text-red-600" title="删除">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
</svg>
</button>
</div>
</td>
</tr>
`;
}).join('');
}
// 模态框控制
function openModal(id) {
document.getElementById(id).classList.remove('hidden');
document.documentElement.style.overflow = 'hidden';
document.body.style.overflow = 'hidden';
}
function closeModal(id) {
document.getElementById(id).classList.add('hidden');
document.documentElement.style.overflow = '';
document.body.style.overflow = '';
}
function openCreateUserModal() {
document.getElementById('createUserForm').reset();
openModal('createUserModal');
}
function closeCreateUserModal() {
closeModal('createUserModal');
}
function openCreateTicketModal() {
document.getElementById('createTicketForm').reset();
openModal('createTicketModal');
}
function closeCreateTicketModal() {
closeModal('createTicketModal');
}
function openCreateAffiliateModal() {
document.getElementById('createAffiliateForm').reset();
openModal('createAffiliateModal');
}
function closeCreateAffiliateModal() {
closeModal('createAffiliateModal');
}
// 推广人详情模态框
let currentAffiliateCode = null;
let currentPendingCommission = 0;
async function openAffiliateDetailModal(code) {
currentAffiliateCode = code;
currentPendingCommission = 0;
openModal('affiliateDetailModal');
// 重置显示
document.getElementById('statTotalOrders').textContent = '-';
document.getElementById('statPaidOrders').textContent = '-';
document.getElementById('statTotalSales').textContent = '-';
document.getElementById('statTotalCommission').textContent = '-';
document.getElementById('statPendingCommission').textContent = '-';
document.getElementById('statTotalSettled').textContent = '-';
document.getElementById('recentOrdersLoading').classList.remove('hidden');
document.getElementById('recentOrdersEmpty').classList.add('hidden');
document.getElementById('recentOrdersList').classList.add('hidden');
try {
const data = await apiRequest(`/api/admin/affiliates/${code}`);
if (data.success) {
const affiliate = data.affiliate;
const stats = affiliate.stats;
// 保存待结佣金
currentPendingCommission = stats.pending_commission || 0;
// 基本信息
document.getElementById('detailAffiliateCode').textContent = `推广码: ${affiliate.code}`;
document.getElementById('detailAffiliateName').textContent = affiliate.name;
document.getElementById('detailCommissionRate').textContent = `${affiliate.commission_rate}%`;
document.getElementById('detailDiscountAmount').textContent = `¥${affiliate.discount_amount}/人`;
document.getElementById('detailCreatedAt').textContent = new Date(affiliate.created_at).toLocaleString('zh-CN');
// 推广链接
const baseUrl = window.location.origin;
document.getElementById('affiliateLink').value = `${baseUrl}/buy?invitecode=${affiliate.code}`;
// 统计数据
document.getElementById('statTotalOrders').textContent = stats.total_orders;
document.getElementById('statPaidOrders').textContent = stats.paid_orders;
document.getElementById('statTotalSales').textContent = `¥${stats.total_sales}`;
document.getElementById('statTotalCommission').textContent = `¥${stats.total_commission.toFixed(2)}`;
document.getElementById('statPendingCommission').textContent = `¥${(stats.pending_commission || 0).toFixed(2)}`;
document.getElementById('statTotalSettled').textContent = `¥${(stats.total_settled || 0).toFixed(2)}`;
// 控制结清按钮显示
const btnSettle = document.getElementById('btnSettleAffiliate');
if (currentPendingCommission <= 0) {
btnSettle.classList.add('opacity-50', 'cursor-not-allowed');
btnSettle.disabled = true;
} else {
btnSettle.classList.remove('opacity-50', 'cursor-not-allowed');
btnSettle.disabled = false;
}
// 最近订单
document.getElementById('recentOrdersLoading').classList.add('hidden');
if (affiliate.recent_orders.length === 0) {
document.getElementById('recentOrdersEmpty').classList.remove('hidden');
} else {
document.getElementById('recentOrdersList').classList.remove('hidden');
renderRecentOrders(affiliate.recent_orders);
}
} else {
showToast(data.message || '获取推广人信息失败', 'error');
}
} catch (error) {
console.error('获取推广人详情失败:', error);
showToast('网络错误', 'error');
}
}
function closeAffiliateDetailModal() {
closeModal('affiliateDetailModal');
currentAffiliateCode = null;
currentPendingCommission = 0;
}
// 结清佣金模态框
function openSettleAffiliateModal() {
if (!currentAffiliateCode || currentPendingCommission <= 0) {
showToast('没有待结佣金', 'error');
return;
}
document.getElementById('settleAffiliateCode').textContent = `推广码: ${currentAffiliateCode}`;
document.getElementById('settlePendingAmount').textContent = `¥${currentPendingCommission.toFixed(2)}`;
document.getElementById('settleAmount').value = currentPendingCommission.toFixed(2);
document.getElementById('settleNote').value = '';
document.getElementById('settleAffiliateModal').classList.remove('hidden');
}
function closeSettleAffiliateModal() {
closeModal('settleAffiliateModal');
}
async function submitSettleAffiliate(event) {
event.preventDefault();
if (!currentAffiliateCode) {
showToast('推广码错误', 'error');
return;
}
const settleAmount = parseFloat(document.getElementById('settleAmount').value);
const note = document.getElementById('settleNote').value.trim();
if (!settleAmount || settleAmount <= 0) {
showToast('结算金额必须大于0', 'error');
return;
}
try {
const data = await apiRequest(`/api/admin/affiliates/${currentAffiliateCode}/settle`, {
method: 'POST',
body: JSON.stringify({
settle_amount: settleAmount,
note: note
})
});
if (data.success) {
showToast('佣金结清成功', 'success');
closeSettleAffiliateModal();
// 刷新详情
openAffiliateDetailModal(currentAffiliateCode);
} else {
showToast(data.message || '结清失败', 'error');
}
} catch (error) {
console.error('结清佣金失败:', error);
showToast('网络错误', 'error');
}
}
function renderRecentOrders(orders) {
const container = document.getElementById('recentOrdersList');
container.innerHTML = orders.map(order => `
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-lg p-3 text-sm">
<div class="flex justify-between items-start">
<div>
<p class="font-medium text-neutral-900 dark:text-white">${order.email}</p>
<p class="text-xs text-neutral-500">订单号: ${order.order_id}</p>
</div>
<div class="text-right">
<p class="font-medium text-neutral-900 dark:text-white">¥${order.final_amount}</p>
<p class="text-xs text-neutral-500">${order.quantity} 份</p>
</div>
</div>
<div class="flex justify-between items-center mt-2 pt-2 border-t border-neutral-200 dark:border-neutral-700">
<span class="text-xs text-neutral-500">${order.paid_at ? new Date(order.paid_at).toLocaleString('zh-CN') : '-'}</span>
<span class="text-xs text-orange-600 dark:text-orange-400">佣金: ¥${order.commission_amount.toFixed(2)}</span>
</div>
${order.ticket_codes && order.ticket_codes.length > 0 ? `
<div class="mt-2 pt-2 border-t border-neutral-200 dark:border-neutral-700">
<p class="text-xs text-neutral-500 mb-1">注册码:</p>
<div class="flex flex-wrap gap-1">
${order.ticket_codes.map(code => `<span class="px-2 py-0.5 bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300 text-xs rounded">${code}</span>`).join('')}
</div>
</div>
` : ''}
</div>
`).join('');
}
function copyAffiliateLink() {
const input = document.getElementById('affiliateLink');
input.select();
document.execCommand('copy');
showToast('推广链接已复制', 'success');
}
function showBatchRefreshModal() {
document.getElementById('batchForceRefresh').checked = false;
document.getElementById('batchRefreshResult').classList.add('hidden');
openModal('batchRefreshModal');
}
function closeBatchRefreshModal() {
closeModal('batchRefreshModal');
}
function refreshUserSession(userId, username) {
document.getElementById('singleRefreshUserId').value = userId;
document.getElementById('singleRefreshUsername').value = username;
document.getElementById('singleRefreshPassword').value = '';
document.getElementById('singleForceRefresh').checked = false;
document.getElementById('singleRefreshResult').innerHTML = '';
openModal('singleRefreshModal');
}
function closeSingleRefreshModal() {
closeModal('singleRefreshModal');
}
// 提交创建用户
async function submitCreateUser(event) {
event.preventDefault();
const username = document.getElementById('newUsername').value.trim();
const password = document.getElementById('newPassword').value;
const isAdmin = document.getElementById('newIsAdmin').checked;
if (!username || !password) {
showToast('请填写完整信息', 'error');
return;
}
try {
const data = await apiRequest('/api/admin/users/create', {
method: 'POST',
body: JSON.stringify({ username, password, is_admin: isAdmin })
});
if (data.success) {
showToast('用户创建成功', 'success');
closeCreateUserModal();
loadUsers();
loadStats();
} else {
showToast(data.message || '创建失败', 'error');
}
} catch (error) {
showToast('网络错误', 'error');
}
}
// 提交创建注册码
async function submitCreateTicket(event) {
event.preventDefault();
const count = parseInt(document.getElementById('ticketCount').value);
const maxUses = parseInt(document.getElementById('ticketMaxUses').value);
const expiryDays = parseInt(document.getElementById('ticketExpiryDays').value);
try {
const data = await apiRequest('/api/admin/tickets/create', {
method: 'POST',
body: JSON.stringify({ count, max_uses: maxUses, expiry_days: expiryDays })
});
if (data.success) {
showToast(`成功生成 ${data.codes.length} 个注册码`, 'success');
closeCreateTicketModal();
if (currentTab === 'tickets') {
loadTickets();
}
} else {
showToast(data.message || '生成失败', 'error');
}
} catch (error) {
showToast('网络错误', 'error');
}
}
// 禁用/启用/删除注册码
async function disableTicket(code) {
if (!confirm(`确定要禁用注册码 ${code} 吗?`)) return;
try {
const data = await apiRequest(`/api/admin/tickets/${code}/disable`, { method: 'POST' });
if (data.success) {
showToast('注册码已禁用', 'success');
loadTickets();
} else {
showToast(data.message || '操作失败', 'error');
}
} catch (error) {
showToast('网络错误', 'error');
}
}
async function enableTicket(code) {
try {
const data = await apiRequest(`/api/admin/tickets/${code}/enable`, { method: 'POST' });
if (data.success) {
showToast('注册码已启用', 'success');
loadTickets();
} else {
showToast(data.message || '操作失败', 'error');
}
} catch (error) {
showToast('网络错误', 'error');
}
}
async function deleteTicket(code) {
if (!confirm(`确定要删除注册码 ${code} 吗?此操作不可恢复。`)) return;
try {
const data = await apiRequest(`/api/admin/tickets/${code}/delete`, { method: 'POST' });
if (data.success) {
showToast('注册码已删除', 'success');
loadTickets();
} else {
showToast(data.message || '操作失败', 'error');
}
} catch (error) {
showToast('网络错误', 'error');
}
}
// 批量检查 Session
async function batchCheckSession() {
if (!confirm('开始批量检查所有用户的 Session 状态?')) return;
showToast('正在检查 Session 状态...', 'info');
try {
const data = await apiRequest('/api/admin/session/batch_check', { method: 'POST', body: JSON.stringify({}) });
if (data.success) {
const results = data.results;
showToast(`检查完成:有效${results.valid}个,过期${results.invalid}个`, 'success');
loadStats();
loadUsers();
} else {
showToast(data.message || '检查失败', 'error');
}
} catch (error) {
showToast('网络错误', 'error');
}
}
// 删除用户
async function deleteUser(userId, username) {
if (!confirm(`确定要删除用户 "${username}" 吗?\n\n此操作将同时删除该用户的所有任务,且不可恢复。`)) return;
try {
const data = await apiRequest(`/api/admin/users/${userId}/delete`, { method: 'POST' });
if (data.success) {
showToast('用户已删除', 'success');
loadUsers();
loadStats();
} else {
showToast(data.message || '删除失败', 'error');
}
} catch (error) {
showToast('网络错误', 'error');
}
}
// 仅检查
async function batchCheckOnly() {
showToast('正在检查...', 'info');
try {
const data = await apiRequest('/api/admin/session/batch_check', { method: 'POST', body: JSON.stringify({}) });
if (data.success) {
const results = data.results;
document.getElementById('resultValid').textContent = results.valid;
document.getElementById('resultRefreshed').textContent = 0;
document.getElementById('resultFailed').textContent = results.invalid + results.no_jwxt;
const tbody = document.getElementById('batchRefreshDetails');
tbody.innerHTML = results.details.map(d => `
<tr>
<td>${escapeHtml(d.username)}</td>
<td>
${d.status === 'valid' ? '<span class="status-badge status-success">有效</span>' :
d.status === 'no_jwxt' ? '<span class="status-badge" style="background: #f3f4f6; color: #6b7280;">未配置</span>' :
'<span class="status-badge status-danger">过期</span>'}
</td>
<td class="text-sm">${escapeHtml(d.message) || '-'}</td>
</tr>
`).join('');
document.getElementById('batchRefreshResult').classList.remove('hidden');
loadStats();
}
} catch (error) {
showToast('检查失败', 'error');
}
}
// 执行批量刷新
async function doBatchRefresh() {
const force = document.getElementById('batchForceRefresh').checked;
showToast('正在刷新...', 'info');
try {
const data = await apiRequest('/api/admin/session/batch_refresh', {
method: 'POST',
body: JSON.stringify({ force })
});
if (data.success) {
const results = data.results;
document.getElementById('resultValid').textContent = results.valid;
document.getElementById('resultRefreshed').textContent = results.refreshed;
document.getElementById('resultFailed').textContent = results.failed + results.no_password;
const tbody = document.getElementById('batchRefreshDetails');
tbody.innerHTML = results.details.map(d => `
<tr>
<td>${escapeHtml(d.username)}</td>
<td>
${d.status === 'valid' ? '<span class="status-badge status-success">有效</span>' :
d.status === 'refreshed' ? '<span class="status-badge status-info">已刷新</span>' :
d.status === 'no_password' ? '<span class="status-badge status-warning">无密码</span>' :
'<span class="status-badge status-danger">失败</span>'}
</td>
<td class="text-sm">${escapeHtml(d.message) || '-'}</td>
</tr>
`).join('');
document.getElementById('batchRefreshResult').classList.remove('hidden');
showToast(`刷新完成`, 'success');
loadStats();
loadUsers();
} else {
showToast(data.message || '刷新失败', 'error');
}
} catch (error) {
showToast('网络错误', 'error');
}
}
// 执行单用户刷新
async function doSingleRefresh() {
const userId = document.getElementById('singleRefreshUserId').value;
const password = document.getElementById('singleRefreshPassword').value.trim();
const force = document.getElementById('singleForceRefresh').checked;
if (!password) {
document.getElementById('singleRefreshResult').innerHTML = '<div class="p-3 bg-amber-50 dark:bg-amber-900/20 text-amber-800 dark:text-amber-200 rounded-lg text-sm">请输入密码</div>';
return;
}
try {
const data = await apiRequest(`/api/admin/users/${userId}/session/refresh`, {
method: 'POST',
body: JSON.stringify({ jwxt_password: password, force })
});
if (data.success) {
document.getElementById('singleRefreshResult').innerHTML = `<div class="p-3 bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200 rounded-lg text-sm">${data.message}</div>`;
setTimeout(() => {
closeSingleRefreshModal();
loadStats();
loadUsers();
}, 1500);
} else {
document.getElementById('singleRefreshResult').innerHTML = `<div class="p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 rounded-lg text-sm">${data.message}</div>`;
}
} catch (error) {
document.getElementById('singleRefreshResult').innerHTML = '<div class="p-3 bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 rounded-lg text-sm">刷新失败</div>';
}
}
// 查看用户任务
function viewUserTasks(userId) {
window.location.href = `/tasks?user_id=${userId}`;
}
// 加载推广码列表
async function loadAffiliates() {
document.getElementById('affiliatesLoading').classList.remove('hidden');
document.getElementById('affiliatesEmpty').classList.add('hidden');
document.getElementById('affiliatesTable').classList.add('hidden');
try {
const data = await apiRequest('/api/admin/affiliates/list');
document.getElementById('affiliatesLoading').classList.add('hidden');
if (!data.success || !data.affiliates || data.affiliates.length === 0) {
document.getElementById('affiliatesEmpty').classList.remove('hidden');
return;
}
renderAffiliatesTable(data.affiliates);
document.getElementById('affiliatesTable').classList.remove('hidden');
} catch (error) {
document.getElementById('affiliatesLoading').classList.add('hidden');
showToast('加载失败', 'error');
}
}
// 渲染推广码表格
function renderAffiliatesTable(affiliates) {
const tbody = document.getElementById('affiliatesTableBody');
tbody.innerHTML = affiliates.map((aff, index) => {
const delay = 50 * index;
return `
<tr class="list-item-enter" style="animation-delay: ${delay}ms;">
<td class="font-mono text-sm font-bold">${aff.code}</td>
<td class="font-medium">${escapeHtml(aff.name)}</td>
<td>
<span class="status-badge status-info">${aff.commission_rate}%</span>
</td>
<td>
<span class="status-badge status-success">-¥${aff.discount_amount}</span>
</td>
<td class="text-sm text-neutral-500">${new Date(aff.created_at).toLocaleDateString('zh-CN')}</td>
<td>
<div class="flex gap-2">
<button onclick="openAffiliateDetailModal('${aff.code}')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition text-green-600" title="查看详情">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"></path>
</svg>
</button>
<button onclick="editAffiliate('${aff.code}')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition text-blue-600" title="编辑">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>
</svg>
</button>
<button onclick="deleteAffiliate('${aff.code}', '${escapeHtml(aff.name)}')" class="p-2 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition text-red-600" title="删除">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
</svg>
</button>
</div>
</td>
</tr>
`}).join('');
}
// 提交创建推广人
async function submitCreateAffiliate(event) {
event.preventDefault();
const code = document.getElementById('affiliateCode').value.trim().toUpperCase();
const name = document.getElementById('affiliateName').value.trim();
const commissionRate = parseInt(document.getElementById('affiliateCommission').value);
const discountAmount = parseInt(document.getElementById('affiliateDiscount').value);
if (!code || !name) {
showToast('请填写完整信息', 'error');
return;
}
try {
const data = await apiRequest('/api/admin/affiliates/create', {
method: 'POST',
body: JSON.stringify({
code,
name,
commission_rate: commissionRate,
discount_amount: discountAmount
})
});
if (data.success) {
showToast('推广人创建成功', 'success');
closeCreateAffiliateModal();
loadAffiliates();
} else {
showToast(data.message || '创建失败', 'error');
}
} catch (error) {
showToast('网络错误', 'error');
}
}
// 删除推广人
async function deleteAffiliate(code, name) {
if (!confirm(`确定要删除推广人 "${name}" (${code}) 吗?\n\n此操作不可恢复。`)) return;
try {
const data = await apiRequest(`/api/admin/affiliates/${code}/delete`, { method: 'POST' });
if (data.success) {
showToast('推广人已删除', 'success');
loadAffiliates();
} else {
showToast(data.message || '删除失败', 'error');
}
} catch (error) {
showToast('网络错误', 'error');
}
}
// 编辑推广人(简化版:直接删除后重新创建)
async function editAffiliate(code) {
// 获取当前信息
try {
const data = await apiRequest(`/api/admin/affiliates/${code}`);
if (data.success && data.affiliate) {
const aff = data.affiliate;
// 填充表单
document.getElementById('affiliateCode').value = aff.code;
document.getElementById('affiliateName').value = aff.name;
document.getElementById('affiliateCommission').value = aff.commission_rate;
document.getElementById('affiliateDiscount').value = aff.discount_amount;
// 禁用推广码输入(不允许修改)
document.getElementById('affiliateCode').disabled = true;
// 显示模态框
document.getElementById('createAffiliateModal').classList.remove('hidden');
// 修改标题
document.querySelector('#createAffiliateModal h3').textContent = '编辑推广人';
// 修改提交函数
document.getElementById('createAffiliateForm').onsubmit = async function(e) {
e.preventDefault();
await updateAffiliate(code);
};
}
} catch (error) {
showToast('加载推广人信息失败', 'error');
}
}
// 更新推广人
async function updateAffiliate(code) {
const name = document.getElementById('affiliateName').value.trim();
const commissionRate = parseInt(document.getElementById('affiliateCommission').value);
const discountAmount = parseInt(document.getElementById('affiliateDiscount').value);
try {
const data = await apiRequest(`/api/admin/affiliates/${code}/update`, {
method: 'POST',
body: JSON.stringify({
name,
commission_rate: commissionRate,
discount_amount: discountAmount
})
});
if (data.success) {
showToast('推广人更新成功', 'success');
closeCreateAffiliateModal();
loadAffiliates();
// 重置表单
document.getElementById('affiliateCode').disabled = false;
document.querySelector('#createAffiliateModal h3').textContent = '添加推广人';
document.getElementById('createAffiliateForm').onsubmit = submitCreateAffiliate;
} else {
showToast(data.message || '更新失败', 'error');
}
} catch (error) {
showToast('网络错误', 'error');
}
}
// ==================== 支付管理功能 ====================
// 加载订单数据
async function loadPaymentOrders() {
document.getElementById('paymentLoadingState').classList.remove('hidden');
document.getElementById('paymentEmptyState').classList.add('hidden');
document.getElementById('paymentOrdersTableBody').innerHTML = '';
try {
const status = document.getElementById('paymentFilterStatus').value;
const search = document.getElementById('paymentSearchInput').value;
let url = '/api/admin/orders?status=' + status;
if (search) {
url += '&search=' + encodeURIComponent(search);
}
const data = await apiRequest(url);
if (data.success) {
currentPaymentOrders = data.orders;
renderPaymentOrders(currentPaymentOrders);
updatePaymentStats(data.stats);
} else {
showToast(data.message || '加载失败', 'error');
}
} catch (error) {
console.error('加载订单失败:', error);
showToast('网络错误', 'error');
}
}
// 渲染订单列表
function renderPaymentOrders(orders) {
const tbody = document.getElementById('paymentOrdersTableBody');
const loadingState = document.getElementById('paymentLoadingState');
const emptyState = document.getElementById('paymentEmptyState');
loadingState.classList.add('hidden');
if (orders.length === 0) {
emptyState.classList.remove('hidden');
tbody.innerHTML = '';
return;
}
emptyState.classList.add('hidden');
tbody.innerHTML = orders.map((order, index) => {
const delay = 50 * index;
return `
<tr class="hover:bg-neutral-50 dark:hover:bg-neutral-800/50 list-item-enter" style="animation-delay: ${delay}ms;">
<td class="font-mono text-xs">${order.order_id}</td>
<td>${escapeHtml(order.email)}</td>
<td>${order.quantity}</td>
<td>¥${order.amount}</td>
<td class="text-green-600">-¥${order.invite_discount_total || 0}</td>
<td class="font-bold">¥${order.final_amount}</td>
<td>
${order.invite_code ? `<span class="px-2 py-1 bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300 rounded text-xs">${order.invite_code}</span>` : '-'}
</td>
<td>${getPaymentStatusBadge(order.status)}</td>
<td class="text-neutral-500">${formatDate(order.created_at)}</td>
<td class="text-neutral-500">${order.paid_at ? formatDate(order.paid_at) : '-'}</td>
<td>
<div class="flex gap-2">
<button onclick="viewPaymentOrderDetail('${order.order_id}')" class="p-1.5 text-blue-600 hover:bg-blue-50 dark:hover:bg-blue-900/20 rounded" title="查看详情">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"></path>
</svg>
</button>
${order.status === 'pending' ? `
<button onclick="openConfirmPayment('${order.order_id}')" class="p-1.5 text-green-600 hover:bg-green-50 dark:hover:bg-green-900/20 rounded" title="确认支付">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</button>
<button onclick="openRejectOrder('${order.order_id}')" class="p-1.5 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 rounded" title="拒绝订单">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
` : ''}
</div>
</td>
</tr>
`}).join('');
}
// 获取状态标签
function getPaymentStatusBadge(status) {
const statusMap = {
'pending': '<span class="status-badge status-pending">待支付</span>',
'paid': '<span class="status-badge status-paid">已支付</span>',
'processed': '<span class="status-badge status-processed">已处理</span>',
'failed': '<span class="status-badge status-failed">支付失败</span>',
'cancelled': '<span class="status-badge status-cancelled">已取消</span>',
'expired': '<span class="status-badge status-cancelled">已过期</span>',
'refunded': '<span class="status-badge status-refunded">已退款</span>'
};
return statusMap[status] || `<span class="status-badge">${status}</span>`;
}
// 更新统计
function updatePaymentStats(stats) {
document.getElementById('paymentStatTotal').textContent = stats.total;
document.getElementById('paymentStatPending').textContent = stats.pending;
document.getElementById('paymentStatPaid').textContent = stats.paid;
document.getElementById('paymentStatProcessed').textContent = stats.processed;
document.getElementById('paymentStatRevenue').textContent = '¥' + stats.revenue;
}
// 查看订单详情
async function viewPaymentOrderDetail(orderId) {
const order = currentPaymentOrders.find(o => o.order_id === orderId);
if (!order) return;
currentPaymentOrderId = orderId;
const content = document.getElementById('paymentOrderDetailContent');
content.innerHTML = `
<div class="space-y-4">
<div class="grid grid-cols-2 gap-4">
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3">
<p class="text-xs text-neutral-500">订单号</p>
<p class="font-mono text-sm">${order.order_id}</p>
</div>
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3">
<p class="text-xs text-neutral-500">状态</p>
<p>${getPaymentStatusBadge(order.status)}</p>
</div>
</div>
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3">
<p class="text-xs text-neutral-500 mb-1">邮箱</p>
<p class="font-medium">${escapeHtml(order.email)}</p>
</div>
<div class="grid grid-cols-2 gap-4">
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3">
<p class="text-xs text-neutral-500">购买数量</p>
<p class="text-lg font-bold">${order.quantity} 份</p>
</div>
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3">
<p class="text-xs text-neutral-500">推广码</p>
<p class="text-lg font-bold">${order.invite_code || '-'}</p>
</div>
</div>
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3">
<p class="text-xs text-neutral-500 mb-2">金额明细</p>
<div class="flex justify-between text-sm">
<span>原价</span>
<span>¥${order.amount}</span>
</div>
<div class="flex justify-between text-sm text-green-600">
<span>推广优惠</span>
<span>-¥${order.invite_discount_total || 0}</span>
</div>
<div class="flex justify-between font-bold mt-1 pt-1 border-t border-neutral-200 dark:border-neutral-700">
<span>实付</span>
<span>¥${order.final_amount}</span>
</div>
</div>
${order.platform_order_no ? `
<div class="bg-neutral-50 dark:bg-neutral-800/50 rounded-xl p-3">
<p class="text-xs text-neutral-500">支付平台订单号</p>
<p class="font-mono text-sm">${order.platform_order_no}</p>
</div>
` : ''}
${order.ticket_codes && order.ticket_codes.length > 0 ? `
<div class="bg-green-50 dark:bg-green-900/20 rounded-xl p-3">
<p class="text-xs text-green-600 mb-2">注册码</p>
<div class="space-y-1">
${order.ticket_codes.map(code => `
<div class="font-mono text-sm bg-white dark:bg-neutral-800 rounded px-2 py-1">${code}</div>
`).join('')}
</div>
</div>
` : ''}
<div class="grid grid-cols-2 gap-4 text-sm">
<div>
<p class="text-xs text-neutral-500">创建时间</p>
<p>${formatDate(order.created_at)}</p>
</div>
<div>
<p class="text-xs text-neutral-500">支付时间</p>
<p>${order.paid_at ? formatDate(order.paid_at) : '-'}</p>
</div>
</div>
${order.status === 'pending' ? `
<button onclick="closePaymentOrderDetail(); openConfirmPayment('${order.order_id}')"
class="w-full py-3 bg-green-600 text-white rounded-xl hover:bg-green-700 transition font-medium">
<svg class="w-4 h-4 inline mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
手动确认支付
</button>
` : ''}
${order.status === 'pending' ? `
<button onclick="closePaymentOrderDetail(); openRejectOrder('${order.order_id}')"
class="w-full py-3 bg-red-600 text-white rounded-xl hover:bg-red-700 transition font-medium">
<svg class="w-4 h-4 inline mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
拒绝订单
</button>
` : ''}
</div>
`;
document.getElementById('paymentOrderDetailModal').classList.remove('hidden');
}
function closePaymentOrderDetail() {
document.getElementById('paymentOrderDetailModal').classList.add('hidden');
}
// 打开确认支付模态框
function openConfirmPayment(orderId) {
currentPaymentOrderId = orderId;
document.getElementById('confirmOrderId').textContent = orderId;
document.getElementById('confirmPaymentModal').classList.remove('hidden');
}
function closeConfirmPayment() {
document.getElementById('confirmPaymentModal').classList.add('hidden');
}
// 打开拒绝订单模态框
let currentRejectOrderId = null;
function openRejectOrder(orderId) {
currentRejectOrderId = orderId;
document.getElementById('rejectOrderId').textContent = orderId;
document.getElementById('rejectReason').value = '';
document.getElementById('rejectOrderModal').classList.remove('hidden');
}
function closeRejectOrder() {
document.getElementById('rejectOrderModal').classList.add('hidden');
currentRejectOrderId = null;
}
// 提交拒绝订单
async function submitRejectOrder() {
if (!currentRejectOrderId) return;
const reason = document.getElementById('rejectReason').value.trim();
try {
const response = await fetch(`/api/orders/${currentRejectOrderId}/cancel`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ reason: reason || '管理员拒绝' })
});
const data = await response.json();
if (data.success) {
showToast('订单已拒绝', 'success');
closeRejectOrder();
loadPaymentOrders();
} else {
showToast(data.message || '拒绝失败', 'error');
}
} catch (error) {
showToast('网络错误', 'error');
}
}
// 提交确认支付
async function submitConfirmPayment() {
try {
const data = await apiRequest('/api/admin/orders/' + currentPaymentOrderId + '/confirm-payment', {
method: 'POST'
});
if (data.success) {
showToast('支付确认成功!注册码已生成并发送给用户。', 'success');
closeConfirmPayment();
loadPaymentOrders();
} else {
showToast('确认失败: ' + (data.message || '未知错误'), 'error');
}
} catch (error) {
console.error('确认支付失败:', error);
showToast('网络错误', 'error');
}
}
// 刷新数据
function refreshPaymentData() {
loadPaymentOrders();
}
// 格式化日期
function formatDate(dateStr) {
if (!dateStr) return '-';
const date = new Date(dateStr);
return date.toLocaleString('zh-CN');
}
// ==================== IP管理相关 ====================
let ipChartHour = null, ipChartRegion = null;
async function loadIpStats() {
const hours = document.getElementById('ipStatsHours') ? document.getElementById('ipStatsHours').value : 24;
const data = await apiRequest(`/api/admin/ip/stats?hours=${hours}`);
if (!data.success) return;
const s = data.stats;
document.getElementById('ipStatTotal').textContent = s.total.toLocaleString();
document.getElementById('ipStatUnique').textContent = s.unique_ips.toLocaleString();
document.getElementById('ipStatBlocked').textContent = s.blocked.toLocaleString();
document.getElementById('ipStatBans').textContent = s.active_bans;
// 时段分布
const now = new Date();
const allHours = [];
for (let i = parseInt(hours) - 1; i >= 0; i--) {
const d = new Date(now.getTime() - i * 3600000);
if (hours <= 24) {
allHours.push(d.toISOString().slice(11, 16)); // HH:MM
} else {
allHours.push(d.toISOString().slice(5, 10)); // MM-DD
}
}
const hourMap = {};
s.by_hour.forEach(h => hourMap[String(h.hour).padStart(2,'0')] = h.count);
const hourData = allHours.map((_, idx) => {
if (hours <= 24) return hourMap[String(idx).padStart(2,'0')] || 0;
const d = new Date(now.getTime() - (parseInt(hours) - 1 - idx) * 3600000);
return hourMap[String(d.getUTCHours()).padStart(2,'0')] || 0;
});
renderIpBar('chartIpHour', allHours, hourData);
// 省市分布 - 环形图
const topRegions = s.by_region.slice(0, 10);
if (topRegions.length > 0) {
renderIpDoughnut('chartIpRegion', topRegions.map(r => r.region || '未知'), topRegions.map(r => r.count));
}
}
function renderIpBar(domId, labels, data) {
const dom = document.getElementById(domId);
if (!dom) return;
if (ipChartHour) {
ipChartHour.dispose();
ipChartHour = null;
}
const isDark = document.documentElement.classList.contains('dark');
ipChartHour = echarts.init(dom);
ipChartHour.setOption({
tooltip: {
trigger: 'axis',
backgroundColor: isDark ? '#262626' : '#fff',
textStyle: { color: isDark ? '#fff' : '#333' }
},
grid: { left: '3%', right: '4%', bottom: '3%', top: '10%', containLabel: true },
xAxis: {
type: 'category',
data: labels,
axisLabel: { color: isDark ? '#888' : '#666', rotate: labels.length > 12 ? 45 : 0 },
axisLine: { lineStyle: { color: isDark ? '#444' : '#ddd' } }
},
yAxis: {
type: 'value',
axisLabel: { color: isDark ? '#888' : '#666' },
splitLine: { lineStyle: { color: isDark ? '#333' : '#eee' } }
},
series: [{
type: 'bar',
data: data,
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#3b82f6' },
{ offset: 1, color: '#60a5fa' }
]),
borderRadius: [4, 4, 0, 0]
},
emphasis: { itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#2563eb' },
{ offset: 1, color: '#3b82f6' }
])}}
}]
});
window.addEventListener('resize', () => ipChartHour && ipChartHour.resize());
}
function renderIpDoughnut(domId, labels, data) {
const dom = document.getElementById(domId);
if (!dom) return;
if (ipChartRegion) {
ipChartRegion.dispose();
ipChartRegion = null;
}
const isDark = document.documentElement.classList.contains('dark');
ipChartRegion = echarts.init(dom);
const colors = ['#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6', '#ec4899', '#06b6d4', '#f97316', '#22c55e', '#6366f1'];
ipChartRegion.setOption({
tooltip: {
trigger: 'item',
backgroundColor: isDark ? '#262626' : '#fff',
textStyle: { color: isDark ? '#fff' : '#333' }
},
legend: {
orient: 'vertical',
right: '5%',
top: 'center',
textStyle: { color: isDark ? '#888' : '#666', fontSize: 11 },
itemWidth: 12,
itemHeight: 12
},
series: [{
type: 'doughnut',
radius: ['45%', '70%'],
center: ['35%', '50%'],
avoidLabelOverlap: true,
itemStyle: { borderRadius: 4, borderColor: isDark ? '#171717' : '#fff', borderWidth: 2 },
label: { show: false },
emphasis: { label: { show: false } },
data: labels.map((label, i) => ({
value: data[i],
name: `${label} (${data[i]})`,
itemStyle: { color: colors[i % colors.length] }
}))
}]
});
window.addEventListener('resize', () => ipChartRegion && ipChartRegion.resize());
}
async function loadIpBansPreview() {
const data = await apiRequest('/api/admin/ip/bans');
const bans = data.bans || [];
const active = bans.filter(b => b.is_active);
const div = document.getElementById('ipBansPreview');
if (active.length === 0) {
div.innerHTML = '<div class="text-center text-neutral-400 py-4">暂无活跃封禁规则</div>';
return;
}
div.innerHTML = `<table class="w-full text-sm">
<thead>
<tr class="text-left text-neutral-500 dark:text-neutral-400 border-b border-neutral-200 dark:border-neutral-700">
<th class="pb-2 pr-4 font-medium">类型</th>
<th class="pb-2 pr-4 font-medium">值</th>
<th class="pb-2 pr-4 font-medium">原因</th>
<th class="pb-2 pr-4 font-medium">到期</th>
<th class="pb-2 font-medium">操作</th>
</tr>
</thead>
<tbody class="divide-y divide-neutral-100 dark:divide-neutral-800">
${active.slice(0, 5).map(b => `
<tr class="hover:bg-neutral-50 dark:hover:bg-neutral-800/50">
<td class="py-2 pr-4"><span class="text-xs px-2 py-0.5 rounded-full font-medium ${b.ban_type==='ip'?'bg-red-100 text-red-600':b.ban_type==='cidr'?'bg-orange-100 text-orange-600':'bg-purple-100 text-purple-600'}">${b.ban_type.toUpperCase()}</span></td>
<td class="py-2 pr-4 font-mono text-sm text-neutral-800 dark:text-neutral-200">${b.value}</td>
<td class="py-2 pr-4 text-xs text-neutral-500">${b.reason || '-'}</td>
<td class="py-2 pr-4 text-xs text-neutral-500">${b.is_permanent ? '<span class="text-red-500 font-semibold">永久</span>' : (b.expires_at ? new Date(b.expires_at.endsWith('Z') ? b.expires_at : b.expires_at + 'Z').toLocaleString('zh-CN', {hour12:false, timeZone:'Asia/Shanghai'}).replace(/\//g, '-') : '-')}</td>
<td class="py-2"><button onclick="unbanIpQuick(${b.id},'${b.value}')" class="text-xs px-2 py-1 rounded-lg bg-green-50 text-green-600 hover:bg-green-100">解封</button></td>
</tr>`).join('')}
</tbody></table>`;
}
async function unbanIpQuick(id, value) {
if (!confirm(`确认解封 ${value}?`)) return;
const data = await apiRequest('/api/admin/ip/unban', { method: 'POST', body: JSON.stringify({ id }) });
showToast(data.message, data.success ? 'success' : 'error');
if (data.success) { loadIpStats(); loadIpBansPreview(); }
}
// 添加封禁 Modal
function openIpBanModal() {
document.getElementById('ipBanModal').classList.remove('hidden');
}
async function submitIpBan() {
const value = document.getElementById('ipBanValue').value.trim();
if (!value) { showToast('请填写封禁值', 'error'); return; }
const data = await apiRequest('/api/admin/ip/ban', {
method: 'POST',
body: JSON.stringify({
value,
ban_type: document.getElementById('ipBanType').value,
duration: document.getElementById('ipBanDuration').value || null,
reason: document.getElementById('ipBanReason').value
})
});
showToast(data.message, data.success ? 'success' : 'error');
if (data.success) {
document.getElementById('ipBanModal').classList.add('hidden');
loadIpStats();
loadIpBansPreview();
}
}
// 频率限制配置 Modal
async function openIpConfigModal() {
const data = await apiRequest('/api/admin/ip/config');
if (data.success) {
document.getElementById('ipCfgWindow').value = data.config.login_window_minutes;
document.getElementById('ipCfgMax').value = data.config.login_max_attempts;
document.getElementById('ipCfgChinaOnly').checked = data.config.enable_china_only === 'true';
}
document.getElementById('ipConfigModal').classList.remove('hidden');
}
async function submitIpConfig() {
const data = await apiRequest('/api/admin/ip/config', {
method: 'POST',
body: JSON.stringify({
login_window_minutes: parseInt(document.getElementById('ipCfgWindow').value),
login_max_attempts: parseInt(document.getElementById('ipCfgMax').value),
enable_china_only: document.getElementById('ipCfgChinaOnly').checked
})
});
showToast(data.message, data.success ? 'success' : 'error');
if (data.success) document.getElementById('ipConfigModal').classList.add('hidden');
}
</script>
{% endblock %}