領収証発行サービス
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.

95 lines
2.2KB

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