<?php

namespace app\common\model\Poster;

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 Poster extends BaseModel
{
    use SoftDelete;
    // 删除字段
    protected $deleteTime = 'poster_delete_time';
    // 设置主键名
    protected $pk = 'poster_guid';
    // 设置废弃字段
    protected $disuse = [];
    // 设置字段信息
    protected $schema = [

        "poster_id" => "int",

        "poster_guid" => "string",

        "poster_location" => "string",

        "poster_img" => "string",

        "poster_title" => "string",

        "poster_describe" => "string",

        "poster_sort" => "string",

        "poster_create_time" => "datetime",

        "poster_create_user_guid" => "string",

        "poster_update_time" => "datetime",

        "poster_update_user_guid" => "string",

        "poster_delete_time" => "datetime",

        "poster_delete_user_guid" => "string",

    ];
    // 设置json类型字段
    protected $json = [''];
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'datetime';
    // 创建时间
    protected $createTime = 'poster_create_time';
    // 修改时间
    protected $updateTime = 'poster_update_time';



    //排序字段
    public $order_field = 'poster_sort';

    /**
     * 新增前
     */
    public static function onBeforeInsert(self $model): void
    {
        Validate::unique(self::class, $model->subject_guid, $model->getData(), [
            'poster_location' => '海报位置',
        ]);
        Tool::sortInsertProc(self::class, $model->poster_sort);
        $model->completeCreateField();
    }

    /**
     * 更新前
     */
    public static function onBeforeUpdate(self $model): void
    {
        Tool::sortEditProc(self::class, $model->poster_guid, $model->poster_sort);
        $model->completeUpdateField();
    }

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