ImportUser.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\UserInfo;
  8. use App\Models\Organization;
  9. use Illuminate\Console\Command;
  10. use Maatwebsite\Excel\Facades\Excel;
  11. class ImportUser extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'import:importUser {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 == 'user'){
  49. $this->makeUser($file_path);
  50. }
  51. }
  52. public function makeUser($file_path)
  53. {
  54. $this->importsUser($file_path);
  55. }
  56. public function importsUser($filePath)
  57. {
  58. $filePath = './public/import/' . $filePath . '.xls';
  59. Excel::import(new UserInfo(), $filePath);
  60. }
  61. }