| | |
| | | if (!verifyCode.startsWith(BenefitVerificationCodeService.MOVIE_TOKEN_PREFIX)) { |
| | | throw new BusinessException(ErrorCode.CONFLICT, "电影票核销码必须由二期生成核销码接口生成"); |
| | | } |
| | | if (movieCodeExpired(probe.getUpdatedAt())) { |
| | | expireMovieClaim(probe.getId()); |
| | | throw new BusinessException(ErrorCode.CONFLICT, "电影票核销码已过期"); |
| | | } |
| | | |
| | | quotaService.current(BenefitQuotaService.MOVIE_TICKET, probe.getCardId(), probe.getTalentId(), probe.getMerchantId(), null); |
| | | BenefitCinemaCouponClaim claim = movieClaimByCode(verifyCode, true); |
| | |
| | | .eq("id", claim.getId()) |
| | | .eq("deleted", 0) |
| | | .eq("exchange_code", verifyCode) |
| | | .apply("upper(coalesce(code_status, 'ACTIVE')) = 'ACTIVE'") |
| | | .apply("updated_at > date_sub(now(), interval 300 second)")); |
| | | .apply("upper(coalesce(code_status, 'ACTIVE')) = 'ACTIVE'")); |
| | | if (updated != 1) { |
| | | throw new BusinessException(ErrorCode.CONFLICT, "电影票核销码已使用或已过期"); |
| | | } |
| | |
| | | throw new BusinessException(ErrorCode.NOT_FOUND, "电影票核销码不存在"); |
| | | } |
| | | BenefitCinemaCoupon coupon = couponMapper.selectById(claim.getCouponId()); |
| | | if (!"ACTIVE".equals(upper(claim.getCodeStatus())) || movieCodeExpired(claim.getUpdatedAt())) { |
| | | if (!"ACTIVE".equals(upper(claim.getCodeStatus()))) { |
| | | throw new BusinessException(ErrorCode.CONFLICT, "电影票核销码已过期"); |
| | | } |
| | | if (coupon == null || expiredDate(claim.getValidEnd()) || intValue(coupon.getStatus()) != 1) { |
| | | throw new BusinessException(ErrorCode.CONFLICT, "电影票权益券当前不可用"); |
| | | } |
| | | } |
| | | |
| | | private void expireMovieClaim(Long claimId) { |
| | | BenefitCinemaCouponClaim claim = claimMapper.selectOne(new QueryWrapper<BenefitCinemaCouponClaim>() |
| | | .eq("id", claimId) |
| | | .eq("deleted", 0) |
| | | .last("limit 1 for update")); |
| | | if (claim == null) { |
| | | return; |
| | | } |
| | | if ("ACTIVE".equals(upper(claim.getCodeStatus())) |
| | | && startsWithMoviePrefix(claim.getExchangeCode()) |
| | | && movieCodeExpired(claim.getUpdatedAt())) { |
| | | int updated = claimMapper.update(null, new UpdateWrapper<BenefitCinemaCouponClaim>() |
| | | .set("code_status", "EXPIRED") |
| | | .set("status", "EXPIRED") |
| | | .eq("id", claimId) |
| | | .eq("deleted", 0) |
| | | .apply("upper(coalesce(code_status, 'ACTIVE')) = 'ACTIVE'")); |
| | | if (updated == 1) { |
| | | couponMapper.update(null, new UpdateWrapper<BenefitCinemaCoupon>() |
| | | .setSql("stock = stock + 1") |
| | | .eq("id", claim.getCouponId()) |
| | | .eq("deleted", 0)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private BenefitCinemaCouponClaim movieClaimByCode(String code, boolean lock) { |
| | | return claimMapper.selectOne(new QueryWrapper<BenefitCinemaCouponClaim>() |
| | | .eq("deleted", 0) |
| | |
| | | return parsed > 0 ? parsed : null; |
| | | } |
| | | |
| | | private boolean movieCodeExpired(LocalDateTime updatedAt) { |
| | | return updatedAt != null && !updatedAt.plusSeconds(BenefitVerificationCodeService.CODE_SECONDS).isAfter(LocalDateTime.now()); |
| | | } |
| | | |
| | | private boolean startsWithMoviePrefix(String code) { |
| | | return code != null && code.startsWith(BenefitVerificationCodeService.MOVIE_TOKEN_PREFIX); |
| | | } |
| | |
| | | |
| | | private record FreeStayCodeContext(BenefitFreeStayVerificationCode code, BenefitFreeStayVoucher voucher) { |
| | | } |
| | | } |
| | | } |