Files
chatroom/app/Models/PositionDutyLog.php
lkddi 5f30220609 feat: 任命/撤销通知系统 + 用户名片UI优化
- 任命/撤销事件增加 type 字段区分类型
- 任命:全屏礼花 + 紫色弹窗 + 紫色系统消息
- 撤销:灰色弹窗 + 灰色系统消息,无礼花
- 消息分发:操作者/被操作者显示在私聊面板,其他人显示在公屏
- 系统消息加随机鼓励语(各5条轮换)
- ChatStateService 修复 Redis key 前缀扫描问题(getAllActiveRoomIds)
- 用户名片折叠优化:管理员视野、职务履历均可折叠
- 管理操作 + 职务操作合并为「🔧 管理操作」折叠区
- 悄悄话改为「🎁 送礼物」按钮,礼物面板内联展开
2026-02-28 23:44:38 +08:00

75 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 文件功能:在职登录记录模型
* 对应 position_duty_logs 表,记录职务持有者每次进房的登录时间、在线时长和退出时间
* 用于勤务台四榜统计和个人履历出勤数据展示
*
* @author ChatRoom Laravel
*
* @version 1.0.0
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PositionDutyLog extends Model
{
/**
* 允许批量赋值的字段
*
* @var list<string>
*/
protected $fillable = [
'user_id',
'user_position_id',
'login_at',
'logout_at',
'duration_seconds',
'ip_address',
'room_id',
];
/**
* 字段类型转换
*/
public function casts(): array
{
return [
'login_at' => 'datetime',
'logout_at' => 'datetime',
'duration_seconds' => 'integer',
];
}
/**
* 对应的用户
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* 对应的在职记录
*/
public function userPosition(): BelongsTo
{
return $this->belongsTo(UserPosition::class);
}
/**
* 格式化在线时长为"Xh Ym"字符串(如 128h 30m
*/
public function getFormattedDurationAttribute(): string
{
$seconds = $this->duration_seconds ?? 0;
$hours = intdiv($seconds, 3600);
$minutes = intdiv($seconds % 3600, 60);
return "{$hours}h {$minutes}m";
}
}