From b13861c869b6841337395676c9551d2118de99c2 Mon Sep 17 00:00:00 2001 From: lkddi Date: Wed, 4 Mar 2026 15:47:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=8F=8C=E8=89=B2?= =?UTF-8?q?=E7=90=83=E5=BD=A9=E7=A5=A8=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=EF=BC=88=E9=98=B6=E6=AE=B5=E4=B8=89=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🎛️ 后台游戏配置页 - lottery 参数标签完整配置(14个参数分组展示) 开奖时间/购票限制/奖池分配/固定小奖/超级期 - 双色球专属手动操作区(仿神秘箱子风格) ✅ 当前期次状态展示(实时加载) ✅ 手动开新期(含确认弹窗) ✅ 强制立即开奖(含二次确认防误触) 🔌 后台接口 - POST /admin/lottery/open-issue 手动开期 - POST /admin/lottery/force-draw 强制开奖 - GameConfigController 新增两个 JsonResponse 方法 📋 全局开关 - 与所有现有游戏一致,后台 toggle 即时生效(60s缓存刷新) - 默认关闭,管理员开启后调度器自动接管 --- .../Admin/GameConfigController.php | 47 ++++- .../views/admin/game-configs/index.blade.php | 186 +++++++++++++++++- routes/web.php | 4 + 3 files changed, 231 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Admin/GameConfigController.php b/app/Http/Controllers/Admin/GameConfigController.php index 70813d8..43d92ff 100644 --- a/app/Http/Controllers/Admin/GameConfigController.php +++ b/app/Http/Controllers/Admin/GameConfigController.php @@ -15,6 +15,8 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\GameConfig; +use App\Models\LotteryIssue; +use App\Services\LotteryService; use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; @@ -97,8 +99,51 @@ class GameConfigController extends Controller $typeNames = ['normal' => '普通箱', 'rare' => '稀有箱', 'trap' => '黑化箱']; return response()->json([ - 'ok' => true, + 'ok' => true, 'message' => "✅ 已投放「{$typeNames[$boxType]}」到 #1 房间,暗号将实时发送到公屏!", ]); } + + /** + * 手动开启新一期双色球彩票。 + * + * 仅在当前无进行中期次时生效,防止重复开期。 + */ + public function openLotteryIssue(): JsonResponse + { + if (! GameConfig::isEnabled('lottery')) { + return response()->json(['ok' => false, 'message' => '双色球彩票未开启,请先开启游戏。']); + } + + if (LotteryIssue::currentIssue()) { + return response()->json(['ok' => false, 'message' => '当前已有进行中的期次,无需重复开期。']); + } + + \App\Jobs\OpenLotteryIssueJob::dispatch(); + + return response()->json(['ok' => true, 'message' => '✅ 已排队开期任务,新期次将就绪建立!']); + } + + /** + * 管理员强制立即开奖(测试专用)。 + * + * 将当前 open 或 closed 期次直接投入开奖队列。 + */ + public function forceLotteryDraw(LotteryService $lottery): JsonResponse + { + $issue = LotteryIssue::query() + ->whereIn('status', ['open', 'closed']) + ->latest() + ->first(); + + if (! $issue) { + return response()->json(['ok' => false, 'message' => '当前无可开奖的期次。']); + } + + // 强制将状态改为 closed + $issue->update(['status' => 'closed']); + \App\Jobs\DrawLotteryJob::dispatch($issue->fresh()); + + return response()->json(['ok' => true, 'message' => "✅ 开奖任务已入队,第 {$issue->issue_no} 期将就绪开奖!"]); + } } diff --git a/resources/views/admin/game-configs/index.blade.php b/resources/views/admin/game-configs/index.blade.php index c9f140a..db28d28 100644 --- a/resources/views/admin/game-configs/index.blade.php +++ b/resources/views/admin/game-configs/index.blade.php @@ -158,6 +158,36 @@ @endif + + {{-- 双色球彩票:手动操作区域 --}} + @if ($game->game_key === 'lottery') +
+
🎟️ 手动操作
+ {{-- 当前期次状态展示 --}} +
+ ⏳ 点击下方「加载期次状态」查看当前状态 +
+
+ + + + 开新期仅在无进行中期次时生效;强制开奖将提前结束当期 +
+
+ @endif @endforeach @@ -263,6 +293,90 @@ icon ); } + + /** + * 加载双色球当前期次状态 + */ + function lotteryLoadStatus() { + const box = document.getElementById('lottery-issue-status'); + box.innerHTML = '⏳ 加载中…'; + fetch('/lottery/current', { + headers: { + 'Accept': 'application/json' + } + }) + .then(r => r.json()) + .then(data => { + if (!data.issue) { + box.innerHTML = '⚠️ 当前无进行中期次,可手动开新期'; + return; + } + const iss = data.issue; + const pool = Number(iss.pool_amount).toLocaleString(); + const statusMap = { + open: '🟢 购票中', + closed: '🔴 已停售', + settled: '✅ 已开奖' + }; + const superTag = iss.is_super_issue ? ' 🎊超级期' : ''; + const drawAt = iss.draw_at ? iss.draw_at.replace('T', ' ') : '--'; + box.innerHTML = `第 ${iss.issue_no} 期${superTag}  ·  状态:${statusMap[iss.status] || iss.status} +  ·  奖池:💰 ${pool} 金币 +  ·  预计开奖:${drawAt} +  ·  已购:${iss.total_tickets || 0} 注`; + }) + .catch(() => { + box.innerHTML = '❌ 加载失败'; + }); + } + + /** + * 手动开启新一期双色球 + */ + function lotteryOpenIssue() { + window.adminDialog.confirm( + '确定要手动开启新一期双色球吗?
仅在无进行中期次时生效,开奖时间将使用当前配置的 draw_hour:draw_minute。', + '手动开新期', () => { + fetch('/admin/lottery/open-issue', { + method: 'POST', + headers: { + 'X-CSRF-TOKEN': '{{ csrf_token() }}', + 'Accept': 'application/json' + }, + }) + .then(r => r.json()) + .then(d => { + window.adminDialog.alert(d.message, d.ok ? '操作成功' : '操作失败', d.ok ? '✅' : '❌'); + if (d.ok) lotteryLoadStatus(); + }) + .catch(() => window.adminDialog.alert('网络错误,请重试', '网络错误', '🌐')); + }, '➕' + ); + } + + /** + * 强制提前开奖(用于测试或管理需要) + */ + function lotteryForceDraw() { + window.adminDialog.confirm( + '确定要立即强制开奖吗?
将对当前 closed 或 open 期次立即执行开奖,此操作不可撤销!', + '强制开奖确认', () => { + fetch('/admin/lottery/force-draw', { + method: 'POST', + headers: { + 'X-CSRF-TOKEN': '{{ csrf_token() }}', + 'Accept': 'application/json' + }, + }) + .then(r => r.json()) + .then(d => { + window.adminDialog.alert(d.message, d.ok ? '开奖完成' : '操作失败', d.ok ? '🎊' : '❌'); + if (d.ok) lotteryLoadStatus(); + }) + .catch(() => window.adminDialog.alert('网络错误,请重试', '网络错误', '🌐')); + }, '🎊' + ); + }