<?php

namespace app\admin\model\teacher;

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


class Exams extends Model
{



    use SoftDelete;

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

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

    // 追加属性
    protected $append = [

    ];

    protected static function init()
    {
        self::beforeUpdate(function ($row) {
            if(!empty($row['createtime'])){
                $pk = $row->getPk();
                $create_time = date('Y-m-d H:i:s',$row['createtime']);
                $update_time = date('Y-m-d H:i:s',$row['updatetime']);
                $row->getQuery()->where($pk, $row[$pk])->update(['create_time' => $create_time,'update_time'=>$update_time]);
            }
        });
        self::afterInsert(function ($row) {
            if(!empty($row['createtime'])){
                $pk = $row->getPk();
                $create_time = date('Y-m-d H:i:s',$row['createtime']);
                $update_time = date('Y-m-d H:i:s',$row['updatetime']);
                $row->getQuery()->where($pk, $row[$pk])->update(['create_time' => $create_time,'update_time'=>$update_time]);
            }
        });
    }

    







}
