Commit 25dd96d4 authored by Junling Bu's avatar Junling Bu
Browse files

feat[litemall-wx-api]: 系统自动删除购物车失效商品

parent f5472192
package org.linlinjava.litemall.wx.web;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.system.SystemConfig;
......@@ -14,10 +15,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import static org.linlinjava.litemall.wx.util.WxResponseCode.GOODS_NO_STOCK;
import static org.linlinjava.litemall.wx.util.WxResponseCode.GOODS_UNSHELVE;
......@@ -60,7 +58,22 @@ public class WxCartController {
return ResponseUtil.unlogin();
}
List<LitemallCart> cartList = cartService.queryByUid(userId);
List<LitemallCart> list = cartService.queryByUid(userId);
List<LitemallCart> cartList = new ArrayList<>();
// TODO
// 如果系统检查商品已删除或已下架,则系统自动删除。
// 更好的效果应该是告知用户商品失效,允许用户点击按钮来清除失效商品。
for (LitemallCart cart : list) {
LitemallGoods goods = goodsService.findById(cart.getGoodsId());
if (goods == null || !goods.getIsOnSale()) {
cartService.deleteById(cart.getId());
logger.debug("系统自动删除失效购物车商品 goodsId=" + cart.getGoodsId() + " productId=" + cart.getProductId());
}
else{
cartList.add(cart);
}
}
Integer goodsCount = 0;
BigDecimal goodsAmount = new BigDecimal(0.00);
Integer checkedGoodsCount = 0;
......@@ -133,7 +146,12 @@ public class WxCartController {
cart.setId(null);
cart.setGoodsSn(goods.getGoodsSn());
cart.setGoodsName((goods.getName()));
cart.setPicUrl(goods.getPicUrl());
if(StringUtils.isEmpty(product.getUrl())){
cart.setPicUrl(goods.getPicUrl());
}
else{
cart.setPicUrl(product.getUrl());
}
cart.setPrice(product.getPrice());
cart.setSpecifications(product.getSpecifications());
cart.setUserId(userId);
......@@ -202,7 +220,12 @@ public class WxCartController {
cart.setId(null);
cart.setGoodsSn(goods.getGoodsSn());
cart.setGoodsName((goods.getName()));
cart.setPicUrl(goods.getPicUrl());
if(StringUtils.isEmpty(product.getUrl())){
cart.setPicUrl(goods.getPicUrl());
}
else{
cart.setPicUrl(product.getUrl());
}
cart.setPrice(product.getPrice());
cart.setSpecifications(product.getSpecifications());
cart.setUserId(userId);
......
Supports Markdown
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