Prechádzať zdrojové kódy

Merge branch 'develop'

whj 4 rokov pred
rodič
commit
60e8d63ef4

+ 20 - 13
app/Console/Commands/ImportOrder.php

xqd xqd
@@ -3,6 +3,7 @@
 namespace App\Console\Commands;
 
 use App\Imports\chatOrder;
+use App\Imports\Order\vaccineOrder;
 use Illuminate\Console\Command;
 use Maatwebsite\Excel\Facades\Excel;
 class ImportOrder extends Command
@@ -43,31 +44,37 @@ class ImportOrder extends Command
 
         //路径相对于项目根目录即 /public
         if(empty($type) || empty($file_path)){
-            dd('请输入完整参数');
+            $this->output->error('请输入完整参数');
         }
         //图文咨询订单导入
         if($type == 'chat'){
             $this->makeChat($file_path);
         }
+        if($type == 'vaccine'){
+            $this->makeVaccine($file_path);
+        }
     }
 
     public function makeChat($file_path)
     {
-        $this->imports($file_path);
+        $filePath = './public/import/'.$file_path.'.xls';
+        if(!file_exists($filePath)){
+            $this->output->error('文件不存在');
+            exit;
+        }
+        Excel::import(new chatOrder(), $filePath);
+        $this->output->success('Import successful');
     }
 
-    public function imports($filePath)
+    public function makeVaccine($file_path)
     {
-        $filePath = './public/import/' . $filePath . '.xls';
-
-        Excel::import(new chatOrder(), $filePath);
+        $filePath = './public/import/'.$file_path.'.xls';
+        if(!file_exists($filePath)){
+            $this->output->error('文件不存在');
+            exit;
+        }
+        Excel::import(new vaccineOrder(), $filePath);
+        $this->output->success('Import successful');
 
-//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 );
-//delete  from bm_order_patients where order_id in (select id from bm_orders where docter_id=10002 );
-//delete  from bm_order_vaccines where order_id in (select id from bm_orders where docter_id=10002 );
-//delete  from bm_order_nurses where order_id in (select id from bm_orders where docter_id= 10002);
-//delete from bm_docters where id = 10002;
-//delete from bm_docter_organization where docter_id  = 10002;
     }
 }

+ 130 - 0
app/Imports/Order/chatOrder.php

xqd
@@ -0,0 +1,130 @@
+<?php
+
+namespace App\Imports\Order;
+
+use AlibabaCloud\Gpdb\V20160503\DeleteDatabase;
+use App\Models\Docter;
+use App\Models\Order;
+use App\Models\OrderPatient;
+use App\Models\Organization;
+use App\Models\Patient;
+use App\User;
+use Illuminate\Support\Facades\Log;
+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,WithBatchInserts,WithChunkReading
+{
+    /**
+    * @param array $row
+    *
+    * @return \Illuminate\Database\Eloquent\Model|null
+    */
+    public function model(array $row)
+    {
+
+
+        if($row[0] == '订单编号') return null;
+//        [
+//            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",
+//        ];
+        //检查是否有该订单
+        $isHave = $this->getValue(new Order(),['order_sn'=>$row[0]],'id');
+        if($isHave) return null;
+
+        $patient_id = $this->getValue(new Patient(),['name'=>$row[2]],'id');
+        $user_id = $this->getValue(new User(),['phone'=>$row[3]],'id');
+
+        //如果没有用户不导入该订单
+        if(empty($user_id)){
+            Log::info('订单没有用户信息,订单编号: '.$row[0].PHP_EOL);
+            return null;
+        }
+//  1 => "未支付"
+//  2 => "待支付"
+//  3 => "进行中"
+//  4 => "已完成"
+//  5 => "已取消"
+//  6 => "已超时"
+//  7 => "已预约"
+        //订单状态
+        $status = Order::getStatus();
+        //订单状态
+        $paystatus = Order::getPayStatus();
+        $pay_status = array_search($row[18],$paystatus);
+        $order_status = array_search($row[9],$status);
+
+
+        $docter_id = $this->getValue(new Docter(),['name'=>$row[4]],'id');
+        $org_id = $this->getValue(new Organization(),['name'=>$row[6]],'id');
+        $evaluate = $row[10] == '已评价'? 1 : 0;
+        $pay_types = [1=>'微信支付',2=>'余额支付',3=>'服务包支付'];
+        //支付方式
+        $payType = array_search($row[16],$pay_types) + 1;
+        if($payType == 1) $payType = 2;
+
+        $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]*100,
+            'discount_amount'=>$row[13]*100,
+            'payment_amount'=>$row[15]*100,
+            'payment_type'=>$payType,
+            'payment_status'=>$pay_status,
+            'product_type'=>1,
+            'created_at'=>$row[19],
+        ];
+        //处理逻辑
+        return new Order($orderInfo);
+    }
+
+    public function startRow(): int
+    {
+        return 2;
+    }
+
+    public function batchSize(): int
+    {
+        return 20;
+    }
+
+    public function chunkSize(): int
+    {
+        return 20;
+    }
+
+    public function getValue($model,$where,$field)
+    {
+        return $model->where($where)->value($field);
+    }
+
+
+}

+ 29 - 0
app/Imports/Order/nurseOrder.php

xqd
@@ -0,0 +1,29 @@
+<?php
+
+namespace App\Imports\Order;
+
+use App\APP\Models\Order;
+use Maatwebsite\Excel\Concerns\ToModel;
+use Maatwebsite\Excel\Concerns\WithBatchInserts;
+use Maatwebsite\Excel\Concerns\WithChunkReading;
+use Maatwebsite\Excel\Concerns\WithMultipleSheets;
+use App\Imports\Order\nurseSheet;
+
+class nurseOrder implements WithMultipleSheets,WithBatchInserts,WithChunkReading
+{
+    public function sheets(): array
+    {
+        return [
+            new nurseSheet()
+        ];
+    }
+    public function batchSize(): int
+    {
+        return 1000;
+    }
+
+    public function chunkSize(): int
+    {
+        return 1000;
+    }
+}

