海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB

  1. <?php
  2. namespace App\AdminSupplier\Forms;
  3. use App\Jobs\ImportProductFromExcel;
  4. use Dcat\Admin\Widgets\Form;
  5. use Illuminate\Support\Facades\Storage;
  6. class ExcelImport extends Form
  7. {
  8. /**
  9. * Handle the form request.
  10. *
  11. * @param array $input
  12. *
  13. * @return mixed
  14. */
  15. public function handle(array $input)
  16. {
  17. foreach ($input['zip_file'] as $zip_file) {
  18. /*# 使用md5_file来重命名文件,保证唯一
  19. $to_path = str_replace(basename($zip_file), '', $zip_file);
  20. $to_path .= md5_file(Storage::disk('public')->path($zip_file)) . '.zip';
  21. Storage::disk('public')->move($zip_file, $to_path);*/
  22. ImportProductFromExcel::dispatch(\Admin::user()->id, Storage::disk('public')->path($zip_file));
  23. }
  24. return $this->response()->success('操作成功,导入产品可能需要几分钟,请勿重复导入,请耐心等待')->refresh();
  25. }
  26. /**
  27. * Build a form here.
  28. */
  29. public function form()
  30. {
  31. $this->multipleFile('zip_file', 'ZIP文件')
  32. ->help('注意:请上传zip文件,上传文件大小不能超过' . ini_get('upload_max_filesize') .
  33. '。<a href="' . Storage::disk('public')->url('import.zip') . '" target="_blank">文件导入模板</a>')
  34. ->accept('zip')
  35. ->uniqueName()->autoUpload()->required();
  36. }
  37. /**
  38. * The data of the form.
  39. *
  40. * @return array
  41. */
  42. public function default()
  43. {
  44. return [];
  45. }
  46. }