initialized) { throw new LogicException("初期化ミス"); } if ($this->order->contract_id !== $newHandler->contract_id) { throw new AppCommonException('契約不正'); } $this->order->handler_id = $newHandler->id; ChangeHandlerEvent::dispatch($this->order); return $this; } /** * 郵送依頼 * * @param array $attr * @return static */ public function mailOrder(array $attr): static { $this->fill($attr); // イベント登録 MailOrderEvent::dispatch($this->order); return $this; } /** * 郵送投函完了 * * @param array $attr * @return static */ public function mailPosted(Carbon $postDate): static { $this->order->status_mail_post_date = $postDate; // イベント登録 MailPostedEvent::dispatch($this->order); return $this; } /** * 郵送投函完了 * * @param array $attr * @return static */ public function emailOrder(string $email, A4Receipt $file, array $attr = []): static { $this->fill([ ReceiptIssuingOrder::COL_NAME_EMAIL => $email, ReceiptIssuingOrder::COL_NAME_STATUS_RECEIPT_EMAIL_SEND_ORDER_DATETIME => DateUtil::now(), ...$attr, ]); // メール送信 $mail = new ReceiptA4($this->order); $mail->setEmail($this->order->email); $manager = new EmailManager($mail); $filename = sprintf("領収証_%s.pdf", $this->order->receipt_no); $manager->attach($file->getFullPath(), $filename, "application/pdf") ->confirm(); $this->fill([ ReceiptIssuingOrder::COL_NAME_RECEIPT_PDF_EMAIL_ID => $manager->getEmailId() ]); // イベント登録 EmailOrderEvent::dispatch($this->order); PollEmailSendStatus::dispatch($this->order); return $this; } /** * 領収証確定 * * @return static */ public function setConfirm(): static { if ($this->order->receipt_no !== null) { throw new LogicException("領収証確定済み変更検知"); } $this->order->receipt_no = $this->generateReceiptnNo(); $this->order->status_receipt_confirm_datetime = DateUtil::now(); // イベント登録 ConfirmedEvent::dispatch($this->order); return $this; } public function fill(array $attr) { $this->order->fill($attr); return $this; } public function update() { // モデル更新 $this->save(); return []; } }