Clazz.php 1.2 KB
<?php

namespace app\school\model\basic;

use think\Model;
use traits\model\SoftDelete;

class Clazz extends Model
{

    use SoftDelete;

    

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

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

    // 追加属性
    protected $append = [
        'clazz_type_text',
        'college_text',
        'specialty_text'
    ];
    
    public function getCollegeTextAttr($value,$data){
        return getCollegeName(isset($data['college_id'])?$data['college_id']:0,'college');
    }

    public function getSpecialtyTextAttr($value,$data){
        return getCollegeName(isset($data['specialty_id'])?$data['specialty_id']:0,'specialty');
    }
    
    public function getClazzTypeList()
    {
        return ['1' => __('Clazz_type 1'), '0' => __('Clazz_type 0')];
    }


    public function getClazzTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['clazz_type']) ? $data['clazz_type'] : '');
        $list = $this->getClazzTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}