| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 | <?phpnamespace app\admin\model\dynamic;use think\Model;class Dynamic extends Model{            // 表名    protected $name = 'dynamic';        // 自动写入时间戳字段    protected $autoWriteTimestamp = 'int';    // 定义时间戳字段名    protected $createTime = 'createtime';    protected $updateTime = 'updatetime';    protected $deleteTime = false;    // 追加属性    protected $append = [        'res_type_text',        'is_online_text',        'is_recommend_text',        'status_text'    ];            public function getResTypeList()    {        return ['1' => __('Res_type 1'), '2' => __('Res_type 2'), '3' => __('Res_type 3')];    }    public function getIsOnlineList()    {        return ['-1' => __('Is_online -1'), '1' => __('Is_online 1')];    }    public function getIsRecommendList()    {        return ['0' => __('Is_recommend 0'), '1' => __('Is_recommend 1')];    }    public function getStatusList()    {        return ['-1' => __('Status -1'), '0' => __('Status 0'), '1' => __('Status 1')];    }    public function getResTypeTextAttr($value, $data)    {        $value = $value ? $value : (isset($data['res_type']) ? $data['res_type'] : '');        $list = $this->getResTypeList();        return isset($list[$value]) ? $list[$value] : '';    }    public function getIsOnlineTextAttr($value, $data)    {        $value = $value ? $value : (isset($data['is_online']) ? $data['is_online'] : '');        $list = $this->getIsOnlineList();        return isset($list[$value]) ? $list[$value] : '';    }    public function getIsRecommendTextAttr($value, $data)    {        $value = $value ? $value : (isset($data['is_recommend']) ? $data['is_recommend'] : '');        $list = $this->getIsRecommendList();        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 user()    {        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);    }}
 |