文件
fenleixinxi/application/admin/model/FcReport.php

74 行
1.5 KiB
PHP

<?php
namespace app\admin\model;
use think\Model;
use app\common\library\FcRelation;
class FcReport extends Model
{
// 表名
protected $name = 'fc_report';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'status_text',
'reporter_name',
'target_title',
];
public function getReporterNameAttr($value, $data)
{
return FcRelation::userName(isset($data['reporter_id']) ? $data['reporter_id'] : 0);
}
public function getTargetTitleAttr($value, $data)
{
$type = isset($data['target_type']) ? $data['target_type'] : '';
$id = isset($data['target_id']) ? $data['target_id'] : 0;
if ($type === 'post') {
return FcRelation::postTitle($id);
}
if ($type === 'comment') {
return FcRelation::commentSnippet($id);
}
return '';
}
public function getStatusList()
{
return [
'pending' => __('待处理'),
'handled' => __('已处理'),
];
}
public function getStatusTextAttr($value, $data)
{
$value = $value ?: ($data['status'] ?? '');
$list = $this->getStatusList();
return $list[$value] ?? '';
}
}