|
- <?php
-
- namespace App\Http\Controllers\Web\Email;
-
- use App\Codes\Email;
- use App\Email\BaseEmailer;
- use App\Email\Members\ChangePlanOrderApprove;
- use App\Email\Members\CouldNotPayNotice;
- use App\Email\Members\EntryApprove;
- use App\Email\Members\EntryApprovePayToBankCheck;
- use App\Email\Members\EntryApprovePayToYucho;
- use App\Email\Members\EntryPaymentComplete;
- use App\Email\Members\RegisterCreditcard;
- use App\Email\Members\TerminateOrderApprove;
- use App\Email\Members\UserInfoUpdateOrderApprove;
- use App\Email\Members\VehicleInfoUpdateOrderApprove;
- use App\Http\Controllers\Web\FromKintoneController;
- use App\Kintone\Models\ChangePaymentMethodCreditcardOrderApplication;
- use App\Kintone\Models\ChangePlanApplication;
- use App\Kintone\Models\PaymentPlan;
- use App\Kintone\Models\SeasonTicketContract;
- use App\Kintone\Models\SeasonTicketContractEntry;
- use App\Kintone\Models\TerminateApplication;
- use App\Kintone\Models\UserInfoUpdateApplication;
- use App\Kintone\Models\VehicleInfoUpdateApplication;
- use App\Logic\EmailManager;
- use App\Util\LoggingUtil;
- use Exception;
- use Illuminate\Http\JsonResponse;
- use Illuminate\Http\Request;
- use LogicException;
-
- class EmailSendController extends FromKintoneController
- {
- private BaseEmailer|null $email = null;
-
- private EmailManager|null $emailManager = null;
-
- public function name(): string
- {
- return "メール送信依頼";
- }
-
- public function description(): string
- {
- return "メール送信依頼を登録する";
- }
-
-
- public function __construct(protected EmailSendParam $param)
- {
- parent::__construct();
- }
-
- protected function run(Request $request): JsonResponse
- {
- try {
- // メール作成
- $this->getEmail();
-
- // 送信
- if ($this->emailManager === null) {
- throw new LogicException("EmailManager不正");
- }
-
-
- info(sprintf("Email送信依頼受信 %s [%s]", $this->param->emailId->value, json_encode($request->toArray())));
-
- $this->emailManager->confirm();
- } catch (Exception $e) {
- LoggingUtil::debugException($e);
- return $this->failedResponse();
- }
-
- return $this->successResponse();
- }
-
-
- private function getEmail()
- {
- $emailId = $this->param->emailId;
-
- if ($emailId === Email::TERMINATE_ORDER_APPROVE) {
- $application = TerminateApplication::findByApplicationNo($this->param->applicationNo);
- $seasonTicketContract = SeasonTicketContract::find($application->seasonTicketContractRecordNo);
- $this->setEmail(new TerminateOrderApprove($seasonTicketContract, $application));
- return;
- }
- if ($emailId === Email::VEHICLE_INFO_UPDATE_ORDER_APPROVE) {
- $application = VehicleInfoUpdateApplication::findByApplicationNo($this->param->applicationNo);
- $seasonTicketContract = SeasonTicketContract::find($application->seasonTicketContractRecordNo);
- $this->setEmail(new VehicleInfoUpdateOrderApprove($seasonTicketContract, $application));
- return;
- }
- if ($emailId === Email::USER_INFO_UPDATE_ORDER_APPROVE) {
- $application = UserInfoUpdateApplication::findByApplicationNo($this->param->applicationNo);
- $this->setEmail(new UserInfoUpdateOrderApprove($application));
- return;
- }
- if ($emailId === Email::ENTRY_APPROVE_YUCHO) {
- $entry = SeasonTicketContractEntry::find($this->param->seasonTicketContractEntryRecordNo);
- $parking = $entry->getParking();
- $plan = $entry->getPlan();
- $email = new EntryApprovePayToYucho($parking, $entry, $plan);
- $email->setFirstMonthPaymentPlan(PaymentPlan::find($entry->firstMonthPaymentPlanRecordNo));
- if ($entry->partitialPaymentPlanRecordNo) {
- $email->setPartitialPaymentPlan(PaymentPlan::find($entry->partitialPaymentPlanRecordNo));
- }
- if ($entry->depositPaymentPlanRecordNo) {
- $email->setDepositPaymentPlan(PaymentPlan::find($entry->depositPaymentPlanRecordNo));
- }
- $this->setEmail($email);
- return;
- }
- if ($emailId === Email::ENTRY_APPROVE_BANK_CHECK) {
- $entry = SeasonTicketContractEntry::find($this->param->seasonTicketContractEntryRecordNo);
- $parking = $entry->getParking();
- $plan = $entry->getPlan();
- $email = new EntryApprovePayToBankCheck($parking, $entry, $plan);
- $email->setFirstMonthPaymentPlan(PaymentPlan::find($entry->firstMonthPaymentPlanRecordNo));
- if ($entry->partitialPaymentPlanRecordNo) {
- $email->setPartitialPaymentPlan(PaymentPlan::find($entry->partitialPaymentPlanRecordNo));
- }
- if ($entry->depositPaymentPlanRecordNo) {
- $email->setDepositPaymentPlan(PaymentPlan::find($entry->depositPaymentPlanRecordNo));
- }
- $this->setEmail($email);
- return;
- }
- if ($emailId === Email::ENTRY_PAYMENT_COMPLETE) {
- $entry = SeasonTicketContractEntry::find($this->param->seasonTicketContractEntryRecordNo);
- $parking = $entry->getParking();
- $plan = $entry->getPlan();
- $seasonTicketContract = $entry->getSeasonTicketContract();
- $this->setEmail(new EntryPaymentComplete($parking, $entry, $plan, $seasonTicketContract));
- return;
- }
- if ($emailId === Email::CHANGE_PLAN_ORDER_APPROVE) {
- $application = ChangePlanApplication::findByApplicationNo($this->param->applicationNo);
- $seasonTicketContract = SeasonTicketContract::find($application->seasonTicketContractRecordNo);
- $this->setEmail(new ChangePlanOrderApprove($seasonTicketContract, $application));
- return;
- }
- if ($emailId === Email::COULD_NOT_PEY_NOTICE) {
- $seasonTicketContract = SeasonTicketContract::find($this->param->seasonTicketContractRecordNo);
- $paymentPlan = PaymentPlan::find($this->param->paymentPlanRecordNo);
- $this->setEmail(new CouldNotPayNotice($seasonTicketContract, $paymentPlan));
- return;
- }
- if ($emailId === Email::REGISTER_CREDITCARD) {
- $application = ChangePaymentMethodCreditcardOrderApplication::findByApplicationNo($this->param->applicationNo);
- $this->setEmail(new RegisterCreditcard($application));
- return;
- }
-
-
- if ($this->email === null || $this->emailManager === null) {
- throw new LogicException("setEmail不正");
- }
- }
-
- private function setEmail(BaseEmailer $email)
- {
- $this->email = $email;
- $this->emailManager = new EmailManager($email);
- }
- }
|