BoxBindingImport.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Imports;
  3. use App\Models\BoxBinding;
  4. use Illuminate\Support\Facades\Log;
  5. use Maatwebsite\Excel\Concerns\OnEachRow;
  6. use Maatwebsite\Excel\Concerns\ToModel;
  7. use Maatwebsite\Excel\Row;
  8. class BoxBindingImport implements OnEachRow
  9. {
  10. // /**
  11. // * @param array $row
  12. // *
  13. // * @return \Illuminate\Database\Eloquent\Model|null 批量导入
  14. // */
  15. // public function model(array $row)
  16. // {
  17. // return new BoxBinding([
  18. // //
  19. // 'box_no' => $row[0]
  20. // ]);
  21. // }
  22. /**
  23. * 逐条插入
  24. * */
  25. public function onRow(Row $row)
  26. {
  27. $rowIndex = $row->getIndex();
  28. $row = $row->toArray();
  29. // Log::info($rowIndex);
  30. if ($rowIndex === 1) return false;
  31. if (!$row[1]) return false;
  32. return BoxBinding::updateOrCreate([
  33. 'box_no' => $row[1],
  34. ], [
  35. 'batch' => $row[0],
  36. 'box_no' => $row[1],
  37. 'device_xing' => $row[2],
  38. 'imei_no' => $row[3],
  39. 'sim_no' => $row[4],
  40. 'imsi_no' => $row[5],
  41. 'iccid_no' => $row[6],
  42. ]);
  43. }
  44. }