ThirdStudy.php 1.1 KB
<?php

namespace app\admin\model;

use think\Model;


class ThirdStudy extends Model
{

    

    

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

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

    // 追加属性
    protected $append = [
        'periodtime_text'
    ];
    

    



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

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


    public function user()
    {
        return $this->belongsTo('User', 'third_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function study()
    {
        return $this->belongsTo('Study', 'study_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}