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

56 行
1.4KB

  1. <?php
  2. namespace App\Logic;
  3. use App\Exceptions\GeneralErrorMessageException;
  4. use App\Kintone\Models\DropDown\SeasonTicketContractEntry\Status;
  5. use App\Kintone\Models\SeasonTicketContractEntry;
  6. class SeasonTicketContractEntryManager
  7. {
  8. private SeasonTicketContractEntry $entry;
  9. public function __construct(int|SeasonTicketContractEntry $recordNo = null, bool $includeCancel = false)
  10. {
  11. if (is_int($recordNo)) {
  12. $this->entry = SeasonTicketContractEntry::find($recordNo);
  13. if (!$includeCancel && $this->entry->status === Status::CANCEL) {
  14. throw new GeneralErrorMessageException("すでにキャンセル済みです");
  15. }
  16. return;
  17. } else if ($recordNo instanceof SeasonTicketContractEntry) {
  18. $this->entry = $recordNo;
  19. return;
  20. }
  21. }
  22. public function getEntry()
  23. {
  24. return $this->entry;
  25. }
  26. public function cancel()
  27. {
  28. $this->entry->status = Status::CANCEL;
  29. return $this;
  30. }
  31. public function save()
  32. {
  33. $this->entry->save();
  34. return $this;
  35. }
  36. public function getHash()
  37. {
  38. $source = sprintf("%010d-%s", $this->entry->getRecordId(), $this->entry->entryDatetime->format("YmdHi"));
  39. return hash('sha256', $source);
  40. }
  41. public function checkHash(string $hash): bool
  42. {
  43. $expect = $this->getHash();
  44. return $expect === $hash;
  45. }
  46. }