DeleteDormantMemberCommand.php-- 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\CallApiService;
  4. use App\Services\DormantService;
  5. use Carbon\Carbon;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Support\Facades\Hash;
  8. class DeleteDormantMemberCommand extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'dormant:delete-member';
  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. $dormantDefault = $this->dormantService->getSetup();
  44. $dt = Carbon::now()->startOfDay();
  45. $dt->addMonths($dormantDefault['DormantMonth']);
  46. $appName = $dormantDefault['GuestApp'];
  47. $memberDormantPage = $this->callApiService->callAppApi([
  48. 'url' => 'member-dormant-page',
  49. 'data' => [
  50. 'PageVars' => [
  51. 'Query' => "created_on >= $dt->timestamp",
  52. 'Limit' => 999999
  53. ]
  54. ],
  55. ], $this->dormantService->getGateToken($appName), $appName);
  56. if ($this->callApiService->verifyApiError($memberDormantPage)) {
  57. return 0;
  58. }
  59. foreach ($memberDormantPage['Page'] ?? [] as $memberDormant) {
  60. $memberDormantAct = $this->callApiService->callAppApi([
  61. 'url' => 'member-dormant-act',
  62. 'data' => [
  63. 'Page' => [
  64. [ 'Id' => $memberDormant['Id'] * -1 ]
  65. ]
  66. ],
  67. ], $this->dormantService->getGateToken($appName), $appName);
  68. // $memberExtAct = $this->callApiService->callApi([
  69. // 'url' => 'member-ext-act',
  70. // 'data' => [
  71. // 'Page' => [
  72. // [ 'Id' => $memberDormant['Id'] * -1 ]
  73. // ]
  74. // ],
  75. // 'headers' => [
  76. // 'GateToken' => $this->dormantService->getGateToken('main')
  77. // ]
  78. // ]);
  79. //
  80. $member = $this->callApiService->callApi([
  81. 'url' => 'member-pick',
  82. 'data' => [
  83. 'Page' => [
  84. [ 'Id' => $memberDormant['Id'] ]
  85. ]
  86. ],
  87. 'headers' => [
  88. 'GateToken' => $this->dormantService->getGateToken('main')
  89. ]
  90. ])['Page'][0];
  91. $memberAct = $this->callApiService->callApi([
  92. 'url' => 'member-act',
  93. 'data' => [
  94. 'Page' => [
  95. [
  96. 'Id' => $memberDormant['Id'],
  97. 'Email' => Hash::make($member['Email'] . $member['Id'] . $member['ActivateCode']),
  98. 'Status' => '6'
  99. ]
  100. ]
  101. ],
  102. 'headers' => [
  103. 'GateToken' => $this->dormantService->getGateToken('main')
  104. ]
  105. ]);
  106. }
  107. return 0;
  108. }
  109. }