فهرست منبع

创建医生导入的所有数据

ChenWuJie 4 سال پیش
والد
کامیت
6d1fbf4802
3فایلهای تغییر یافته به همراه127 افزوده شده و 0 حذف شده
  1. 21 0
      app/Console/Commands/ImportDocter.php
  2. 52 0
      app/Imports/Docter/DocterInfo.php
  3. 54 0
      app/Imports/Docter/DocterOrganizationInfo.php

+ 21 - 0
app/Console/Commands/ImportDocter.php

xqd xqd xqd
@@ -4,6 +4,7 @@ namespace App\Console\Commands;
 
 use App\Imports\chatOrder;
 use App\Imports\Docter\DocterInfo;
+use App\Imports\Docter\DocterOrganizationInfo;
 use App\Imports\Docter\OrganizationInfo;
 use App\Models\Organization;
 use Illuminate\Console\Command;
@@ -54,8 +55,17 @@ class ImportDocter extends Command
         if($type == 'organization'){
             $this->makeOrganization($file_path);
         }
+        if($type == 'docter_organization'){
+            $this->makeDocterOrganization($file_path);
+        }
     }
 
+    /*
+     * 导入医生要分为3个步骤
+     * 1.先导入机构模块
+     * 2.先导入医生模块
+     * 3.再导入医生机构模块
+     * */
     //医生模块
     public function makeDocter($file_path)
     {
@@ -67,6 +77,17 @@ class ImportDocter extends Command
 
         Excel::import(new DocterInfo(), $filePath);
     }
+    //医生机构模块
+    public function makeDocterOrganization($file_path)
+    {
+        $this->importsDocterOrganization($file_path);
+    }
+    public function importsDocterOrganization($filePath)
+    {
+        $filePath = './public/import/' . $filePath . '.xls';
+
+        Excel::import(new DocterOrganizationInfo(), $filePath);
+    }
 
     //机构模块
     public function makeOrganization($file_path)

+ 52 - 0
app/Imports/Docter/DocterInfo.php

xqd
@@ -0,0 +1,52 @@
+<?php
+
+namespace App\Imports\Docter;
+
+use App\Models\Docter;
+use App\Models\Organization;
+use App\Models\Qualification;
+use Maatwebsite\Excel\Concerns\ToModel;
+
+class DocterInfo implements ToModel
+{
+    /**
+    * @param array $row
+    *
+    * @return \Illuminate\Database\Eloquent\Model|null
+    */
+    public function model(array $row)
+    {
+        if (($row[0] == "姓名")) {
+            return null;
+        }
+        //职称
+        $qualification_id = 0;
+        if ($row[2])
+        {
+            $qualification_id = Qualification::firstOrCreate([
+                'name' => $row[2]
+            ],[
+                'name' => $row[2],
+                'status' =>1
+            ]);
+        }
+        if ($row[5] == null)
+        {
+            $avatar = '';
+        }else
+        {
+            $avatar = $row[5];
+        }
+
+        return new Docter([
+            //
+            'name' => $row[0],
+            'phone' => $row[1],
+            'qualification_id' => $qualification_id,
+            'card_photo' => $row[3],
+            'practice' => $row[4],
+            'avatar' => $avatar,
+            'is_then' => 1
+        ]);
+    }
+}

+ 54 - 0
app/Imports/Docter/DocterOrganizationInfo.php

xqd
@@ -0,0 +1,54 @@
+<?php
+
+namespace App\Imports\Docter;
+
+use App\Models\Docter;
+use App\Models\DocterOrganization;
+use App\Models\Organization;
+use App\Models\Qualification;
+use Maatwebsite\Excel\Concerns\ToModel;
+
+class DocterOrganizationInfo implements ToModel
+{
+    /**
+    * @param array $row
+    *
+    * @return \Illuminate\Database\Eloquent\Model|null
+    */
+    public function model(array $row)
+    {
+        if (($row[0] == "姓名")) {
+            return null;
+        }
+        $docter_id = null;
+        if ($row[0]){
+            $docter_id = Docter::firstOrCreate([
+                'name' => $row[0],
+            ]);
+        }
+        $org_id = null;
+        if ($row[6]){
+            $org_id = Organization::firstOrCreate([
+               'name' => $row[6],
+            ]);
+        }
+
+        $qualification_id = null;
+        if ($row[2])
+        {
+            $qualification_id = Qualification::firstOrCreate([
+                'name' => $row[2]
+            ],[
+                'name' => $row[2],
+                'status' =>1
+            ]);
+        }
+        return new DocterOrganization([
+            //
+            'docter_id' => $docter_id['id'],
+            'organization_id' => $org_id['id'],
+            'qualifications_id' =>$qualification_id['id'],
+            'state' => 1
+        ]);
+    }
+}