diff --git a/src/main/java/com/ycwl/basic/pricing/service/IAutoCouponService.java b/src/main/java/com/ycwl/basic/pricing/service/IAutoCouponService.java index c51ceed4..7df0c95f 100644 --- a/src/main/java/com/ycwl/basic/pricing/service/IAutoCouponService.java +++ b/src/main/java/com/ycwl/basic/pricing/service/IAutoCouponService.java @@ -17,5 +17,5 @@ public interface IAutoCouponService { * @param productType 商品类型 * @return 是否成功发券 */ - boolean autoGrantFirstPrintCoupon(Long memberId, Long faceId, Long scenicId, ProductType productType); + boolean autoGrantCoupon(Long memberId, Long faceId, Long scenicId, ProductType productType); } diff --git a/src/main/java/com/ycwl/basic/pricing/service/impl/AutoCouponServiceImpl.java b/src/main/java/com/ycwl/basic/pricing/service/impl/AutoCouponServiceImpl.java index d2592700..f44d5889 100644 --- a/src/main/java/com/ycwl/basic/pricing/service/impl/AutoCouponServiceImpl.java +++ b/src/main/java/com/ycwl/basic/pricing/service/impl/AutoCouponServiceImpl.java @@ -27,7 +27,7 @@ public class AutoCouponServiceImpl implements IAutoCouponService { private final ICouponService couponService; @Override - public boolean autoGrantFirstPrintCoupon(Long memberId, Long faceId, Long scenicId, ProductType productType) { + public boolean autoGrantCoupon(Long memberId, Long faceId, Long scenicId, ProductType productType) { try { // 1. 校验参数 if (memberId == null || faceId == null || scenicId == null || productType == null) { @@ -37,7 +37,7 @@ public class AutoCouponServiceImpl implements IAutoCouponService { } // 2. 查找该景区、该商品类型的首次打印优惠券配置 - Long couponId = findFirstPrintCouponId(scenicId, productType); + Long couponId = findFirstCouponId(scenicId, productType); if (couponId == null) { log.debug("景区未配置首次打印优惠券: scenicId={}, productType={}", scenicId, productType); return false; @@ -60,7 +60,7 @@ public class AutoCouponServiceImpl implements IAutoCouponService { memberId, couponId, scenicId.toString(), - "AUTO_FIRST_PRINT" // 标记为自动发券来源 + "AUTO_GRANT" // 标记为自动发券来源 ); couponService.claimCoupon(request); @@ -85,7 +85,7 @@ public class AutoCouponServiceImpl implements IAutoCouponService { * @param productType 商品类型 * @return 优惠券ID,未找到返回null */ - private Long findFirstPrintCouponId(Long scenicId, ProductType productType) { + private Long findFirstCouponId(Long scenicId, ProductType productType) { try { // 查询该景区的有效优惠券 List coupons = couponConfigMapper.selectValidCouponsByScenicId( @@ -94,9 +94,7 @@ public class AutoCouponServiceImpl implements IAutoCouponService { for (PriceCouponConfig coupon : coupons) { // 检查优惠券名称是否包含"首次"关键字 - if (coupon.getCouponName() != null && - (coupon.getCouponName().contains("首次") || - coupon.getCouponName().contains("first"))) { + if (coupon.getCouponName() != null && (coupon.getCouponName().contains("首次"))) { // 检查适用商品类型 String applicableProducts = coupon.getApplicableProducts(); diff --git a/src/main/java/com/ycwl/basic/service/printer/impl/PrinterServiceImpl.java b/src/main/java/com/ycwl/basic/service/printer/impl/PrinterServiceImpl.java index b8971c30..090ac1b9 100644 --- a/src/main/java/com/ycwl/basic/service/printer/impl/PrinterServiceImpl.java +++ b/src/main/java/com/ycwl/basic/service/printer/impl/PrinterServiceImpl.java @@ -441,6 +441,20 @@ public class PrinterServiceImpl implements PrinterService { request.setProducts(productItems); + if (mobileCount > 0) { + try { + autoCouponService.autoGrantCoupon( + memberId, + faceId, + scenicId, + ProductType.PHOTO_PRINT_MU + ); + } catch (Exception e) { + log.warn("自动发券失败,不影响下单流程: memberId={}, faceId={}, scenicId={}, error={}", + memberId, faceId, scenicId, e.getMessage()); + } + } + // 使用统一价格计算服务 PriceCalculationResult result = priceCalculationService.calculatePrice(request); @@ -589,21 +603,6 @@ public class PrinterServiceImpl implements PrinterService { throw new BaseException("没有可打印的照片"); } - // 【新增】检测并自动发放首次打印优惠券 - if (mobileCount > 0) { - try { - autoCouponService.autoGrantFirstPrintCoupon( - memberId, - faceId, - scenicId, - ProductType.PHOTO_PRINT_MU - ); - } catch (Exception e) { - log.warn("自动发券失败,不影响下单流程: memberId={}, faceId={}, scenicId={}, error={}", - memberId, faceId, scenicId, e.getMessage()); - } - } - OrderEntity order = new OrderEntity(); Long orderId = SnowFlakeUtil.getLongId(); redisTemplate.opsForValue().set("printer_size:"+orderId, printer.getPreferPaper(), 60, TimeUnit.SECONDS);