12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- /**
- * Created by PhpStorm.
- * User: 中闽 < 1464674022@qq.com >
- * Date: 2020/6/11
- * Time: 14:07
- */
- namespace app\common\model;
- use think\Cache;
- use think\Db;
- use think\Model;
- class Webconfig extends Model
- {
- private static $web_config;
- /**
- * 获取配置项
- * @param $name [配置名称]
- * @param int $expire [默认不缓存,0永久缓存,3600是一个小时]
- * @return mixed
- */
- public static function getValue($name, $expire = -1)
- {
- $key = 'web_config_cache_' . $name;
- if ($expire >= 0 && cache($key) !== false) {
- return cache($key);
- }
- if (!self::$web_config) {
- self::$web_config = Db::name('webconfig')->where('id', 1)->find();
- }
- $value = self::$web_config[$name]??'';
- if ($expire >= 0) {
- Cache::set($key, $value, $expire);
- }
- return $value;
- }
- }
|