12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace app\common\service;
- use app\admin\model\Admin;
- use app\admin\model\AuthGroupAccess;
- use app\admin\model\AuthRule;
- use traits\think\Instance;
- class SubService{
- use Instance;
- /** @var Admin */
- protected $admin;
- protected $chanId;
- protected $rules=[];
- public function __construct($chanId)
- {
- $this->chanId=$chanId;
- $this->admin=Admin::get($chanId);
- $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()
- {
- return $this->admin;
- }
- /**
- * @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);
- }
- 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';
- }
- }
|