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.

121 line
3.6KB

  1. <?php
  2. namespace App\Logics\QRService;
  3. use App\Codes\DepositTransferReason;
  4. use App\Codes\Model\QRServiceUsage;
  5. use App\Exceptions\AppCommonException;
  6. use App\Models\HtpmsCustomer\Mst\ShopNoRelation;
  7. use App\Models\HtpmsCustomer\QRService\CertificationAvailableSetting;
  8. use App\Models\HtpmsCustomer\QRService\CertificationTicket;
  9. use App\Util\DateUtil;
  10. use Illuminate\Support\Carbon;
  11. class CertificateLogic
  12. {
  13. use DepositCheck;
  14. public static function certificate(
  15. string $parkingManagementCode,
  16. string $adjusterTerminalCode,
  17. Carbon $publishingDate,
  18. int $seqNo,
  19. string $shopId,
  20. int $discountTicketCode
  21. ) {
  22. // 割引設定有無の確認
  23. $check = CertificationAvailableSetting::whereParkingManagementCode($parkingManagementCode)
  24. ->whereShopId($shopId)
  25. ->whereDiscountTicketCode($discountTicketCode)
  26. ->exists();
  27. if (!$check) {
  28. throw new AppCommonException("認証できない割引");
  29. }
  30. // デポジットチェック
  31. if (!self::canCertificate($shopId)) {
  32. throw new AppCommonException("認証不可 デポジット");
  33. }
  34. [$shop] = self::getData($shopId);
  35. $qr = new CertificationTicket();
  36. $qr->parking_management_code = $parkingManagementCode;
  37. $qr->publishing_terminal_code = $adjusterTerminalCode;
  38. $qr->publishing_date = $publishingDate;
  39. $qr->publishing_no = $seqNo;
  40. $qr->shop_id = $shopId;
  41. $qr->discount_ticket_code = $discountTicketCode;
  42. // 店舗番号の解決
  43. $relation = ShopNoRelation::byKey(
  44. $shopId,
  45. $parkingManagementCode,
  46. QRServiceUsage::認証方式
  47. )
  48. ->first();
  49. if ($relation instanceof ShopNoRelation === false) {
  50. throw new AppCommonException("店舗番号紐づけ未設定");
  51. }
  52. $qr->shop_no = $relation->shop_no;
  53. // 有効期限設定
  54. $qr->expires_at = DateUtil::now()->addMinutes($shop->qr_service_expire_min);
  55. $qr->save();
  56. return $qr;
  57. }
  58. public static function getUsable(
  59. string $parkingManagementCode,
  60. string $adjusterTerminalCode,
  61. Carbon $publishingDate,
  62. int $seqNo
  63. ): CertificationTicket {
  64. $qr = CertificationTicket::whereParkingManagementCode($parkingManagementCode)
  65. ->wherePublishingTerminalCode($adjusterTerminalCode)
  66. ->wherePublishingDate($publishingDate)
  67. ->wherePublishingNo($seqNo)
  68. ->first();
  69. if ($qr instanceof CertificationTicket === false) {
  70. throw new AppCommonException("QR 認証なし");
  71. }
  72. if ($qr->iseExpired()) {
  73. throw new AppCommonException("QR 期限切れ");
  74. }
  75. if ($qr->isUsed()) {
  76. throw new AppCommonException("QR 使用済み");
  77. }
  78. return $qr;
  79. }
  80. public static function use(
  81. string $parkingManagementCode,
  82. string $adjusterTerminalCode,
  83. Carbon $publishingDate,
  84. int $seqNo,
  85. int $discountTicketCode,
  86. Carbon $adjustDatetime,
  87. int $discountAmount,
  88. ) {
  89. // QRコード情報の取得
  90. $qr = self::getUsable($parkingManagementCode, $adjusterTerminalCode, $publishingDate, $seqNo);
  91. // デポジット処理
  92. self::useDeposit($qr->shop_id, $discountAmount, DepositTransferReason::駐車料金割引_認証);
  93. $qr->used_at = $adjustDatetime;
  94. $qr->discount_amount = $discountAmount;
  95. $qr->discount_ticket_code = $discountTicketCode;
  96. $qr->save();
  97. }
  98. }