## 新功能 - 神秘箱子系统(MysteryBox)完整实现: - 新增 MysteryBox / MysteryBoxClaim 模型及迁移文件 - DropMysteryBoxJob / ExpireMysteryBoxJob 队列作业 - MysteryBoxController(/mystery-box/status + /mystery-box/claim) - 支持三种类型:普通箱(500~2000金)/ 稀有箱(5000~20000金)/ 黑化箱(陷阱扣200~1000金) - 调度器自动投放 + 管理员手动投放 - CurrencySource 新增 MYSTERY_BOX / MYSTERY_BOX_TRAP 枚举 - 婚姻状态弹窗(工具栏「婚姻」按钮): - 工具栏「呼叫」改为「婚姻」,点击打开婚姻状态弹窗 - 动态渲染三种状态:单身 / 求婚中 / 已婚 - 被求婚方可直接「答应 / 婉拒」;已婚可申请离婚(含二次确认) ## 优化修复 - frame.blade.php:Alpine.js CDN 补加 defer,修复所有组件初始化报错 - scripts.blade.php:神秘箱子暗号主动拦截(不依赖轮询),领取成功后弹 chatDialog 展示结果,更新金币余额 - MysteryBoxController:claim() 时 change() 补传 room_id 记录来源房间 - 后台游戏管理页(game-configs):投放箱子按钮颜色修复;弹窗替换为 window.adminDialog - admin/layouts:新增全局 adminDialog 弹窗组件(替代原生 alert/confirm) - baccarat-panel:FAB 拖动重构为 Alpine.js baccaratFab() 组件,与 slotFab 一致 - GAMES_TODO.md:神秘箱子移入已完成区,补全修复记录
105 lines
3.3 KiB
PHP
105 lines
3.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 文件功能:游戏配置后台管理控制器
|
|
*
|
|
* 管理员可在此页面统一管理所有娱乐游戏的开关状态和核心参数。
|
|
* 每个游戏的参数说明通过前端渲染,后台只做通用 JSON 存储。
|
|
*
|
|
* @author ChatRoom Laravel
|
|
*
|
|
* @version 1.0.0
|
|
*/
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\GameConfig;
|
|
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}」参数已保存!");
|
|
}
|
|
|
|
/**
|
|
* 管理员手动投放神秘箱子。
|
|
*
|
|
* 立即分发 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([
|
|
'ok' => true,
|
|
'message' => "✅ 已投放「{$typeNames[$boxType]}」到 #1 房间,暗号将实时发送到公屏!",
|
|
]);
|
|
}
|
|
}
|