From 4751a5578e075224b9357286a39dea73bf183067 Mon Sep 17 00:00:00 2001 From: lkddi Date: Sat, 25 Apr 2026 13:23:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=B8=B8=E6=88=8F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=89=8B=E5=8A=A8=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/js/admin/game-configs.js | 224 ++++++++++++++++++ .../views/admin/game-configs/index.blade.php | 173 ++------------ 2 files changed, 245 insertions(+), 152 deletions(-) diff --git a/resources/js/admin/game-configs.js b/resources/js/admin/game-configs.js index 530d249..a8ebe55 100644 --- a/resources/js/admin/game-configs.js +++ b/resources/js/admin/game-configs.js @@ -2,6 +2,12 @@ let adminGameConfigControlsBound = false; +const MYSTERY_BOX_META = { + normal: { name: "普通箱", icon: "📦" }, + rare: { name: "稀有箱", icon: "💎" }, + trap: { name: "黑化箱", icon: "☠️" }, +}; + /** * 读取后台 layout 注入的 CSRF token。 * @@ -221,6 +227,174 @@ async function toggleGame(button) { } } +/** + * 管理员手动投放神秘箱子。 + * + * @param {HTMLButtonElement} button 投放按钮 + * @returns {void} + */ +function dropMysteryBox(button) { + const boxType = button.getAttribute("data-game-drop-box-type") || "normal"; + const dropUrl = button.getAttribute("data-game-drop-box-url") || ""; + const meta = MYSTERY_BOX_META[boxType] || MYSTERY_BOX_META.normal; + + if (!dropUrl) { + return; + } + + window.adminDialog?.confirm( + `确定要向 #1 房间 投放一个「${meta.name}」吗?
箱子投放后将立即在公屏广播暗号,用户限时领取。`, + `投放${meta.name}`, + () => { + fetch(dropUrl, { + method: "POST", + headers: { + "X-CSRF-TOKEN": getCsrfToken(), + "Content-Type": "application/json", + "Accept": "application/json", + }, + body: JSON.stringify({ box_type: boxType }), + }) + .then((response) => response.json()) + .then((data) => { + window.adminDialog?.alert( + data.message || (data.ok ? "投放成功!" : "投放失败"), + data.ok ? "投放成功" : "投放失败", + data.ok ? meta.icon : "❌", + ); + }) + .catch(() => window.adminDialog?.alert("网络错误,请重试", "网络错误", "🌐")); + }, + meta.icon, + ); +} + +/** + * 加载双色球当前期次状态。 + * + * @param {HTMLButtonElement} button 状态加载按钮 + * @returns {Promise} + */ +async function loadLotteryStatus(button) { + const currentUrl = button.getAttribute("data-game-lottery-current-url") || ""; + const statusPanel = document.getElementById("lottery-issue-status"); + + if (!currentUrl || !statusPanel) { + return; + } + + statusPanel.innerHTML = '⏳ 加载中…'; + + try { + const response = await fetch(currentUrl, { + headers: { "Accept": "application/json" }, + }); + const data = await response.json(); + + if (!data.issue) { + statusPanel.innerHTML = '⚠️ 当前无进行中期次,可手动开新期'; + return; + } + + const issue = data.issue; + const pool = Number(issue.pool_amount).toLocaleString(); + const statusMap = { + open: "🟢 购票中", + closed: "🔴 已停售", + settled: "✅ 已开奖", + }; + const superTag = issue.is_super_issue ? " 🎊超级期" : ""; + const drawAt = issue.draw_at ? issue.draw_at.replace("T", " ") : "--"; + + statusPanel.innerHTML = `第 ${issue.issue_no} 期${superTag}  ·  状态:${statusMap[issue.status] || issue.status} +  ·  奖池:💰 ${pool} 金币 +  ·  预计开奖:${drawAt} +  ·  已购:${issue.total_tickets || 0} 注`; + } catch (error) { + statusPanel.innerHTML = '❌ 加载失败'; + } +} + +/** + * 手动开启新一期双色球。 + * + * @param {HTMLButtonElement} button 开期按钮 + * @returns {void} + */ +function openLotteryIssue(button) { + const openUrl = button.getAttribute("data-game-lottery-open-url") || ""; + + if (!openUrl) { + return; + } + + window.adminDialog?.confirm( + '确定要手动开启新一期双色球吗?
仅在无进行中期次时生效,开奖时间将使用当前配置的 draw_hour:draw_minute。', + "手动开新期", + () => { + fetch(openUrl, { + method: "POST", + headers: { + "X-CSRF-TOKEN": getCsrfToken(), + "Accept": "application/json", + }, + }) + .then((response) => response.json()) + .then((data) => { + window.adminDialog?.alert(data.message, data.ok ? "操作成功" : "操作失败", data.ok ? "✅" : "❌"); + if (data.ok) { + const statusButton = document.querySelector("[data-game-lottery-current-url]"); + if (statusButton instanceof HTMLButtonElement) { + void loadLotteryStatus(statusButton); + } + } + }) + .catch(() => window.adminDialog?.alert("网络错误,请重试", "网络错误", "🌐")); + }, + "➕", + ); +} + +/** + * 强制提前开奖,用于测试或管理需要。 + * + * @param {HTMLButtonElement} button 强制开奖按钮 + * @returns {void} + */ +function forceLotteryDraw(button) { + const drawUrl = button.getAttribute("data-game-lottery-force-url") || ""; + + if (!drawUrl) { + return; + } + + window.adminDialog?.confirm( + '确定要立即强制开奖吗?
将对当前 closed 或 open 期次立即执行开奖,此操作不可撤销!', + "强制开奖确认", + () => { + fetch(drawUrl, { + method: "POST", + headers: { + "X-CSRF-TOKEN": getCsrfToken(), + "Accept": "application/json", + }, + }) + .then((response) => response.json()) + .then((data) => { + window.adminDialog?.alert(data.message, data.ok ? "开奖完成" : "操作失败", data.ok ? "🎊" : "❌"); + if (data.ok) { + const statusButton = document.querySelector("[data-game-lottery-current-url]"); + if (statusButton instanceof HTMLButtonElement) { + void loadLotteryStatus(statusButton); + } + } + }) + .catch(() => window.adminDialog?.alert("网络错误,请重试", "网络错误", "🌐")); + }, + "🎊", + ); +} + /** * 绑定游戏管理页通用操作按钮。 * @@ -248,6 +422,56 @@ export function bindAdminGameConfigControls() { if (toggleButton instanceof HTMLButtonElement) { event.preventDefault(); void toggleGame(toggleButton); + return; + } + + const dropBoxButton = event.target.closest("[data-game-drop-box-type]"); + if (dropBoxButton instanceof HTMLButtonElement) { + event.preventDefault(); + dropMysteryBox(dropBoxButton); + return; + } + + const lotteryStatusButton = event.target.closest("[data-game-lottery-current-url]"); + if (lotteryStatusButton instanceof HTMLButtonElement) { + event.preventDefault(); + void loadLotteryStatus(lotteryStatusButton); + return; + } + + const lotteryOpenButton = event.target.closest("[data-game-lottery-open-url]"); + if (lotteryOpenButton instanceof HTMLButtonElement) { + event.preventDefault(); + openLotteryIssue(lotteryOpenButton); + return; + } + + const lotteryForceButton = event.target.closest("[data-game-lottery-force-url]"); + if (lotteryForceButton instanceof HTMLButtonElement) { + event.preventDefault(); + forceLotteryDraw(lotteryForceButton); + } + }); + + document.addEventListener("mouseover", (event) => { + if (!(event.target instanceof Element)) { + return; + } + + const hoverButton = event.target.closest("[data-game-hover-opacity]"); + if (hoverButton instanceof HTMLElement) { + hoverButton.style.opacity = hoverButton.getAttribute("data-game-hover-opacity") || ""; + } + }); + + document.addEventListener("mouseout", (event) => { + if (!(event.target instanceof Element)) { + return; + } + + const hoverButton = event.target.closest("[data-game-hover-opacity]"); + if (hoverButton instanceof HTMLElement) { + hoverButton.style.opacity = "1"; } }); } diff --git a/resources/views/admin/game-configs/index.blade.php b/resources/views/admin/game-configs/index.blade.php index a7ac5ab..6b51513 100644 --- a/resources/views/admin/game-configs/index.blade.php +++ b/resources/views/admin/game-configs/index.blade.php @@ -157,19 +157,22 @@
🎯 手动投放箱子
- - - 直接向 #1 房间投放,立即广播暗号 @@ -187,19 +190,19 @@ ⏳ 点击下方「加载期次状态」查看当前状态
- - - 开新期仅在无进行中期次时生效;强制开奖将提前结束当期 @@ -219,140 +222,6 @@
- - @endsection @php