李忠征信平台后端管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

74 lines
1.7 KiB

<?php
namespace app\admin\model;
use think\Model;
use traits\model\SoftDelete;
class Advert extends Model
{
use SoftDelete;
// 表名
protected $name = 'advert';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'datetime';
protected $dateFormat = 'Y-m-d H:i:s';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'starttime_text',
'endtime_text',
'status_text'
];
public function getStatusList()
{
return ['1' => '正常','-1'=>'已过期'];
}
public function getStarttimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['starttime']) ? $data['starttime'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getEndtimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
protected function setStarttimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
protected function setEndtimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
}