<?php

namespace app\admin\model;

use app\BaseModel;

class IpConfig extends BaseModel
{
    protected $autoWriteTimestamp = true;
    protected $createTime = 'created_at';
    protected $updateTime = 'updated_at';
    
    public static function getWhitelist(){
        //使用缓存
        $cache = cache('ip_whitelist');
        if ($cache) {
            return $cache;
        }
        $whitelist = self::where('type', 2)->where('status', 1)->column('ip');
        //缓存白名单（1小时）
        cache('ip_whitelist', $whitelist, 60 * 60);
        return $whitelist;
    }
    public static function getBlacklist(){
        //使用缓存
        $cache = cache('ip_blacklist');
        if ($cache) {
            return $cache;
        }
        $blacklist = self::where('type', 1)->where('status', 1)->column('ip');
        //缓存黑名单（1小时）
        cache('ip_blacklist', $blacklist, 60 * 60);
        return $blacklist;
    }
}