Browse Source

咨询订单导入

whj 4 years ago
parent
commit
a3c10b4602
2 changed files with 91 additions and 4 deletions
  1. 6 1
      app/Console/Commands/ImportOrder.php
  2. 85 3
      app/Imports/chatOrder.php

+ 6 - 1
app/Console/Commands/ImportOrder.php

xqd
@@ -60,7 +60,12 @@ class ImportOrder extends Command
     {
         $filePath = './public/import/' . $filePath . '.xls';
 
-        Excel::import(new chatOrder(), $filePath);
+//        进度条
+//        https://docs.laravel-excel.com/3.1/imports/progress-bar.html
+//        $this->output->title('Starting import');
+//        (new chatOrder)->withOutput($this->output)->import($filePath);
+//        $this->output->success('Import successful');
+           Excel::import(new chatOrder(), $filePath);
 
 //delete from bm_docter_settings where docter_id  = 10002;
 //delete  from bm_order_packs where order_id in (select docter_id from bm_orders where docter_id=10002 );

+ 85 - 3
app/Imports/chatOrder.php

xqd xqd
@@ -2,10 +2,19 @@
 
 namespace App\Imports;
 
-use App\Order;
+use App\Models\Docter;
+use App\Models\Order;
+use App\Models\OrderPatient;
+use App\Models\Organization;
+use App\Models\Patient;
+use App\User;
 use Maatwebsite\Excel\Concerns\ToModel;
+use Maatwebsite\Excel\Concerns\WithHeadingRow;
+use Maatwebsite\Excel\Concerns\WithBatchInserts;
+use Maatwebsite\Excel\Concerns\WithChunkReading;
+use Maatwebsite\Excel\Concerns\WithProgressBar;
 
-class chatOrder implements ToModel
+class chatOrder implements ToModel,WithBatchInserts,WithChunkReading
 {
     /**
     * @param array $row
@@ -14,10 +23,83 @@ class chatOrder implements ToModel
     */
     public function model(array $row)
     {
+
+
+        if($row[0] == '订单编号') return '';
+        [
+            0 => "im20210118173813522",
+            1 => "云南运营主体",
+            2 => "熊振宇",
+            3 => "13708872753",
+            4 => "文菊焱",
+            5 => "",
+            6 => "云南省昆明市昆明市盘龙区联盟街道金康园社区卫生服务站",
+            7 => "妇保科",
+            8 => "否",
+            9 => "进行中",
+            10 => "",
+            11 => "否",
+            12 => "1.99",
+            13 => "0.00",
+            14 => "1.99",
+            15 => "1.99",
+            16 => "微信支付",
+            17 => "单次图文咨询",
+            18 => "已付款",
+            19 => "2021-01-18 17:38:13",
+        ];
+
+        $patient_id = $this->getValue(new Patient(),['name'=>$row[2]],'id');
+        $user_id = $this->getValue(new User(),['phone'=>$row[3]],'id');
+        $docter_id = $this->getValue(new Docter(),['name'=>$row[4]],'id');
+        $org_id = $this->getValue(new Organization(),['name'=>$row[6]],'id');
+        $order_status = $row[9];
+        $evaluate = $row[10] == '已评价'? 1 : 0;
+
+
+//        14
+        $orderInfo = [
+            'order_sn'=>$row[0],
+            'patient_id'=>$patient_id,
+            'user_id'=>$user_id,
+            'docter_id'=>$docter_id,
+            'order_status'=>$order_status,
+            'organization_id'=>$org_id,
+            'is_evaluate'=>$evaluate,
+            'is_discount'=>$row[11],
+            'total_amount'=>$row[12],
+            'discount_amount'=>$row[13],
+            'payment_amount'=>$row[15],
+            'payment_type'=>$row[16],
+            'payment_status'=>$row[18],
+            'created_at'=>$row[19],
+        ];
+        dd($orderInfo);
         //处理逻辑
-        dd($row);
         return new Order([
             //
         ]);
     }
+
+    public function startRow(): int
+    {
+        return 2;
+    }
+
+    public function batchSize(): int
+    {
+        return 1000;
+    }
+
+    public function chunkSize(): int
+    {
+        return 1000;
+    }
+
+    public function getValue($model,$where,$field)
+    {
+        return $model->where($where)->value($field);
+    }
+
+
 }