2026-03-01 20:17:18 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文件功能:游戏配置后台管理控制器
|
|
|
|
|
*
|
|
|
|
|
* 管理员可在此页面统一管理所有娱乐游戏的开关状态和核心参数。
|
|
|
|
|
* 每个游戏的参数说明通过前端渲染,后台只做通用 JSON 存储。
|
|
|
|
|
*
|
|
|
|
|
* @author ChatRoom Laravel
|
|
|
|
|
*
|
|
|
|
|
* @version 1.0.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Models\GameConfig;
|
2026-03-04 15:47:09 +08:00
|
|
|
use App\Models\LotteryIssue;
|
|
|
|
|
use App\Services\LotteryService;
|
2026-03-01 20:17:18 +08:00
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
|
|
class GameConfigController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* 游戏管理总览页面。
|
|
|
|
|
*/
|
|
|
|
|
public function index(): View
|
|
|
|
|
{
|
|
|
|
|
$games = GameConfig::orderBy('id')->get();
|
|
|
|
|
|
|
|
|
|
return view('admin.game-configs.index', compact('games'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 切换游戏开启/关闭状态。
|
|
|
|
|
*/
|
|
|
|
|
public function toggle(GameConfig $gameConfig): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
$gameConfig->update(['enabled' => ! $gameConfig->enabled]);
|
|
|
|
|
$gameConfig->clearCache();
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'ok' => true,
|
|
|
|
|
'enabled' => $gameConfig->enabled,
|
|
|
|
|
'message' => $gameConfig->enabled
|
|
|
|
|
? "「{$gameConfig->name}」已开启"
|
|
|
|
|
: "「{$gameConfig->name}」已关闭",
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存游戏核心参数。
|
|
|
|
|
*
|
|
|
|
|
* 接收前端提交的 params JSON 对象并合并至现有配置。
|
|
|
|
|
*/
|
|
|
|
|
public function updateParams(Request $request, GameConfig $gameConfig): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$request->validate([
|
|
|
|
|
'params' => 'required|array',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// 合并参数,保留已有键,只更新传入的键
|
|
|
|
|
$current = $gameConfig->params ?? [];
|
|
|
|
|
$updated = array_merge($current, $request->input('params'));
|
|
|
|
|
|
|
|
|
|
$gameConfig->update(['params' => $updated]);
|
|
|
|
|
$gameConfig->clearCache();
|
|
|
|
|
|
|
|
|
|
return back()->with('success', "「{$gameConfig->name}」参数已保存!");
|
|
|
|
|
}
|
2026-03-03 19:29:43 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 管理员手动投放神秘箱子。
|
|
|
|
|
*
|
|
|
|
|
* 立即分发 DropMysteryBoxJob 到队列,由 Horizon 执行箱子投放和公屏广播。
|
|
|
|
|
*/
|
|
|
|
|
public function dropMysteryBox(Request $request): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
if (! \App\Models\GameConfig::isEnabled('mystery_box')) {
|
|
|
|
|
return response()->json(['ok' => false, 'message' => '神秘箱子功能未开放,请先开启。']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$boxType = $request->input('box_type', 'normal');
|
|
|
|
|
|
|
|
|
|
if (! in_array($boxType, ['normal', 'rare', 'trap'], true)) {
|
|
|
|
|
return response()->json(['ok' => false, 'message' => '无效的箱子类型。']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查是否有正在开放的箱子(避免同时多个)
|
|
|
|
|
if (\App\Models\MysteryBox::currentOpenBox()) {
|
|
|
|
|
return response()->json(['ok' => false, 'message' => '当前已有一个神秘箱子正在等待领取,请等它结束后再投放。']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
\App\Jobs\DropMysteryBoxJob::dispatch($boxType, 1, null, (int) auth()->id());
|
|
|
|
|
|
|
|
|
|
$typeNames = ['normal' => '普通箱', 'rare' => '稀有箱', 'trap' => '黑化箱'];
|
|
|
|
|
|
|
|
|
|
return response()->json([
|
2026-03-04 15:47:09 +08:00
|
|
|
'ok' => true,
|
2026-03-03 19:29:43 +08:00
|
|
|
'message' => "✅ 已投放「{$typeNames[$boxType]}」到 #1 房间,暗号将实时发送到公屏!",
|
|
|
|
|
]);
|
|
|
|
|
}
|
2026-03-04 15:47:09 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 手动开启新一期双色球彩票。
|
|
|
|
|
*
|
|
|
|
|
* 仅在当前无进行中期次时生效,防止重复开期。
|
|
|
|
|
*/
|
|
|
|
|
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} 期将就绪开奖!"]);
|
|
|
|
|
}
|
2026-03-01 20:17:18 +08:00
|
|
|
}
|