+ 54 - 0
app/Imports/Order/nurseSheet.php

xqd
@@ -0,0 +1,54 @@
+<?php
+
+namespace App\Imports\Order;
+
+use App\Models\Order;
+use App\Models\Organization;
+use App\Models\Vaccine;
+use App\User;
+use Illuminate\Support\Collection;
+use Maatwebsite\Excel\Concerns\ToCollection;
+
+class nurseSheet implements ToCollection
+{
+    /**
+     * @param Collection $collection
+     */
+    public function collection(Collection $collection)
+    {
+        // todo 缺少患者信息导致患者信息无法确定,支付方式,无订单编号,无法去重,没机构,没用户如何处理
+        $i = 1;
+        $order_info = [];
+        foreach ($collection as $row) {
+            if($row[0] == '就诊人姓名') continue;
+            $user_id = $this->getValue(new User(),['phone'=>$row[1]],'id');
+            $vaccine_id = $this->getValue(new Vaccine(),['name'=>$row[3]],'id');
+            if(empty($user_id)){
+                Log::info('订单没有用户信息: '.$row[0].' 电话:'.$row[1].' 时间:'.$row[4].PHP_EOL);
+                continue;
+            }
+            $i ++ ;
+            $status = Order::getStatus();
+            //订单状态
+            $order_status = array_search($row[5],$status);
+            $org_id = $this->getValue(new Organization(),['name'=>$row[6]],'id');
+            if(empty($org_id)) $org_id = 0;
+            $order_sn = build_sn($i);
+            //todo 写入计免订单表,订单患者表
+            $order_info[] = [
+                'order_sn'=>$order_sn,
+                'user_id'=>$user_id,
+                'docter_id'=>0,
+                'order_status'=>$order_status,
+                'organization_id'=>$org_id,
+                'product_type'=>4,
+            ];
+        }
+        Order::insert($order_info);
+    }
+
+    public function getValue($model,$where,$field)
+    {
+        return $model->where($where)->value($field);
+    }
+}

+ 29 - 0
app/Imports/Order/vaccineOrder.php

xqd
@@ -0,0 +1,29 @@
+<?php
+
+namespace App\Imports\Order;
+
+use App\Models\Orders;
+use Maatwebsite\Excel\Concerns\WithBatchInserts;
+use Maatwebsite\Excel\Concerns\WithChunkReading;
+use Maatwebsite\Excel\Concerns\WithMultipleSheets;
+use App\Imports\Order\vaccineSheet;
+
+class vaccineOrder implements WithMultipleSheets,WithBatchInserts,WithChunkReading
+{
+    public function sheets(): array
+    {
+        return [
+            new vaccineSheet()
+        ];
+    }
+
+    public function batchSize(): int
+    {
+        return 1000;
+    }
+
+    public function chunkSize(): int
+    {
+        return 1000;
+    }
+}

+ 57 - 0
app/Imports/Order/vaccineSheet.php

xqd
@@ -0,0 +1,57 @@
+<?php
+
+namespace App\Imports\Order;
+
+use App\Models\Docter;
+use App\Models\Order;
+use App\Models\Organization;
+use App\Models\Vaccine;
+use App\User;
+use Illuminate\Support\Collection;
+use Maatwebsite\Excel\Concerns\ToCollection;
+use Illuminate\Support\Facades\Log;
+
+class vaccineSheet implements ToCollection
+{
+    /**
+    * @param Collection $collection
+    */
+    public function collection(Collection $collection)
+    {
+        // todo 缺少患者信息导致患者信息无法确定,支付方式,无订单编号,无法去重,没机构,没用户如何处理
+        $i = 1;
+        $order_info = [];
+        foreach ($collection as $row) {
+            if($row[0] == '就诊人姓名') continue;
+            $user_id = $this->getValue(new User(),['phone'=>$row[1]],'id');
+            $vaccine_id = $this->getValue(new Vaccine(),['name'=>$row[3]],'id');
+            if(empty($user_id)){
+                Log::info('订单没有用户信息: '.$row[0].' 电话:'.$row[1].' 时间:'.$row[4].PHP_EOL);
+               continue;
+            }
+            $i ++ ;
+            $status = Order::getStatus();
+            //订单状态
+            $order_status = array_search($row[5],$status);
+            $org_id = $this->getValue(new Organization(),['name'=>$row[6]],'id');
+            if(empty($org_id)) $org_id = 0;
+            $order_sn = build_sn($i);
+            //todo 写入计免订单表,订单患者表
+            $order_info[] = [
+                'order_sn'=>$order_sn,
+                'user_id'=>$user_id,
+                'docter_id'=>0,
+                'order_status'=>$order_status,
+                'organization_id'=>$org_id,
+                'product_type'=>4,
+            ];
+        }
+        return null;
+        Order::insert($order_info);
+    }
+
+    public function getValue($model,$where,$field)
+    {
+        return $model->where($where)->value($field);
+    }
+}

+ 0 - 23
app/Imports/chatOrder.php

xqd
@@ -1,23 +0,0 @@
-<?php
-
-namespace App\Imports;
-
-use App\Order;
-use Maatwebsite\Excel\Concerns\ToModel;
-
-class chatOrder implements ToModel
-{
-    /**
-    * @param array $row
-    *
-    * @return \Illuminate\Database\Eloquent\Model|null
-    */
-    public function model(array $row)
-    {
-        //处理逻辑
-        dd($row);
-        return new Order([
-            //
-        ]);
-    }
-}