Kaynağa Gözat

机构科室职称的导入

ChenWuJie 4 yıl önce
ebeveyn
işleme
8a41a2963e

+ 30 - 15
app/Console/Commands/ImportDocter.php

xqd xqd xqd
@@ -6,6 +6,7 @@ use App\Imports\chatOrder;
 use App\Imports\Docter\DocterInfo;
 use App\Imports\Docter\DocterOrganizationInfo;
 use App\Imports\Docter\OrganizationInfo;
+use App\Imports\Docter\OrganizationOffice;
 use App\Models\Organization;
 use Illuminate\Console\Command;
 use Maatwebsite\Excel\Facades\Excel;
@@ -55,8 +56,11 @@ class ImportDocter extends Command
         if($type == 'organization'){
             $this->makeOrganization($file_path);
         }
-        if($type == 'docter_organization'){
-            $this->makeDocterOrganization($file_path);
+//        if($type == 'docter_organization'){
+//            $this->makeDocterOrganization($file_path);
+//        }
+        if($type == 'organization_office'){
+            $this->makeOrganizationOffice($file_path);
         }
     }
 
@@ -73,31 +77,42 @@ class ImportDocter extends Command
     }
     public function imports($filePath)
     {
-        $filePath = './public/import/' . $filePath . '.xls';
-
+        $filePath = './public/import/' . $filePath . '.xlsx';
         Excel::import(new DocterInfo(), $filePath);
     }
-    //医生机构模块
-    public function makeDocterOrganization($file_path)
+//    //医生机构模块
+//    public function makeDocterOrganization($file_path)
+//    {
+//        $this->importsDocterOrganization($file_path);
+//    }
+//    public function importsDocterOrganization($filePath)
+//    {
+//        $filePath = './public/import/' . $filePath . '.xlsx';
+//
+//        Excel::import(new DocterOrganizationInfo(), $filePath);
+//    }
+
+    //机构模块
+    public function makeOrganization($file_path)
     {
-        $this->importsDocterOrganization($file_path);
+        $this->importsOrganization($file_path);
     }
-    public function importsDocterOrganization($filePath)
+    public function importsOrganization($filePath)
     {
-        $filePath = './public/import/' . $filePath . '.xls';
+        $filePath = './public/import/' . $filePath . '.xlsx';
 
-        Excel::import(new DocterOrganizationInfo(), $filePath);
+        Excel::import(new OrganizationInfo(), $filePath);
     }
 
-    //机构模块
-    public function makeOrganization($file_path)
+    //机构科室模块
+    public function makeOrganizationOffice($file_path)
     {
-        $this->importsOrganization($file_path);
+        $this->importsOrganizationOffice($file_path);
     }
-    public function importsOrganization($filePath)
+    public function importsOrganizationOffice($filePath)
     {
         $filePath = './public/import/' . $filePath . '.xls';
 
-        Excel::import(new OrganizationInfo(), $filePath);
+        Excel::import(new OrganizationOffice(), $filePath);
     }
 }

+ 12 - 12
app/Imports/Docter/DocterInfo.php

xqd xqd
@@ -19,17 +19,17 @@ class DocterInfo implements ToModel
         if (($row[0] == "姓名")) {
             return null;
         }
-        //职称
-        $qualification_id = 0;
-        if ($row[2])
-        {
-            $qualification_id = Qualification::firstOrCreate([
-                'name' => $row[2]
-            ],[
-                'name' => $row[2],
-                'status' =>1
-            ]);
-        }
+//        //职称
+//        $qualification_id = 0;
+//        if ($row[2])
+//        {
+//            $qualification_id = Qualification::firstOrCreate([
+//                'name' => $row[2]
+//            ],[
+//                'name' => $row[2],
+//                'status' =>1
+//            ]);
+//        }
         if ($row[5] == null)
         {
             $avatar = '';
@@ -42,7 +42,7 @@ class DocterInfo implements ToModel
             //
             'name' => $row[0],
             'phone' => $row[1],
-            'qualification_id' => $qualification_id,
+//            'qualification_id' => $qualification_id,
             'card_photo' => $row[3],
             'practice' => $row[4],
             'avatar' => $avatar,

+ 4 - 3
app/Imports/Docter/OrganizationInfo.php

xqd xqd
@@ -27,14 +27,14 @@ class OrganizationInfo implements ToModel
             $address = $row[5];
         }
         //经度默认值
-        if ($row[7] == null)
+        if ($row[6] == null)
         {
             $latitude = 0;
         }else{
-            $latitude = $row[7];
+            $latitude = $row[6];
         }
         //纬度默认值
-        if ($row[8] == null)
+        if ($row[7] == null)
         {
             $longitude = 0;
         }else{
@@ -71,6 +71,7 @@ class OrganizationInfo implements ToModel
         }
         return new Organization([
             //
+            'type' => 1,
             'name' => $row[0],
             'level' => $level,
             'introduce' => $row[2],

+ 59 - 0
app/Imports/Docter/OrganizationOffice.php

xqd
@@ -0,0 +1,59 @@
+<?php
+
+namespace App\Imports\Docter;
+
+use App\Models\Office;
+use App\Models\Organization;
+use App\Models\Qualification;
+use Maatwebsite\Excel\Concerns\ToModel;
+use phpDocumentor\Reflection\Types\Nullable;
+
+class OrganizationOffice implements ToModel
+{
+    /**
+    * @param array $row
+    *
+    * @return \Illuminate\Database\Eloquent\Model|null
+    */
+    public function model(array $row)
+    {
+        //跳过首行
+        if (($row[0] == "姓名")) {
+            return null;
+        }
+        $org_id = null;
+        $office_id = null;
+        //所属医院
+        if ($row[3])
+        {
+            $org_id = Organization::firstOrCreate([
+                'name' => $row[3]
+            ],[
+                'name' => $row[3],
+                'type' => 1,
+                'level' => 0,
+                'introduce' => '',
+                'phone' => '',
+                'address' => '',
+                'latitude' => 0,
+                'longitude' => 0,
+            ]);
+        }
+        //所属科室
+        if ($row[4]&&$org_id)
+        {
+            $office_id = Office::firstOrCreate([
+                'org_id' => $org_id['id'],
+                'name' => $row[4]
+            ]);
+        }
+        if ($row[5]==null)
+        {
+            $row[5] ='其它';
+        }else{
+            Qualification::firstOrCreate([
+                'name' => $row[5]
+            ]);
+        }
+    }
+}