API: - 新增 player-messages 域:充值审核通过/拒绝、Banner/公告推广消息,支持多语言模板 - 新增 presence 域:Redis 心跳在线状态,管理端可查询在线玩家数 - User 表增加 visible_menus 字段;新增 player_messages 表及迁移 - 充值审核通过/拒绝时按系统配置自动写入玩家站内消息 - 管理端新增 GET /deposit-orders/pending-count、GET /presence/online-count - 玩家端新增消息 CRUD、presence/ping、home 返回 inbox 开关配置 - 员工管理支持 visibleMenus 配置与删除保护(不能删自己/最后超管) - SystemConfig 增加 inbox 功能开关及各类通知开关 Admin: - 员工管理:按角色默认菜单 + 可勾选可见菜单项 - ManageLayout:按 visibleMenus 过滤侧栏;充值待审数量角标轮询 - Contents:富文本编辑器、图片字段组件重构 - DashboardPlayers:展示在线玩家数;AdminPlayerStatusCell 在线状态列 - 多页面 i18n 与权限细节调整 Player: - 站内邮箱中心(InboxHub):消息列表/详情、未读角标、一键已读/删除 - 公告列表与详情页;走马灯可跳转详情 - 客服 Modal 改为 Panel,与邮箱 Hub 整合 - 充值状态轮询通知;presence 心跳;BetSlip 清空二次确认 - HomeView 今日赛事板块;FootballView 等体验优化 Shared: 新增 CANNOT_DELETE_SELF、STAFF_NOT_FOUND、MESSAGE_NOT_FOUND 等错误码 Docs: 玩家端缺失功能分析文档 Chore: 移除 .agents/skills 设计类 skill 文件 Co-authored-by: Cursor <cursoragent@cursor.com>
175 lines
4.2 KiB
TypeScript
175 lines
4.2 KiB
TypeScript
import api from '../api';
|
|
import { usePlayerProfile } from './usePlayerProfile';
|
|
import { usePlayerMessages } from './usePlayerMessages';
|
|
|
|
interface DepositOrderRow {
|
|
id: string;
|
|
orderNo: string;
|
|
amount: string;
|
|
status: string;
|
|
rejectReason?: string | null;
|
|
}
|
|
|
|
const POLL_FAST_MS = 8_000;
|
|
const POLL_SLOW_MS = 30_000;
|
|
const TRACKED_STORAGE_KEY = 'player_deposit_tracked_pending';
|
|
|
|
const lastStatus = new Map<string, string>();
|
|
const trackedPending = new Set<string>();
|
|
const notifiedKeys = new Set<string>();
|
|
let pollTimer: ReturnType<typeof setInterval> | null = null;
|
|
let pollingActive = false;
|
|
|
|
function notifyKey(orderId: string, type: 'approved' | 'rejected') {
|
|
return `${orderId}:${type}`;
|
|
}
|
|
|
|
function loadTrackedFromStorage() {
|
|
try {
|
|
const raw = sessionStorage.getItem(TRACKED_STORAGE_KEY);
|
|
if (!raw) return;
|
|
const ids: string[] = JSON.parse(raw);
|
|
for (const id of ids) {
|
|
if (id) trackedPending.add(String(id));
|
|
}
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
}
|
|
|
|
function persistTrackedToStorage() {
|
|
try {
|
|
sessionStorage.setItem(TRACKED_STORAGE_KEY, JSON.stringify([...trackedPending]));
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
}
|
|
|
|
function addTracked(orderId: string) {
|
|
trackedPending.add(orderId);
|
|
persistTrackedToStorage();
|
|
}
|
|
|
|
function removeTracked(orderId: string) {
|
|
if (!trackedPending.delete(orderId)) return;
|
|
persistTrackedToStorage();
|
|
}
|
|
|
|
function hasPendingInterest() {
|
|
return trackedPending.size > 0;
|
|
}
|
|
|
|
function schedulePoll(intervalMs: number) {
|
|
if (pollTimer) clearInterval(pollTimer);
|
|
pollTimer = setInterval(() => {
|
|
void pollOnce();
|
|
}, intervalMs);
|
|
}
|
|
|
|
function adjustPollInterval() {
|
|
if (!pollingActive) return;
|
|
schedulePoll(hasPendingInterest() ? POLL_FAST_MS : POLL_SLOW_MS);
|
|
}
|
|
|
|
function trackPendingOrder(orderId: string) {
|
|
const id = String(orderId);
|
|
if (!id) return;
|
|
addTracked(id);
|
|
lastStatus.set(id, 'PENDING');
|
|
adjustPollInterval();
|
|
void pollOnce();
|
|
}
|
|
|
|
function shouldNotify(orderId: string, prev: string | undefined, next: string) {
|
|
if (next !== 'APPROVED' && next !== 'REJECTED') return false;
|
|
if (prev === 'PENDING') return true;
|
|
if (trackedPending.has(orderId)) return true;
|
|
return false;
|
|
}
|
|
|
|
function handleStatusChange(order: DepositOrderRow): boolean {
|
|
const prev = lastStatus.get(order.id);
|
|
const next = order.status;
|
|
lastStatus.set(order.id, next);
|
|
|
|
if (next === 'PENDING') {
|
|
addTracked(order.id);
|
|
return false;
|
|
}
|
|
|
|
removeTracked(order.id);
|
|
|
|
if (!shouldNotify(order.id, prev, next)) return false;
|
|
|
|
const type = next === 'APPROVED' ? 'approved' : 'rejected';
|
|
const key = notifyKey(order.id, type);
|
|
if (notifiedKeys.has(key)) return false;
|
|
notifiedKeys.add(key);
|
|
|
|
void usePlayerMessages().refreshUnreadCount();
|
|
return next === 'APPROVED';
|
|
}
|
|
|
|
async function pollOnce() {
|
|
try {
|
|
const { data } = await api.get('/player/deposit-orders', { params: { page: 1 } });
|
|
const items: DepositOrderRow[] = data.data?.items ?? [];
|
|
const { refreshProfile } = usePlayerProfile();
|
|
|
|
let needsProfileRefresh = false;
|
|
for (const order of items) {
|
|
if (handleStatusChange(order)) needsProfileRefresh = true;
|
|
}
|
|
|
|
if (needsProfileRefresh) await refreshProfile();
|
|
adjustPollInterval();
|
|
} catch {
|
|
/* silent retry on next tick */
|
|
}
|
|
}
|
|
|
|
function onVisibilityChange() {
|
|
if (!document.hidden && pollingActive) void pollOnce();
|
|
}
|
|
|
|
function startPolling() {
|
|
if (pollingActive) {
|
|
void pollOnce();
|
|
return;
|
|
}
|
|
pollingActive = true;
|
|
loadTrackedFromStorage();
|
|
for (const id of trackedPending) {
|
|
if (!lastStatus.has(id)) lastStatus.set(id, 'PENDING');
|
|
}
|
|
document.addEventListener('visibilitychange', onVisibilityChange);
|
|
void pollOnce();
|
|
schedulePoll(hasPendingInterest() ? POLL_FAST_MS : POLL_SLOW_MS);
|
|
}
|
|
|
|
function stopPolling() {
|
|
pollingActive = false;
|
|
trackedPending.clear();
|
|
lastStatus.clear();
|
|
notifiedKeys.clear();
|
|
try {
|
|
sessionStorage.removeItem(TRACKED_STORAGE_KEY);
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
if (pollTimer) {
|
|
clearInterval(pollTimer);
|
|
pollTimer = null;
|
|
}
|
|
document.removeEventListener('visibilitychange', onVisibilityChange);
|
|
}
|
|
|
|
export function useDepositNotifications() {
|
|
return {
|
|
trackPendingOrder,
|
|
startPolling,
|
|
stopPolling,
|
|
pollOnce,
|
|
};
|
|
}
|