cqpCow před 10 měsíci
rodič
revize
12bdbe40c5
2 změnil soubory, kde provedl 16 přidání a 21 odebrání
  1. 11 0
      app/Service/BasicTypeService.php
  2. 5 21
      app/Service/ImportService.php

+ 11 - 0
app/Service/BasicTypeService.php

@@ -185,6 +185,17 @@ class BasicTypeService extends Service
         return array_column($basic,'id');
     }
 
+    //获取当前
+    public function getMyBasicList($user, $type){
+        if(! is_array($type)) $type = [$type];
+        $depart_id = $this->getDepart($user);
+        $top_depart_id = $user['depart_map'][$depart_id] ?? 0;
+        return BasicType::where('del_time',0)
+            ->whereIn('type',$type)
+            ->where('top_depart_id',$top_depart_id)
+            ->get()->toArray();
+    }
+
     public function maked(){
         $list = BasicType::where('del_time',0)
             ->select('title','type','top_depart_id')

+ 5 - 21
app/Service/ImportService.php

@@ -164,10 +164,7 @@ class ImportService extends Service
         $config_array = config($config) ?? [];
         if(empty($config_array)) return [false, '配置文件不存在', ''];
 
-        $depart_id = $this->getDepart($user);
-        $top_depart_id = $user['depart_map'][$depart_id] ?? 0;
-        $result = BasicType::whereRaw('type = 22 And del_time = 0 And top_depart_id = ' . $top_depart_id)->get()->toArray();
-
+        $result = (new BasicTypeService())->getMyBasicList($user, 22);
         if(! empty($result)){
             foreach ($result as $value){
                 $config_array[] = [
@@ -251,12 +248,7 @@ class ImportService extends Service
             ->pluck('id','title')
             ->toArray();
 
-        $model = BasicType::TopClear($user,[]);
-        $basic = $model->where('del_time',0)
-            ->whereIn('type',[1,2,3,4,5,9,10,30])
-            ->select('id','title','type')
-            ->get()
-            ->toArray();
+        $basic = (new BasicTypeService())->getMyBasicList($user, [1,2,3,4,5,9,10,30]);
         $basic_list = [];
         foreach ($basic as $value){
             if($value['type'] == 1){
@@ -477,11 +469,8 @@ class ImportService extends Service
             ->where('top_depart_id',$top_depart_id)
             ->get()->toArray();
 
-        $model = BasicType::TopClear($user,[]);
-        $basic = $model->where('del_time',0)
-            ->where('type',20)
-            ->pluck('id','title')
-            ->toArray();
+        $basic = (new BasicTypeService())->getMyBasicList($user, 20);
+        $basic = array_column($basic,'id','title');
 
         $category = ProductCategory::whereIn('title',array_unique(array_column($array,'2')))
             ->where('del_time',0)
@@ -596,12 +585,7 @@ class ImportService extends Service
         unset($array[0]);
         if(empty($array)) return [false, '导入数据不能为空'];
 
-        $model = BasicType::TopClear($user,[]);
-        $basic = $model->where('del_time',0)
-            ->whereIn('type',[18,23,24,29])
-            ->select('id','title','type')
-            ->get()
-            ->toArray();
+        $basic = (new BasicTypeService())->getMyBasicList($user, [18,23,24,29]);
         $basic_list = [];
         foreach ($basic as $value){
             if($value['type'] == 18){