<?php

namespace app\common\model\News;

use app\common\arw\adjfut\src\Validate;
use app\BaseModel;
use think\model\concern\SoftDelete;
use app\Request;

class News extends BaseModel
{
    use SoftDelete;
    // 删除字段
    protected $deleteTime = 'news_delete_time';
    // 设置主键名
    protected $pk = 'news_guid';
    // 设置废弃字段
    protected $disuse = [];
    // 设置字段信息
    protected $schema = [

        "news_id" => "int",

        "news_guid" => "string",

        "news_title" => "string",

        "news_author" => "string",

        "news_intro" => "string",

        "news_type" => "string",

        "news_img" => "string",

        "news_content" => "string",

        "news_detail_time" => "datetime",

        "news_num" => "int",

        "news_create_time" => "datetime",

        "news_create_user_guid" => "string",

        "news_update_time" => "datetime",

        "news_update_user_guid" => "string",

        "news_delete_time" => "datetime",

        "news_delete_user_guid" => "string",

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

    /**
     * 新增前
     */
    public static function onBeforeInsert(self $model): void
    {
        // self::checkRepeatData($model);
        $model->completeCreateField();
    }

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

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

    /**
     * 产品类型获取器
     */
    public function getNewsCreatedTimeAttr($value, $data)
    {
        $news_create_time = $data['news_create_time'];
       $news_create_time = date("m-d");
        return $news_create_time;
    }
}
