ImportOrder.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Imports\chatOrder;
  4. use Illuminate\Console\Command;
  5. use Maatwebsite\Excel\Facades\Excel;
  6. class ImportOrder extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'importOrder {type} {filepath}';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '订单数据导入';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $type = $this->argument('type');
  37. $file_path = $this->argument('filepath');
  38. //路径相对于项目根目录即 /public
  39. if(empty($type) || empty($file_path)){
  40. dd('请输入完整参数');
  41. }
  42. //图文咨询订单导入
  43. if($type == 'chat'){
  44. $this->makeChat($file_path);
  45. }
  46. }
  47. public function makeChat($file_path)
  48. {
  49. $this->imports($file_path);
  50. }
  51. public function imports($filePath)
  52. {
  53. $filePath = './public/import/' . $filePath . '.xls';
  54. // 进度条
  55. // https://docs.laravel-excel.com/3.1/imports/progress-bar.html
  56. // $this->output->title('Starting import');
  57. // (new chatOrder)->withOutput($this->output)->import($filePath);
  58. // $this->output->success('Import successful');
  59. Excel::import(new chatOrder(), $filePath);
  60. //delete from bm_docter_settings where docter_id = 10002;
  61. //delete from bm_order_packs where order_id in (select docter_id from bm_orders where docter_id=10002 );
  62. //delete from bm_order_patients where order_id in (select id from bm_orders where docter_id=10002 );
  63. //delete from bm_order_vaccines where order_id in (select id from bm_orders where docter_id=10002 );
  64. //delete from bm_order_nurses where order_id in (select id from bm_orders where docter_id= 10002);
  65. //delete from bm_docters where id = 10002;
  66. //delete from bm_docter_organization where docter_id = 10002;
  67. }
  68. }