1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- 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
- {
- /**
- * 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)){
- $this->output->error('请输入完整参数');
- }
- //图文咨询订单导入
- if($type == 'chat'){
- $this->makeChat($file_path);
- }
- if($type == 'vaccine'){
- $this->makeVaccine($file_path);
- }
- }
- public function makeChat($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 makeVaccine($file_path)
- {
- $filePath = './public/import/'.$file_path.'.xls';
- if(!file_exists($filePath)){
- $this->output->error('文件不存在');
- exit;
- }
- Excel::import(new vaccineOrder(), $filePath);
- $this->output->success('Import successful');
- }
- }
|