whereShopId($shopId) ->whereDiscountTicketCode($discountTicketCode) ->exists(); if (!$check) { throw new AppCommonException("認証できない割引"); } // デポジットチェック if (!self::canCertificate($shopId)) { throw new AppCommonException("認証不可 デポジット"); } [$shop] = self::getData($shopId); $qr = new CertificationTicket(); $qr->parking_management_code = $parkingManagementCode; $qr->publishing_terminal_code = $adjusterTerminalCode; $qr->publishing_date = $publishingDate; $qr->publishing_no = $seqNo; $qr->shop_id = $shopId; $qr->discount_ticket_code = $discountTicketCode; // 店舗番号の解決 $relation = ShopNoRelation::byKey( $shopId, $parkingManagementCode, QRServiceUsage::認証方式 ) ->first(); if ($relation instanceof ShopNoRelation === false) { throw new AppCommonException("店舗番号紐づけ未設定"); } $qr->shop_no = $relation->shop_no; // 有効期限設定 $qr->expires_at = DateUtil::now()->addMinutes($shop->qr_service_expire_min); $qr->save(); return $qr; } public static function getUsable( string $parkingManagementCode, string $adjusterTerminalCode, Carbon $publishingDate, int $seqNo ): CertificationTicket { $qr = CertificationTicket::whereParkingManagementCode($parkingManagementCode) ->wherePublishingTerminalCode($adjusterTerminalCode) ->wherePublishingDate($publishingDate) ->wherePublishingNo($seqNo) ->first(); if ($qr instanceof CertificationTicket === false) { throw new AppCommonException("QR 認証なし"); } if ($qr->iseExpired()) { throw new AppCommonException("QR 期限切れ"); } if ($qr->isUsed()) { throw new AppCommonException("QR 使用済み"); } return $qr; } public static function use( string $parkingManagementCode, string $adjusterTerminalCode, Carbon $publishingDate, int $seqNo, int $discountTicketCode, Carbon $adjustDatetime, int $discountAmount, ) { // QRコード情報の取得 $qr = self::getUsable($parkingManagementCode, $adjusterTerminalCode, $publishingDate, $seqNo); // デポジット処理 self::useDeposit($qr->shop_id, $discountAmount, DepositTransferReason::駐車料金割引_認証); $qr->used_at = $adjustDatetime; $qr->discount_amount = $discountAmount; $qr->discount_ticket_code = $discountTicketCode; $qr->save(); } }