12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace App\Imports;
- use App\Models\Sys\SysStarInstitution;
- use Maatwebsite\Excel\Concerns\ToModel;
- use Maatwebsite\Excel\Concerns\WithStartRow;
- use Maatwebsite\Excel\Concerns\WithUpserts;
- class StarInstitutionImport implements ToModel, WithUpserts, WithStartRow
- {
- public $groupId;
- public $sysUserId;
- private $rows = 0;
- public function __construct($groupId, $sysUserId)
- {
- $this->groupId = $groupId;
- $this->sysUserId = $sysUserId;
- }
- /**
- * @param array $row
- *
- * @return \Illuminate\Database\Eloquent\Model|null
- */
- public function model(array $row)
- {
- ++$this->rows;
- return new SysStarInstitution([
- 'group_id' => $this->groupId,
- 'sys_user_id' => $this->sysUserId,
- 'ins_id' => isset($row[2]) ? hash('fnv164', $row[2], false) : null,
- 'name' => $row[2],
- 'cat_id' => isset($row[1]) ? hash('fnv164', $row[1], false) : null,
- 'category' => $row[1],
- 'rebate_ratio' => $row[0],
- 'star_count' => $row[3],
- 'platforms' => $row[4],
- 'is_sign' => $row[5],
- 'contact' => $row[6],
- 'address' => $row[7]
- ]);
- }
- /**
- * @return string|array
- */
- public function uniqueBy()
- {
- return ['group_id', 'ins_id'];
- }
- /**
- * @return int
- */
- public function startRow(): int
- {
- return 2;
- }
- public function getRowCount(): int
- {
- return $this->rows;
- }
- }
|