提交代码

master
胡锐 6 months ago committed by yuanye
parent 896dd4d250
commit e8ed022290
  1. 26
      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.RandomUtils;
import com.hfkj.common.utils.RedisUtil; import com.hfkj.common.utils.RedisUtil;
import com.hfkj.dao.BsOrderMapper; import com.hfkj.dao.BsOrderMapper;
import com.hfkj.dao.CouponDiscountGoodsRelMapper;
import com.hfkj.entity.*; import com.hfkj.entity.*;
import com.hfkj.model.order.OrderChildModel; import com.hfkj.model.order.OrderChildModel;
import com.hfkj.model.order.OrderModel; import com.hfkj.model.order.OrderModel;
@ -37,6 +38,7 @@ import org.thymeleaf.util.DateUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* @className: BsOrderServiceImpl * @className: BsOrderServiceImpl
@ -148,6 +150,18 @@ public class BsOrderServiceImpl implements BsOrderService {
if (deduction.getUserCouponDiscountId() != null) { if (deduction.getUserCouponDiscountId() != null) {
// 使用优惠券 // 使用优惠券
useDeduction(order, deduction, order.getDeduction().getUserCouponDiscountId()); 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 { } else {
deduction.setCouponDiscountPrice(new BigDecimal("0")); deduction.setCouponDiscountPrice(new BigDecimal("0"));
deduction.setCouponDiscountActualPrice(new BigDecimal("0")); deduction.setCouponDiscountActualPrice(new BigDecimal("0"));
@ -245,12 +259,6 @@ public class BsOrderServiceImpl implements BsOrderService {
useDeduction(order, deduction,userCouponDiscountId); useDeduction(order, deduction,userCouponDiscountId);
} }
try { try {
} catch (Exception e) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "积分交易异常");
} finally {
redisTemplate.delete(key);
}
// 查询用户优惠券 // 查询用户优惠券
CouponDiscountUserRel discountUserRel = couponDiscountUserRelService.getRel(userCouponDiscountId); CouponDiscountUserRel discountUserRel = couponDiscountUserRelService.getRel(userCouponDiscountId);
if (discountUserRel == null) { if (discountUserRel == null) {
@ -289,6 +297,12 @@ public class BsOrderServiceImpl implements BsOrderService {
deduction.setTotalDeductionPrice(deduction.getCouponDiscountActualPrice() deduction.setTotalDeductionPrice(deduction.getCouponDiscountActualPrice()
.add(new BigDecimal(deduction.getIntegralDiscountPrice().toString()).divide(new BigDecimal("100")))); .add(new BigDecimal(deduction.getIntegralDiscountPrice().toString()).divide(new BigDecimal("100"))));
orderDeductionService.editData(deduction); orderDeductionService.editData(deduction);
} catch (Exception e) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "积分交易异常");
} finally {
redisTemplate.delete(key);
}
return deduction; return deduction;
} }

Loading…
Cancel
Save