Browse Source

导入模板

whj 4 years ago
parent
commit
fc1e1e869b
3 changed files with 98 additions and 0 deletions
  1. 73 0
      app/Console/Commands/ImportOrder.php
  2. 2 0
      app/Console/Kernel.php
  3. 23 0
      app/Imports/chatOrder.php

+ 73 - 0
app/Console/Commands/ImportOrder.php

xqd
@@ -0,0 +1,73 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Imports\chatOrder;
+use Illuminate\Console\Command;
+use Maatwebsite\Excel\Facades\Excel;
+class ImportOrder extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'importOrder {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 == 'chat'){
+            $this->makeChat($file_path);
+        }
+    }
+
+    public function makeChat($file_path)
+    {
+        $this->imports($file_path);
+    }
+
+    public function imports($filePath)
+    {
+        $filePath = './public/import/' . $filePath . '.xls';
+
+        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 );
+//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;
+    }
+}

+ 2 - 0
app/Console/Kernel.php

xqd xqd
@@ -2,6 +2,7 @@
 
 namespace App\Console;
 
+use App\Console\Commands\ImportOrder;
 use App\Console\Commands\overTimeOrder;
 use App\Console\Commands\packExpiredCheck;
 use Illuminate\Console\Scheduling\Schedule;
@@ -19,6 +20,7 @@ class Kernel extends ConsoleKernel
         'order'=>overTimeOrder::class,
         'scheduleNotice'=>overTimeOrder::class,
         'packExpiredCheck'=>packExpiredCheck::class,
+        'importOrder'=>ImportOrder::class,
     ];
 
     /**

+ 23 - 0
app/Imports/chatOrder.php

xqd
@@ -0,0 +1,23 @@
+<?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([
+            //
+        ]);
+    }
+}