|
- <?php
-
- namespace App\Logics\QRService;
-
- use App\Exceptions\AppCommonException;
- use App\Models\HtpmsCustomer\Mst\ShopNoRelation;
- use App\Models\HtpmsCustomer\QRService\CertificationAvailableSetting;
- use App\Models\HtpmsCustomer\QRService\CertificationTicket;
- use App\Util\DateUtil;
- use Illuminate\Support\Carbon;
-
- class CertificateLogic
- {
- use DepositCheck;
-
- public static function certificate(
- string $parkingManagementCode,
- string $adjusterTerminalCode,
- Carbon $publishingDate,
- int $seqNo,
- string $shopId,
- int $discountTicketCode
- ) {
-
-
- // 割引設定有無の確認
- $check = CertificationAvailableSetting::whereParkingManagementCode($parkingManagementCode)
- ->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::whereShopId($shopId)
- ->whereParkingManagementCode($parkingManagementCode)
- ->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);
- $qr->used_at = $adjustDatetime;
- $qr->discount_amount = $discountAmount;
- $qr->discount_ticket_code = $discountTicketCode;
-
- $qr->save();
- }
- }
|