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

117 行
3.5KB

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