123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace app\model;
- use think\facade\Cache;
- use think\Model;
- class SettingModel extends Model
- {
- protected $name = "setting";
- protected $pk = "keys";
- static $CacheConfig = false;
- public static function Config($key = false, $default = '##')
- {
- $config = self::$CacheConfig;
- if (!$config) {
- $config = Cache::get('webConfig');
- if (!$config) {
- $config = self::select()->toArray();
- $config = array_column($config, 'value', 'keys');
- Cache::set('webConfig', $config, 300);
- }
- }
- if ($key) {
- if (isset($config[$key])) {
- return $config[$key];
- }
- if ($default !== '##') {
- return $default;
- }
- }
- return $config;
- }
- public static function refreshSetting()
- {
- Cache::delete('webConfig');
- }
- }
|