<?php
|
|
namespace app\common\model\user;
|
|
use think\Model;
|
use traits\model\SoftDelete;
|
|
|
class Browse extends Model
|
{
|
use softDelete;
|
|
// 表名
|
protected $name = 'user_browse';
|
|
// 自动写入时间戳字段
|
protected $autoWriteTimestamp = false;
|
|
// 定义时间戳字段名
|
protected $createTime = false;
|
protected $updateTime = false;
|
protected $deleteTime = 'delete_time';
|
|
// 追加属性
|
protected $append = [
|
'sourceType_text',
|
'faction_text',
|
'browse_time_text',
|
'delete_time_text'
|
];
|
|
|
|
public function getSourcetypeList()
|
{
|
return ['tb' => __('Sourcetype tb'), 'jd' => __('Sourcetype jd'), 'pdd' => __('Sourcetype pdd'), 'wph' => __('Sourcetype wph'), 'tm' => __('Sourcetype tm')];
|
}
|
|
public function getFactionList()
|
{
|
return ['t' => __('Faction t'), 'j' => __('Faction j'), 'p' => __('Faction p'), 'w' => __('Faction w')];
|
}
|
|
|
public function getSourcetypeTextAttr($value, $data)
|
{
|
$value = $value ? $value : (isset($data['sourceType']) ? $data['sourceType'] : '');
|
$list = $this->getSourcetypeList();
|
return isset($list[$value]) ? $list[$value] : '';
|
}
|
|
|
public function getFactionTextAttr($value, $data)
|
{
|
$value = $value ? $value : (isset($data['faction']) ? $data['faction'] : '');
|
$list = $this->getFactionList();
|
return isset($list[$value]) ? $list[$value] : '';
|
}
|
|
|
public function getBrowseTimeTextAttr($value, $data)
|
{
|
$value = $value ? $value : (isset($data['browse_time']) ? $data['browse_time'] : '');
|
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
|
}
|
|
|
public function getDeleteTimeTextAttr($value, $data)
|
{
|
$value = $value ? $value : (isset($data['delete_time']) ? $data['delete_time'] : '');
|
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
|
}
|
|
protected function setBrowseTimeAttr($value)
|
{
|
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
|
}
|
|
protected function setDeleteTimeAttr($value)
|
{
|
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
|
}
|
|
|
public function user()
|
{
|
return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
|
}
|
}
|