优化 后台等级设置
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台等级经验阈值配置控制器
|
||||
*
|
||||
* 将 sysparam 表中的 levelexp 配置拆分为独立后台页面,
|
||||
* 以列表模式维护每一级所需的累计经验值。
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\UpdateLevelExpConfigRequest;
|
||||
use App\Models\Sysparam;
|
||||
use App\Services\ChatStateService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* 类功能:负责展示和保存等级经验阈值列表。
|
||||
*/
|
||||
class LevelExpConfigController extends Controller
|
||||
{
|
||||
/**
|
||||
* 方法功能:注入系统参数缓存同步服务。
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly ChatStateService $chatState
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 方法功能:显示等级经验阈值列表页。
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$rawThresholds = Sysparam::getLevelExpThresholds();
|
||||
$maxLevel = (int) Sysparam::getValue('maxlevel', '99');
|
||||
|
||||
$thresholds = collect($rawThresholds)
|
||||
->values()
|
||||
->map(fn (int $exp, int $index): array => [
|
||||
'level' => $index + 1,
|
||||
'exp' => $exp,
|
||||
'increment' => $index === 0 ? $exp : $exp - $rawThresholds[$index - 1],
|
||||
]);
|
||||
|
||||
return view('admin.level-exp-configs.index', [
|
||||
'thresholds' => $thresholds,
|
||||
'maxLevel' => $maxLevel,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:保存等级经验阈值配置,并同步刷新缓存。
|
||||
*/
|
||||
public function update(UpdateLevelExpConfigRequest $request): RedirectResponse
|
||||
{
|
||||
$thresholds = $request->validated('thresholds');
|
||||
|
||||
// 将列表页提交的阈值重新拼成兼容旧逻辑的逗号字符串。
|
||||
$body = implode(',', $thresholds);
|
||||
|
||||
Sysparam::updateOrCreate(
|
||||
['alias' => 'levelexp'],
|
||||
[
|
||||
'body' => $body,
|
||||
'guidetxt' => '按列表逐级维护升级所需的累计经验阈值',
|
||||
]
|
||||
);
|
||||
|
||||
// 同步更新 Redis / Cache,确保前台经验等级计算即时生效。
|
||||
$this->chatState->setSysParam('levelexp', $body);
|
||||
Sysparam::clearCache('levelexp');
|
||||
|
||||
return redirect()->route('admin.level-exp-configs.index')->with('success', '等级经验阈值已保存并生效!');
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,14 @@ class SystemController extends Controller
|
||||
// 只接受通用系统页白名单内的字段,忽略任何伪造提交的敏感键。
|
||||
$data = $request->only($this->editableSystemAliases());
|
||||
|
||||
if (array_key_exists('maxlevel', $data)) {
|
||||
$normalizedMaxLevel = max(1, (int) $data['maxlevel']);
|
||||
|
||||
// 管理员级别始终跟随最高等级 + 1,避免两个配置页出现口径漂移。
|
||||
$data['maxlevel'] = (string) $normalizedMaxLevel;
|
||||
$data['superlevel'] = (string) ($normalizedMaxLevel + 1);
|
||||
}
|
||||
|
||||
foreach ($data as $alias => $body) {
|
||||
$normalizedBody = (string) $body;
|
||||
|
||||
@@ -88,7 +96,7 @@ class SystemController extends Controller
|
||||
return SysParam::query()
|
||||
->orderBy('id')
|
||||
->pluck('alias')
|
||||
->filter(fn (string $alias): bool => ! $this->isSensitiveAlias($alias))
|
||||
->filter(fn (string $alias): bool => ! $this->isSensitiveAlias($alias) && ! $this->isDedicatedAlias($alias))
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
@@ -104,4 +112,12 @@ class SystemController extends Controller
|
||||
|
||||
return Str::endsWith($alias, ['_password', '_secret', '_token', '_key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断参数是否已经迁移到独立配置页。
|
||||
*/
|
||||
private function isDedicatedAlias(string $alias): bool
|
||||
{
|
||||
return in_array($alias, ['levelexp'], true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:校验后台等级经验阈值配置请求
|
||||
*
|
||||
* 约束管理员以列表模式提交的每级经验值,
|
||||
* 确保阈值为正整数且严格递增。
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\Sysparam;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* 类功能:验证等级经验阈值列表的结构与数值合法性。
|
||||
*/
|
||||
class UpdateLevelExpConfigRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* 方法功能:允许已通过后台鉴权的用户提交该请求。
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:预处理输入,过滤空行并统一转成整数序列。
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$thresholds = collect($this->input('thresholds', []))
|
||||
->map(fn ($value): string => trim((string) $value))
|
||||
->filter(fn (string $value): bool => $value !== '')
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$this->merge([
|
||||
'thresholds' => $thresholds,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:返回等级经验阈值表单的校验规则。
|
||||
*
|
||||
* @return array<string, ValidationRule|array<int, ValidationRule|string>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'thresholds' => ['required', 'array', 'min:1', $this->strictlyIncreasingRule(), $this->maxLevelLimitRule()],
|
||||
'thresholds.*' => ['required', 'integer', 'min:1'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:返回中文校验错误消息。
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'thresholds.required' => '请至少配置一个等级经验阈值。',
|
||||
'thresholds.array' => '等级经验阈值提交格式不正确。',
|
||||
'thresholds.min' => '请至少保留一个等级经验阈值。',
|
||||
'thresholds.*.required' => '等级经验阈值不能为空。',
|
||||
'thresholds.*.integer' => '等级经验阈值必须是整数。',
|
||||
'thresholds.*.min' => '等级经验阈值必须大于 0。',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:自定义校验阈值必须严格递增。
|
||||
*/
|
||||
private function strictlyIncreasingRule(): ValidationRule
|
||||
{
|
||||
return new class implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* 方法功能:执行严格递增校验。
|
||||
*
|
||||
* @param Closure(string): void $fail
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (! is_array($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$previous = null;
|
||||
|
||||
foreach ($value as $index => $threshold) {
|
||||
if (! is_numeric($threshold)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$current = (int) $threshold;
|
||||
|
||||
// 每一级累计经验必须大于前一级,避免等级计算出现倒挂。
|
||||
if ($previous !== null && $current <= $previous) {
|
||||
$fail('等级经验阈值必须按等级从小到大严格递增,第 '.($index + 1).' 级配置不正确。');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$previous = $current;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:校验等级阈值数量不能超过用户最高可达等级。
|
||||
*/
|
||||
private function maxLevelLimitRule(): ValidationRule
|
||||
{
|
||||
return new class((int) Sysparam::getValue('maxlevel', '99')) implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* 方法功能:构造数量上限校验器。
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly int $maxLevel
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 方法功能:执行阈值数量与最高等级的上限校验。
|
||||
*
|
||||
* @param Closure(string): void $fail
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (! is_array($value) || $this->maxLevel < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 阈值行数对应可升级的等级数,不能超过用户最高可达等级。
|
||||
if (count($value) > $this->maxLevel) {
|
||||
$fail('等级经验阈值数量不能超过用户最高可达等级,请先提高最高等级或删除多余等级。');
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -35,18 +35,6 @@
|
||||
<span class="w-32 text-gray-500 inline-block font-sans">PHP 版本:</span>
|
||||
<span class="text-indigo-600">{{ PHP_VERSION }}</span>
|
||||
</li>
|
||||
<li class="flex items-center text-sm font-mono mt-4 pt-4 border-t">
|
||||
<span class="mr-4 text-gray-500 inline-block font-sans items-center flex">队列监控面板</span>
|
||||
<!-- Laravel Horizon 的默认路由前缀由开发者确认或自己改。这里默认是 /horizon -->
|
||||
<a href="{{ url('/horizon') }}" target="_blank"
|
||||
class="text-blue-600 hover:text-blue-800 hover:underline flex items-center">
|
||||
<span>打开 Horizon 控制台</span>
|
||||
<svg class="w-4 h-4 ml-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"></path>
|
||||
</svg>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -64,6 +64,10 @@
|
||||
class="block px-4 py-3 rounded-md transition {{ request()->routeIs('admin.system.*') ? 'bg-indigo-600 font-bold' : 'hover:bg-white/10' }}">
|
||||
{!! '⚙️ 聊天室参数' !!}
|
||||
</a>
|
||||
<a href="{{ route('admin.level-exp-configs.index') }}"
|
||||
class="block px-4 py-3 rounded-md transition {{ request()->routeIs('admin.level-exp-configs.*') ? 'bg-indigo-600 font-bold' : 'hover:bg-white/10' }}">
|
||||
{!! '📶 等级经验阈值' !!}
|
||||
</a>
|
||||
<a href="{{ route('admin.currency-logs.index') }}"
|
||||
class="block px-4 py-3 rounded-md transition {{ request()->routeIs('admin.currency-logs.*') ? 'bg-indigo-600 font-bold' : 'hover:bg-white/10' }}">
|
||||
{!! '💴 用户流水' !!}
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
@extends('admin.layouts.app')
|
||||
|
||||
@section('title', '等级经验阈值管理')
|
||||
|
||||
@section('content')
|
||||
@php require resource_path('views/admin/partials/list-theme.php'); @endphp
|
||||
@php
|
||||
$formThresholds = collect(old('thresholds', $thresholds->pluck('exp')->all()))
|
||||
->map(fn ($value) => trim((string) $value))
|
||||
->filter(fn (string $value) => $value !== '')
|
||||
->values();
|
||||
|
||||
if ($formThresholds->isEmpty()) {
|
||||
$formThresholds = $thresholds->pluck('exp')->map(fn ($value) => (string) $value)->values();
|
||||
}
|
||||
@endphp
|
||||
|
||||
<div class="{{ $adminListPageClass }}">
|
||||
<div class="{{ $adminListHeaderCardClass }}">
|
||||
<p class="{{ $adminListHeaderSubtitleClass }} mt-0">按列表维护每一级升级所需的累计经验值,并统一管理用户最高可达等级与管理员级别。</p>
|
||||
</div>
|
||||
|
||||
<form action="{{ route('admin.level-exp-configs.update') }}" method="POST" class="{{ $adminListCardClass }}">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<div class="grid gap-5 border-b border-gray-100 bg-gray-50 px-6 py-5 md:grid-cols-1">
|
||||
<div class="rounded-xl border border-amber-200 bg-amber-50 px-4 py-4">
|
||||
<div class="text-xs font-semibold uppercase tracking-wider text-amber-700">等级阈值说明</div>
|
||||
<p class="mt-2 text-sm leading-6 text-amber-900">
|
||||
当前页面按列表逐级维护升级经验阈值:每一行对应一个等级,填写“升到该等级所需的累计经验值”。
|
||||
等级阈值必须严格递增,且等级行数不能超过“用户最高可达等级”。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="{{ $adminListTableWrapClass }}">
|
||||
<table class="{{ $adminListTableClass }}">
|
||||
<thead class="{{ $adminListTableHeadRowClass }}">
|
||||
<tr>
|
||||
<th class="{{ $adminListTableHeadCellClass }} w-36">等级</th>
|
||||
<th class="{{ $adminListTableHeadCellClass }}">累计经验阈值</th>
|
||||
<th class="{{ $adminListTableHeadCellClass }}">较上一等级新增</th>
|
||||
<th class="{{ $adminListTableHeadCellClass }} w-28 text-right">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="{{ $adminListTableBodyClass }}" data-level-exp-table-body>
|
||||
@foreach ($formThresholds as $index => $exp)
|
||||
@php
|
||||
$currentExp = (int) $exp;
|
||||
$previousExp = $index === 0 ? 0 : (int) $formThresholds[$index - 1];
|
||||
@endphp
|
||||
<tr class="{{ $adminListTableRowClass }}" data-level-exp-row>
|
||||
<td class="px-4 py-3 {{ $adminListPrimaryTextClass }}" data-level-exp-label>第 {{ $index + 1 }} 级</td>
|
||||
<td class="px-4 py-3">
|
||||
<input type="number" min="1" step="1" name="thresholds[]" value="{{ $exp }}"
|
||||
class="w-full max-w-xs rounded-lg border border-gray-300 px-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
|
||||
required>
|
||||
</td>
|
||||
<td class="px-4 py-3 {{ $adminListBodyTextClass }}" data-level-exp-increment>
|
||||
+{{ number_format($currentExp - $previousExp) }}
|
||||
</td>
|
||||
<td class="px-4 py-3 text-right">
|
||||
<button type="button"
|
||||
class="{{ $adminListActionButtonClass }} bg-red-50 text-red-600 hover:bg-red-100"
|
||||
data-level-exp-remove>
|
||||
删除
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between gap-4 border-t border-gray-100 bg-gray-50 px-6 py-4">
|
||||
<div class="space-y-1">
|
||||
<button type="button" class="{{ $adminListSecondaryButtonClass }}" data-level-exp-add>
|
||||
+ 添加等级
|
||||
</button>
|
||||
<p class="text-xs text-gray-500" data-level-exp-limit-text>
|
||||
当前已配置 {{ $formThresholds->count() }} 个等级阈值,最高可配置到 {{ $maxLevel }} 级。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="{{ $adminListPrimaryButtonClass }}">
|
||||
保存配置
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<template id="level-exp-row-template">
|
||||
<tr class="{{ $adminListTableRowClass }}" data-level-exp-row>
|
||||
<td class="px-4 py-3 {{ $adminListPrimaryTextClass }}" data-level-exp-label></td>
|
||||
<td class="px-4 py-3">
|
||||
<input type="number" min="1" step="1" name="thresholds[]" value=""
|
||||
class="w-full max-w-xs rounded-lg border border-gray-300 px-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:ring-indigo-500"
|
||||
required>
|
||||
</td>
|
||||
<td class="px-4 py-3 {{ $adminListBodyTextClass }}" data-level-exp-increment>--</td>
|
||||
<td class="px-4 py-3 text-right">
|
||||
<button type="button"
|
||||
class="{{ $adminListActionButtonClass }} bg-red-50 text-red-600 hover:bg-red-100"
|
||||
data-level-exp-remove>
|
||||
删除
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const tableBody = document.querySelector('[data-level-exp-table-body]');
|
||||
const addButton = document.querySelector('[data-level-exp-add]');
|
||||
const template = document.querySelector('#level-exp-row-template');
|
||||
const limitText = document.querySelector('[data-level-exp-limit-text]');
|
||||
const maxLevel = {{ $maxLevel }};
|
||||
|
||||
if (!tableBody || !addButton || !template || !limitText) {
|
||||
return;
|
||||
}
|
||||
|
||||
const syncRows = () => {
|
||||
const rows = Array.from(tableBody.querySelectorAll('[data-level-exp-row]'));
|
||||
let previousValue = 0;
|
||||
|
||||
rows.forEach((row, index) => {
|
||||
const label = row.querySelector('[data-level-exp-label]');
|
||||
const input = row.querySelector('input[name=\"thresholds[]\"]');
|
||||
const increment = row.querySelector('[data-level-exp-increment]');
|
||||
const currentValue = Number.parseInt(input?.value ?? '', 10);
|
||||
|
||||
if (label) {
|
||||
label.textContent = `第 ${index + 1} 级`;
|
||||
}
|
||||
|
||||
if (increment) {
|
||||
if (Number.isNaN(currentValue)) {
|
||||
increment.textContent = '--';
|
||||
} else {
|
||||
increment.textContent = `+${(currentValue - previousValue).toLocaleString('zh-CN')}`;
|
||||
}
|
||||
}
|
||||
|
||||
previousValue = Number.isNaN(currentValue) ? previousValue : currentValue;
|
||||
});
|
||||
|
||||
const removeButtons = tableBody.querySelectorAll('[data-level-exp-remove]');
|
||||
removeButtons.forEach((button) => {
|
||||
button.disabled = rows.length === 1;
|
||||
button.classList.toggle('opacity-40', rows.length === 1);
|
||||
button.classList.toggle('cursor-not-allowed', rows.length === 1);
|
||||
});
|
||||
|
||||
limitText.textContent = `当前已配置 ${rows.length} 个等级阈值,最高可配置到 ${maxLevel} 级。`;
|
||||
|
||||
const canAddMore = rows.length < maxLevel;
|
||||
addButton.disabled = !canAddMore;
|
||||
addButton.classList.toggle('opacity-40', !canAddMore);
|
||||
addButton.classList.toggle('cursor-not-allowed', !canAddMore);
|
||||
};
|
||||
|
||||
addButton.addEventListener('click', () => {
|
||||
const currentRows = tableBody.querySelectorAll('[data-level-exp-row]').length;
|
||||
|
||||
if (currentRows >= maxLevel) {
|
||||
syncRows();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const fragment = template.content.cloneNode(true);
|
||||
tableBody.appendChild(fragment);
|
||||
syncRows();
|
||||
|
||||
const inputs = tableBody.querySelectorAll('input[name=\"thresholds[]\"]');
|
||||
inputs[inputs.length - 1]?.focus();
|
||||
});
|
||||
|
||||
tableBody.addEventListener('click', (event) => {
|
||||
const trigger = event.target.closest('[data-level-exp-remove]');
|
||||
|
||||
if (!trigger) {
|
||||
return;
|
||||
}
|
||||
|
||||
const rows = tableBody.querySelectorAll('[data-level-exp-row]');
|
||||
|
||||
if (rows.length <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
trigger.closest('[data-level-exp-row]')?.remove();
|
||||
syncRows();
|
||||
});
|
||||
|
||||
tableBody.addEventListener('input', (event) => {
|
||||
if (event.target.matches('input[name=\"thresholds[]\"]')) {
|
||||
syncRows();
|
||||
}
|
||||
});
|
||||
|
||||
syncRows();
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
@@ -81,6 +81,29 @@
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{{-- 队列监控面板 --}}
|
||||
<div class="border border-gray-200 rounded-xl p-5 hover:shadow-sm transition">
|
||||
<div class="flex items-center gap-3 mb-2">
|
||||
<span class="text-2xl">📈</span>
|
||||
<div>
|
||||
<div class="font-bold text-gray-800 text-sm">队列监控面板</div>
|
||||
<div class="text-xs text-gray-400">Laravel Horizon</div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-xs text-gray-500 mb-4 leading-relaxed">
|
||||
打开 Horizon 控制台查看队列吞吐、失败任务与进程状态。<br>
|
||||
需要排查异步任务堆积、失败重试或 Supervisor 状态时从这里进入。
|
||||
</p>
|
||||
<a href="{{ url('/horizon') }}" target="_blank" rel="noopener noreferrer"
|
||||
class="inline-flex items-center px-4 py-2 bg-indigo-600 text-white rounded-lg text-sm font-bold hover:bg-indigo-700 transition shadow-sm">
|
||||
<span>打开 Horizon 控制台</span>
|
||||
<svg class="w-4 h-4 ml-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||
d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"></path>
|
||||
</svg>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{-- 房间在线名单清理 --}}
|
||||
<div class="border border-red-100 rounded-xl p-5 bg-red-50 hover:shadow-sm transition">
|
||||
<div class="flex items-center gap-3 mb-2">
|
||||
|
||||
@@ -25,13 +25,24 @@
|
||||
@php
|
||||
$fieldValue = (string) $body;
|
||||
$shouldUseTextarea = strlen($fieldValue) > 50 || str_contains($fieldValue, "\n") || str_contains($fieldValue, '<');
|
||||
$isMaxLevelField = $alias === 'maxlevel';
|
||||
$isSuperLevelField = $alias === 'superlevel';
|
||||
@endphp
|
||||
<div>
|
||||
<label class="block text-sm font-bold text-gray-700 mb-2">
|
||||
{{ $descriptions[$alias] ?? $alias }}
|
||||
<span class="text-gray-400 font-normal ml-2">[{{ $alias }}]</span>
|
||||
</label>
|
||||
@if ($shouldUseTextarea)
|
||||
@if ($isMaxLevelField)
|
||||
<p class="mb-2 text-xs text-gray-500">修改后会自动同步管理员级别为“最高等级 + 1”。</p>
|
||||
<input type="number" min="1" step="1" id="system-maxlevel" name="{{ $alias }}" value="{{ $fieldValue }}"
|
||||
class="w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2.5 bg-gray-50 border">
|
||||
@elseif ($isSuperLevelField)
|
||||
<p class="mb-2 text-xs text-gray-500">该值会随“用户最高可达等级”自动计算,仅用于展示当前结果。</p>
|
||||
<input type="number" id="system-superlevel" value="{{ $fieldValue }}"
|
||||
class="w-full border-gray-200 rounded-md shadow-sm p-2.5 bg-gray-100 border text-gray-600"
|
||||
readonly>
|
||||
@elseif ($shouldUseTextarea)
|
||||
<textarea name="{{ $alias }}" rows="4"
|
||||
class="w-full border-gray-300 rounded-md shadow-sm focus:border-indigo-500 focus:ring-indigo-500 p-2.5 bg-gray-50 border whitespace-pre-wrap">{{ $fieldValue }}</textarea>
|
||||
@else
|
||||
@@ -53,4 +64,30 @@
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const maxLevelInput = document.querySelector('#system-maxlevel');
|
||||
const superLevelInput = document.querySelector('#system-superlevel');
|
||||
|
||||
if (!maxLevelInput || !superLevelInput) {
|
||||
return;
|
||||
}
|
||||
|
||||
const syncSuperLevel = () => {
|
||||
const maxLevel = Number.parseInt(maxLevelInput.value ?? '', 10);
|
||||
|
||||
if (Number.isNaN(maxLevel) || maxLevel < 1) {
|
||||
superLevelInput.value = '';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
superLevelInput.value = String(maxLevel + 1);
|
||||
};
|
||||
|
||||
maxLevelInput.addEventListener('input', syncSuperLevel);
|
||||
syncSuperLevel();
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
@@ -445,6 +445,10 @@ Route::middleware(['chat.auth', 'chat.has_position'])->prefix('admin')->name('ad
|
||||
Route::get('/system', [\App\Http\Controllers\Admin\SystemController::class, 'edit'])->name('system.edit');
|
||||
Route::put('/system', [\App\Http\Controllers\Admin\SystemController::class, 'update'])->name('system.update');
|
||||
|
||||
// 等级经验阈值配置
|
||||
Route::get('/level-exp-configs', [\App\Http\Controllers\Admin\LevelExpConfigController::class, 'index'])->name('level-exp-configs.index');
|
||||
Route::put('/level-exp-configs', [\App\Http\Controllers\Admin\LevelExpConfigController::class, 'update'])->name('level-exp-configs.update');
|
||||
|
||||
// 微信机器人配置
|
||||
Route::get('/wechat-bot', [\App\Http\Controllers\Admin\WechatBotController::class, 'edit'])->name('wechat_bot.edit');
|
||||
Route::put('/wechat-bot', [\App\Http\Controllers\Admin\WechatBotController::class, 'update'])->name('wechat_bot.update');
|
||||
|
||||
@@ -61,6 +61,8 @@ class AdminDashboardControllerTest extends TestCase
|
||||
$response->assertOk();
|
||||
$response->assertSee('当前在线人数');
|
||||
$response->assertSee('2');
|
||||
$response->assertDontSee('队列监控面板');
|
||||
$response->assertDontSee('打开 Horizon 控制台');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台等级经验阈值配置页测试
|
||||
*
|
||||
* 覆盖独立菜单页的展示、保存与非法阈值拦截,
|
||||
* 确保 levelexp 已从通用系统参数页中拆分出来单独维护。
|
||||
*/
|
||||
|
||||
namespace Tests\Feature\Feature;
|
||||
|
||||
use App\Models\Sysparam;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 类功能:验证后台等级经验阈值独立配置页的核心行为。
|
||||
*/
|
||||
class AdminLevelExpConfigControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* 方法功能:验证独立配置页会按列表模式展示每一级阈值。
|
||||
*/
|
||||
public function test_level_exp_index_displays_threshold_rows(): void
|
||||
{
|
||||
$this->seedLevelExpParam();
|
||||
$admin = $this->createSuperAdmin();
|
||||
|
||||
$response = $this->actingAs($admin)->get(route('admin.level-exp-configs.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertSee('等级经验阈值管理');
|
||||
$response->assertSee('第 1 级');
|
||||
$response->assertSee('第 3 级');
|
||||
$response->assertSee('10');
|
||||
$response->assertSee('150');
|
||||
$response->assertSee('最高可配置到 99 级');
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:验证独立配置页可保存新的等级经验阈值。
|
||||
*/
|
||||
public function test_level_exp_update_persists_thresholds(): void
|
||||
{
|
||||
$this->seedLevelExpParam();
|
||||
$admin = $this->createSuperAdmin();
|
||||
|
||||
$response = $this->actingAs($admin)->put(route('admin.level-exp-configs.update'), [
|
||||
'thresholds' => ['20', '80', '180', '360'],
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('admin.level-exp-configs.index'));
|
||||
$response->assertSessionHas('success');
|
||||
|
||||
$this->assertDatabaseHas('sysparam', [
|
||||
'alias' => 'levelexp',
|
||||
'body' => '20,80,180,360',
|
||||
]);
|
||||
$this->assertDatabaseHas('sysparam', [
|
||||
'alias' => 'maxlevel',
|
||||
'body' => '99',
|
||||
]);
|
||||
$this->assertDatabaseHas('sysparam', [
|
||||
'alias' => 'superlevel',
|
||||
'body' => '100',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:验证阈值必须严格递增,防止错误配置写入。
|
||||
*/
|
||||
public function test_level_exp_update_requires_strictly_increasing_thresholds(): void
|
||||
{
|
||||
$this->seedLevelExpParam();
|
||||
$admin = $this->createSuperAdmin();
|
||||
|
||||
$response = $this->from(route('admin.level-exp-configs.index'))
|
||||
->actingAs($admin)
|
||||
->put(route('admin.level-exp-configs.update'), [
|
||||
'thresholds' => ['20', '18', '100'],
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('admin.level-exp-configs.index'));
|
||||
$response->assertSessionHasErrors('thresholds');
|
||||
|
||||
$this->assertDatabaseHas('sysparam', [
|
||||
'alias' => 'levelexp',
|
||||
'body' => '10,50,150',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:验证等级数量不能超过用户最高可达等级。
|
||||
*/
|
||||
public function test_level_exp_update_requires_threshold_count_not_exceed_maxlevel(): void
|
||||
{
|
||||
$this->seedLevelExpParam();
|
||||
Sysparam::updateOrCreate(
|
||||
['alias' => 'maxlevel'],
|
||||
['body' => '2', 'guidetxt' => '用户最高可达等级']
|
||||
);
|
||||
$admin = $this->createSuperAdmin();
|
||||
|
||||
$response = $this->from(route('admin.level-exp-configs.index'))
|
||||
->actingAs($admin)
|
||||
->put(route('admin.level-exp-configs.update'), [
|
||||
'thresholds' => ['20', '80', '180'],
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('admin.level-exp-configs.index'));
|
||||
$response->assertSessionHasErrors('thresholds');
|
||||
|
||||
$this->assertDatabaseHas('sysparam', [
|
||||
'alias' => 'levelexp',
|
||||
'body' => '10,50,150',
|
||||
]);
|
||||
$this->assertDatabaseHas('sysparam', [
|
||||
'alias' => 'maxlevel',
|
||||
'body' => '2',
|
||||
]);
|
||||
$this->assertDatabaseHas('sysparam', [
|
||||
'alias' => 'superlevel',
|
||||
'body' => '100',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:创建可访问后台页面的超级管理员。
|
||||
*/
|
||||
private function createSuperAdmin(): User
|
||||
{
|
||||
return User::factory()->create([
|
||||
'user_level' => 100,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:初始化等级经验阈值参数。
|
||||
*/
|
||||
private function seedLevelExpParam(): void
|
||||
{
|
||||
$rows = [
|
||||
'levelexp' => [
|
||||
'body' => '10,50,150',
|
||||
'guidetxt' => '按列表逐级维护升级所需的累计经验阈值',
|
||||
],
|
||||
'maxlevel' => [
|
||||
'body' => '99',
|
||||
'guidetxt' => '用户最高可达等级',
|
||||
],
|
||||
'superlevel' => [
|
||||
'body' => '100',
|
||||
'guidetxt' => '管理员级别(= 最高等级 + 1,拥有最高权限的等级阈值)',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($rows as $alias => $payload) {
|
||||
Sysparam::updateOrCreate(
|
||||
['alias' => $alias],
|
||||
$payload
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:运维工具页面展示测试
|
||||
*
|
||||
* 覆盖运维工具页中 Horizon 控制台入口的展示,
|
||||
* 并验证该入口已从后台仪表盘迁移到运维工具页面。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace Tests\Feature\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 类功能:验证运维工具页面的核心展示内容。
|
||||
*/
|
||||
class AdminOpsControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* 方法功能:验证运维工具页会展示 Horizon 控制台入口。
|
||||
*/
|
||||
public function test_ops_page_displays_horizon_console_entry(): void
|
||||
{
|
||||
$siteOwner = User::factory()->create([
|
||||
'id' => 1,
|
||||
'username' => 'site-owner',
|
||||
'user_level' => 100,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($siteOwner)->get(route('admin.ops.index'));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertSee('队列监控面板');
|
||||
$response->assertSee('打开 Horizon 控制台');
|
||||
$response->assertSee('/horizon');
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,9 @@ class AdminSystemControllerTest extends TestCase
|
||||
$response->assertDontSee('vip_payment_app_secret');
|
||||
$response->assertDontSee('wechat_bot_config');
|
||||
$response->assertDontSee('chatbot_max_gold');
|
||||
$response->assertDontSee('levelexp');
|
||||
$response->assertSee('maxlevel');
|
||||
$response->assertSee('superlevel');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,6 +54,9 @@ class AdminSystemControllerTest extends TestCase
|
||||
$response = $this->actingAs($admin)->put(route('admin.system.update'), [
|
||||
'sys_name' => '新版聊天室',
|
||||
'sys_notice' => '新的公共公告',
|
||||
'levelexp' => '20,80,180',
|
||||
'maxlevel' => '88',
|
||||
'superlevel' => '666',
|
||||
'smtp_host' => 'attacker.smtp.example',
|
||||
'vip_payment_app_secret' => 'tampered-secret',
|
||||
'wechat_bot_config' => '{"api":{"bot_key":"stolen"}}',
|
||||
@@ -69,6 +75,18 @@ class AdminSystemControllerTest extends TestCase
|
||||
'alias' => 'sys_notice',
|
||||
'body' => '新的公共公告',
|
||||
]);
|
||||
$this->assertDatabaseHas('sysparam', [
|
||||
'alias' => 'levelexp',
|
||||
'body' => '10,50,150',
|
||||
]);
|
||||
$this->assertDatabaseHas('sysparam', [
|
||||
'alias' => 'maxlevel',
|
||||
'body' => '88',
|
||||
]);
|
||||
$this->assertDatabaseHas('sysparam', [
|
||||
'alias' => 'superlevel',
|
||||
'body' => '89',
|
||||
]);
|
||||
|
||||
// 敏感配置必须保持原值,不能被通用系统页伪造请求覆盖。
|
||||
$this->assertDatabaseHas('sysparam', [
|
||||
@@ -128,6 +146,9 @@ class AdminSystemControllerTest extends TestCase
|
||||
return [
|
||||
'sys_name' => '原始聊天室',
|
||||
'sys_notice' => '原始公告',
|
||||
'levelexp' => '10,50,150',
|
||||
'maxlevel' => '99',
|
||||
'superlevel' => '100',
|
||||
'smtp_host' => 'owner.smtp.example',
|
||||
'vip_payment_app_secret' => 'owner-secret',
|
||||
'wechat_bot_config' => '{"api":{"bot_key":"owner-only"}}',
|
||||
|
||||
Reference in New Issue
Block a user