修复拼团商品限购数量问题,添加创建订单流程过后清除缓存key
This commit is contained in:
parent
7564a4627a
commit
337775013e
@ -50,8 +50,17 @@ public class CartController {
|
||||
public ResultMessage<Object> add(@NotNull(message = "产品id不能为空") String skuId,
|
||||
@NotNull(message = "购买数量不能为空") @Min(value = 1, message = "加入购物车数量必须大于0") Integer num,
|
||||
String cartType) {
|
||||
cartService.add(skuId, num, cartType);
|
||||
return ResultUtil.success();
|
||||
try {
|
||||
// 读取选中的列表
|
||||
cartService.add(skuId, num, cartType);
|
||||
return ResultUtil.success();
|
||||
} catch (ServiceException se) {
|
||||
log.error(se.getMsg(), se);
|
||||
return ResultUtil.error(se.getResultCode().code(), se.getResultCode().message());
|
||||
} catch (Exception e) {
|
||||
log.error(ResultCode.CART_ERROR.message(), e);
|
||||
throw new ServiceException(ResultCode.CART_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -150,8 +159,9 @@ public class CartController {
|
||||
try {
|
||||
// 读取选中的列表
|
||||
return ResultUtil.data(this.cartService.getCheckedTradeDTO(CartTypeEnum.valueOf(way)));
|
||||
} catch (ServiceException e) {
|
||||
throw e;
|
||||
} catch (ServiceException se) {
|
||||
log.error(se.getMsg(), se);
|
||||
return ResultUtil.error(se.getResultCode().code(), se.getResultCode().message());
|
||||
} catch (Exception e) {
|
||||
log.error(ResultCode.CART_ERROR.message(), e);
|
||||
throw new ServiceException(ResultCode.CART_ERROR);
|
||||
@ -193,6 +203,9 @@ public class CartController {
|
||||
try {
|
||||
cartService.shippingMethod(selleId, shippingMethod, way);
|
||||
return ResultUtil.success();
|
||||
} catch (ServiceException se) {
|
||||
log.error(se.getMsg(), se);
|
||||
return ResultUtil.error(se.getResultCode().code(), se.getResultCode().message());
|
||||
} catch (Exception e) {
|
||||
log.error(ResultCode.CART_ERROR.message(), e);
|
||||
throw new ServiceException(ResultCode.CART_ERROR);
|
||||
@ -228,8 +241,9 @@ public class CartController {
|
||||
try {
|
||||
// 读取选中的列表
|
||||
return ResultUtil.data(this.cartService.createTrade(tradeParams));
|
||||
} catch (ServiceException e) {
|
||||
throw e;
|
||||
} catch (ServiceException se) {
|
||||
log.error(se.getMsg(), se);
|
||||
return ResultUtil.error(se.getResultCode().code(), se.getResultCode().message());
|
||||
} catch (Exception e) {
|
||||
log.error(ResultCode.ORDER_ERROR.message(), e);
|
||||
throw new ServiceException(ResultCode.ORDER_ERROR);
|
||||
|
@ -44,6 +44,7 @@ public class OrderMessageListener implements RocketMQListener<MessageExt> {
|
||||
case ORDER_CREATE:
|
||||
String key = new String(messageExt.getBody());
|
||||
TradeDTO tradeDTO = (TradeDTO) cache.get(key);
|
||||
boolean result = true;
|
||||
for (TradeEvent event : tradeEvent) {
|
||||
try {
|
||||
event.orderCreate(tradeDTO);
|
||||
@ -52,8 +53,14 @@ public class OrderMessageListener implements RocketMQListener<MessageExt> {
|
||||
tradeDTO.getSn(),
|
||||
event.getClass().getName(),
|
||||
e);
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
// 如所有步骤顺利完成
|
||||
if (Boolean.TRUE.equals(result)) {
|
||||
// 清除记录信息的trade cache key
|
||||
cache.remove(key);
|
||||
}
|
||||
break;
|
||||
//订单状态变更
|
||||
case STATUS_CHANGE:
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.lili.modules.order.cart.render.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.utils.CurrencyUtil;
|
||||
import cn.lili.common.utils.StringUtils;
|
||||
import cn.lili.modules.order.cart.entity.dto.MemberCouponDTO;
|
||||
@ -13,10 +14,14 @@ import cn.lili.modules.order.cart.entity.vo.PriceDetailVO;
|
||||
import cn.lili.modules.order.cart.render.CartRenderStep;
|
||||
import cn.lili.modules.order.order.entity.dto.PriceDetailDTO;
|
||||
import cn.lili.modules.promotion.entity.dos.MemberCoupon;
|
||||
import cn.lili.modules.promotion.entity.dos.Pintuan;
|
||||
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
|
||||
import cn.lili.modules.promotion.entity.dto.GoodsSkuPromotionPriceDTO;
|
||||
import cn.lili.modules.promotion.entity.dto.PromotionPriceDTO;
|
||||
import cn.lili.modules.promotion.entity.dto.PromotionPriceParamDTO;
|
||||
import cn.lili.modules.promotion.entity.dto.StorePromotionPriceDTO;
|
||||
import cn.lili.modules.promotion.entity.enums.PromotionTypeEnum;
|
||||
import cn.lili.modules.promotion.service.PintuanService;
|
||||
import cn.lili.modules.promotion.service.PromotionGoodsService;
|
||||
import cn.lili.modules.promotion.service.PromotionPriceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -45,12 +50,16 @@ public class SkuPromotionRender implements CartRenderStep {
|
||||
@Autowired
|
||||
private PromotionGoodsService promotionGoodsService;
|
||||
|
||||
@Autowired
|
||||
private PintuanService pintuanService;
|
||||
|
||||
@Override
|
||||
public void render(TradeDTO tradeDTO) {
|
||||
|
||||
//主要渲染各个优惠的价格
|
||||
this.renderSkuPromotion(tradeDTO);
|
||||
|
||||
this.checkPromotionLimit(tradeDTO);
|
||||
}
|
||||
|
||||
|
||||
@ -289,4 +298,20 @@ public class SkuPromotionRender implements CartRenderStep {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void checkPromotionLimit(TradeDTO tradeDTO) {
|
||||
if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.PINTUAN)) {
|
||||
// 如果为拼团订单,则获取拼团活动ID
|
||||
Optional<String> pintuanId = tradeDTO.getSkuList().get(0).getPromotions().stream().filter(i -> i.getPromotionType().equals(PromotionTypeEnum.PINTUAN.name())).map(PromotionGoods::getPromotionId).findFirst();
|
||||
if (pintuanId.isPresent()) {
|
||||
Pintuan pintuan = pintuanService.getPintuanById(pintuanId.get());
|
||||
Integer limitNum = pintuan.getLimitNum();
|
||||
for (CartSkuVO cartSkuVO : tradeDTO.getSkuList()) {
|
||||
if (limitNum != 0 && cartSkuVO.getNum() > limitNum) {
|
||||
throw new ServiceException("购买数量超过拼团活动限制数量");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -149,6 +149,8 @@ public class CartServiceImpl implements CartService {
|
||||
tradeDTO.setStoreCoupons(null);
|
||||
tradeDTO.setPlatformCoupon(null);
|
||||
this.resetTradeDTO(tradeDTO);
|
||||
} catch (ServiceException se) {
|
||||
throw se;
|
||||
} catch (Exception e) {
|
||||
log.error("购物车渲染异常", e);
|
||||
throw new ServiceException(errorMessage);
|
||||
@ -324,14 +326,16 @@ public class CartServiceImpl implements CartService {
|
||||
List<String> storeIds = new ArrayList<>();
|
||||
List<EsGoodsIndex> esGoodsList = esGoodsSearchService.getEsGoodsBySkuIds(ids);
|
||||
for (EsGoodsIndex esGoodsIndex : esGoodsList) {
|
||||
if (esGoodsIndex.getPromotionMap() != null) {
|
||||
List<String> couponIds = esGoodsIndex.getPromotionMap().keySet().parallelStream().filter(i -> i.contains(PromotionTypeEnum.COUPON.name())).map(i -> i.substring(i.lastIndexOf("-") + 1)).collect(Collectors.toList());
|
||||
if (!couponIds.isEmpty()) {
|
||||
List<MemberCoupon> currentGoodsCanUse = memberCouponService.getCurrentGoodsCanUse(tradeDTO.getMemberId(), couponIds, totalPrice);
|
||||
count = currentGoodsCanUse.size();
|
||||
if (esGoodsIndex != null) {
|
||||
if (esGoodsIndex.getPromotionMap() != null) {
|
||||
List<String> couponIds = esGoodsIndex.getPromotionMap().keySet().parallelStream().filter(i -> i.contains(PromotionTypeEnum.COUPON.name())).map(i -> i.substring(i.lastIndexOf("-") + 1)).collect(Collectors.toList());
|
||||
if (!couponIds.isEmpty()) {
|
||||
List<MemberCoupon> currentGoodsCanUse = memberCouponService.getCurrentGoodsCanUse(tradeDTO.getMemberId(), couponIds, totalPrice);
|
||||
count = currentGoodsCanUse.size();
|
||||
}
|
||||
}
|
||||
storeIds.add(esGoodsIndex.getStoreId());
|
||||
}
|
||||
storeIds.add(esGoodsIndex.getStoreId());
|
||||
}
|
||||
List<MemberCoupon> allScopeMemberCoupon = memberCouponService.getAllScopeMemberCoupon(tradeDTO.getMemberId(), storeIds);
|
||||
if (allScopeMemberCoupon != null && !allScopeMemberCoupon.isEmpty()) {
|
||||
@ -628,7 +632,7 @@ public class CartServiceImpl implements CartService {
|
||||
promotionGoods -> (promotionGoods.getPromotionType().equals(PromotionTypeEnum.PINTUAN.name())))
|
||||
.collect(Collectors.toList());
|
||||
//拼团活动判定
|
||||
if (currentPromotion.size() > 0) {
|
||||
if (!currentPromotion.isEmpty()) {
|
||||
//写入拼团信息
|
||||
cartSkuVO.setPintuanId(currentPromotion.get(0).getPromotionId());
|
||||
} else {
|
||||
|
@ -672,10 +672,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
* @param list 需要更新拼团状态为成功的拼团订单列表
|
||||
*/
|
||||
private void pintuanOrderSuccess(List<Order> list) {
|
||||
list.stream().forEach(order -> {
|
||||
if (order.getOrderType().equals(OrderTypeEnum.VIRTUAL)) {
|
||||
list.forEach(order -> {
|
||||
if (order.getOrderType().equals(OrderTypeEnum.VIRTUAL.name())) {
|
||||
this.virtualOrderConfirm(order.getSn());
|
||||
} else if (order.getOrderType().equals(OrderTypeEnum.NORMAL)) {
|
||||
} else if (order.getOrderType().equals(OrderTypeEnum.NORMAL.name())) {
|
||||
this.normalOrderConfirm(order.getSn());
|
||||
}
|
||||
});
|
||||
@ -793,7 +793,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
*/
|
||||
private void checkOrder(Order order) {
|
||||
//订单类型为拼团订单,检测购买数量是否超过了限购数量
|
||||
if (OrderPromotionTypeEnum.PINTUAN.name().equals(order.getOrderPromotionType())) {
|
||||
if (OrderPromotionTypeEnum.PINTUAN.name().equals(order.getOrderType())) {
|
||||
Pintuan pintuan = pintuanService.getPintuanById(order.getPromotionId());
|
||||
Integer limitNum = pintuan.getLimitNum();
|
||||
if (limitNum != 0 && order.getGoodsNum() > limitNum) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user