ImportUser.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\User\PatientsInfo;
  8. use App\Imports\User\UserInfo;
  9. use App\Models\Organization;
  10. use Illuminate\Console\Command;
  11. use Maatwebsite\Excel\Facades\Excel;
  12. class ImportUser extends Command
  13. {
  14. /**
  15. * The name and signature of the console command.
  16. *
  17. * @var string
  18. */
  19. protected $signature = 'import:importUser {type} {filepath}';
  20. /**
  21. * The console command description.
  22. *
  23. * @var string
  24. */
  25. protected $description = '用户数据导入';
  26. /**
  27. * Create a new command instance.
  28. *
  29. * @return void
  30. */
  31. public function __construct()
  32. {
  33. parent::__construct();
  34. }
  35. /**
  36. * Execute the console command.
  37. *
  38. * @return mixed
  39. */
  40. public function handle()
  41. {
  42. $type = $this->argument('type');
  43. $file_path = $this->argument('filepath');
  44. //路径相对于项目根目录即 /public
  45. if(empty($type) || empty($file_path)){
  46. dd('请输入完整参数');
  47. }
  48. //用户信息导入
  49. if($type == 'user'){
  50. $this->makeUser($file_path);
  51. }
  52. if($type == 'patients'){
  53. $this->makePatients($file_path);
  54. }
  55. }
  56. //导入用户
  57. public function makeUser($file_path)
  58. {
  59. $this->importsUser($file_path);
  60. }
  61. public function importsUser($filePath)
  62. {
  63. $filePath = './public/import/' . $filePath . '.xlsx';
  64. Excel::import(new UserInfo(), $filePath);
  65. }
  66. //导入患者
  67. public function makePatients($file_path)
  68. {
  69. $this->importsPatients($file_path);
  70. }
  71. public function importsPatients($filePath)
  72. {
  73. $filePath = './public/import/' . $filePath . '.xlsx';
  74. Excel::import(new PatientsInfo(), $filePath);
  75. }
  76. }