Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

151 Zeilen
4.5KB

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