Webconfig.php 916 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 中闽 < 1464674022@qq.com >
  5. * Date: 2020/6/11
  6. * Time: 14:07
  7. */
  8. namespace app\common\model;
  9. use think\Cache;
  10. use think\Db;
  11. use think\Model;
  12. class Webconfig extends Model
  13. {
  14. private static $web_config;
  15. /**
  16. * 获取配置项
  17. * @param $name [配置名称]
  18. * @param int $expire [默认不缓存,0永久缓存,3600是一个小时]
  19. * @return mixed
  20. */
  21. public static function getValue($name, $expire = -1)
  22. {
  23. $key = 'web_config_cache_' . $name;
  24. if ($expire >= 0 && cache($key) !== false) {
  25. return cache($key);
  26. }
  27. if (!self::$web_config) {
  28. self::$web_config = Db::name('webconfig')->where('id', 1)->find();
  29. }
  30. $value = self::$web_config[$name]??'';
  31. if ($expire >= 0) {
  32. Cache::set($key, $value, $expire);
  33. }
  34. return $value;
  35. }
  36. }