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());