You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
5.3KB

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