user = $user; $this->search = $search; } public function apply(Builder $builder, Model $model) { //是否所有部门 $is_all_depart = $this->user['is_all_depart'] ?? 0; //权限范围内的部门 $depart_range = $this->user['depart_range'] ?? []; //顶级部门 $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; } if($is_all_depart){ //所有部门 if(empty($search_depart_id)){ //全部 $builder->whereIn('top_depart_id', $depart_range); }else{ //查看某个分社 $builder->where('top_depart_id', $top_depart_id); } }else{ //某个分社全部 $builder->where('top_depart_id', $top_depart_id); } } }