<?php

namespace app\admin\model;

use think\Model;


class Keyworldfilter extends Model
{

    

    

    // 表名
    protected $table = 'keyworldfilter';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];

    protected static function init()
    {
        self::afterUpdate(function ($row) {
            self::refreshFile();
        });

        self::afterInsert(function ($row){
            self::refreshFile();
        });

        self::afterDelete(function ($row){
            self::refreshFile();
        });
    }

    //刷新文件缓存
    public static function refreshFile()
    {
        $config = [];
        $configList = self::all();
        foreach ($configList as $k => $v) {
            $value = $v->toArray();
            $config[] = $value['keyworld'];
        }

        file_put_contents(
            CONF_PATH . 'extra' . DS . 'keyworld.php',
            '<?php' . "\n\nreturn " . var_export_short($config) . ";\n"
        );
        return true;
    }
    







}
