選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

160 行
4.9KB

  1. <?php
  2. namespace App\Logic;
  3. use App\Exceptions\AppCommonException;
  4. use App\Kintone\Models\BankAccountUpdateApplication;
  5. use App\Kintone\Models\ChangePaymentMethodCreditcardOrderApplication;
  6. use App\Kintone\Models\ChangePlanApplication;
  7. use App\Kintone\Models\Customer;
  8. use App\Kintone\Models\GeneralApplication;
  9. use App\Kintone\Models\Parking;
  10. use App\Kintone\Models\ParkingCertificateApplication;
  11. use App\Kintone\Models\ParkingUseTypeChangeOrderApplication;
  12. use App\Kintone\Models\SeasonTicketContract;
  13. use App\Kintone\Models\SeasonTicketReOrderApplication;
  14. use App\Kintone\Models\StickerReOrderApplication;
  15. use App\Kintone\Models\TerminateApplication;
  16. use App\Kintone\Models\UserInfoUpdateApplication;
  17. use App\Kintone\Models\VehicleInfoUpdateApplication;
  18. use App\Util\DateUtil;
  19. use LogicException;
  20. /**
  21. * @template T of GeneralApplication
  22. */
  23. class GeneralApplicationManager
  24. {
  25. private ?Customer $customer = null;
  26. private ?SeasonTicketContract $seasonTicketContract = null;
  27. private ?Parking $parking = null;
  28. /**
  29. * @param T $model
  30. */
  31. public function __construct(private GeneralApplication $model)
  32. {
  33. if ($model instanceof TerminateApplication) {
  34. $this->setType("解約申請");
  35. return;
  36. }
  37. if ($model instanceof ParkingCertificateApplication) {
  38. $this->setType("車庫証明発行申請");
  39. return;
  40. }
  41. if ($model instanceof StickerReOrderApplication) {
  42. $this->setType("シール再発行申請");
  43. return;
  44. }
  45. if ($model instanceof ParkingUseTypeChangeOrderApplication) {
  46. $this->setType("IC定期_駐車場利用方法変更申請");
  47. return;
  48. }
  49. if ($model instanceof SeasonTicketReOrderApplication) {
  50. $this->setType("定期券再発行申請");
  51. return;
  52. }
  53. if ($model instanceof VehicleInfoUpdateApplication) {
  54. $this->setType("車両番号・防犯登録番号変更");
  55. return;
  56. }
  57. if ($model instanceof UserInfoUpdateApplication) {
  58. $this->setType("利用者情報変更");
  59. return;
  60. }
  61. if ($model instanceof UserInfoUpdateApplication) {
  62. $this->setType("振替頻度変更");
  63. return;
  64. }
  65. if ($model instanceof BankAccountUpdateApplication) {
  66. $this->setType("口座変更申請");
  67. return;
  68. }
  69. if ($model instanceof ChangePlanApplication) {
  70. $this->setType("プラン変更");
  71. return;
  72. }
  73. if ($model instanceof ParkingUseTypeChangeOrderApplication) {
  74. $this->setType("IC定期_駐車場利用方法変更申請");
  75. return;
  76. }
  77. if ($model instanceof ChangePaymentMethodCreditcardOrderApplication) {
  78. $this->setType("クレジット支払変更申請");
  79. return;
  80. }
  81. }
  82. public function setCustomer(Customer $customer): static
  83. {
  84. $this->customer = $customer;
  85. return $this;
  86. }
  87. public function setSeasonTicketContract(SeasonTicketContract $seasonTicketContract): static
  88. {
  89. $this->seasonTicketContract = $seasonTicketContract;
  90. return $this;
  91. }
  92. public function setParking(Parking $parking): static
  93. {
  94. $this->parking = $parking;
  95. return $this;
  96. }
  97. /**
  98. * @return T
  99. */
  100. public function makeApplication()
  101. {
  102. $this->model->applicationDatetime = DateUtil::now();
  103. $this->model->status = "新規登録";
  104. $this->model->applicationNo = $this->getApplicationNo();
  105. if ($this->customer === null) {
  106. throw new LogicException("顧客未設定のため失敗");
  107. }
  108. $this->model->customerCode = $this->customer->customerCode;
  109. if ($this->seasonTicketContract !== null) {
  110. $this->model->seasonTicketContractRecordNo = $this->seasonTicketContract->getRecordId();
  111. }
  112. if ($this->parking !== null) {
  113. $this->model->parkingName = $this->parking->parkingName;
  114. }
  115. if ($this->model instanceof BankAccountUpdateApplication) {
  116. $this->model->applicationCustomerCode = $this->customer->customerCode;
  117. }
  118. return $this->model;
  119. }
  120. private function setType(string $type): static
  121. {
  122. $this->model->applicationType = $type;
  123. return $this;
  124. }
  125. private function getApplicationNo(): string
  126. {
  127. /**
  128. * 申請番号を発番する。重複チェックを一定回数行う。
  129. */
  130. for ($i = 0; $i < 10; $i++) {
  131. $no = sprintf("%s-%06d", DateUtil::now()->format('Ymd'), rand(1, 999999));
  132. $check = GeneralApplication::getAccess()->some(GeneralApplication::getQuery()->where(GeneralApplication::FIELD_APPLICATION_NO, $no));
  133. if ($check->isEmpty()) {
  134. return $no;
  135. }
  136. }
  137. throw new AppCommonException('申請番号取得失敗');
  138. }
  139. }