Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

128 lines
4.5KB

  1. <?php
  2. namespace App\Http\Controllers\Web\Email;
  3. use App\Codes\Email;
  4. use App\Email\BaseEmailer;
  5. use App\Email\Members\ChangePlanOrderApprove;
  6. use App\Email\Members\EntryApprove;
  7. use App\Email\Members\EntryPaymentComplete;
  8. use App\Email\Members\TerminateOrderApprove;
  9. use App\Email\Members\UserInfoUpdateOrderApprove;
  10. use App\Email\Members\VehicleInfoUpdateOrderApprove;
  11. use App\Http\Controllers\Web\FromKintoneController;
  12. use App\Kintone\Models\ChangePlanApplication;
  13. use App\Kintone\Models\SeasonTicketContract;
  14. use App\Kintone\Models\SeasonTicketContractEntry;
  15. use App\Kintone\Models\TerminateApplication;
  16. use App\Kintone\Models\UserInfoUpdateApplication;
  17. use App\Kintone\Models\VehicleInfoUpdateApplication;
  18. use App\Logic\EmailManager;
  19. use App\Util\LoggingUtil;
  20. use Exception;
  21. use Illuminate\Http\JsonResponse;
  22. use Illuminate\Http\Request;
  23. use LogicException;
  24. class EmailSendController extends FromKintoneController
  25. {
  26. private BaseEmailer|null $email = null;
  27. private EmailManager|null $emailManager = null;
  28. public function name(): string
  29. {
  30. return "メール送信依頼";
  31. }
  32. public function description(): string
  33. {
  34. return "メール送信依頼を登録する";
  35. }
  36. public function __construct(protected EmailSendParam $param)
  37. {
  38. parent::__construct();
  39. }
  40. protected function run(Request $request): JsonResponse
  41. {
  42. try {
  43. // メール作成
  44. $this->getEmail();
  45. // 送信
  46. if ($this->emailManager === null) {
  47. throw new LogicException("EmailManager不正");
  48. }
  49. info(sprintf("Email送信依頼受信 %s [%s]", $this->param->emailId->value, json_encode($request->toArray())));
  50. $this->emailManager->confirm();
  51. } catch (Exception $e) {
  52. LoggingUtil::debugException($e);
  53. return $this->failedResponse();
  54. }
  55. return $this->successResponse();
  56. }
  57. private function getEmail()
  58. {
  59. $emailId = $this->param->emailId;
  60. if ($emailId === Email::TERMINATE_ORDER_APPROVE) {
  61. $application = TerminateApplication::findByApplicationNo($this->param->applicationNo);
  62. $seasonTicketContract = SeasonTicketContract::find($application->seasonTicketContractRecordNo);
  63. $this->setEmail(new TerminateOrderApprove($seasonTicketContract, $application));
  64. return;
  65. }
  66. if ($emailId === Email::VEHICLE_INFO_UPDATE_ORDER_APPROVE) {
  67. $application = VehicleInfoUpdateApplication::findByApplicationNo($this->param->applicationNo);
  68. $seasonTicketContract = SeasonTicketContract::find($application->seasonTicketContractRecordNo);
  69. $this->setEmail(new VehicleInfoUpdateOrderApprove($seasonTicketContract, $application));
  70. return;
  71. }
  72. if ($emailId === Email::USER_INFO_UPDATE_ORDER_APPROVE) {
  73. $application = UserInfoUpdateApplication::findByApplicationNo($this->param->applicationNo);
  74. $seasonTicketContract = SeasonTicketContract::find($application->seasonTicketContractRecordNo);
  75. $this->setEmail(new UserInfoUpdateOrderApprove($seasonTicketContract, $application));
  76. return;
  77. }
  78. if ($emailId === Email::ENTRY_APPROVE) {
  79. $entry = SeasonTicketContractEntry::find($this->param->seasonTicketContractEntryRecordNo);
  80. $parking = $entry->getParking();
  81. $plan = $entry->getPlan();
  82. $this->setEmail(new EntryApprove($parking, $entry, $plan));
  83. return;
  84. }
  85. if ($emailId === Email::ENTRY_PAYMENT_COMPLETE) {
  86. $entry = SeasonTicketContractEntry::find($this->param->seasonTicketContractEntryRecordNo);
  87. $parking = $entry->getParking();
  88. $plan = $entry->getPlan();
  89. $this->setEmail(new EntryPaymentComplete($parking, $entry, $plan));
  90. return;
  91. }
  92. if ($emailId === Email::CHANGE_PLAN_ORDER_APPROVE) {
  93. $application = ChangePlanApplication::findByApplicationNo($this->param->applicationNo);
  94. $seasonTicketContract = SeasonTicketContract::find($application->seasonTicketContractRecordNo);
  95. $this->setEmail(new ChangePlanOrderApprove($seasonTicketContract, $application));
  96. return;
  97. }
  98. if ($this->email === null || $this->emailManager === null) {
  99. throw new LogicException("setEmail不正");
  100. }
  101. }
  102. private function setEmail(BaseEmailer $email)
  103. {
  104. $this->email = $email;
  105. $this->emailManager = new EmailManager($email);
  106. }
  107. }