暂无描述

StarInstitutionImport.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Imports;
  3. use App\Models\Sys\SysStarInstitution;
  4. use Maatwebsite\Excel\Concerns\ToModel;
  5. use Maatwebsite\Excel\Concerns\WithStartRow;
  6. use Maatwebsite\Excel\Concerns\WithUpserts;
  7. class StarInstitutionImport implements ToModel, WithUpserts, WithStartRow
  8. {
  9. public $groupId;
  10. public $sysUserId;
  11. private $rows = 0;
  12. public function __construct($groupId, $sysUserId)
  13. {
  14. $this->groupId = $groupId;
  15. $this->sysUserId = $sysUserId;
  16. }
  17. /**
  18. * @param array $row
  19. *
  20. * @return \Illuminate\Database\Eloquent\Model|null
  21. */
  22. public function model(array $row)
  23. {
  24. ++$this->rows;
  25. return new SysStarInstitution([
  26. 'group_id' => $this->groupId,
  27. 'sys_user_id' => $this->sysUserId,
  28. 'ins_id' => isset($row[2]) ? hash('fnv164', $row[2], false) : null,
  29. 'name' => $row[2],
  30. 'cat_id' => isset($row[1]) ? hash('fnv164', $row[1], false) : null,
  31. 'category' => $row[1],
  32. 'rebate_ratio' => $row[0],
  33. 'star_count' => $row[3],
  34. 'platforms' => $row[4],
  35. 'is_sign' => $row[5],
  36. 'contact' => $row[6],
  37. 'address' => $row[7]
  38. ]);
  39. }
  40. /**
  41. * @return string|array
  42. */
  43. public function uniqueBy()
  44. {
  45. return ['group_id', 'ins_id'];
  46. }
  47. /**
  48. * @return int
  49. */
  50. public function startRow(): int
  51. {
  52. return 2;
  53. }
  54. public function getRowCount(): int
  55. {
  56. return $this->rows;
  57. }
  58. }