|
- <?php
-
- namespace App\Logic\ReceiptIssuingOrder;
-
- use App\Events\ReceiptIssuingOrder\ChangeHandlerEvent;
- use App\Events\ReceiptIssuingOrder\ConfirmedEvent;
- use App\Events\ReceiptIssuingOrder\MailOrderEvent;
- use App\Events\ReceiptIssuingOrder\MailPostedEvent;
- use App\Exceptions\AppCommonException;
- use App\Logic\SMS\SMSManager;
- use App\Models\ReceiptIssuingOrder;
- use App\Models\User;
- use App\Util\DateUtil;
- use Illuminate\Support\Carbon;
- use LogicException;
-
- class UpdateManager extends ReceiptIssuingOrderManager
- {
-
- public function __construct(
- protected ReceiptIssuingOrder $order,
- protected SMSManager $smsManager
- ) {
- parent::__construct($order);
- }
-
- public function changeHandler(User $newHandler)
- {
- if (!$this->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;
- }
-
- /**
- * 領収証確定
- *
- * @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 [];
- }
- }
|