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('网络错误,请重试', '网络错误', '🌐')); + }, '🎊' + ); + }