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

168 行
6.7KB

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