From afd81600d4d7889123904ce22bedfbce612a7a71 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Tue, 21 May 2024 11:57:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CouponDiscountUserRelService.java | 7 +++++++ .../CouponDiscountUserRelServiceImpl.java | 5 +++++ .../order/impl/BsOrderServiceImpl.java | 20 ++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/service/src/main/java/com/hfkj/service/discount/CouponDiscountUserRelService.java b/service/src/main/java/com/hfkj/service/discount/CouponDiscountUserRelService.java index a834249..089c4b3 100644 --- a/service/src/main/java/com/hfkj/service/discount/CouponDiscountUserRelService.java +++ b/service/src/main/java/com/hfkj/service/discount/CouponDiscountUserRelService.java @@ -27,4 +27,11 @@ public interface CouponDiscountUserRelService { * @return java.util.List */ List getList(Map map); + + /** + * 查询关系 + * @param id + * @return + */ + CouponDiscountUserRel getRel(Long id); } diff --git a/service/src/main/java/com/hfkj/service/discount/impl/CouponDiscountUserRelServiceImpl.java b/service/src/main/java/com/hfkj/service/discount/impl/CouponDiscountUserRelServiceImpl.java index 8d85d0b..afa40ad 100644 --- a/service/src/main/java/com/hfkj/service/discount/impl/CouponDiscountUserRelServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/discount/impl/CouponDiscountUserRelServiceImpl.java @@ -42,5 +42,10 @@ public class CouponDiscountUserRelServiceImpl implements CouponDiscountUserRelSe return couponDiscountUserRelMapper.selectByExample(example); } + @Override + public CouponDiscountUserRel getRel(Long id) { + return couponDiscountUserRelMapper.selectByPrimaryKey(id); + } + } diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java index 7e91738..80a60b2 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java @@ -11,6 +11,8 @@ import com.hfkj.entity.*; import com.hfkj.model.order.OrderChildModel; import com.hfkj.model.order.OrderModel; import com.hfkj.mqtopic.OrderTopic; +import com.hfkj.service.discount.CouponDiscountService; +import com.hfkj.service.discount.CouponDiscountUserRelService; import com.hfkj.service.order.*; import com.hfkj.service.user.UserIntegralService; import com.hfkj.sysenum.UserIntegralRecordOpUserTypeEnum; @@ -67,6 +69,10 @@ public class BsOrderServiceImpl implements BsOrderService { private OrderPaySuccessService orderPaySuccessService; @Resource private UserIntegralService userIntegralService; + @Resource + private CouponDiscountUserRelService couponDiscountUserRelService; + @Resource + private CouponDiscountService couponDiscountService; @Override public BsOrder editData(BsOrder order) { order.setUpdateTime(new Date()); @@ -103,8 +109,20 @@ public class BsOrderServiceImpl implements BsOrderService { deduction.setOrderNo(order.getOrderNo()); deduction.setIntegralDiscountPrice(deduction.getIntegralDiscountPrice()==null?0L: deduction.getIntegralDiscountPrice()); if (order.getDeduction().getUserCouponDiscountId() != null) { + // 查询用户优惠券 + CouponDiscountUserRel discountUserRel = couponDiscountUserRelService.getRel(order.getDeduction().getUserCouponDiscountId()); + if (discountUserRel == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知优惠券"); + } + if (discountUserRel.getStatus() != 1) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态不处于待使用"); + } + // 查询优惠券 + CouponDiscount discount = couponDiscountService.queryDetail(discountUserRel.getDiscountId()); + if (discount == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知优惠券"); + } // 计算优惠 - CouponDiscount discount = new CouponDiscount(); deduction.setCouponDiscountId(discount.getId()); deduction.setCouponDiscountType(discount.getType()); deduction.setCouponDiscountPrice(discount.getPrice());