新增聊天室成就系统与消息保留策略
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:用户成就解锁记录模型。
|
||||
*
|
||||
* 保存每个用户在固定成就目录中的进度快照、达成时间与通知状态。
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* 类功能:封装用户成就记录字段、类型转换与用户关联。
|
||||
*/
|
||||
class UserAchievement extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserAchievementFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* 允许批量赋值的字段。
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'achievement_key',
|
||||
'progress_value',
|
||||
'achieved_at',
|
||||
'notified_at',
|
||||
'metadata',
|
||||
];
|
||||
|
||||
/**
|
||||
* 属性类型转换。
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'progress_value' => 'integer',
|
||||
'achieved_at' => 'datetime',
|
||||
'notified_at' => 'datetime',
|
||||
'metadata' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联:成就记录所属用户。
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user