您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

118 行
3.3KB

  1. <?php
  2. namespace App\Logic;
  3. use App\Kintone\Models\Customer;
  4. use App\Kintone\Models\GeneralApplication;
  5. use App\Kintone\Models\Parking;
  6. use App\Kintone\Models\ParkingCertificateApplication;
  7. use App\Kintone\Models\SeasonTicketContract;
  8. use App\Kintone\Models\SeasonTicketReOrderApplication;
  9. use App\Kintone\Models\StickerReOrderApplication;
  10. use App\Kintone\Models\TerminateApplication;
  11. use App\Kintone\Models\UserInfoUpdateApplication;
  12. use App\Kintone\Models\VehicleInfoUpdateApplication;
  13. use App\Util\DateUtil;
  14. use LogicException;
  15. /**
  16. * @template T of GeneralApplication
  17. */
  18. class GeneralApplicationManager
  19. {
  20. private ?Customer $customer = null;
  21. private ?SeasonTicketContract $seasonTicketContract = null;
  22. private ?Parking $parking = null;
  23. /**
  24. * @param T $model
  25. */
  26. public function __construct(private GeneralApplication $model)
  27. {
  28. if ($model instanceof TerminateApplication) {
  29. $this->setType("解約申請");
  30. return;
  31. }
  32. if ($model instanceof ParkingCertificateApplication) {
  33. $this->setType("車庫証明発行申請");
  34. return;
  35. }
  36. if ($model instanceof StickerReOrderApplication) {
  37. $this->setType("シール再発行申請");
  38. return;
  39. }
  40. if ($model instanceof SeasonTicketReOrderApplication) {
  41. $this->setType("定期券再発行申請");
  42. return;
  43. }
  44. if ($model instanceof VehicleInfoUpdateApplication) {
  45. $this->setType("車両番号・防犯登録番号変更");
  46. return;
  47. }
  48. if ($model instanceof UserInfoUpdateApplication) {
  49. $this->setType("利用者情報変更");
  50. return;
  51. }
  52. if ($model instanceof UserInfoUpdateApplication) {
  53. $this->setType("振替頻度変更");
  54. return;
  55. }
  56. }
  57. public function setCustomer(Customer $customer): static
  58. {
  59. $this->customer = $customer;
  60. return $this;
  61. }
  62. public function setSeasonTicketContract(SeasonTicketContract $seasonTicketContract): static
  63. {
  64. $this->seasonTicketContract = $seasonTicketContract;
  65. return $this;
  66. }
  67. public function setParking(Parking $parking): static
  68. {
  69. $this->parking = $parking;
  70. return $this;
  71. }
  72. /**
  73. * @return T
  74. */
  75. public function makeApplication()
  76. {
  77. $this->model->applicationDatetime = DateUtil::now();
  78. $this->model->status = "新規登録";
  79. $this->model->applicationNo = $this->getApplicationNo();
  80. if ($this->customer === null) {
  81. throw new LogicException("顧客未設定のため失敗");
  82. }
  83. $this->model->customerCode = $this->customer->customerCode;
  84. if ($this->seasonTicketContract !== null) {
  85. $this->model->seasonTicketContractRecordNo = $this->seasonTicketContract->seasonTicketSeqNo;
  86. }
  87. if ($this->parking !== null) {
  88. $this->model->parkingName = $this->parking->parkingName;
  89. }
  90. return $this->model;
  91. }
  92. private function setType(string $type): static
  93. {
  94. $this->model->applicationType = $type;
  95. return $this;
  96. }
  97. private function getApplicationNo(): string
  98. {
  99. return sprintf("%s-%06d", DateUtil::now()->format('Ymd'), rand(1, 999999));
  100. }
  101. }