增强:完善用户考勤记录机制,增加进出房间时间和登录次数统计

This commit is contained in:
2026-02-27 10:11:09 +08:00
parent ea7331dd98
commit 5c2172c2af
2 changed files with 18 additions and 3 deletions

View File

@@ -121,6 +121,9 @@ class AuthController extends Controller
{
Auth::login($user);
// 递增访问次数
$user->increment('visit_num');
// 更新最后登录IP和时间
$user->update([
'last_ip' => $ip,
@@ -143,8 +146,11 @@ class AuthController extends Controller
{
if (Auth::check()) {
$user = Auth::user();
// 记录退出时间
$user->update(['out_time' => now()]);
// 记录退出时间和退出信息
$user->update([
'out_time' => now(),
'out_info' => '正常退出了聊天室',
]);
}
Auth::logout();

View File

@@ -51,6 +51,9 @@ class ChatController extends Controller
// 房间人气 +1每次访问递增复刻原版人气计数
$room->increment('visit_num');
// 用户进房时间刷新
$user->update(['in_time' => now()]);
// 1. 将当前用户加入到 Redis 房间在线列表(包含 VIP 和管理员信息)
$superLevel = (int) Sysparam::getValue('superlevel', '100');
@@ -319,6 +322,12 @@ class ChatController extends Controller
// 1. 从 Redis 删除该用户
$this->chatState->userLeave($id, $user->username);
// 记录退出时间和退出信息
$user->update([
'out_time' => now(),
'out_info' => "正常退出了房间",
]);
// 2. 广播通知他人
broadcast(new UserLeft($id, $user->username))->toOthers();
@@ -356,7 +365,7 @@ class ChatController extends Controller
*/
public function changeAvatar(Request $request): JsonResponse
{
$user = auth()->user();
$user = Auth::user();
$headface = $request->input('headface', '');
if (empty($headface)) {