苍穹外卖--删除一条购物车
This commit is contained in:
@@ -45,4 +45,13 @@ public class ShoppingCartController {
|
|||||||
shoppingCartService.cleanShoppingCart();
|
shoppingCartService.cleanShoppingCart();
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/sub")
|
||||||
|
@ApiOperation("删除购物车中一个商品")
|
||||||
|
public Result subShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
|
||||||
|
log.info("删除购物车中一个商品");
|
||||||
|
shoppingCartService.subShoppingCart(shoppingCartDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,4 +26,7 @@ public interface ShoppingCartMapper {
|
|||||||
|
|
||||||
@Delete("delete from shopping_cart where user_id = #{userId}")
|
@Delete("delete from shopping_cart where user_id = #{userId}")
|
||||||
void deleteByUserId(Long userId);
|
void deleteByUserId(Long userId);
|
||||||
|
|
||||||
|
@Delete("delete from shopping_cart where id = #{id}")
|
||||||
|
void deleteById(Long id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,4 +20,7 @@ public interface ShoppingCartService {
|
|||||||
清空购物车
|
清空购物车
|
||||||
*/
|
*/
|
||||||
void cleanShoppingCart();
|
void cleanShoppingCart();
|
||||||
|
|
||||||
|
void subShoppingCart(ShoppingCartDTO shoppingCartDTO);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,4 +113,25 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
|||||||
|
|
||||||
shoppingCartMapper.deleteByUserId(BaseContext.getCurrentId());
|
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