Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

116 rindas
3.5KB

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