DormantAccountDeletionReminder.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Services\DormantAction;
  3. use App\Services\CallApiService;
  4. use App\Services\Msg\MailTemplateService;
  5. use Carbon\Carbon;
  6. class DormantAccountDeletionReminder
  7. {
  8. private $callApiService;
  9. private $mailTemplateService;
  10. public function __construct(CallApiService $callApiService, MailTemplateService $mailTemplateService)
  11. {
  12. $this->callApiService = $callApiService;
  13. $this->mailTemplateService = $mailTemplateService;
  14. }
  15. public function sendNotificationEmail($gateToken, $setup): bool
  16. {
  17. $dt = Carbon::now();
  18. $dt->subMonths($setup['FinishMonth'])->addDays($setup['FinishNoticeDays']);
  19. $formTimestamp = $dt->startOfDay()->timestamp;
  20. $toTimestamp = $dt->endOfDay()->timestamp;
  21. $memberPage = $this->callApiService->callApi([
  22. 'url' => 'member-dormant-page',
  23. 'data' => [
  24. 'PageVars' => [
  25. 'Query' => "(created_on between $formTimestamp and $toTimestamp)",
  26. 'Limit' => 999999
  27. ]
  28. ],
  29. 'headers' => [
  30. 'GateToken' => $gateToken
  31. ]
  32. ]);
  33. if ($this->callApiService->verifyApiError($memberPage)) {
  34. return false;
  35. }
  36. foreach ($memberPage['Page'] ?? [] as $member) {
  37. $this->mailTemplateService->send('msg.dabory.pro.ko_KR.email.auth.dormant-finish-1', [ 'C11' => $member['Email'], 'C12' => Carbon::createFromTimestamp($member['CreatedOn'])->addMonths($setup['FinishMonth'])->format('Y-m-d') ],
  38. $member['Email'], sprintf('[%s] 휴먼 계정 삭제 안내입니다.', config('app.name')), $gateToken);
  39. }
  40. return true;
  41. }
  42. public function getAppGuestPage($appName)
  43. {
  44. return $this->callApiService->callApi([
  45. 'url' => 'app-guest-page',
  46. 'data' => [
  47. 'PageVars' => [
  48. 'Query' => "app_name = '$appName' and is_on_use = 1",
  49. 'Limit' => 1,
  50. ]
  51. ],
  52. 'headers' => [
  53. 'GateToken' => $this->gateToken['main']
  54. ]
  55. ])['Page'][0];
  56. }
  57. public function setAppGateToken($appName, $apiUri, $appBase64)
  58. {
  59. $response = \Unirest\Request::post(
  60. $apiUri . '/gate-token-get',
  61. [ 'Accept' => 'application/json' ],
  62. [ 'AppBase64' => $appBase64 ]
  63. );
  64. if ($response->code == 200) {
  65. $data = json_encode($response->body ?? []);
  66. $this->gateToken[$appName] = json_decode($data, true);
  67. } else {
  68. return false;
  69. }
  70. }
  71. }