diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CartController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CartController.java index 3fbb33a..ee5e9e4 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CartController.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CartController.java @@ -44,6 +44,11 @@ public class CartController extends BaseController { return R.result(iCartService.updateById(cart)); } + @PostMapping("changeNum/{cartId}/{number}") + public R changeNum(@PathVariable Long cartId, @PathVariable Integer number) { + return iCartService.changeNum(cartId, number); + } + @PostMapping("addNum/{cartId}/{number}") public R addNum(@PathVariable Long cartId, @PathVariable Integer number) { return iCartService.addNum(cartId, number); diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ICartService.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ICartService.java index a24d725..9fab64e 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ICartService.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ICartService.java @@ -16,6 +16,7 @@ public interface ICartService extends IService { /** * 检查用户购物车中是否有商品货品 + * * @param userId * @param goodsId * @param productId @@ -36,18 +37,43 @@ public interface ICartService extends IService { /** * 计算购物车中商品数量 + * * @return R */ R goodsCount(); /** * 查询用户购物车商品 + * * @param userId 用户ID * @return R */ R list(Long userId); + /** + * 改变购物车商品数量 + * + * @param cartId 购物车商品ID + * @param number 商品数量 + * @return r + */ + R changeNum(Long cartId, Integer number); + + /** + * 添加购物车商品数量 + * + * @param cartId 购物车商品ID + * @param number 商品数量 + * @return r + */ R addNum(Long cartId, Integer number); + /** + * 减少购物车商品数量 + * + * @param cartId 购物车商品ID + * @param number 商品数量 + * @return r + */ R minusNum(Long cartId, Integer number); } diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/CartServiceImpl.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/CartServiceImpl.java index 4e64d43..12c390a 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/CartServiceImpl.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/CartServiceImpl.java @@ -111,6 +111,11 @@ public class CartServiceImpl extends ServiceImpl implements IC return R.success().add("data", cartList); } + @Override + public R changeNum(Long cartId, Integer number) { + return R.result(update().setSql("number = " + number).eq("id", cartId).update(), "修改失败"); + } + @Override public R addNum(Long cartId, Integer number) { return R.result(update().setSql("number = number + 1").eq("id", cartId).update(), "添加失败");