<?php

namespace app\admin\model\device;

use think\Model;


class Chargedevice extends Model
{

    

    

    // 表名
    protected $name = 'charge_device';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'authorizestatus_text',
        'authorizetime_text'
    ];
    

    
    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2')];
    }

    public function getAuthorizestatusList()
    {
        return ['1' => __('Authorizestatus 1'), '2' => __('Authorizestatus 2')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAuthorizestatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['authorizestatus']) ? $data['authorizestatus'] : '');
        $list = $this->getAuthorizestatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAuthorizetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['authorizetime']) ? $data['authorizetime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setAuthorizetimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function users(){
        return self::hasOne("app\admin\model\users\Users",'id',"user_id");
    }

    public function agent(){
        return self::hasOne("app\admin\model\users\Agent",'id',"agent_user_id");
    }

}
