Base.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\facade\Db;
  5. class Base extends \app\BaseController
  6. {
  7. public $post=[];
  8. public $uid='';
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->post =$this->request->post();
  13. $this->validateToken();
  14. }
  15. public function validateToken()
  16. {
  17. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  18. if($token==""){
  19. return error_show(101,'token不能为空');
  20. }
  21. $effetc = VerifyTokens($token);
  22. if(!empty($effetc) && $effetc['code']!=0) {
  23. return error_show($effetc['code'], $effetc['message']);
  24. }
  25. $this->uid=isset($effetc['data']['user']['id']) ?$effetc['data']['user']['id']:"";
  26. }
  27. public function checkRole(){
  28. $uid = Db::name("user_role")->where(['uid'=>$this->uid,"is_del"=>0,"status"=>1])->find();
  29. if($uid==false){
  30. return [];
  31. }
  32. $action=[];
  33. $role =Db::name("role_action")->where(["role_id"=>$uid['roleid'],"status"=>1])->find();
  34. $action['action_conllect']=isset($role['action_conllect'])? $role['action_conllect']:'';
  35. $action['write'][]=$this->uid;
  36. $group=[];
  37. $group = Db::name("role_group")->where("FIND_IN_SET($this->uid,group_user) > 0")->column("id");
  38. // echo Db::name("role_group")->getLastSql();
  39. $where="to_user=$this->uid";
  40. if(!empty($group)){
  41. $where.=" or to_group in (".implode(",",$group).")";
  42. }
  43. // var_dump($group);
  44. $share =Db::name("role_share")->where(["is_del"=>0,"status"=>1])->where($where) ->select();
  45. // echo Db::name("role_share")->getLastSql();
  46. if(!empty($share)){
  47. foreach ($share as $value){
  48. if($value['action']==1){
  49. if($value['share_user']!=""){
  50. $action['write'][]=$value['share_user'];
  51. $user=Db::name("user_role")->where(['uid'=>$value['share_user'],"is_del"=>0,"status"=>1])->find();
  52. if($user!=false){
  53. $role =Db::name("role_action")->where(["role_id"=>$user['roleid'],"status"=>1])->find();
  54. if($role!=false){
  55. $conlect =Db::name("action")->where(['menuid'=>explode(",",$value['action_collect'])])->column("id");
  56. $shar=explode(",",$value['action_collect']);
  57. $wish =array_intersect($conlect,$shar);
  58. $action['action_conllect'].=empty($wish)?"":",".implode(",",$wish);
  59. }
  60. }
  61. }
  62. }
  63. if($value['action']===0){
  64. if($value['share_user']!="") $action['write'][]=$value['share_user'];
  65. if($value['action_collect']!=''){
  66. $act =Db::name("action")->where(['menuid'=>explode(",",$value['action_collect']),"action_code"=>'001'])->column("id");
  67. $action['action_conllect'].=empty($act)?"":",".implode(",",$act);
  68. }
  69. }
  70. if($value['action']===''){
  71. if($value['action_collect']!=''){
  72. $act =Db::name("action")->where(['menuid'=>explode(",",$value['action_collect']),"action_code"=>'001'])->column("id");
  73. $action['action_conllect'].=empty($act)?"":",".implode(",",$act);
  74. }
  75. }
  76. }
  77. }
  78. /**
  79. * 离职交接权限
  80. */
  81. $resgin= Db::name("resign_info")->where([["hand_uid","=",$this->uid],["is_del","=",0],['status',"=",4]])
  82. ->column(['resign_uid']);
  83. if(!empty($resgin)){
  84. $resgin['write']= array_unique(array_merge($resgin['write'],$resgin));
  85. }
  86. /**
  87. * 超级管理员看到所有人的数据
  88. */
  89. if($uid['roleid']==1){
  90. $action['write']=[];
  91. }
  92. $action['action_conllect']=implode(",",array_unique(explode(",",$action['action_conllect'])));
  93. return $action;
  94. }
  95. }