cqpCow 1 年間 前
コミット
74cad2ae5f
1 ファイル変更17 行追加0 行削除
  1. 17 0
      app/Service/EmployeeService.php

+ 17 - 0
app/Service/EmployeeService.php

@@ -564,6 +564,23 @@ class EmployeeService extends Service
             if($title_count[$value] > 1) return [false,'名称不能重复'];
         }
 
+        $count = 0;
+        foreach ($data['data'] as $value){
+            if(empty($value['parent_id']) && ! empty($value['is_main'])) $count ++;
+        }
+        if($count > 1) return [false,'顶级总社只允许存在一个!'];
+        if($count == 1){
+            $id = $data['id'] ?? 0;
+            $bool = Depart::where('del_time',0)
+                ->where('parent_id',0)
+                ->where('is_main',1)
+                ->when(! empty($id), function ($query) use ($id) {
+                    return $query->where('id', '<>',$id);
+                })
+                ->exists();
+            if($bool) return [false,'顶级总社只允许存在一个!'];
+        }
+
         foreach ($data['data'] as $key => $value){
             if(empty($value['parent_id'])) $data['data'][$key]['parent_id'] = 0;