ResendEmailsCommand.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Events\DormantAccountNotify;
  4. use App\Services\CallApiService;
  5. use App\Services\DormantService;
  6. use Carbon\Carbon;
  7. use Illuminate\Console\Command;
  8. class ResendEmailsCommand extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'dormant:resend-email';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '휴먼계정 안내 메일 재발송';
  22. private $callApiService;
  23. private $dormantService;
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct(CallApiService $callApiService, DormantService $dormantService)
  30. {
  31. parent::__construct();
  32. $this->callApiService = $callApiService;
  33. $this->dormantService = $dormantService;
  34. }
  35. /**
  36. * Execute the console command.
  37. *
  38. * @return int
  39. */
  40. public function handle()
  41. {
  42. $this->dormantService->setMainToken();
  43. $memberPage = $this->callApiService->callApi([
  44. 'url' => 'member-page',
  45. 'data' => [
  46. 'PageVars' => [
  47. 'Query' => "dormant_mail_on = -1",
  48. 'Limit' => 999999
  49. ]
  50. ],
  51. 'headers' => [
  52. 'GateToken' => $this->dormantService->getGateToken('main')
  53. ]
  54. ]);
  55. $result = [];
  56. foreach ($memberPage['Page'] ?? [] as $member) {
  57. $result[] = event(new DormantAccountNotify([
  58. 'email' => $member['Email'],
  59. 'due_date' => Carbon::now()->startOfDay()->format('Y-m-d'),
  60. ]));
  61. }
  62. $mailSendList = collect($result)->collapse()->collapse()->toArray();
  63. $mailSendPage = collect($memberPage['Page'])->map(function ($member) use ($mailSendList) {
  64. if ($mailSendList[$member['Email']]) {
  65. $dormantMailOn = Carbon::now()->timestamp;
  66. } else {
  67. $dormantMailOn = -1;
  68. }
  69. return ['Id' => $member['Id'], 'DormantMailOn' => $dormantMailOn];
  70. })->toArray();
  71. if (empty($mailSendPage)) {
  72. return 0;
  73. }
  74. $memberAct = $this->callApiService->callApi([
  75. 'url' => 'member-act',
  76. 'data' => [
  77. 'Page' => $mailSendPage
  78. ],
  79. 'headers' => [
  80. 'GateToken' => $this->dormantService->getGateToken('main')
  81. ]
  82. ]);
  83. return 0;
  84. }
  85. }