105 lines
2.2 KiB
PHP
105 lines
2.2 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 文件功能:职务权限使用记录模型
|
|||
|
|
* 对应 position_authority_logs 表,记录职务持有者每次行使职权的操作
|
|||
|
|
* 包含任命、撤销、奖励金币、警告、踢出、禁言、封IP等操作类型
|
|||
|
|
*
|
|||
|
|
* @author ChatRoom Laravel
|
|||
|
|
*
|
|||
|
|
* @version 1.0.0
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
namespace App\Models;
|
|||
|
|
|
|||
|
|
use Illuminate\Database\Eloquent\Model;
|
|||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||
|
|
|
|||
|
|
class PositionAuthorityLog extends Model
|
|||
|
|
{
|
|||
|
|
/**
|
|||
|
|
* 禁用 updated_at(只有 created_at)
|
|||
|
|
*/
|
|||
|
|
public const UPDATED_AT = null;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 允许批量赋值的字段
|
|||
|
|
*
|
|||
|
|
* @var list<string>
|
|||
|
|
*/
|
|||
|
|
protected $fillable = [
|
|||
|
|
'user_id',
|
|||
|
|
'user_position_id',
|
|||
|
|
'action_type',
|
|||
|
|
'target_user_id',
|
|||
|
|
'target_position_id',
|
|||
|
|
'amount',
|
|||
|
|
'remark',
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 字段类型转换
|
|||
|
|
*/
|
|||
|
|
public function casts(): array
|
|||
|
|
{
|
|||
|
|
return [
|
|||
|
|
'amount' => 'integer',
|
|||
|
|
'created_at' => 'datetime',
|
|||
|
|
];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 操作类型中文标签
|
|||
|
|
*/
|
|||
|
|
public static array $actionLabels = [
|
|||
|
|
'appoint' => '任命',
|
|||
|
|
'revoke' => '撤销职务',
|
|||
|
|
'reward' => '奖励金币',
|
|||
|
|
'warn' => '警告',
|
|||
|
|
'kick' => '踢出',
|
|||
|
|
'mute' => '禁言',
|
|||
|
|
'banip' => '封锁IP',
|
|||
|
|
'other' => '其他',
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 操作人
|
|||
|
|
*/
|
|||
|
|
public function user(): BelongsTo
|
|||
|
|
{
|
|||
|
|
return $this->belongsTo(User::class);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 操作时使用的在职记录
|
|||
|
|
*/
|
|||
|
|
public function userPosition(): BelongsTo
|
|||
|
|
{
|
|||
|
|
return $this->belongsTo(UserPosition::class);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 操作对象用户
|
|||
|
|
*/
|
|||
|
|
public function targetUser(): BelongsTo
|
|||
|
|
{
|
|||
|
|
return $this->belongsTo(User::class, 'target_user_id');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 任命/撤销时的目标职务
|
|||
|
|
*/
|
|||
|
|
public function targetPosition(): BelongsTo
|
|||
|
|
{
|
|||
|
|
return $this->belongsTo(Position::class, 'target_position_id');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取操作类型的中文标签
|
|||
|
|
*/
|
|||
|
|
public function getActionLabelAttribute(): string
|
|||
|
|
{
|
|||
|
|
return self::$actionLabels[$this->action_type] ?? $this->action_type;
|
|||
|
|
}
|
|||
|
|
}
|