wenminjie
2026-08-06 8898f00c2150048a03ca561b7ed98dbf9c80732b
talent-card-server/src/main/java/com/talentcard/server/service/BenefitVerificationService.java
@@ -100,10 +100,6 @@
        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);
@@ -117,8 +113,7 @@
                .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, "电影票核销码已使用或已过期");
        }
@@ -231,40 +226,13 @@
            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)
@@ -441,10 +409,6 @@
        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);
    }
@@ -505,4 +469,4 @@
    private record FreeStayCodeContext(BenefitFreeStayVerificationCode code, BenefitFreeStayVoucher voucher) {
    }
}
}