123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace App\Imports;
- use App\Models\Sys\SysStarInformation;
- use Maatwebsite\Excel\Concerns\ToModel;
- use Maatwebsite\Excel\Concerns\WithStartRow;
- use Maatwebsite\Excel\Concerns\WithUpserts;
- class StarInformationImport implements ToModel, WithUpserts, WithStartRow
- {
- public $ptype;
- public $groupId;
- public $sysUserId;
- private $rows = 0;
- public function __construct($ptype, $groupId, $sysUserId)
- {
- $this->ptype = $ptype;
- $this->groupId = $groupId;
- $this->sysUserId = $sysUserId;
- }
- /**
- * @param array $row
- *
- * @return \Illuminate\Database\Eloquent\Model|null
- */
- public function model(array $row)
- {
- // 跳过空数据
- if (empty($row[3]) || !is_numeric($row[3])) return null;
- $fieldParam = [
- 'group_id' => $this->groupId,
- 'ptype' => $this->ptype,
- 'sys_user_id' => $this->sysUserId,
- 'platform' => $row[0],
- 'cat_id' => isset($row[1]) ? hash('fnv164', $row[1], false) : null,
- 'category' => $row[1],
- 'nickname' => $row[2],
- 'accid' => $row[3],
- 'fans' => $row[4],
- ];
- switch ($this->ptype) {
- case 1:
- case 2:
- $fieldParam['quoted_price_1'] = $row[5];
- $fieldParam['ins_id'] = isset($row[6]) ? hash('fnv164', $row[6], false) : null;
- $fieldParam['institution'] = $row[6];
- $fieldParam['contact'] = $row[7];
- $fieldParam['home_link'] = $row[8];
- $fieldParam['cooperate_type'] = $row[9];
- $fieldParam['gender_ratio'] = $row[13];
- $fieldParam['age_ratio'] = $row[14];
- $fieldParam['avg_play'] = $row[10];
- $fieldParam['avg_interact'] = $row[11];
- $fieldParam['cpm'] = $row[12];
- break;
- case 3:
- $fieldParam['quoted_price_1'] = $row[6];
- $fieldParam['quoted_price_2'] = $row[5];
- $fieldParam['ins_id'] = isset($row[7]) ? hash('fnv164', $row[7], false) : null;
- $fieldParam['institution'] = $row[7];
- $fieldParam['contact'] = $row[8];
- $fieldParam['home_link'] = $row[9];
- $fieldParam['cooperate_type'] = $row[10];
- $fieldParam['gender_ratio'] = $row[14];
- $fieldParam['age_ratio'] = $row[15];
- $fieldParam['med_read'] = $row[11];
- $fieldParam['med_interact'] = $row[12];
- $fieldParam['interact_rate'] = $row[13];
- break;
- default:
- return null;
- }
- ++$this->rows;
- return new SysStarInformation($fieldParam);
- }
- /**
- * @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;
- }
- }
|