- 任命/撤销事件增加 type 字段区分类型 - 任命:全屏礼花 + 紫色弹窗 + 紫色系统消息 - 撤销:灰色弹窗 + 灰色系统消息,无礼花 - 消息分发:操作者/被操作者显示在私聊面板,其他人显示在公屏 - 系统消息加随机鼓励语(各5条轮换) - ChatStateService 修复 Redis key 前缀扫描问题(getAllActiveRoomIds) - 用户名片折叠优化:管理员视野、职务履历均可折叠 - 管理操作 + 职务操作合并为「🔧 管理操作」折叠区 - 悄悄话改为「🎁 送礼物」按钮,礼物面板内联展开
54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
||
|
||
/**
|
||
* 文件功能:在职职务验证中间件
|
||
* 只要用户当前持有在职职务(user_positions.is_active=true),即可访问后台。
|
||
* id=1 超级管理员无需职务,直接通过。
|
||
*
|
||
* @author ChatRoom Laravel
|
||
*
|
||
* @version 1.0.0
|
||
*/
|
||
|
||
namespace App\Http\Middleware;
|
||
|
||
use App\Models\Sysparam;
|
||
use Closure;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Facades\Auth;
|
||
use Symfony\Component\HttpFoundation\Response;
|
||
|
||
class HasActivePosition
|
||
{
|
||
/**
|
||
* 校验用户是否有在职职务(或为超级管理员)。
|
||
*
|
||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||
*/
|
||
public function handle(Request $request, Closure $next): Response
|
||
{
|
||
if (! Auth::check()) {
|
||
return redirect()->route('home');
|
||
}
|
||
|
||
$user = Auth::user();
|
||
$superLevel = (int) Sysparam::getValue('superlevel', '100');
|
||
|
||
// id=1 或 superlevel 及以上:无需职务,直通
|
||
if ($user->id === 1 || $user->user_level >= $superLevel) {
|
||
return $next($request);
|
||
}
|
||
|
||
// 检查是否有在职职务
|
||
if (! $user->activePosition()->exists()) {
|
||
if ($request->expectsJson()) {
|
||
return response()->json(['message' => '权限不足:您尚未持有任何职务', 'status' => 'error'], 403);
|
||
}
|
||
|
||
abort(403, '权限不足:您尚未持有任何职务,无法访问后台。');
|
||
}
|
||
|
||
return $next($request);
|
||
}
|
||
}
|