Teacher.php 2.6 KB
<?php

namespace app\school\model\basic;

use fast\Random;
use think\Model;
use think\Db;
use traits\model\SoftDelete;

class Teacher extends Model
{

    use SoftDelete;

    

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

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';
    public static  $teacherType = [
        0 => '无',
        1 => '校园导师',
        2 => '企业导师'
    ];
    //学位
    const DEGREE = [
        0 => '学士',
        1 => '硕士',
        2 => '博士',
    ];
    //教师职称
    const POSITION = [
        0 => '助教',
        1 => '讲师',
        2 => '副教授',
        3 => '教授',
        4 => '副研究员',
    ];

    const EDUCATION = [
        0 => '学前',
        1 => '小学',
        2 => '初中',
        3 => '高中',
        4 => '中专',
        5 => '大专',
        6 => '本科',
        7 => '硕士',
        8 => '博士',
    ];


    // 追加属性
    protected $append = [
        'status_text',
        'college_text',
        'education_text',
        'degree_text',
        'position_text'
    ];

    //获取教师所属学院
    public function getcollegeTextAttr($value,$data){

        return Db::name('college')->where(['id' =>$data['college_id']])->value('college_name');
    }


    public function getdegreeTextAttr($value,$data){
        return self::DEGREE[$data['degree']];
    }

    public function getpositionTextAttr($value,$data){
        return self::POSITION[$data['position']];
    }


    //获取教师学历
    public function geteducationTextAttr($value,$data){
        $arr = [
            0 => '学前',
            1 => '小学',
            2 => '初中',
            3 => '高中',
            4 => '中专',
            5 => '大专',
            6 => '本科',
            7 => '硕士',
            8 => '博士'
        ];
        return $arr[$data['education']];
    }


    public function getEducational(){
        return self::EDUCATION;
    }

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


    public function getStatusTextAttr($value, $data)
    {

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

   /* public function getResumeAttr($value, $data){
        return !empty($data['resume']) ? json_decode($data['resume'],true):'';
    }*/

}