Aucune description

OverseasStarInfoImport.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Imports;
  3. use App\Models\Overseas\OverseasStar;
  4. use App\Services\OverseasStar\StarService;
  5. use App\Support\EmailQueue;
  6. use App\Support\Log;
  7. use Maatwebsite\Excel\Concerns\ToModel;
  8. use Maatwebsite\Excel\Concerns\WithStartRow;
  9. use Maatwebsite\Excel\Concerns\WithUpserts;
  10. class OverseasStarInfoImport implements ToModel, WithUpserts, WithStartRow
  11. {
  12. public $sysUserId;
  13. public $groupId;
  14. private $rows = 0;
  15. public function __construct($groupId, $sysUserId)
  16. {
  17. $this->groupId = $groupId;
  18. $this->sysUserId = $sysUserId;
  19. }
  20. /**
  21. * @param array $row
  22. *
  23. * @return \Illuminate\Database\Eloquent\Model|null
  24. */
  25. public function model(array $row)
  26. {
  27. // 跳过空数据
  28. if (empty($row[3])) return null;
  29. $platformId = StarService::getEnumForPlatform($row[1]);
  30. if(empty($platformId)) {
  31. EmailQueue::rPush('海外达人信息导入时存在未识别的平台', json_encode($row, 256), ['xiaohua.hou@kuxuan-inc.com'], '聚星');
  32. return null;
  33. }
  34. $fieldParam = array(
  35. 'group_id' => $this->groupId, 'sys_user_id' => $this->sysUserId, 'platform' => $platformId,
  36. 'area' => $row[0], 'star_handle' => $row[2], 'home_page' => $row[3], 'gender' => StarService::getEnumForGender($row[4]),
  37. 'fans_total' => is_numeric($row[5]) ? $row[5] * 1000 : 0, 'view_avg' => is_numeric($row[6]) ? $row[6] : 0,
  38. 'tag_list' => StarService::starTagDeal($platformId, $row[7]), 'quote' => $row[8],
  39. 'email' => $row[9], 'whats_app' => $row[10], 'address' => $row[11], 'mcn' => $row[12],
  40. );
  41. ++$this->rows;
  42. return new OverseasStar($fieldParam);
  43. }
  44. /**
  45. * @return string|array
  46. */
  47. public function uniqueBy()
  48. {
  49. return ['platform', 'group_id', 'star_handle'];
  50. }
  51. /**
  52. * @return int
  53. */
  54. public function startRow(): int
  55. {
  56. return 3;
  57. }
  58. public function getRowCount(): int
  59. {
  60. return $this->rows;
  61. }
  62. }