car4s/application/common/model/user4s/Visit.php
2022-06-05 14:30:14 +08:00

65 lines
1.3 KiB
PHP

<?php
namespace app\common\model\user4s;
use think\Model;
use traits\model\SoftDelete;
class Visit extends Model
{
use SoftDelete;
// 表名
protected $name = 'user4s_visit';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'visittime_text'
];
public function getVisittimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['visittime']) ? $data['visittime'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setVisittimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
public function visittype()
{
return $this->belongsTo('Visittype', 'type_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function user()
{
return $this->belongsTo('User', 'user4s_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function admin()
{
return $this->belongsTo('app\common\model\Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}