ImportDocter.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Imports\chatOrder;
  4. use App\Imports\Docter\DocterInfo;
  5. use App\Imports\Docter\OrganizationInfo;
  6. use App\Models\Organization;
  7. use Illuminate\Console\Command;
  8. use Maatwebsite\Excel\Facades\Excel;
  9. class ImportDocter extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'import:importDocter {type} {filepath}';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = '医生数据导入';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return mixed
  36. */
  37. public function handle()
  38. {
  39. $type = $this->argument('type');
  40. $file_path = $this->argument('filepath');
  41. //路径相对于项目根目录即 /public
  42. if(empty($type) || empty($file_path)){
  43. dd('请输入完整参数');
  44. }
  45. //医生信息导入
  46. if($type == 'docter'){
  47. $this->makeDocter($file_path);
  48. }
  49. if($type == 'organization'){
  50. $this->makeOrganization($file_path);
  51. }
  52. }
  53. //医生模块
  54. public function makeDocter($file_path)
  55. {
  56. $this->imports($file_path);
  57. }
  58. public function imports($filePath)
  59. {
  60. $filePath = './public/import/' . $filePath . '.xls';
  61. Excel::import(new DocterInfo(), $filePath);
  62. }
  63. //机构模块
  64. public function makeOrganization($file_path)
  65. {
  66. $this->importsOrganization($file_path);
  67. }
  68. public function importsOrganization($filePath)
  69. {
  70. $filePath = './public/import/' . $filePath . '.xls';
  71. Excel::import(new OrganizationInfo(), $filePath);
  72. }
  73. }