GrowingIOUserGender.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Console\Commands\Sync;
  3. use App\Jobs\GrowingIO\TestingReportJob;
  4. use App\Jobs\GrowingIO\UserInfoReportJob;
  5. use App\Models\User\UserModel;
  6. use GuzzleHttp\Client;
  7. use Illuminate\Console\Command;
  8. use Illuminate\Database\Eloquent\Collection;
  9. class GrowingIOUserGender extends Command
  10. {
  11. protected $signature = 'sync:gio-user-gender';
  12. protected $description = 'Command description';
  13. public function handle()
  14. {
  15. $this->comment('total ' . UserModel::count());
  16. $count = 0;
  17. UserModel::orderBy('uid', 'asc')->chunk(99, function ($users) use (&$count) {
  18. /** @var Collection $users */
  19. $data = $users->map(function ($user) {
  20. /** @var UserModel $user */
  21. if ($user->sex === 1) {
  22. $gender = '男性';
  23. } elseif ($user->sex === 2) {
  24. $gender = '女性';
  25. } else {
  26. $gender = '未知';
  27. }
  28. $uid = (string)$user->uid;
  29. dispatch_now(new TestingReportJob($uid));
  30. return [
  31. 'loginUserId' => $uid,
  32. 'gender' => $gender,
  33. ];
  34. })->all();
  35. $count += count($data);
  36. dispatch_now(new UserInfoReportJob($data));
  37. $this->comment('handled ' . $count);
  38. });
  39. }
  40. }