IpConfig.php 958 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace app\admin\model;
  3. use app\BaseModel;
  4. class IpConfig extends BaseModel
  5. {
  6. protected $autoWriteTimestamp = true;
  7. protected $createTime = 'created_at';
  8. protected $updateTime = 'updated_at';
  9. public static function getWhitelist(){
  10. //使用缓存
  11. $cache = cache('ip_whitelist');
  12. if ($cache) {
  13. return $cache;
  14. }
  15. $whitelist = self::where('type', 2)->where('status', 1)->column('ip');
  16. //缓存白名单(1小时)
  17. cache('ip_whitelist', $whitelist, 60 * 60);
  18. return $whitelist;
  19. }
  20. public static function getBlacklist(){
  21. //使用缓存
  22. $cache = cache('ip_blacklist');
  23. if ($cache) {
  24. return $cache;
  25. }
  26. $blacklist = self::where('type', 1)->where('status', 1)->column('ip');
  27. //缓存黑名单(1小时)
  28. cache('ip_blacklist', $blacklist, 60 * 60);
  29. return $blacklist;
  30. }
  31. }