123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace app\admin\controller;
- use think\App;
- use think\facade\Db;
- class Base extends \app\BaseController
- {
- public $post=[];
- public $uid='';
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post =$this->request->post();
- $this->validateToken();
- }
- public function validateToken()
- {
- $token = isset($this->post['token']) ? trim($this->post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if(!empty($effetc) && $effetc['code']!=0) {
- return error_show($effetc['code'], $effetc['message']);
- }
- $this->uid=isset($effetc['data']['user']['id']) ?$effetc['data']['user']['id']:"";
- }
- public function checkRole(){
- $uid = Db::name("user_role")->where(['uid'=>$this->uid,"is_del"=>0,"status"=>1])->find();
- if($uid==false){
- return [];
- }
- $action=[];
- $role =Db::name("role_action")->where(["role_id"=>$uid['roleid'],"status"=>1])->find();
- $action['action_conllect']=isset($role['action_conllect'])? $role['action_conllect']:'';
- $action['write'][]=$this->uid;
- $group=[];
- $group = Db::name("role_group")->where("FIND_IN_SET($this->uid,group_user) > 0")->column("id");
- // echo Db::name("role_group")->getLastSql();
- $where="to_user=$this->uid";
- if(!empty($group)){
- $where.=" or to_group in (".implode(",",$group).")";
- }
- // var_dump($group);
- $share =Db::name("role_share")->where(["is_del"=>0,"status"=>1])->where($where) ->select();
- // echo Db::name("role_share")->getLastSql();
- if(!empty($share)){
- foreach ($share as $value){
- if($value['action']==1){
- if($value['share_user']!=""){
- $action['write'][]=$value['share_user'];
- $user=Db::name("user_role")->where(['uid'=>$value['share_user'],"is_del"=>0,"status"=>1])->find();
- if($user!=false){
- $role =Db::name("role_action")->where(["role_id"=>$user['roleid'],"status"=>1])->find();
- if($role!=false){
- $conlect =Db::name("action")->where(['menuid'=>explode(",",$value['action_collect'])])->column("id");
- $shar=explode(",",$value['action_collect']);
- $wish =array_intersect($conlect,$shar);
- $action['action_conllect'].=empty($wish)?"":",".implode(",",$wish);
- }
- }
- }
- }
- if($value['action']===0){
- if($value['share_user']!="") $action['write'][]=$value['share_user'];
- if($value['action_collect']!=''){
- $act =Db::name("action")->where(['menuid'=>explode(",",$value['action_collect']),"action_code"=>'001'])->column("id");
- $action['action_conllect'].=empty($act)?"":",".implode(",",$act);
- }
- }
- if($value['action']===''){
- if($value['action_collect']!=''){
- $act =Db::name("action")->where(['menuid'=>explode(",",$value['action_collect']),"action_code"=>'001'])->column("id");
- $action['action_conllect'].=empty($act)?"":",".implode(",",$act);
- }
- }
- }
- }
- $action['action_conllect']=implode(",",array_unique(explode(",",$action['action_conllect'])));
- return $action;
- }
- }
|