73 lines
1.9 KiB
PHP
73 lines
1.9 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}」参数已保存!");
|
||
|
|
}
|
||
|
|
}
|