您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

151 行
5.8KB

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