123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?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;
- }
- //ftp配置
- public static function getFtpConfig()
- {
- $replace = self::getValue('article_ftp_config');
- $replace = json_decode($replace, true);
- return is_array($replace) ? $replace : [];
- }
- }
|