You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 line
2.2KB

  1. <?php
  2. namespace App\Models\HtpmsCustomer\QRService;
  3. use App\Models\Cast;
  4. use App\Models\ColumnName;
  5. use App\Models\HistoryModel;
  6. use App\Models\HtpmsCustomer\HtpmsCustomerAppModel;
  7. use App\Util\DateUtil;
  8. use Illuminate\Support\Carbon;
  9. /**
  10. * 取得済みQRサービス券
  11. */
  12. class AcquisitionTicket extends HtpmsCustomerAppModel
  13. {
  14. const COL_NAME_SHOP_ID = ColumnName::SHOP_ID; // 店舗ID
  15. const COL_NAME_PUBLISHING_DATE = ColumnName::PUBLISHING_DATE;
  16. const COL_NAME_PUBLISHING_NO = ColumnName::PUBLISHING_NO;
  17. const COL_NAME_QR_SERVICE_PARKING_GROUP_ID = ColumnName::QR_SERVICE_PARKING_GROUP_ID;
  18. const COL_NAME_DISCOUNT_TICKET_CODE = ColumnName::DISCOUNT_TICKET_CODE; // サービス券コード
  19. const COL_NAME_SHOP_NO = ColumnName::SHOP_NO; // 店舗番号
  20. const COL_NAME_EXPIRES_AT = "expires_at"; // 有効期限
  21. const COL_NAME_PARKING_MANAGEMENT_CODE = ColumnName::PARKING_MANAGEMENT_CODE; // 駐車場管理コード
  22. const COL_NAME_USED_AT = "used_at"; // 利用日時
  23. const COL_NAME_DISCOUNT_AMOUNT = "discount_amount"; // 割引金額
  24. protected $table = "tbl3_qrs_acquisition_tickets";
  25. protected $casts = [
  26. self::COL_NAME_PUBLISHING_DATE => Cast::DATE,
  27. self::COL_NAME_EXPIRES_AT => Cast::DATETIME,
  28. self::COL_NAME_USED_AT => Cast::DATETIME,
  29. ];
  30. public function getHistory(): ?HistoryModel
  31. {
  32. return null;
  33. }
  34. public function getModelName(): string
  35. {
  36. return "取得済みQRサービス券";
  37. }
  38. /**
  39. * 期限切れ判定 切れている場合trueを返却
  40. */
  41. public function iseExpired(?Carbon $基準時刻 = null): bool
  42. {
  43. if ($this->expires_at === null) return false;
  44. if ($基準時刻 === null) {
  45. $基準時刻 = DateUtil::now();
  46. }
  47. if ($this->expires_at < $基準時刻) {
  48. return true;
  49. }
  50. return false;
  51. }
  52. /**
  53. * 使用済み判定 使用済みの場合trueを返却
  54. *
  55. * @return boolean
  56. */
  57. public function isUsed(): bool
  58. {
  59. return $this->used_at !== null;
  60. }
  61. public function canUse(): bool
  62. {
  63. return $this->isUsed() === false && $this->iseExpired() === false;
  64. }
  65. }