user = $user; $this->search = $search; } public function apply(Builder $builder, Model $model) { //权限范围内的部门 $depart_range = $this->user['depart_range'] ?? []; //我可见的 $is_see = $this->search['is_see'] ?? 0; //可见范围方法 $range_function = $this->user['range_function'] ?? ""; $is_function_range = $this->hasMethod(new RangeService(),$range_function); //顶级部门 $search_depart_id = $this->search['top_depart_id'] ?? 0; //顶级公司 if(empty($search_depart_id)){ //默认进来 自身顶级公司 $top_depart_id = $this->user['depart_top'][0] ?? []; $top_depart_id = $top_depart_id['depart_id'] ?? 0; }else{ //查询 顶级公司 $top_depart_id = $search_depart_id; } //顶级部门下 权限范围内部门的所有数据 $builder->where('top_depart_id', $top_depart_id) ->whereIn('depart_id', $depart_range); //加上可见范围 部门 人以后的数据 $id = []; if($is_see && $is_function_range) $id = RangeService::$range_function($this->user); $builder->orWhereIn('id', $id); if(! empty($this->user['is_search_main'])) $builder->orWhere('is_main', '>',0); } function hasMethod($class, $methodName) { $reflection = new \ReflectionClass($class); return $reflection->hasMethod($methodName); } }