|
- <?php
-
- namespace App\Logic\ReceiptIssuingOrder;
-
- use App\Codes\ReceiptIssuingOrderStatus;
- use App\Codes\SMSSendPurpose;
- use App\Logic\SMS\SMSManager;
- use App\Models\ReceiptIssuingOrder;
- use App\Util\DateUtil;
- use Illuminate\Support\Facades\View;
- use LogicException;
-
- class CreateManager extends ReceiptIssuingOrderManager
- {
-
- public function __construct(
- protected ReceiptIssuingOrder $order,
- protected SMSManager $smsManager
- ) {
- parent::__construct($order);
- }
-
- public function init()
- {
- $order = $this->order;
-
-
- $this->initialized = true;
- return $this;
- }
-
- public function id(): string
- {
- return $this->order->id ?? "";
- }
-
- public function fill(array $attr)
- {
- $this->order->fill($attr);
- return $this;
- }
-
- public function create(): array
- {
- $order = $this->order;
-
- // パラメータチェック
- $messages = $this->paramCheck();
- if (count($messages) !== 0) {
- return $messages;
- }
-
- // モデル更新
- $order->status = ReceiptIssuingOrderStatus::CREATED;
- $order->order_datetime = DateUtil::now();
- $this->refreshToken();
-
- $contractId = $this->loginUser()->getContractId();
- if ($contractId === null) {
- throw new LogicException("契約不良");
- }
- $order->setContract($contractId)
- ->save();
-
-
- // SMS配信
- $smsSendOrder = $this->smsManager::makeSMSSendOrder($order, SMSSendPurpose::SEND_RECEIPT_ISSUING_ORDER_FORM, $this->makeSMSContents());
- $smsSendOrder->send();
-
- return [];
- }
-
- private function paramCheck(): array
- {
- $ret = [];
- $order = $this->order;
-
- return $ret;
- }
-
- private function makeSMSContents(): string
- {
- return View::make('sms.announce_receipt_issusing_order_form', [
- 'url' => implode('/', [config('app.url'), 'receipt-issuing-order/create', $this->order->access_token])
- ])->render();
- }
- }
|