<?php
|
|
namespace app\admin\model;
|
|
use think\Model;
|
use traits\model\SoftDelete;
|
|
|
class Homemenu extends Model
|
{
|
use softDelete;
|
// 表名
|
protected $name = 'homemenu';
|
|
// 自动写入时间戳字段
|
protected $autoWriteTimestamp = true;
|
|
// 定义时间戳字段名
|
protected $createTime = 'create_time';
|
protected $updateTime = 'update_time';
|
protected $deleteTime = 'delete_time';
|
|
// 追加属性
|
protected $append = [
|
'type_text',
|
'group_text',
|
'url_type_text',
|
'status_text',
|
'is_top_text',
|
'system_type_text',
|
'create_time_text',
|
'update_time_text',
|
'delete_time_text'
|
];
|
|
protected static function init()
|
{
|
self::beforeInsert(function ($row) {
|
$row->parameter_json = json_encode($row->parameter_json);
|
});
|
self::beforeUpdate(function($row){
|
$row->parameter_json = json_encode($row->parameter_json);
|
});
|
}
|
|
|
|
public function getTypeList()
|
{
|
return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3')];
|
}
|
|
public function getGroupList()
|
{
|
return ['1' => __('Group 1'), '2' => __('Group 2'), '3' => __('Group 3'),'4' => '限时推广','5' => '订单相关','6' => '物料相关'];
|
}
|
|
public function getUrlTypeList()
|
{
|
return ['0' => __('Url_type 0'), '1' => __('Url_type 1'), '2' => __('Url_type 2'), '3' => __('Url_type 3'), '7' => __('Url_type 7'), '11' => __('Url_type 11'), '12' => __('Url_type 12'), '13' => __('Url_type 13'),'14'=>'单页转链接','15' => __('Url_type 15'),'999'=>'不跳转'];
|
}
|
|
public function getStatusList()
|
{
|
return ['0' => __('Status 0'), '1' => __('Status 1')];
|
}
|
|
public function getIsTopList()
|
{
|
return ['0' => __('Is_top 0'), '1' => __('Is_top 1')];
|
}
|
|
public function getSystemTypeList()
|
{
|
return ['0' => __('System_type 0'), '1' => __('System_type 1'), '2' => __('System_type 2')];
|
}
|
|
|
public function getTypeTextAttr($value, $data)
|
{
|
$value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
|
$list = $this->getTypeList();
|
return isset($list[$value]) ? $list[$value] : '';
|
}
|
|
|
public function getGroupTextAttr($value, $data)
|
{
|
$value = $value ? $value : (isset($data['group']) ? $data['group'] : '');
|
$list = $this->getGroupList();
|
return isset($list[$value]) ? $list[$value] : '';
|
}
|
|
|
public function getUrlTypeTextAttr($value, $data)
|
{
|
$value = $value ? $value : (isset($data['url_type']) ? $data['url_type'] : '');
|
$list = $this->getUrlTypeList();
|
return isset($list[$value]) ? $list[$value] : '';
|
}
|
|
|
public function getStatusTextAttr($value, $data)
|
{
|
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
|
$list = $this->getStatusList();
|
return isset($list[$value]) ? $list[$value] : '';
|
}
|
|
|
public function getIsTopTextAttr($value, $data)
|
{
|
$value = $value ? $value : (isset($data['is_top']) ? $data['is_top'] : '');
|
$list = $this->getIsTopList();
|
return isset($list[$value]) ? $list[$value] : '';
|
}
|
|
|
public function getSystemTypeTextAttr($value, $data)
|
{
|
$value = $value ? $value : (isset($data['system_type']) ? $data['system_type'] : '');
|
$list = $this->getSystemTypeList();
|
return isset($list[$value]) ? $list[$value] : '';
|
}
|
|
|
public function getCreateTimeTextAttr($value, $data)
|
{
|
$value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
|
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
|
}
|
|
|
public function getUpdateTimeTextAttr($value, $data)
|
{
|
$value = $value ? $value : (isset($data['update_time']) ? $data['update_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 setCreateTimeAttr($value)
|
{
|
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
|
}
|
|
protected function setUpdateTimeAttr($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 getParameterJsonAttr($value, $data)
|
{
|
return empty($value) ? [] : (is_array($value) ? $value : json_decode($value, true));
|
}
|
|
|
}
|