1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace App\Imports;
- use App\Models\Overseas\OverseasStar;
- use App\Services\OverseasStar\StarService;
- use App\Support\EmailQueue;
- use App\Support\Log;
- use Maatwebsite\Excel\Concerns\ToModel;
- use Maatwebsite\Excel\Concerns\WithStartRow;
- use Maatwebsite\Excel\Concerns\WithUpserts;
- class OverseasStarInfoImport implements ToModel, WithUpserts, WithStartRow
- {
- public $sysUserId;
- public $groupId;
- 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)
- {
- // 跳过空数据
- if (empty($row[3])) return null;
- $platformId = StarService::getEnumForPlatform($row[1]);
- if(empty($platformId)) {
- EmailQueue::rPush('海外达人信息导入时存在未识别的平台', json_encode($row, 256), ['xiaohua.hou@kuxuan-inc.com'], '聚星');
- return null;
- }
- $fieldParam = array(
- 'group_id' => $this->groupId, 'sys_user_id' => $this->sysUserId, 'platform' => $platformId,
- 'area' => $row[0], 'star_handle' => $row[2], 'home_page' => $row[3], 'gender' => StarService::getEnumForGender($row[4]),
- 'fans_total' => is_numeric($row[5]) ? $row[5] * 1000 : 0, 'view_avg' => is_numeric($row[6]) ? $row[6] : 0,
- 'tag_list' => StarService::starTagDeal($platformId, $row[7]), 'quote' => $row[8],
- 'email' => $row[9], 'whats_app' => $row[10], 'address' => $row[11], 'mcn' => $row[12],
- );
- ++$this->rows;
- return new OverseasStar($fieldParam);
- }
- /**
- * @return string|array
- */
- public function uniqueBy()
- {
- return ['platform', 'group_id', 'star_handle'];
- }
- /**
- * @return int
- */
- public function startRow(): int
- {
- return 3;
- }
- public function getRowCount(): int
- {
- return $this->rows;
- }
- }
|