Sfoglia il codice sorgente

Merge branch 'master' of ssh://git.9026.com:2212/swdz-WangHaijun/BaoMa

zilong 4 anni fa
parent
commit
0a0ed3e374

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

xqd
@@ -0,0 +1,82 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Imports\chatOrder;
+use App\Imports\Docter\DocterInfo;
+use App\Imports\Docter\OrganizationInfo;
+use App\Models\Organization;
+use Illuminate\Console\Command;
+use Maatwebsite\Excel\Facades\Excel;
+class ImportDocter extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'import:importDocter {type} {filepath}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '医生数据导入';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $type = $this->argument('type');
+        $file_path = $this->argument('filepath');
+        //路径相对于项目根目录即 /public
+        if(empty($type) || empty($file_path)){
+            dd('请输入完整参数');
+        }
+        //医生信息导入
+        if($type == 'docter'){
+            $this->makeDocter($file_path);
+        }
+        if($type == 'organization'){
+            $this->makeOrganization($file_path);
+        }
+    }
+
+    //医生模块
+    public function makeDocter($file_path)
+    {
+        $this->imports($file_path);
+    }
+    public function imports($filePath)
+    {
+        $filePath = './public/import/' . $filePath . '.xls';
+
+        Excel::import(new DocterInfo(), $filePath);
+    }
+
+    //机构模块
+    public function makeOrganization($file_path)
+    {
+        $this->importsOrganization($file_path);
+    }
+    public function importsOrganization($filePath)
+    {
+        $filePath = './public/import/' . $filePath . '.xls';
+
+        Excel::import(new OrganizationInfo(), $filePath);
+    }
+}

+ 87 - 0
app/Imports/Docter/OrganizationInfo.php

xqd
@@ -0,0 +1,87 @@
+<?php
+
+namespace App\Imports\Docter;
+
+use App\Models\Organization;
+use Maatwebsite\Excel\Concerns\ToModel;
+use phpDocumentor\Reflection\Types\Nullable;
+
+class OrganizationInfo implements ToModel
+{
+    /**
+    * @param array $row
+    *
+    * @return \Illuminate\Database\Eloquent\Model|null
+    */
+    public function model(array $row)
+    {
+        //跳过首行
+        if (($row[0] == "名称")) {
+            return null;
+        }
+        //地址默认值
+        if ($row[5]== null)
+        {
+            $address = '';
+        }else{
+            $address = $row[5];
+        }
+        //经度默认值
+        if ($row[7] == null)
+        {
+            $latitude = 0;
+        }else{
+            $latitude = $row[7];
+        }
+        //纬度默认值
+        if ($row[8] == null)
+        {
+            $longitude = 0;
+        }else{
+            $longitude = $row[7];
+        }
+
+
+
+        //判断机构等级
+        switch ($row[1]){
+            case "未定级" :
+                $level = 0;
+                break;
+            case "一级" :
+                $level = 1;
+                break;
+            case "二级" :
+                $level = 2;
+                break;
+            case "三级" :
+                $level = 3;
+                break;
+            default :
+                $level = 0;
+                break;
+        }
+
+
+        $num = Organization::where('name',$row[0])->count();
+        if ($num > 0)
+        {
+            \Log::info('重复的机构'.$row[0]);
+            return null ;
+        }
+        return new Organization([
+            //
+            'name' => $row[0],
+            'level' => $level,
+            'introduce' => $row[2],
+            'phone' => $row[3],
+            'address' => $address,
+            'latitude' => $latitude,
+            'longitude' => $longitude,
+        ]);
+    }
+    public function uniqueBy()
+    {
+        return 'name';
+    }
+}