暫無描述

WXPopulationInfoImport.php 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Imports;
  3. use App\Models\WXPopulation;
  4. use Maatwebsite\Excel\Concerns\ToModel;
  5. use Maatwebsite\Excel\Concerns\WithStartRow;
  6. use Maatwebsite\Excel\Concerns\WithUpserts;
  7. class WXPopulationInfoImport implements ToModel, WithUpserts, WithStartRow
  8. {
  9. private $rows = 0;
  10. /**
  11. * @param array $row
  12. *
  13. * @return \Illuminate\Database\Eloquent\Model|null
  14. */
  15. public function model(array $row)
  16. {
  17. // 跳过空数据
  18. if (empty($row[0])) return null;
  19. $fieldParam = array(
  20. 'advertiser_id' => $row[0], 'orientation_id' => $row[2], 'orientation_name' => $row[1]
  21. );
  22. ++$this->rows;
  23. return new WXPopulation($fieldParam);
  24. }
  25. /**
  26. * @return string|array
  27. */
  28. public function uniqueBy()
  29. {
  30. return ['advertiser_id', 'orientation_id'];
  31. }
  32. /**
  33. * @return int
  34. */
  35. public function startRow(): int
  36. {
  37. return 3;
  38. }
  39. public function getRowCount(): int
  40. {
  41. return $this->rows;
  42. }
  43. }