領収証発行サービス
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 line
1.8KB

  1. <?php
  2. namespace App\Logic\ReceiptIssuingOrder;
  3. use App\Codes\ReceiptIssuingOrderStatus;
  4. use App\Codes\SMSSendPurpose;
  5. use App\Logic\SMS\SMSManager;
  6. use App\Models\ReceiptIssuingOrder;
  7. use Illuminate\Support\Facades\View;
  8. use LogicException;
  9. class CreateManager extends ReceiptIssuingOrderManager
  10. {
  11. public function __construct(
  12. protected ReceiptIssuingOrder $order,
  13. protected SMSManager $smsManager
  14. ) {
  15. }
  16. public function init()
  17. {
  18. $order = $this->order;
  19. $this->initialized = true;
  20. return $this;
  21. }
  22. public function fill(array $attr)
  23. {
  24. $this->order->fill($attr);
  25. return $this;
  26. }
  27. public function create(): array
  28. {
  29. $order = $this->order;
  30. // パラメータチェック
  31. $messages = $this->paramCheck();
  32. if (count($messages) !== 0) {
  33. return $messages;
  34. }
  35. // モデル更新
  36. $order->status = ReceiptIssuingOrderStatus::CREATED;
  37. $this->refreshToken();
  38. $contractId = $this->loginUser()->getContractId();
  39. if ($contractId === null) {
  40. throw new LogicException("契約不良");
  41. }
  42. $order->setContract($contractId)
  43. ->save();
  44. // SMS配信
  45. $smsSendOrder = $this->smsManager::makeSMSSendOrder($order, SMSSendPurpose::SEND_RECEIPT_ISSUING_ORDER_FORM, $this->makeSMSContents());
  46. $smsSendOrder->send();
  47. return [];
  48. }
  49. private function paramCheck(): array
  50. {
  51. $ret = [];
  52. $order = $this->order;
  53. return $ret;
  54. }
  55. private function makeSMSContents(): string
  56. {
  57. return View::make('sms.announce_receipt_issusing_order_form', [
  58. 'url' => implode('/', [config('app.url'), 'receipt-issuing-order/create', $this->order->access_token])
  59. ])->render();
  60. }
  61. }