ImportDocter.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Imports\chatOrder;
  4. use App\Imports\Docter\DocterInfo;
  5. use App\Imports\Docter\DocterOrganizationInfo;
  6. use App\Imports\Docter\OrganizationInfo;
  7. use App\Models\Organization;
  8. use Illuminate\Console\Command;
  9. use Maatwebsite\Excel\Facades\Excel;
  10. class ImportDocter extends Command
  11. {
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'import:importDocter {type} {filepath}';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = '医生数据导入';
  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. dd('请输入完整参数');
  45. }
  46. //医生信息导入
  47. if($type == 'docter'){
  48. $this->makeDocter($file_path);
  49. }
  50. if($type == 'organization'){
  51. $this->makeOrganization($file_path);
  52. }
  53. if($type == 'docter_organization'){
  54. $this->makeDocterOrganization($file_path);
  55. }
  56. }
  57. /*
  58. * 导入医生要分为3个步骤
  59. * 1.先导入机构模块
  60. * 2.先导入医生模块
  61. * 3.再导入医生机构模块
  62. * */
  63. //医生模块
  64. public function makeDocter($file_path)
  65. {
  66. $this->imports($file_path);
  67. }
  68. public function imports($filePath)
  69. {
  70. $filePath = './public/import/' . $filePath . '.xls';
  71. Excel::import(new DocterInfo(), $filePath);
  72. }
  73. //医生机构模块
  74. public function makeDocterOrganization($file_path)
  75. {
  76. $this->importsDocterOrganization($file_path);
  77. }
  78. public function importsDocterOrganization($filePath)
  79. {
  80. $filePath = './public/import/' . $filePath . '.xls';
  81. Excel::import(new DocterOrganizationInfo(), $filePath);
  82. }
  83. //机构模块
  84. public function makeOrganization($file_path)
  85. {
  86. $this->importsOrganization($file_path);
  87. }
  88. public function importsOrganization($filePath)
  89. {
  90. $filePath = './public/import/' . $filePath . '.xls';
  91. Excel::import(new OrganizationInfo(), $filePath);
  92. }
  93. }