cqp 11 luni în urmă
părinte
comite
ae61564039
1 a modificat fișierele cu 20 adăugiri și 118 ștergeri
  1. 20 118
      app/Service/EmployeeService.php

+ 20 - 118
app/Service/EmployeeService.php

@@ -92,7 +92,7 @@ class EmployeeService extends Service
             if($model->pic != $data['pic']){
                 // 使用正则表达式匹配特定路径部分并替换为空
                 $pattern = '/^https?:\/\/[^\/]+\/image\//';
-                $replacedUrl = preg_replace($pattern, '', $data['pic']);
+                $replacedUrl = preg_replace($pattern, '', $model->pic);
                 (new FileUploadService())->delLocalPublicFile($replacedUrl);
             }
             $model->pic = $data['pic'] ?? "";
@@ -1203,7 +1203,7 @@ class EmployeeService extends Service
      * @param $employee_id
      * @return array|string[]
      */
-    public static function getLoginDepart($employee_id, $top_depart_id = 0){
+    public static function getLoginDepart($employee_id){
         if(empty($employee_id)) return [];
 
         //自己绑定的部门 启用的部门
@@ -1211,134 +1211,36 @@ class EmployeeService extends Service
             ->join('depart as b','b.id','a.depart_id')
             ->where('a.employee_id',$employee_id)
             ->where('b.is_use',Depart::IS_UES)
-            ->select('a.depart_id','b.is_main','b.parent_id','b.basic_type_id','b.title')
+            ->select('a.depart_id','b.parent_id','b.title')
             ->orderBy('b.parent_id','asc')
-            ->orderBy('b.is_main','desc')
             ->orderBy('a.depart_id','asc')
             ->get()->toArray();
 
-        $top = $map = $rule = $head = [];
-        $res_data = [];//获取当前所在部门(也可能是门店 为了 depart_id)
-        $my_depart = [];//当前门店下 我勾选的门店以及部门信息
-        $is_all_depart = 0;
+        $depart_range = [];
         if(! empty($depart)){
-            //库存校验
-            $set_map = ProductInventorySet::where('del_time',0)->pluck('param_one','top_depart_id')->toArray();
-
             //所有部门
             $list = Depart::where('del_time',0)->get()->toArray();
-            $depart_map = array_column($list,null,'id');
-
-            foreach ($depart as $key => $value){
-                if($value['parent_id'] == 0){
-                    $is_stock = $set_map[$value['depart_id']] ?? 1;
-                    $depart[$key]['is_stock'] = $is_stock;
-                    $top[$value['depart_id']] = [
-                        'depart_id' => $value['depart_id'],
-                        'is_main' => $value['is_main'],
-                        'basic_type_id' => $value['basic_type_id'],
-                        'title' => $value['title'],
-                        'is_stock' => $is_stock,
-                    ];
-                    $map[$value['depart_id']] = $value['depart_id'];
-
-                    if($value['depart_id'] == $top_depart_id) {
-                        $my_depart[] = $depart[$key];
-                        if(empty($res_data)){
-                            $res_data = $depart[$key];
-                        }else{
-                            if($value['depart_id'] >= $res_data['depart_id']) $res_data = $depart[$key];
-                        }
-                    }
-                }else{
-                    $t = self::getTopParentId($value['depart_id'],$list);
-                    if($t && isset($depart_map[$t])) {
-                        $is_stock = $set_map[$t] ?? 1;
-                        $depart[$key]['is_stock'] = $is_stock;
-                        $t_tmp = $depart_map[$t] ?? [];
-                        if( ! isset($top[$t_tmp['id']])){
-                            $top[$t_tmp['id']] = [
-                                'depart_id' => $t_tmp['id'],
-                                'is_main' => $t_tmp['is_main'],
-                                'basic_type_id' => $t_tmp['basic_type_id'],
-                                'title' => $t_tmp['title'],
-                                'is_stock' => $set_map[$t] ?? 1,
-                            ];
-                        }
-                        $map[$value['depart_id']] = $t;
-                    }
-                    if($t == $top_depart_id){
-                        $my_depart[] = $depart[$key];
-                        if(empty($res_data)){
-                            $res_data = $depart[$key];
-                        }else{
-                            if($value['depart_id'] >= $res_data['depart_id']) $res_data = $depart[$key];
-                        }
-                    }
-                }
+            foreach ($depart as $value){
+                if(in_array($value['depart_id'], $depart_range)) continue;
+                $tmp = self::getAllIds($list, $value['depart_id']);
+                $depart_range = array_merge_recursive($depart_range, $tmp);
             }
+            $depart_range = array_unique($depart_range);
+        }
 
-            //-------------重组当前所在门店
-            $top = array_values($top);
-            usort($top, function($a, $b) {
-                return $b['is_main'] - $a['is_main'];
-            });
-            if(! empty($top_depart_id)){
-                $targetArray = null;
-                foreach ($top as $key => $value) {
-                    if ($value['depart_id'] == $top_depart_id) {
-                        $targetArray = $value;
-                        unset($top[$key]); // 从原数组中移除目标数组
-                        break; // 找到后跳出循环
-                    }
-                }
-                if ($targetArray) array_unshift($top, $targetArray);
-            }
-            //-------------重组当前所在门店
-
-            //-------------拥有的数据权限(门店、部门)
-            $my_top = $top[0] ?? [];
-            foreach ($my_depart as $value){
-                if(in_array($value['depart_id'],$rule)) continue;
-                if(! $value['parent_id']){ //顶级
-                    if(! empty($value['is_main']) && ! $is_all_depart) $is_all_depart = 1;
-                    if($value['is_main']) {//是总公司
-                        //所有部门都有
-                        $rule = array_column($list,'id');
-                    }else{//不是总公司
-                        //自己以及子部门
-                        $depart_id = array_merge(self::getAllIds($list,$map[$value['depart_id']]),[$map[$value['depart_id']]]);
-                        $rule = array_merge_recursive($rule,$depart_id);
-                    }
-                }else{//非顶级
-                    if(! empty($my_top['is_main']) && $value['is_main'] && ! $is_all_depart) $is_all_depart = 1;
-
-                    if($value['is_main']) {//是总社
-                        $top_tmp = $map[$value['depart_id']];
-                        if(! empty($depart_map[$top_tmp]['is_main'])){
-                            //顶级公司是总公司 所有部门都有
-                            $rule = array_column($list,'id');
-                        }else{
-                            //顶级公司是分公司 分公司所有部门
-                            $depart_id = array_merge(self::getAllIds($list,$top_tmp),[$top_tmp]);
-                            $rule = array_merge_recursive($rule,$depart_id);
-                        }
-                    }else{//不是总社
-                        $rule = array_merge($rule,[$value['depart_id']]);
-                    }
-                }
-            }
-            //-------------拥有的数据权限(门店、部门)
+        return $depart_range;
+    }
 
-            //总店
-            foreach ($list as $value){
-                if(empty($value['parent_id']) && ! empty($value['is_main'])) $head = $value;
-            }
-        }
+    public static function getLoginDepartOfMan($depart){
+        if(empty($depart)) return [];
 
-        $rule = array_unique($rule);
+        $employee_id = EmployeeDepartPermission::whereIn('depart_id',$depart)
+            ->select('employee_id')
+            ->get()->toArray();
 
-        return [$depart,$top,$map,$rule,$is_all_depart,$head,$res_data];
+        return Employee::whereIn('id',array_unique($employee_id))
+            ->select('id','number')
+            ->get()->toArray();
     }
 
     //获取用户的所属门店信息