123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace App\Model;
- use App\Service\RangeService;
- use Illuminate\Database\Eloquent\Model;
- class UseScopeBaseModel extends Model
- {
- //可见范围
- const range_function = '';
- const is_check_function = '';
- public function __construct(array $attributes = [])
- {
- parent::__construct($attributes);
- }
- //顶级部门过滤
- public function scopeTopClear($query, $user, $search)
- {
- //是否所有部门
- $is_all_depart = $user['is_all_depart'] ?? 0;
- //权限范围内的部门
- $depart_range = $user['depart_range'] ?? [];
- //顶级部门
- $search_depart_id = $search['top_depart_id'] ?? 0;
- if(empty($search_depart_id)){
- //默认进来 自身顶级公司
- $top_depart_id = $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)){
- //全部
- $query->whereIn('top_depart_id', $depart_range);
- }else{
- //查看某个分社
- $query->where('top_depart_id', $top_depart_id);
- }
- }else{
- //某个分社全部
- $query->where('top_depart_id', $top_depart_id);
- }
- //获取当前门店下
- if(! empty($search['get_my_top_depart_data'])){
- $depart = ! empty($user['depart_top'][0]) ? $user['depart_top'][0]: [];
- $depart_id = $depart['depart_id'] ?? 0;
- $query->where('top_depart_id', $depart_id);
- }
- return $query;
- }
- //
- public function scopeKqClear($query, $user, $search)
- {
- //权限范围内的人
- $man_range = $user['man_range'] ?? [];
- $man_number = array_unique(array_column($man_range,'number'));
- //个人部门所有
- $auth_type = $this->getQx($search,$user);
- if($auth_type <= 0){
- //不需要分个人部门所有的数据
- if($auth_type == 0) $query->whereIn('number', $man_number);
- }else{
- if($auth_type == 1) { //我的
- $query->where('number',$user['number']);
- }elseif ($auth_type == 2 || $auth_type == 3){
- //自己权限范围内的部门 或 所有
- $query->whereIn('number', $man_number);
- }
- }
- }
- public function getQx($data, $user){
- if(empty($data['menu_authority_id'])) return 0;
- if($user['id'] == Employee::SPECIAL_ADMIN) return -1;
- if(! empty($user['role_authority'][$data['menu_authority_id']])) {
- //指定菜单 显示对应权限
- return $user['role_authority'][$data['menu_authority_id']];
- }else{
- return 1;
- }
- }
- function hasMethod($class, $methodName)
- {
- $reflection = new \ReflectionClass($class);
- return $reflection->hasMethod($methodName);
- }
- }
|