|
- <?php
-
- namespace App\Logic;
-
- use App\Exceptions\AppCommonException;
- use App\Kintone\Models\BankAccountUpdateApplication;
- use App\Kintone\Models\ChangePaymentMethodCreditcardOrderApplication;
- use App\Kintone\Models\ChangePlanApplication;
- use App\Kintone\Models\Customer;
- use App\Kintone\Models\GeneralApplication;
- use App\Kintone\Models\Parking;
- use App\Kintone\Models\ParkingCertificateApplication;
- use App\Kintone\Models\ParkingUseTypeChangeOrderApplication;
- use App\Kintone\Models\SeasonTicketContract;
- use App\Kintone\Models\SeasonTicketReOrderApplication;
- use App\Kintone\Models\StickerReOrderApplication;
- use App\Kintone\Models\TerminateApplication;
- use App\Kintone\Models\UserInfoUpdateApplication;
- use App\Kintone\Models\VehicleInfoUpdateApplication;
- use App\Util\DateUtil;
- use LogicException;
-
- /**
- * @template T of GeneralApplication
- */
- class GeneralApplicationManager
- {
- private ?Customer $customer = null;
-
- private ?SeasonTicketContract $seasonTicketContract = null;
-
- private ?Parking $parking = null;
-
-
- /**
- * @param T $model
- */
- public function __construct(private GeneralApplication $model)
- {
- if ($model instanceof TerminateApplication) {
- $this->setType("解約申請");
- return;
- }
- if ($model instanceof ParkingCertificateApplication) {
- $this->setType("車庫証明発行申請");
- return;
- }
- if ($model instanceof StickerReOrderApplication) {
- $this->setType("シール再発行申請");
- return;
- }
- if ($model instanceof ParkingUseTypeChangeOrderApplication) {
- $this->setType("IC定期_駐車場利用方法変更申請");
- return;
- }
- if ($model instanceof SeasonTicketReOrderApplication) {
- $this->setType("定期券再発行申請");
- return;
- }
- if ($model instanceof VehicleInfoUpdateApplication) {
- $this->setType("車両番号・防犯登録番号変更");
- return;
- }
- if ($model instanceof UserInfoUpdateApplication) {
- $this->setType("利用者情報変更");
- return;
- }
- if ($model instanceof UserInfoUpdateApplication) {
- $this->setType("振替頻度変更");
- return;
- }
- if ($model instanceof BankAccountUpdateApplication) {
- $this->setType("口座変更申請");
- return;
- }
- if ($model instanceof ChangePlanApplication) {
- $this->setType("プラン変更");
- return;
- }
- if ($model instanceof ParkingUseTypeChangeOrderApplication) {
- $this->setType("IC定期_駐車場利用方法変更申請");
- return;
- }
- if ($model instanceof ChangePaymentMethodCreditcardOrderApplication) {
- $this->setType("クレジット支払変更申請");
- return;
- }
- }
-
- public function setCustomer(Customer $customer): static
- {
- $this->customer = $customer;
- return $this;
- }
- public function setSeasonTicketContract(SeasonTicketContract $seasonTicketContract): static
- {
- $this->seasonTicketContract = $seasonTicketContract;
- return $this;
- }
- public function setParking(Parking $parking): static
- {
- $this->parking = $parking;
- return $this;
- }
-
- /**
- * @return T
- */
- public function makeApplication()
- {
- $this->model->applicationDatetime = DateUtil::now();
- $this->model->status = "新規登録";
- $this->model->applicationNo = $this->getApplicationNo();
-
- if ($this->customer === null) {
- throw new LogicException("顧客未設定のため失敗");
- }
-
- $this->model->customerCode = $this->customer->customerCode;
-
- if ($this->seasonTicketContract !== null) {
- $this->model->seasonTicketContractRecordNo = $this->seasonTicketContract->getRecordId();
- }
-
- if ($this->parking !== null) {
- $this->model->parkingName = $this->parking->parkingName;
- }
-
- if ($this->model instanceof BankAccountUpdateApplication) {
- $this->model->applicationCustomerCode = $this->customer->customerCode;
- }
-
- return $this->model;
- }
-
- private function setType(string $type): static
- {
- $this->model->applicationType = $type;
- return $this;
- }
-
- private function getApplicationNo(): string
- {
-
- /**
- * 申請番号を発番する。重複チェックを一定回数行う。
- */
- for ($i = 0; $i < 10; $i++) {
-
- $no = sprintf("%s-%06d", DateUtil::now()->format('Ymd'), rand(1, 999999));
-
- $check = GeneralApplication::getAccess()->some(GeneralApplication::getQuery()->where(GeneralApplication::FIELD_APPLICATION_NO, $no));
- if ($check->isEmpty()) {
- return $no;
- }
- }
- throw new AppCommonException('申請番号取得失敗');
- }
- }
|