Ver Fonte

小高薪

cqp há 3 meses atrás
pai
commit
7ef5c4631b
1 ficheiros alterados com 12 adições e 0 exclusões
  1. 12 0
      app/Service/EmployeeService.php

+ 12 - 0
app/Service/EmployeeService.php

@@ -211,6 +211,18 @@ class EmployeeService extends Service
                 ->select('employee_id')->get()->toArray();
             $model->whereIn('id',array_column($emp,'employee_id'));
         }
+        if(! empty($data['depart'])) {
+            // 1. 获取所有子部门 ID(包含自身)
+            $allDeparts = Depart::where('del_time', 0)->select('id', 'parent_id')->get();
+            $departIds = array_merge($this->getAllDescendants($allDeparts->toArray(), $data['depart']), [$data['depart']]);
+
+            // 2. 优化:直接使用子查询,避免拉取巨大的 $employee_id 数组到内存
+            $model->whereIn('id', function ($query) use ($departIds) {
+                $query->select('employee_id')
+                    ->from('employee_depart_permission')
+                    ->whereIn('depart_id', $departIds);
+            });
+        }
 
         return $model;
     }