提交代码

dev
胡锐 6 months ago
parent 714980b866
commit 7a4c8eb063
  1. 92
      service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java

@ -7,6 +7,7 @@ import com.hfkj.common.utils.DateUtil;
import com.hfkj.common.utils.RandomUtils;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.dao.BsOrderMapper;
import com.hfkj.dao.CouponDiscountGoodsRelMapper;
import com.hfkj.entity.*;
import com.hfkj.model.order.OrderChildModel;
import com.hfkj.model.order.OrderModel;
@ -37,6 +38,7 @@ import org.thymeleaf.util.DateUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
/**
* @className: BsOrderServiceImpl
@ -148,6 +150,18 @@ public class BsOrderServiceImpl implements BsOrderService {
if (deduction.getUserCouponDiscountId() != null) {
// 使用优惠券
useDeduction(order, deduction, order.getDeduction().getUserCouponDiscountId());
// 使用优惠券限制
Map<String, Object> param = new HashMap<>();
param.put("discountId", deduction.getCouponDiscountId());
List<CouponDiscountGoodsRel> couponDiscountGoodsRelList = couponDiscountService.getListGoodsRel(param);
for(OrderChildModel orderChild : order.getOrderChildList()) {
List<CouponDiscountGoodsRel> collect = couponDiscountGoodsRelList.stream()
.filter(o -> o.getSpecsId() != null && o.getSpecsId().equals(o.getSpecsId())).collect(Collectors.toList());
if (collect.isEmpty()) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, orderChild.getProductName()+"【"+orderChild.getProductSpecName()+"】"+"无法使用此优惠券");
}
}
} else {
deduction.setCouponDiscountPrice(new BigDecimal("0"));
deduction.setCouponDiscountActualPrice(new BigDecimal("0"));
@ -245,50 +259,50 @@ public class BsOrderServiceImpl implements BsOrderService {
useDeduction(order, deduction,userCouponDiscountId);
}
try {
// 查询用户优惠券
CouponDiscountUserRel discountUserRel = couponDiscountUserRelService.getRel(userCouponDiscountId);
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, "未知优惠券");
}
// 计算优惠
deduction.setCouponDiscountId(discount.getId());
deduction.setCouponDiscountType(discount.getType());
deduction.setCouponDiscountPrice(discount.getPrice());
// 卡卷类型 1:满减 2:抵扣 3:折扣
if (1 == discount.getType()) {
deduction.setCouponDiscountActualPrice(discount.getPrice());
} else if (2 == discount.getType()) {
if (discount.getCondition().compareTo(order.getProductTotalPrice()) < 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未满足优惠券满减条件");
}
deduction.setCouponDiscountActualPrice(discount.getPrice());
} else if (3 == discount.getType()) {
deduction.setCouponDiscountActualPrice(
order.getTotalPrice()
.multiply(discount.getPrice().divide(new BigDecimal("100")))
.setScale(2, BigDecimal.ROUND_DOWN)
);
} else {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券优惠类型");
}
// 优惠券优惠金额 + 积分抵扣实际金额
deduction.setTotalDeductionPrice(deduction.getCouponDiscountActualPrice()
.add(new BigDecimal(deduction.getIntegralDiscountPrice().toString()).divide(new BigDecimal("100"))));
orderDeductionService.editData(deduction);
} catch (Exception e) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "积分交易异常");
} finally {
redisTemplate.delete(key);
}
// 查询用户优惠券
CouponDiscountUserRel discountUserRel = couponDiscountUserRelService.getRel(userCouponDiscountId);
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, "未知优惠券");
}
// 计算优惠
deduction.setCouponDiscountId(discount.getId());
deduction.setCouponDiscountType(discount.getType());
deduction.setCouponDiscountPrice(discount.getPrice());
// 卡卷类型 1:满减 2:抵扣 3:折扣
if (1 == discount.getType()) {
deduction.setCouponDiscountActualPrice(discount.getPrice());
} else if (2 == discount.getType()) {
if (discount.getCondition().compareTo(order.getProductTotalPrice()) < 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未满足优惠券满减条件");
}
deduction.setCouponDiscountActualPrice(discount.getPrice());
} else if (3 == discount.getType()) {
deduction.setCouponDiscountActualPrice(
order.getTotalPrice()
.multiply(discount.getPrice().divide(new BigDecimal("100")))
.setScale(2, BigDecimal.ROUND_DOWN)
);
} else {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券优惠类型");
}
// 优惠券优惠金额 + 积分抵扣实际金额
deduction.setTotalDeductionPrice(deduction.getCouponDiscountActualPrice()
.add(new BigDecimal(deduction.getIntegralDiscountPrice().toString()).divide(new BigDecimal("100"))));
orderDeductionService.editData(deduction);
return deduction;
}

Loading…
Cancel
Save