model = new SystemConfig(); } /** * 静态化入口 * @return static|null */ public static function make() { if(!self::$instance){ self::$instance = new static(); } return self::$instance; } /** * 按分组获取配置信息 * @param $groupKey 分组 * @return array|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getConfigByGroup($groupKey) { $cacheKey = "caches:config:group:{$groupKey}"; $data = RedisCache::get($cacheKey); if($data){ return $data; } $where = ['group'=> $groupKey]; $data = $this->model->where($where)->column('id,name,group,value,remark','name'); if($data){ RedisCache::set($cacheKey, $data, rand(10,20)); } return $data; } /** * 按配置名获取配置信息或者值 * @param $name 配置名 * @param int $type 返回类型:1-返回值,2-返回列信息 * @param string $groupKey 分组 * @return SystemConfig|array|mixed|\think\Model|null * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function getConfigByName($name, $type=1, $groupKey='') { $cacheKey = "caches:config:info:{$name}_{$type}{$groupKey}"; $data = RedisCache::get($cacheKey); if($data){ return $data; } $where = ['name'=> $name]; if($groupKey){ $where['group'] = $groupKey; } if($type == 1){ $data = $this->model->where($where)->value('value'); }else{ $data = $this->model->where($where)->field('id,name,group,value,remark')->find(); } if($data){ RedisCache::set($cacheKey, $data, rand(10,20)); } return $data; } }