12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\controller;
- use app\admin\model\RoleGroup;
- use app\admin\model\RoleShare;use app\BaseController;
- use think\App;
- class Base extends BaseController
- {
- protected $noLogin=[];
- protected $uid=0;
- protected $uname="system";
- protected $roleid=0;
- protected $level=0;
- protected $token="";
- protected $model=null;
- public function __construct(App $app) {
- parent::__construct($app);
- $this->token = $this->request->param('token','','trim');
- if (!action_in_arr($this->noLogin)){
- if($this->token=='')throw new \Exception('token不能为空',101);
- $this->Auth();
- }
- }
- /**授权token鉴定
- * @return \think\response\Json|void
- */
- public function Auth(){
- $User = \app\common\User::instance();
- $reLaNo= $this->request->param('relaComNo','','trim');
- $User->init($this->token);
- if (!$User->isLogin()) throw new \Exception($User->getError(),$User->getErroCode());
- $this->uid = $User->id;
- $this->uname = $User->nickname;
- $this->level = $User->level;
- $this->roleid =1;
- if($User->level==2){
- $this->roleid = \app\admin\model\UserRole::GetRoleIdByCompnyNoAndUid($reLaNo,$User->id);
- if($this->roleid==='') throw new \Exception( '没有该公司的角色','101');
- }
- }
- public function checkRole(){
- $action = [
- 'action_conllect'=>'',
- 'write'=>[],
- 'platform'=>[],
- 'roleid'=>$this->roleid
- ];
- if($this->level==2){
- $roleinfo =\app\admin\model\RoleAction::where('roleid',$this->roleid)->findOrEmpty();
- $action['action_conllect'] = $roleinfo->action_conllect;
- $action['write'][] = $this->uid;
- $group= RoleGroup::whereFindInSet('group_user',$this->uid)->column("id");
- $where = ["to_user"=>$this->uid];
- if(!empty($group)){
- $where['to_group'] =$group;
- }
- $platform = \app\admin\model\UserPlatform::where(['uid' => $this->uid, 'is_del' => 0])->findOrEmpty();
- $action['platform'] = $platform->platform??[];
- $share = RoleShare::where(['is_del' => 0, 'status' => 1])->whereOr($where)->select();
- if(!$share->isEmpty()){
- $share->each(function ($item) use (&$action) {
- switch ($item->action) {
- case 1:
- if($item->share_user==''){
- $action['write'][] =$item->share_user;
- $user = \app\admin\model\UserRole::where(["uid"=>$item->share_user,"is_del"=>0,"status"=>1])->findOrEmpty();
- if(!$user->isEmpty()){
- $action['write'][] =$user->roleid;
- }
- }
- }
- });
- }
- }
- }
- }
|