Base.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\admin\model\RoleGroup;
  5. use app\admin\model\RoleShare;use app\BaseController;
  6. use think\App;
  7. class Base extends BaseController
  8. {
  9. protected $noLogin=[];
  10. protected $uid=0;
  11. protected $uname="system";
  12. protected $roleid=0;
  13. protected $level=0;
  14. protected $token="";
  15. protected $model=null;
  16. public function __construct(App $app) {
  17. parent::__construct($app);
  18. $this->token = $this->request->param('token','','trim');
  19. if (!action_in_arr($this->noLogin)){
  20. if($this->token=='')throw new \Exception('token不能为空',101);
  21. $this->Auth();
  22. }
  23. }
  24. /**授权token鉴定
  25. * @return \think\response\Json|void
  26. */
  27. public function Auth(){
  28. $User = \app\common\User::instance();
  29. $reLaNo= $this->request->param('relaComNo','','trim');
  30. $User->init($this->token);
  31. if (!$User->isLogin()) throw new \Exception($User->getError(),$User->getErroCode());
  32. $this->uid = $User->id;
  33. $this->uname = $User->nickname;
  34. $this->level = $User->level;
  35. $this->roleid =1;
  36. if($User->level==2){
  37. $this->roleid = \app\admin\model\UserRole::GetRoleIdByCompnyNoAndUid($reLaNo,$User->id);
  38. if($this->roleid==='') throw new \Exception( '没有该公司的角色','101');
  39. }
  40. }
  41. public function checkRole(){
  42. $action = [
  43. 'action_conllect'=>'',
  44. 'write'=>[],
  45. 'platform'=>[],
  46. 'roleid'=>$this->roleid
  47. ];
  48. if($this->level==2){
  49. $roleinfo =\app\admin\model\RoleAction::where('roleid',$this->roleid)->findOrEmpty();
  50. $action['action_conllect'] = $roleinfo->action_conllect;
  51. $action['write'][] = $this->uid;
  52. $group= RoleGroup::whereFindInSet('group_user',$this->uid)->column("id");
  53. $where = ["to_user"=>$this->uid];
  54. if(!empty($group)){
  55. $where['to_group'] =$group;
  56. }
  57. $platform = \app\admin\model\UserPlatform::where(['uid' => $this->uid, 'is_del' => 0])->findOrEmpty();
  58. $action['platform'] = $platform->platform??[];
  59. $share = RoleShare::where(['is_del' => 0, 'status' => 1])->whereOr($where)->select();
  60. if(!$share->isEmpty()){
  61. $share->each(function ($item) use (&$action) {
  62. switch ($item->action) {
  63. case 1:
  64. if($item->share_user==''){
  65. $action['write'][] =$item->share_user;
  66. $user = \app\admin\model\UserRole::where(["uid"=>$item->share_user,"is_del"=>0,"status"=>1])->findOrEmpty();
  67. if(!$user->isEmpty()){
  68. $action['write'][] =$user->roleid;
  69. }
  70. }
  71. }
  72. });
  73. }
  74. }
  75. }
  76. }