ImportOrder.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Imports\Order\chatOrder;
  4. use App\Imports\Order\nurseOrder;
  5. use App\Imports\Order\phoneOrder;
  6. use App\Imports\Order\serviceOrder;
  7. use App\Imports\Order\vaccineOrder;
  8. use Illuminate\Console\Command;
  9. use Maatwebsite\Excel\Facades\Excel;
  10. class ImportOrder extends Command
  11. {
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'importOrder {type} {filepath}';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = '订单数据导入 importOrder {订单类型} {导入xls文件名}';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @return mixed
  37. */
  38. public function handle()
  39. {
  40. $type = $this->argument('type');
  41. $file_path = $this->argument('filepath');
  42. //路径相对于项目根目录即 /public
  43. if(empty($type) || empty($file_path)){
  44. $this->output->error('请输入完整参数');
  45. }
  46. //图文咨询订单导入
  47. switch ($type){
  48. case 'chat';
  49. $this->makeChat($file_path);
  50. break;
  51. case 'phone';
  52. $this->makePhone($file_path);
  53. break;
  54. case 'vaccine';
  55. $this->makeVaccine($file_path);
  56. break;
  57. case 'nurse';
  58. $this->makeNurse($file_path);
  59. break;
  60. case 'service';
  61. $this->makeService($file_path);
  62. break;
  63. default;
  64. $this->output->error('请输入正确参数');
  65. break;
  66. }
  67. }
  68. //图文订单
  69. public function makeChat($file_path)
  70. {
  71. $filePath = './public/import/'.$file_path.'.xls';
  72. if(!file_exists($filePath)){
  73. $this->output->error('文件不存在');
  74. exit;
  75. }
  76. Excel::import(new chatOrder(), $filePath);
  77. $this->output->success('Import successful');
  78. }
  79. //电话订单
  80. public function makePhone($file_path)
  81. {
  82. $filePath = './public/import/'.$file_path.'.xls';
  83. if(!file_exists($filePath)){
  84. $this->output->error('文件不存在');
  85. exit;
  86. }
  87. Excel::import(new phoneOrder(), $filePath);
  88. $this->output->success('Import successful');
  89. }
  90. //疫苗订单
  91. public function makeVaccine($file_path)
  92. {
  93. $filePath = './public/import/'.$file_path.'.xls';
  94. if(!file_exists($filePath)){
  95. $this->output->error('文件不存在');
  96. exit;
  97. }
  98. Excel::import(new vaccineOrder(), $filePath);
  99. $this->output->success('Import successful');
  100. }
  101. //儿保订单
  102. public function makeNurse($file_path)
  103. {
  104. $filePath = './public/import/'.$file_path.'.xls';
  105. if(!file_exists($filePath)){
  106. $this->output->error('文件不存在');
  107. exit;
  108. }
  109. Excel::import(new nurseOrder(), $filePath);
  110. $this->output->success('Import successful');
  111. }
  112. //服务包订单
  113. public function makeService($file_path)
  114. {
  115. $filePath = './public/import/'.$file_path.'.xls';
  116. if(!file_exists($filePath)){
  117. $this->output->error('文件不存在');
  118. exit;
  119. }
  120. Excel::import(new serviceOrder(), $filePath);
  121. $this->output->success('Import successful');
  122. }
  123. }