1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Imports;
- use App\Models\WXPopulation;
- use Maatwebsite\Excel\Concerns\ToModel;
- use Maatwebsite\Excel\Concerns\WithStartRow;
- use Maatwebsite\Excel\Concerns\WithUpserts;
- class WXPopulationInfoImport implements ToModel, WithUpserts, WithStartRow
- {
- private $rows = 0;
- /**
- * @param array $row
- *
- * @return \Illuminate\Database\Eloquent\Model|null
- */
- public function model(array $row)
- {
- // 跳过空数据
- if (empty($row[0])) return null;
- $fieldParam = array(
- 'advertiser_id' => $row[0], 'orientation_id' => $row[2], 'orientation_name' => $row[1]
- );
- ++$this->rows;
- return new WXPopulation($fieldParam);
- }
- /**
- * @return string|array
- */
- public function uniqueBy()
- {
- return ['advertiser_id', 'orientation_id'];
- }
- /**
- * @return int
- */
- public function startRow(): int
- {
- return 3;
- }
- public function getRowCount(): int
- {
- return $this->rows;
- }
- }
|