苍穹外卖--删除一条购物车
This commit is contained in:
@@ -20,4 +20,7 @@ public interface ShoppingCartService {
|
||||
清空购物车
|
||||
*/
|
||||
void cleanShoppingCart();
|
||||
|
||||
void subShoppingCart(ShoppingCartDTO shoppingCartDTO);
|
||||
|
||||
}
|
||||
|
||||
@@ -113,4 +113,25 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
||||
|
||||
shoppingCartMapper.deleteByUserId(BaseContext.getCurrentId());
|
||||
}
|
||||
|
||||
/*
|
||||
删除购物车中一个商品
|
||||
*/
|
||||
@Override
|
||||
public void subShoppingCart(ShoppingCartDTO shoppingCartDTO) {
|
||||
ShoppingCart cart = new ShoppingCart();
|
||||
BeanUtils.copyProperties(shoppingCartDTO,cart);
|
||||
cart.setUserId(BaseContext.getCurrentId());
|
||||
List<ShoppingCart> cartList = shoppingCartMapper.list(cart);
|
||||
if (cartList != null && cartList.size() > 0) {
|
||||
cart = cartList.get(0);
|
||||
|
||||
if (cart.getNumber() > 1) {
|
||||
cart.setNumber(cart.getNumber() - 1);
|
||||
shoppingCartMapper.updateNumberById(cart);
|
||||
} else {
|
||||
shoppingCartMapper.deleteById(cart.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user