<?php

namespace app\common\model\AboutUs\TeachingEnvir;

use app\common\arw\adjfut\src\Validate;
use app\BaseModel;
use think\model\concern\SoftDelete;
use app\common\arw\adjfut\src\Excel;
use app\Request;
use app\common\exception\Tool;
use think\facade\Db;

class TeachingEnvir extends BaseModel
{
    use SoftDelete;
    // 删除字段
    protected $deleteTime = 'teaching_envir_delete_time';
    // 设置主键名
    protected $pk = 'teaching_envir_guid';
    // 设置废弃字段
    protected $disuse = [];
    // 设置字段信息
    protected $schema = [
        "teaching_envir_id" => "int",
        "teaching_envir_guid" => "string",
        "teaching_envir_type_guid" => "string",
        "teaching_envir_title" => "string",
        "teaching_envir_img" => "string",
        "teaching_envir_intro" => "string",
        "teaching_envir_details" => "string",
        "teaching_envir_create_time" => "datetime",
        "teaching_envir_create_user_guid" => "string",
        "teaching_envir_update_time" => "datetime",
        "teaching_envir_update_user_guid" => "string",
        "teaching_envir_delete_time" => "datetime",
        "teaching_envir_delete_user_guid" => "string",
    ];
    // 设置json类型字段
    protected $json = [''];
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'datetime';
    // 创建时间
    protected $createTime = 'teaching_envir_create_time';
    // 修改时间
    protected $updateTime = 'teaching_envir_update_time';

    /**
     * 新增前
     */
    public static function onBeforeInsert(self $model): void
    {
        Validate::unique(
            self::class,
            $model->teaching_envir_type_guid,
            $model->getData(),
            ['teaching_envir_type_guid' => '环境类型',],
            ['teaching_envir_type_guid' => '一个教学环境类型只能拥有一个教学环境数据']
        );
        $model->completeCreateField();
    }

    /**
     * 更新前
     */
    public static function onBeforeUpdate(self $model): void
    {
        $model->completeUpdateField();
    }

    /**
     * 删除前
     */
    public static function onBeforeDelete(self $model): void
    {
        $model->completeDeleteField();
    }
}
