新增:双色球彩票后台管理(阶段三)

🎛️ 后台游戏配置页
  - lottery 参数标签完整配置(14个参数分组展示)
    开奖时间/购票限制/奖池分配/固定小奖/超级期
  - 双色球专属手动操作区(仿神秘箱子风格)
     当前期次状态展示(实时加载)
     手动开新期(含确认弹窗)
     强制立即开奖(含二次确认防误触)

🔌 后台接口
  - POST /admin/lottery/open-issue  手动开期
  - POST /admin/lottery/force-draw  强制开奖
  - GameConfigController 新增两个 JsonResponse 方法

📋 全局开关
  - 与所有现有游戏一致,后台 toggle 即时生效(60s缓存刷新)
  - 默认关闭,管理员开启后调度器自动接管
This commit is contained in:
2026-03-04 15:47:09 +08:00
parent 4114571040
commit b13861c869
3 changed files with 231 additions and 6 deletions
@@ -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} 期将就绪开奖!"]);
}
}
@@ -158,6 +158,36 @@
</div>
</div>
@endif
{{-- 双色球彩票:手动操作区域 --}}
@if ($game->game_key === 'lottery')
<div class="mt-4 pt-4 border-t border-gray-100">
<div class="text-xs font-bold text-gray-600 mb-3">🎟️ 手动操作</div>
{{-- 当前期次状态展示 --}}
<div id="lottery-issue-status"
class="mb-3 text-xs text-gray-500 bg-red-50 border border-red-100 rounded-lg p-3">
<span class="text-red-400"> 点击下方「加载期次状态」查看当前状态</span>
</div>
<div class="flex items-center gap-3 flex-wrap">
<button onclick="lotteryLoadStatus()"
style="padding:8px 16px; background:linear-gradient(135deg,#475569,#64748b); color:#fff; border:none; border-radius:8px; font-size:13px; font-weight:700; cursor:pointer; transition:opacity .15s;"
onmouseover="this.style.opacity='.85'" onmouseout="this.style.opacity='1'">
🔄 加载期次状态
</button>
<button onclick="lotteryOpenIssue()"
style="padding:8px 16px; background:linear-gradient(135deg,#059669,#10b981); color:#fff; border:none; border-radius:8px; font-size:13px; font-weight:700; cursor:pointer; transition:opacity .15s;"
onmouseover="this.style.opacity='.85'" onmouseout="this.style.opacity='1'">
手动开新期
</button>
<button onclick="lotteryForceDraw()"
style="padding:8px 16px; background:linear-gradient(135deg,#dc2626,#ef4444); color:#fff; border:none; border-radius:8px; font-size:13px; font-weight:700; cursor:pointer; transition:opacity .15s;"
onmouseover="this.style.opacity='.85'" onmouseout="this.style.opacity='1'">
🎊 立即强制开奖
</button>
<span class="text-xs text-gray-400">开新期仅在无进行中期次时生效;强制开奖将提前结束当期</span>
</div>
</div>
@endif
</div>
</div>
@endforeach
@@ -263,6 +293,90 @@
icon
);
}
/**
* 加载双色球当前期次状态
*/
function lotteryLoadStatus() {
const box = document.getElementById('lottery-issue-status');
box.innerHTML = '<span class="text-gray-400">⏳ 加载中…</span>';
fetch('/lottery/current', {
headers: {
'Accept': 'application/json'
}
})
.then(r => r.json())
.then(data => {
if (!data.issue) {
box.innerHTML = '<span class="text-orange-500">⚠️ 当前无进行中期次,可手动开新期</span>';
return;
}
const iss = data.issue;
const pool = Number(iss.pool_amount).toLocaleString();
const statusMap = {
open: '🟢 购票中',
closed: '🔴 已停售',
settled: '✅ 已开奖'
};
const superTag = iss.is_super_issue ? ' 🎊<b>超级期</b>' : '';
const drawAt = iss.draw_at ? iss.draw_at.replace('T', ' ') : '--';
box.innerHTML = ` <b>${iss.issue_no}</b> ${superTag} &nbsp;·&nbsp; 状态:${statusMap[iss.status] || iss.status}
&nbsp;·&nbsp; 奖池:<b style="color:#dc2626">💰 ${pool} 金币</b>
&nbsp;·&nbsp; 预计开奖:${drawAt}
&nbsp;·&nbsp; 已购:${iss.total_tickets || 0} `;
})
.catch(() => {
box.innerHTML = '<span class="text-red-400">❌ 加载失败</span>';
});
}
/**
* 手动开启新一期双色球
*/
function lotteryOpenIssue() {
window.adminDialog.confirm(
'确定要手动开启新一期双色球吗?<br><span style="color:#64748b;font-size:12px;">仅在无进行中期次时生效,开奖时间将使用当前配置的 draw_hour:draw_minute。</span>',
'手动开新期', () => {
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(
'确定要<b style="color:red">立即强制开奖</b>吗?<br><span style="color:#64748b;font-size:12px;">将对当前 closed 或 open 期次立即执行开奖,此操作不可撤销!</span>',
'强制开奖确认', () => {
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('网络错误,请重试', '网络错误', '🌐'));
}, '🎊'
);
}
</script>
<script>
@@ -383,11 +497,11 @@
</div>
<div class="space-y-1.5">
${card.items.map(item => `
<div class="flex justify-between text-xs">
<span class="text-gray-500">${item.label}</span>
<span class="font-bold text-gray-700">${item.value}</span>
</div>
`).join('')}
<div class="flex justify-between text-xs">
<span class="text-gray-500">${item.label}</span>
<span class="font-bold text-gray-700">${item.value}</span>
</div>
`).join('')}
</div>
</div>
`).join('');
@@ -501,6 +615,68 @@
'fishing_wait_max' => ['label' => '浮漂等待最长', 'type' => 'number', 'unit' => '秒', 'min' => 1],
'fishing_cooldown' => ['label' => '收竿后冷却时间', 'type' => 'number', 'unit' => '秒', 'min' => 10],
],
'lottery' => [
// ── 开奖时间 ──
'draw_hour' => [
'label' => '开奖时(24h制)',
'type' => 'number',
'unit' => '时',
'min' => 0,
'max' => 23,
],
'draw_minute' => ['label' => '开奖分', 'type' => 'number', 'unit' => '分', 'min' => 0, 'max' => 59],
'stop_sell_minutes' => ['label' => '停售提前', 'type' => 'number', 'unit' => '分钟', 'min' => 1],
// ── 购票限制 ──
'ticket_price' => ['label' => '每注金额', 'type' => 'number', 'unit' => '金币', 'min' => 1],
'max_tickets_per_user' => ['label' => '单人每期上限', 'type' => 'number', 'unit' => '注', 'min' => 1],
'max_tickets_per_buy' => ['label' => '单次购买上限', 'type' => 'number', 'unit' => '注', 'min' => 1],
// ── 奖池分配 ──
'pool_ratio' => [
'label' => '购票进奖池比例',
'type' => 'number',
'unit' => '%',
'min' => 1,
'max' => 100,
],
'prize_1st_ratio' => [
'label' => '一等奖占奖池',
'type' => 'number',
'unit' => '%',
'min' => 1,
'max' => 100,
],
'prize_2nd_ratio' => [
'label' => '二等奖占奖池',
'type' => 'number',
'unit' => '%',
'min' => 1,
'max' => 100,
],
'prize_3rd_ratio' => [
'label' => '三等奖占奖池',
'type' => 'number',
'unit' => '%',
'min' => 1,
'max' => 100,
],
'carry_ratio' => ['label' => '强制滚存', 'type' => 'number', 'unit' => '%', 'min' => 0, 'max' => 50],
// ── 固定小奖 ──
'prize_4th_fixed' => ['label' => '四等奖固定金额/注', 'type' => 'number', 'unit' => '金币', 'min' => 0],
'prize_5th_fixed' => ['label' => '五等奖固定金额/注', 'type' => 'number', 'unit' => '金币', 'min' => 0],
// ── 超级期 ──
'super_issue_threshold' => [
'label' => '超级期触发连续无一等奖',
'type' => 'number',
'unit' => '期',
'min' => 1,
],
'super_issue_inject' => [
'label' => '超级期系统注入上限',
'type' => 'number',
'unit' => '金币',
'min' => 0,
],
],
default => [],
};
}
+4
View File
@@ -428,6 +428,10 @@ Route::middleware(['chat.auth', 'chat.has_position'])->prefix('admin')->name('ad
// 📦 神秘箱子:管理员手动投放
Route::post('/mystery-box/drop', [\App\Http\Controllers\Admin\GameConfigController::class, 'dropMysteryBox'])->name('mystery-box.drop');
// 🎟️ 双色球彩票:管理员手动操作
Route::post('/lottery/open-issue', [\App\Http\Controllers\Admin\GameConfigController::class, 'openLotteryIssue'])->name('lottery.open-issue');
Route::post('/lottery/force-draw', [\App\Http\Controllers\Admin\GameConfigController::class, 'forceLotteryDraw'])->name('lottery.force-draw');
// 🎣 钓鱼事件管理
Route::prefix('fishing')->name('fishing.')->group(function () {
Route::get('/', [\App\Http\Controllers\Admin\FishingEventController::class, 'index'])->name('index');