cqp hai 1 mes
pai
achega
388907bf0d
Modificáronse 1 ficheiros con 78 adicións e 24 borrados
  1. 78 24
      app/Model/UseScopeBaseNewModel.php

+ 78 - 24
app/Model/UseScopeBaseNewModel.php

@@ -316,32 +316,86 @@ class UseScopeBaseNewModel extends Model
         });
     }
 
-    private function notAllDepart(&$query, $is_check, $auth_type, $user, $depart_range, $top_depart_id, $tmpTable, $check_search) {
-        $query->where(function ($q) use ($top_depart_id, $auth_type, $user, $depart_range, $is_check, $check_search, $tmpTable) {
-
-            $q->where('top_depart_id', $top_depart_id);
-
-            $q->where(function ($sub) use ($auth_type, $user, $depart_range, $tmpTable) {
-                if ($auth_type == 1) {
-                    $sub->where('crt_id', $user['id']);
-                } elseif ($auth_type == 2) {
-                    $sub->whereIn('depart_id', $depart_range);
-                }
-
-                // 关键:合并可见范围临时表
-                if ($tmpTable) {
-                    $sub->orWhereExists(function ($exists) use ($tmpTable) {
-                        $exists->select(DB::raw(1))
-                            ->from($tmpTable)
-                            ->whereRaw("{$tmpTable}.range_allowed_id = id");
+    //非所有权限
+    private function notAllDepart(&$query, $is_check, $auth_type, $user, $depart_range, $top_depart_id, $tmpTable, $check_search){
+        if ($is_check){
+            if(! $auth_type || $auth_type == 3){
+                //指定公司下全部  且加上可见
+                $query->where('top_depart_id', $top_depart_id)
+                    ->when(! empty($check_search), function ($query) use ($check_search) {
+                        return $query->whereRaw($check_search);
+                    })
+                    ->when($tmpTable, function ($query) use ($tmpTable) {
+                        return $query->orWhereExists(function ($q) use ($tmpTable) {
+                            $q->select(DB::raw(1))
+                                ->from($tmpTable)
+                                ->whereRaw("{$tmpTable}.range_allowed_id = id");
+                        });
+                    });
+            }else if($auth_type == 1) {
+                //指定公司下 且 我创建的 且加上可见
+                $query->where('top_depart_id', $top_depart_id)
+                    ->where('crt_id',$user['id'])
+                    ->when(! empty($check_search), function ($query) use ($check_search) {
+                        return $query->whereRaw($check_search);
+                    })
+                    ->when($tmpTable, function ($query) use ($tmpTable) {
+                        return $query->orWhereExists(function ($q) use ($tmpTable) {
+                            $q->select(DB::raw(1))
+                                ->from($tmpTable)
+                                ->whereRaw("{$tmpTable}.range_allowed_id = id");
+                        });
+                    });
+            }elseif ($auth_type == 2) {
+                //指定公司下 且 自己权限范围内的部门 且加上可见
+                $query->where('top_depart_id', $top_depart_id)
+                    ->whereIn('depart_id', $depart_range)
+                    ->when(! empty($check_search), function ($query) use ($check_search) {
+                        return $query->whereRaw($check_search);
+                    })
+                    ->when($tmpTable, function ($query) use ($tmpTable) {
+                        return $query->orWhereExists(function ($q) use ($tmpTable) {
+                            $q->select(DB::raw(1))
+                                ->from($tmpTable)
+                                ->whereRaw("{$tmpTable}.range_allowed_id = id");
+                        });
                     });
-                }
-            });
-
-            if ($is_check && !empty($check_search)) {
-                $q->whereRaw($check_search);
             }
-        });
+        }else{
+            if(! $auth_type || $auth_type == 3){
+                //指定公司下全部|所有  且加上可见
+                $query->where('top_depart_id', $top_depart_id)
+                    ->when($tmpTable, function ($query) use ($tmpTable) {
+                        return $query->orWhereExists(function ($q) use ($tmpTable) {
+                            $q->select(DB::raw(1))
+                                ->from($tmpTable)
+                                ->whereRaw("{$tmpTable}.range_allowed_id = id");
+                        });
+                    });
+            }elseif($auth_type == 1) {
+                //指定公司下 且 我创建的 且加上可见
+                $query->where('top_depart_id', $top_depart_id)
+                    ->where('crt_id',$user['id'])
+                    ->when($tmpTable, function ($query) use ($tmpTable) {
+                        return $query->orWhereExists(function ($q) use ($tmpTable) {
+                            $q->select(DB::raw(1))
+                                ->from($tmpTable)
+                                ->whereRaw("{$tmpTable}.range_allowed_id = id");
+                        });
+                    });
+            }elseif ($auth_type == 2) {
+                //指定公司下 且 自己权限范围内的部门 且加上可见
+                $query->where('top_depart_id', $top_depart_id)
+                    ->whereIn('depart_id', $depart_range)
+                    ->when($tmpTable, function ($query) use ($tmpTable) {
+                        return $query->orWhereExists(function ($q) use ($tmpTable) {
+                            $q->select(DB::raw(1))
+                                ->from($tmpTable)
+                                ->whereRaw("{$tmpTable}.range_allowed_id = id");
+                        });
+                    });
+            }
+        }
     }
 
     public function getQx($data, $user)