Commit 0730c5b4 by 周晓航

添加日志

parent 2e2c6978
......@@ -38,4 +38,7 @@ public class ShopGoodsReplaceVo extends BaseRequestVo {
* 收货地址ID、svc卡支付外卖订单必传
*/
private String receiveId;
// 测试的时候 使用
private Integer hook;
}
......@@ -2955,7 +2955,10 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
if (CollectionUtils.isEmpty(excludeGoods)) {
return ResponseUtil.error(ResponseResult.SHOPPING_CART_REPLACE_GOODS_AND_CLEAR);
}
//testDemo(excludeGoods,replaceGoodsRequestVo,userId);
if (replaceGoodsRequestVo.getHook()!=null) {
testDemo(excludeGoods,replaceGoodsRequestVo,userId);
return ResponseUtil.success();
}
boolean fullReplace = true;
......@@ -3093,10 +3096,93 @@ public class ShoppingCartNewServiceImpl implements ShoppingCartNewService {
cartGoods.setProductGroupList(productGroupList);
cartGoods.setProductMaterialList(materialGoodsList);
// 获取商品详细信息
List<ProductBean> productBeanListSpuClass = assortmentSdkService.getProductsInfo(partnerId, storeId
, Collections.singletonList(spuId),replaceGoodsRequestVo.getMenuType(), this.shoppingCartBaseService);
List<Long> productIds = new ArrayList<>();
productIds.add(Long.parseLong(goodsId));
List<CartGoods> allCartGoodsList = new ArrayList<>();
List<CartGoods> oldCartGoodsList = new ArrayList<>();
Integer checkQty = this.checkSkuQty(allCartGoodsList, cartGoods);
//购物车添加数量限制
Integer productsCount = limitGoodsQty(allCartGoodsList,cartGoods,appId);
//查询多个商品库存信息 TODO
queryManyGoodsStocks(replaceGoodsRequestVo.getMenuType(),replaceGoodsRequestVo.getPartnerId(),replaceGoodsRequestVo.getShopId(), productIds, productBeanListSpuClass, skuId, checkQty);
updateCartGoodsLegal(cartGoods,userId,replaceGoodsRequestVo, new ShoppingCartGoodsResponseVo(), oldCartGoodsList);
});
}
private void updateCartGoodsLegal(CartGoods cartGoods, String userId, ShopGoodsReplaceVo replaceGoodsRequestVo, ShoppingCartGoodsResponseVo addShoppingCartGoodsRequestVo, List<CartGoods> oldAllCartGoodsList) {
//存储新添加的购物车信息
List<CartGoods> nowCartGoodsList = new ArrayList<>();
oldAllCartGoodsList.add(cartGoods);
//当商品全部添加完毕,校验购物车商品(是否合法,上下架,点餐方式,是否在当前菜单中...),并移除非法商品
CheckCartRequest checkCartRequest = assortmentSdkService.checkShoppingCartSdk(oldAllCartGoodsList, replaceGoodsRequestVo.getPartnerId(),
replaceGoodsRequestVo.getShopId(), addShoppingCartGoodsRequestVo, replaceGoodsRequestVo.getOrderType(),
"", replaceGoodsRequestVo.getMenuType(),shoppingCartBaseService);
if (checkCartRequest.getShoppingCartGoodsResponseVo() != null) {
addShoppingCartGoodsRequestVo.setToastMsg(checkCartRequest.getShoppingCartGoodsResponseVo().getToastMsg());
addShoppingCartGoodsRequestVo.setChanged(checkCartRequest.getShoppingCartGoodsResponseVo().getChanged());
}
List<CartGoods> allCartGoodsList = JSONArray.parseArray(JSONObject.toJSONString(checkCartRequest.getCartGoodsList()), CartGoods.class);
//判断当前商品在购物车是否已存在,存在则数量+1,不存在商品行 + 1
allCartGoodsList.forEach(oldCartGoods -> {
int index;
if ((index = nowCartGoodsList.indexOf(oldCartGoods)) >= 0) {
nowCartGoodsList.get(index).setQty(nowCartGoodsList.get(index).getQty() + cartGoods.getQty());
} else {
nowCartGoodsList.add(oldCartGoods);
}
});
// 重新set购物车信息到缓存中
assortmentSdkService.setShoppingCart(replaceGoodsRequestVo.getPartnerId(), replaceGoodsRequestVo.getShopId(),
userId, nowCartGoodsList, replaceGoodsRequestVo.getSessionId(), null, this.shoppingCartBaseService);
oldAllCartGoodsList.clear();
oldAllCartGoodsList.addAll(nowCartGoodsList);
}
private void queryManyGoodsStocks(String menuType, String partnerId, String shopId, List<Long> productIds, List<ProductBean> productBeanListSpuClass, String skuId, Integer qty) {
GetProductStockRequestDto requestDto = new GetProductStockRequestDto();
requestDto.setChannel(BusinessTypeEnum.getByType(menuType).getCode());
requestDto.setPartnerId(partnerId);
requestDto.setStoreId(shopId);
requestDto.setProductIds(productIds);
GetProductStockResponseDto availableStocks = null;
if (productBeanListSpuClass.get(0).getType() == ProductType.NOSPEC.getCode()
&& productBeanListSpuClass.get(0).getStockLimit() == 1) {
availableStocks = stockClient.getAvailableStocks(requestDto);
} else {
for (ProductBean.SkuProductBean skuProductBean : productBeanListSpuClass.get(0).getSkuList()) {
if (skuId.equals(skuProductBean.getSkuId()) && skuProductBean.getStockLimit() == 1) {
availableStocks = stockClient.getAvailableStocks(requestDto);
break;
}
}
}
if (availableStocks != null && !ResponseCodeConstant.RESPONSE_SUCCESS_STR.equals(availableStocks.getCode())) {
throw new ServiceException(ResponseResult.SHOPPING_CART_STOCK_NOT_HAVE);
}
if (availableStocks != null && ResponseCodeConstant.RESPONSE_SUCCESS_STR.equals(availableStocks.getCode()) &&
(CollectionUtils.isEmpty(availableStocks.getResult()) || availableStocks.getResult().get(0).getQty() == null
|| availableStocks.getResult().get(0).getQty() < qty)) {
Integer stock = 0;
if (!CollectionUtils.isEmpty(availableStocks.getResult()) && (stock = availableStocks.getResult().get(0).getQty()) > 0) {
throw new BizServiceException(ResponseResult.SHOPPING_CART_STOCK_NOT_HAVE, "仅剩" + stock + "件库存了");
}
throw new ServiceException(ResponseResult.SHOPPING_CART_STOCK_NOT_HAVE);
}
}
private boolean updateCartGoodsLegal(List<CartGoods> excludeGoods, String userId, ShopGoodsReplaceVo replaceGoodsRequestVo, ShoppingCartGoodsResponseVo shoppingCartGoodsResponseVo,boolean fullReplace) {
//存储新添加的购物车信息
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment