ImportDocter.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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\Imports\Docter\OrganizationOffice;
  8. use App\Models\Organization;
  9. use Illuminate\Console\Command;
  10. use Maatwebsite\Excel\Facades\Excel;
  11. class ImportDocter extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'import:importDocter {type} {filepath}';
  19. /**
  20. * The console command description.
  21. *
  22. * @var string
  23. */
  24. protected $description = '医生数据导入';
  25. /**
  26. * Create a new command instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct()
  31. {
  32. parent::__construct();
  33. }
  34. /**
  35. * Execute the console command.
  36. *
  37. * @return mixed
  38. */
  39. public function handle()
  40. {
  41. $type = $this->argument('type');
  42. $file_path = $this->argument('filepath');
  43. //路径相对于项目根目录即 /public
  44. if(empty($type) || empty($file_path)){
  45. dd('请输入完整参数');
  46. }
  47. //医生信息导入
  48. if($type == 'docter'){
  49. $this->makeDocter($file_path);
  50. }
  51. if($type == 'organization'){
  52. $this->makeOrganization($file_path);
  53. }
  54. // if($type == 'docter_organization'){
  55. // $this->makeDocterOrganization($file_path);
  56. // }
  57. if($type == 'organization_office'){
  58. $this->makeOrganizationOffice($file_path);
  59. }
  60. }
  61. /*
  62. * 导入医生要分为3个步骤
  63. * 1.先导入机构模块
  64. * 2.先导入医生模块
  65. * 3.再导入医生机构模块
  66. * */
  67. //医生模块
  68. public function makeDocter($file_path)
  69. {
  70. $this->imports($file_path);
  71. }
  72. public function imports($filePath)
  73. {
  74. $filePath = './public/import/' . $filePath . '.xlsx';
  75. Excel::import(new DocterInfo(), $filePath);
  76. }
  77. // //医生机构模块
  78. // public function makeDocterOrganization($file_path)
  79. // {
  80. // $this->importsDocterOrganization($file_path);
  81. // }
  82. // public function importsDocterOrganization($filePath)
  83. // {
  84. // $filePath = './public/import/' . $filePath . '.xlsx';
  85. //
  86. // Excel::import(new DocterOrganizationInfo(), $filePath);
  87. // }
  88. //机构模块
  89. public function makeOrganization($file_path)
  90. {
  91. $this->importsOrganization($file_path);
  92. }
  93. public function importsOrganization($filePath)
  94. {
  95. $filePath = './public/import/' . $filePath . '.xlsx';
  96. Excel::import(new OrganizationInfo(), $filePath);
  97. }
  98. //机构科室模块
  99. public function makeOrganizationOffice($file_path)
  100. {
  101. $this->importsOrganizationOffice($file_path);
  102. }
  103. public function importsOrganizationOffice($filePath)
  104. {
  105. $filePath = './public/import/' . $filePath . '.xls';
  106. Excel::import(new OrganizationOffice(), $filePath);
  107. }
  108. }