chanId=$chanId; if($fromWhere=='admin'){ $this->admin=Admin::where('id',$chanId)->find(); }elseif ($fromWhere=='api'){ $this->admin=Admin::sub()->where('id',$chanId)->find(); } $this->getRules(); } protected function getRules(){ if($this->getAdminId()){ $groupRules=AuthGroupAccess::where((new AuthGroupAccess())->getTable().'.uid',$this->getAdminId()) ->join('auth_group',(new AuthGroupAccess())->getTable().'.group_id=auth_group.id') ->group('auth_group.id') ->column('auth_group.rules'); $rules=[]; foreach ($groupRules as $rule){ $rules=array_merge($rules,array_filter(explode(',',$rule))); } $this->rules=$rules; } } /** * @return Admin */ public function getAdmin($field=null) { if(is_null($field)) { return $this->admin; }else{ return $this->admin[$field]??null; } } /** * @return mixed */ public function getAdminId() { return $this->admin?$this->admin['id']:null; } /** * @param mixed $chanId */ public function setChanId($chanId) { $this->chanId = $chanId; return $this; } public function getChanId(){ return $this->chanId; } public function hasSortPower(){ $id=$this->getRuleIdByName('mobile/mobile_sort'); return in_array($id,$this->rules); } public function hasRecPower(){ $id=$this->getRuleIdByName('mobile/mobile_rec_sub'); return in_array($id,$this->rules); } public function hasTopPower(){ $id=$this->getRuleIdByName('mobile/mobile_top_sub'); return in_array($id,$this->rules); } public function hasAllowWxQrPower(){ $id=$this->getRuleIdByName('admin/_allow_wx_qr_power'); return in_array($id,$this->rules); } protected function getRuleIdByName($name){ static $names=[]; if(!isset($names[$name])){ $names[$name]=AuthRule::where('name',$name)->value('id',false); } return $names[$name]; } public function isFastHand(){ return $this->chanId=='kuaishou'; } /** * @var null|static 实例对象 */ protected static $instance = null; /** * 获取示例 * @param array $options 实例配置 * @return static */ public static function instance($chanId,$fromWhere) { if (is_null(self::$instance)) self::$instance = new self($chanId,$fromWhere); return self::$instance; } }