一、钓鱼全局开关
- 钓鱼纳入 GameConfig(game_key=fishing),游戏管理页可一键开关
- cast() 接口加开关校验,关闭时返回 403 友好提示
- GameConfigSeeder 新增 fishing 配置(含4个参数)
二、钓鱼事件数据库化
- 新建 fishing_events 表(emoji/name/message/exp/jjb/weight/is_active/sort)
- FishingEvent 模型含 rollOne() 加权随机方法
- FishingEventSeeder 填充7条初始事件(经验降低、金币提升)
- FishingController::randomFishResult() 改为读数据库事件
三、钓鱼参数迁移至 GameConfig
- fishing_cost/wait_min/wait_max/cooldown 改为 GameConfig::param() 读取
- 保留 Sysparam fallback 兼容旧数据
四、后台管理页面
- 新建 FishingEventController(CRUD + AJAX toggle)
- 新建 admin/fishing/index.blade.php(事件列表+概率显示+编辑弹窗)
- 侧边栏「游戏管理」下方新增「🎣 钓鱼事件」入口
- 游戏管理视图 gameParamLabels 新增钓鱼参数标签
109 lines
3.3 KiB
PHP
109 lines
3.3 KiB
PHP
<?php
|
||
|
||
/**
|
||
* 文件功能:钓鱼事件后台管理控制器
|
||
* 提供钓鱼事件的列表展示、创建、编辑、删除、启用/禁用功能
|
||
*
|
||
* @author ChatRoom Laravel
|
||
*
|
||
* @version 1.0.0
|
||
*/
|
||
|
||
namespace App\Http\Controllers\Admin;
|
||
|
||
use App\Http\Controllers\Controller;
|
||
use App\Models\FishingEvent;
|
||
use Illuminate\Http\JsonResponse;
|
||
use Illuminate\Http\RedirectResponse;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\View\View;
|
||
|
||
class FishingEventController extends Controller
|
||
{
|
||
/**
|
||
* 显示所有钓鱼事件列表
|
||
*/
|
||
public function index(): View
|
||
{
|
||
$events = FishingEvent::orderBy('sort')->orderBy('id')->get();
|
||
$totalWeight = $events->where('is_active', true)->sum('weight');
|
||
|
||
return view('admin.fishing.index', compact('events', 'totalWeight'));
|
||
}
|
||
|
||
/**
|
||
* 创建新钓鱼事件
|
||
*/
|
||
public function store(Request $request): RedirectResponse
|
||
{
|
||
$data = $request->validate([
|
||
'emoji' => 'required|string|max:10',
|
||
'name' => 'required|string|max:100',
|
||
'message' => 'required|string|max:255',
|
||
'exp' => 'required|integer',
|
||
'jjb' => 'required|integer',
|
||
'weight' => 'required|integer|min:1|max:9999',
|
||
'sort' => 'required|integer|min:0',
|
||
'is_active' => 'boolean',
|
||
]);
|
||
|
||
$data['is_active'] = $request->boolean('is_active', true);
|
||
FishingEvent::create($data);
|
||
|
||
return redirect()->route('admin.fishing.index')->with('success', '钓鱼事件已添加!');
|
||
}
|
||
|
||
/**
|
||
* 更新钓鱼事件
|
||
*
|
||
* @param FishingEvent $fishing 路由模型绑定
|
||
*/
|
||
public function update(Request $request, FishingEvent $fishing): RedirectResponse
|
||
{
|
||
$data = $request->validate([
|
||
'emoji' => 'required|string|max:10',
|
||
'name' => 'required|string|max:100',
|
||
'message' => 'required|string|max:255',
|
||
'exp' => 'required|integer',
|
||
'jjb' => 'required|integer',
|
||
'weight' => 'required|integer|min:1|max:9999',
|
||
'sort' => 'required|integer|min:0',
|
||
'is_active' => 'boolean',
|
||
]);
|
||
|
||
$data['is_active'] = $request->boolean('is_active');
|
||
$fishing->update($data);
|
||
|
||
return redirect()->route('admin.fishing.index')->with('success', "事件「{$fishing->name}」已更新!");
|
||
}
|
||
|
||
/**
|
||
* 切换事件启用/禁用状态(AJAX)
|
||
*
|
||
* @param FishingEvent $fishing 路由模型绑定
|
||
*/
|
||
public function toggle(FishingEvent $fishing): JsonResponse
|
||
{
|
||
$fishing->update(['is_active' => ! $fishing->is_active]);
|
||
|
||
return response()->json([
|
||
'ok' => true,
|
||
'is_active' => $fishing->is_active,
|
||
'message' => $fishing->is_active ? "「{$fishing->name}」已启用" : "「{$fishing->name}」已禁用",
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* 删除钓鱼事件
|
||
*
|
||
* @param FishingEvent $fishing 路由模型绑定
|
||
*/
|
||
public function destroy(FishingEvent $fishing): RedirectResponse
|
||
{
|
||
$name = $fishing->name;
|
||
$fishing->delete();
|
||
|
||
return redirect()->route('admin.fishing.index')->with('success', "事件「{$name}」已删除!");
|
||
}
|
||
}
|