This commit is contained in:
lifenlong 2021-05-21 17:24:15 +08:00
commit 5cae710304
2 changed files with 22 additions and 5 deletions

View File

@ -92,7 +92,11 @@ public class TradeBuilder {
tradeDTO.setSkuList(collect); tradeDTO.setSkuList(collect);
//按照计划进行渲染 //按照计划进行渲染
for (int index : defaultRender) { for (int index : defaultRender) {
cartRenderSteps.get(index).render(tradeDTO); try {
cartRenderSteps.get(index).render(tradeDTO);
} catch (Exception e) {
log.error("购物车渲染异常:", e);
}
} }
List<CartVO> cartVOList = new ArrayList<>(); List<CartVO> cartVOList = new ArrayList<>();
for (CartVO i : tradeDTO.getCartList()) { for (CartVO i : tradeDTO.getCartList()) {

View File

@ -294,7 +294,7 @@ public class CartServiceImpl implements CartService {
@Override @Override
public TradeDTO getCheckedTradeDTO(CartTypeEnum way) { public TradeDTO getCheckedTradeDTO(CartTypeEnum way) {
return tradeBuilder.buildTrade(way); return this.readDTO(way);
} }
/** /**
@ -443,7 +443,9 @@ public class CartServiceImpl implements CartService {
*/ */
@Override @Override
public Long getCartNum(Boolean checked) { public Long getCartNum(Boolean checked) {
//构建购物车
TradeDTO tradeDTO = this.getCheckedTradeDTO(CartTypeEnum.CART); TradeDTO tradeDTO = this.getCheckedTradeDTO(CartTypeEnum.CART);
//过滤sku列表
List<CartSkuVO> collect = tradeDTO.getSkuList().stream().filter(i -> Boolean.FALSE.equals(i.getInvalid())).collect(Collectors.toList()); List<CartSkuVO> collect = tradeDTO.getSkuList().stream().filter(i -> Boolean.FALSE.equals(i.getInvalid())).collect(Collectors.toList());
long count = 0L; long count = 0L;
if (!tradeDTO.getSkuList().isEmpty()) { if (!tradeDTO.getSkuList().isEmpty()) {
@ -458,12 +460,17 @@ public class CartServiceImpl implements CartService {
@Override @Override
public void selectCoupon(String couponId, String way, boolean use) { public void selectCoupon(String couponId, String way, boolean use) {
//获取购物车然后重新写入优惠券
CartTypeEnum cartTypeEnum = getCartType(way); CartTypeEnum cartTypeEnum = getCartType(way);
TradeDTO tradeDTO = tradeBuilder.buildTrade(cartTypeEnum); TradeDTO tradeDTO = this.readDTO(cartTypeEnum);
MemberCoupon memberCoupon = memberCouponService.getOne(new LambdaQueryWrapper<MemberCoupon>().eq(MemberCoupon::getMemberCouponStatus, MemberCouponStatusEnum.NEW.name()).eq(MemberCoupon::getId, couponId)); MemberCoupon memberCoupon =
memberCouponService.getOne(
new LambdaQueryWrapper<MemberCoupon>()
.eq(MemberCoupon::getMemberCouponStatus, MemberCouponStatusEnum.NEW.name())
.eq(MemberCoupon::getId, couponId));
if (memberCoupon == null) { if (memberCoupon == null) {
throw new ServiceException("当前优惠券可用数量不足"); throw new ServiceException(ResultCode.COUPON_EXPIRED);
} }
//使用优惠券 与否 //使用优惠券 与否
if (use && checkCoupon(memberCoupon, tradeDTO)) { if (use && checkCoupon(memberCoupon, tradeDTO)) {
@ -537,6 +544,12 @@ public class CartServiceImpl implements CartService {
} }
} }
/**
* 获取购物车类型
*
* @param way
* @return
*/
private CartTypeEnum getCartType(String way) { private CartTypeEnum getCartType(String way) {
//默认购物车 //默认购物车
CartTypeEnum cartTypeEnum = CartTypeEnum.CART; CartTypeEnum cartTypeEnum = CartTypeEnum.CART;