BoxBindingImport.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. if ($rowIndex === 1) return false;
  30. if (!$row[1]) return false;
  31. return BoxBinding::updateOrCreate([
  32. 'box_no' => $row[1],
  33. ], [
  34. 'batch' => '20200822',
  35. 'box_no' => $row[1],
  36. 'device_xing' => $row[2],
  37. 'imei_no' => $row[3],
  38. // 'sim_no' => $row[4],
  39. 'imsi_no' => $row[4],
  40. 'iccid_no' => $row[1],
  41. 'manufacturer' => 2,
  42. 'bluetooth_mac' => $row[5],
  43. 'bluetooth_token' => $row[5]
  44. ]);
  45. }
  46. }