You've already forked FrameTour-BE
refactor(pricing): 重构自动发券服务方法命名及逻辑
- 将 autoGrantFirstPrintCoupon 方法重命名为 autoGrantCoupon - 修改 findFirstPrintCouponId 方法名为 findFirstCouponId - 调整优惠券名称匹配逻辑,移除对"first"关键字的检查 - 更新调用方 PrinterServiceImpl 中的方法引用 - 优化自动发券异常处理,确保不影响主流程
This commit is contained in:
@@ -17,5 +17,5 @@ public interface IAutoCouponService {
|
|||||||
* @param productType 商品类型
|
* @param productType 商品类型
|
||||||
* @return 是否成功发券
|
* @return 是否成功发券
|
||||||
*/
|
*/
|
||||||
boolean autoGrantFirstPrintCoupon(Long memberId, Long faceId, Long scenicId, ProductType productType);
|
boolean autoGrantCoupon(Long memberId, Long faceId, Long scenicId, ProductType productType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class AutoCouponServiceImpl implements IAutoCouponService {
|
|||||||
private final ICouponService couponService;
|
private final ICouponService couponService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean autoGrantFirstPrintCoupon(Long memberId, Long faceId, Long scenicId, ProductType productType) {
|
public boolean autoGrantCoupon(Long memberId, Long faceId, Long scenicId, ProductType productType) {
|
||||||
try {
|
try {
|
||||||
// 1. 校验参数
|
// 1. 校验参数
|
||||||
if (memberId == null || faceId == null || scenicId == null || productType == null) {
|
if (memberId == null || faceId == null || scenicId == null || productType == null) {
|
||||||
@@ -37,7 +37,7 @@ public class AutoCouponServiceImpl implements IAutoCouponService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. 查找该景区、该商品类型的首次打印优惠券配置
|
// 2. 查找该景区、该商品类型的首次打印优惠券配置
|
||||||
Long couponId = findFirstPrintCouponId(scenicId, productType);
|
Long couponId = findFirstCouponId(scenicId, productType);
|
||||||
if (couponId == null) {
|
if (couponId == null) {
|
||||||
log.debug("景区未配置首次打印优惠券: scenicId={}, productType={}", scenicId, productType);
|
log.debug("景区未配置首次打印优惠券: scenicId={}, productType={}", scenicId, productType);
|
||||||
return false;
|
return false;
|
||||||
@@ -60,7 +60,7 @@ public class AutoCouponServiceImpl implements IAutoCouponService {
|
|||||||
memberId,
|
memberId,
|
||||||
couponId,
|
couponId,
|
||||||
scenicId.toString(),
|
scenicId.toString(),
|
||||||
"AUTO_FIRST_PRINT" // 标记为自动发券来源
|
"AUTO_GRANT" // 标记为自动发券来源
|
||||||
);
|
);
|
||||||
|
|
||||||
couponService.claimCoupon(request);
|
couponService.claimCoupon(request);
|
||||||
@@ -85,7 +85,7 @@ public class AutoCouponServiceImpl implements IAutoCouponService {
|
|||||||
* @param productType 商品类型
|
* @param productType 商品类型
|
||||||
* @return 优惠券ID,未找到返回null
|
* @return 优惠券ID,未找到返回null
|
||||||
*/
|
*/
|
||||||
private Long findFirstPrintCouponId(Long scenicId, ProductType productType) {
|
private Long findFirstCouponId(Long scenicId, ProductType productType) {
|
||||||
try {
|
try {
|
||||||
// 查询该景区的有效优惠券
|
// 查询该景区的有效优惠券
|
||||||
List<PriceCouponConfig> coupons = couponConfigMapper.selectValidCouponsByScenicId(
|
List<PriceCouponConfig> coupons = couponConfigMapper.selectValidCouponsByScenicId(
|
||||||
@@ -94,9 +94,7 @@ public class AutoCouponServiceImpl implements IAutoCouponService {
|
|||||||
|
|
||||||
for (PriceCouponConfig coupon : coupons) {
|
for (PriceCouponConfig coupon : coupons) {
|
||||||
// 检查优惠券名称是否包含"首次"关键字
|
// 检查优惠券名称是否包含"首次"关键字
|
||||||
if (coupon.getCouponName() != null &&
|
if (coupon.getCouponName() != null && (coupon.getCouponName().contains("首次"))) {
|
||||||
(coupon.getCouponName().contains("首次") ||
|
|
||||||
coupon.getCouponName().contains("first"))) {
|
|
||||||
|
|
||||||
// 检查适用商品类型
|
// 检查适用商品类型
|
||||||
String applicableProducts = coupon.getApplicableProducts();
|
String applicableProducts = coupon.getApplicableProducts();
|
||||||
|
|||||||
@@ -441,6 +441,20 @@ public class PrinterServiceImpl implements PrinterService {
|
|||||||
|
|
||||||
request.setProducts(productItems);
|
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);
|
PriceCalculationResult result = priceCalculationService.calculatePrice(request);
|
||||||
|
|
||||||
@@ -589,21 +603,6 @@ public class PrinterServiceImpl implements PrinterService {
|
|||||||
throw new BaseException("没有可打印的照片");
|
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();
|
OrderEntity order = new OrderEntity();
|
||||||
Long orderId = SnowFlakeUtil.getLongId();
|
Long orderId = SnowFlakeUtil.getLongId();
|
||||||
redisTemplate.opsForValue().set("printer_size:"+orderId, printer.getPreferPaper(), 60, TimeUnit.SECONDS);
|
redisTemplate.opsForValue().set("printer_size:"+orderId, printer.getPreferPaper(), 60, TimeUnit.SECONDS);
|
||||||
|
|||||||
Reference in New Issue
Block a user