del(self::CACHE_KEY_ID.$id); //删除默认平台缓存 $redis->del(self::CACHE_KEY_DEFAULT_LIST); } public function getInfo($id=null){ $redis = Redis::instance(); if(empty($id)){ //获取默认平台信息 $modulename = request()->module(); if($modulename == 'admin' && PHP_SAPI != 'cli'){ $arr = $this->where(['isdefault'=>'1','status'=>1])->find(); if(!$arr){ $arr = $this->where(['status'=>1])->find(); } if($arr){ $arr = $arr->toArray(); } }else{ if($redis->exists(self::CACHE_KEY_DEFAULT_LIST)){ $arr = $redis->hgetall(self::CACHE_KEY_DEFAULT_LIST); }else{ $arr = $this->where(['isdefault'=>'1','status'=>1])->find(); if(!$arr){ $arr = $this->where(['status'=>1])->find(); } if($arr){ $arr = $arr->toArray(); $redis->hmset(self::CACHE_KEY_DEFAULT_LIST,$arr); $redis->expire(self::CACHE_KEY_DEFAULT_LIST,86400); } } } }else{ //获取指定平台信息 $modulename = request()->module(); if($modulename == 'admin' && PHP_SAPI != 'cli'){ //如果是后台域名 $arr = $this->where('id',$id)->find(); if($arr){ $arr = $arr->toArray(); } }else{ $key = self::CACHE_KEY_ID.$id; $arr = null; if (Cache::has($key)) { Log::info("获取缓存:$key filecache命中"); $arr = Cache::get($key); } if (!$arr) { if ($redis->exists($key)) { $arr = $redis->hgetall($key); Log::info("获取缓存:$key redis命中"); Cache::set($key, $arr, 10); } } if (!$arr) { $arr = $this->where('id', $id)->find(); if ($arr) { Log::info("获取缓存:$key mysql命中"); $arr = $arr->toArray(); $redis->hmset($key, $arr); $redis->expire($key, 3600); } } } } return $arr; } /** * 获取当前渠道已授权的平台ID * @param $channel_id * @param null $platform_list 过滤指定的平台列表 * @return string * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getChannelHaveAuthorizedPlatformId($channel_id,$platform_list = null){ $result = []; if($platform_list){ if(!is_array($platform_list)){ $platform_list = explode(',',$platform_list); } } $list = $this->join('ptoken p','platform.id=p.platform_id and p.admin_id = '.$channel_id)->where('p.refresh_token','not null')->field('platform.*')->order('platform.id','desc')->select(); if($list){ if($platform_list){ foreach($platform_list as $val){ foreach($list as $platform){ if($val == $platform['id']){ array_push($result,$platform['id']); } } } }else{ foreach($list as $platform){ array_push($result,$platform['id']); } } }else{ if($platform_list){ $result = $platform_list; } } return trim(implode(',',$result),','); } public function getPlatformList($admin_id=0) { if(empty($admin_id)){ $list = $this->where("status = '1'")->order('id','desc')->select(); }else{ $list = $this->join('ptoken p','platform.id=p.platform_id and p.admin_id='.$admin_id)->where('p.refresh_token','not null')->field('platform.*')->order('platform.id','desc')->select(); } return $list; } public function getStatusList() { return ['0' => __('Status 0'),'1' => __('Status 1')]; } public function getIsdefaultList() { return ['0' => __('Isdefault 0'),'1' => __('Isdefault 1')]; } public function getStatusTextAttr($value, $data) { $value = $value ? $value : $data['status']; $list = $this->getStatusList(); return isset($list[$value]) ? $list[$value] : ''; } public function getIsdefaultTextAttr($value, $data) { $value = $value ? $value : $data['isdefault']; $list = $this->getIsdefaultList(); return isset($list[$value]) ? $list[$value] : ''; } }