<?php

namespace app\common\model\Banner;

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 Banner extends BaseModel
{
    use SoftDelete;
    // 删除字段
    protected $deleteTime = 'banner_delete_time';
    // 设置主键名
    protected $pk = 'banner_guid';
    // 设置废弃字段
    protected $disuse = [];
    // 设置字段信息
    protected $schema = [
        "banner_id" => "int",
        "banner_img" => "string",
        "banner_location" => "string",
        "banner_order" => "int",
        "banner_guid" => "string",
        "banner_create_time" => "datetime",
        "banner_create_user_guid" => "string",
        "banner_update_time" => "datetime",
        "banner_update_user_guid" => "string",
        "banner_delete_time" => "datetime",
        "banner_delete_user_guid" => "string",
    ];
    // 设置json类型字段
    protected $json = [''];
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'datetime';
    // 创建时间
    protected $createTime = 'banner_create_time';
    // 修改时间
    protected $updateTime = 'banner_update_time';

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

    /**
     * 新增前
     */
    public static function onBeforeInsert(self $model): void
    {
        Tool::sortInsertProc(self::class, $model->banner_order);
        $model->completeCreateField();
    }

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

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