| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace app\common\model;
- use think\Cache;
- /**
- * 系统配置表
- * @author Administrator
- */
- class Setting extends \think\Model
- {
- protected $pk = 'id';
- protected $table = 'cy_setting';
- protected $dateFormat = false; //时间戳格式不自动转换
- const CACHE_KEY = "clearable_get_setting:";
- const CACHE_TAG = "clearable_get_setting";
- protected static function init()
- {
- Setting::afterUpdate(function ($info) {
- Cache::clear(self::CACHE_TAG);
- Cache::rm(self::CACHE_KEY . $info['name']);
- });
- Setting::afterWrite(function ($info) {
- Cache::clear(self::CACHE_TAG);
- Cache::rm(self::CACHE_KEY . $info['name']);
- });
- }
- public static function getSetting($name = '')
- {
- if (empty($name)) {
- return false;
- }
- $cache_key = self::CACHE_KEY.$name;
- $info = Cache::get($cache_key);
- if (empty($info)) {
- $info = self::where(['name' => $name])->value('value');
- if (empty($info)) {
- return false;
- }
- Cache::tag(self::CACHE_TAG)->set($cache_key, $info, 3600 * 24);
- }
- return $info;
- }
- }
|