<?php

namespace app\manystore\model\school\classes;

use think\Model;


class VirtualUser extends Model
{

    

    

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

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

    // 追加属性
    protected $append = [
        'time_text',
        'jointype_text',
        'havetype_text'
    ];
    

    
    public function getJointypeList()
    {
        return ['1' => __('Jointype 1'), '0' => __('Jointype 0')];
    }

    public function getHavetypeList()
    {
        return ['1' => __('Havetype 1'), '0' => __('Havetype 0')];
    }


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


    public function getJointypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['jointype']) ? $data['jointype'] : '');
        $list = $this->getJointypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getHavetypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['havetype']) ? $data['havetype'] : '');
        $list = $this->getHavetypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

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


    public function schoolclasseslib()
    {
        return $this->belongsTo('app\manystore\model\SchoolClassesLib', 'classes_lib_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
