ExternalCaseImport.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Imports;
  3. use App\Http\Models\Business;
  4. use App\Http\Models\LinkCase;
  5. use Illuminate\Support\Collection;
  6. use Maatwebsite\Excel\Concerns\Importable;
  7. use Maatwebsite\Excel\Concerns\ToCollection;
  8. class ExternalCaseImport implements ToCollection
  9. {
  10. use Importable;
  11. public function collection(Collection $collections)
  12. {
  13. $linkType = array_flip(LinkCase::TYPES);
  14. $list = [];
  15. foreach ($collections as $key => $collection) {
  16. if ($key < 1) {
  17. continue;
  18. }
  19. $data = [
  20. 'type' => $linkType[$collection[0]],//对不上直接抛异常
  21. 'url' => $collection[1] ?? '',
  22. 'username_history' => $collection[2] ?? '',
  23. 'email_history' => $collection[3] ?? '',
  24. 'password_history' => $collection[4] ?? '',
  25. 'url_history' => $collection[5] ?? '',
  26. 'created_at' => date('Y-m-d H:i:s')
  27. ];
  28. $list[] = $data;
  29. }
  30. LinkCase::query()->insert($list);
  31. }
  32. }