|
- <?php
-
- namespace App\Logic;
-
- use App\Exceptions\GeneralErrorMessageException;
- use App\Kintone\Models\DropDown\SeasonTicketContractEntry\Status;
- use App\Kintone\Models\SeasonTicketContractEntry;
-
- class SeasonTicketContractEntryManager
- {
- private SeasonTicketContractEntry $entry;
-
- public function __construct(int|SeasonTicketContractEntry $recordNo = null, bool $includeCancel = false)
- {
- if (is_int($recordNo)) {
- $this->entry = SeasonTicketContractEntry::find($recordNo);
- if (!$includeCancel && $this->entry->status === Status::CANCEL) {
- throw new GeneralErrorMessageException("すでにキャンセル済みです");
- }
- return;
- } else if ($recordNo instanceof SeasonTicketContractEntry) {
- $this->entry = $recordNo;
- return;
- }
- }
-
- public function getEntry()
- {
- return $this->entry;
- }
-
- public function cancel()
- {
- $this->entry->status = Status::CANCEL;
- return $this;
- }
-
- public function save()
- {
- $this->entry->save();
- return $this;
- }
-
- public function getHash()
- {
- $source = sprintf("%010d-%s", $this->entry->getRecordId(), $this->entry->entryDatetime->format("YmdHi"));
- return hash('sha256', $source);
- }
-
- public function checkHash(string $hash): bool
- {
- $expect = $this->getHash();
- return $expect === $hash;
- }
- }
|