From 9980b12551e9cd5ce59b5e497b6754cf8209654f Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 3 May 2023 00:30:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=B4=AD=E7=89=A9=E8=BD=A6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=94=AF=E6=8C=81=20add=20=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=97=B6=EF=BC=8C=E9=80=82=E9=85=8D=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E8=A6=81=E5=88=A0=E9=99=A4=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/app/cart/vo/AppTradeCartAddReqVO.java | 2 -- .../module/trade/service/cart/TradeCartServiceImpl.java | 8 +++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartAddReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartAddReqVO.java index c1e3ebd2f..1018ec9a2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartAddReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartAddReqVO.java @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.trade.controller.app.cart.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; @Schema(description = "用户 App - 购物车添加购物项 Request VO") @@ -16,7 +15,6 @@ public class AppTradeCartAddReqVO { @Schema(description = "新增商品数量", required = true, example = "1") @NotNull(message = "数量不能为空") - @Min(message = "数量必须大于 0", value = 1L) private Integer count; @Schema(description = "是否添加到购物车", required = true, example = "true") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/cart/TradeCartServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/cart/TradeCartServiceImpl.java index ffd75a07a..f92068644 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/cart/TradeCartServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/cart/TradeCartServiceImpl.java @@ -58,9 +58,15 @@ public class TradeCartServiceImpl implements TradeCartService { cart.getCount() + addReqVO.getCount() : addReqVO.getCount(); ProductSkuRespDTO sku = checkProductSku(addReqVO.getSkuId(), count); + // 情况零:特殊,count 小于等于 0,说明前端项目删除 // 情况一:存在,则进行数量更新 if (cart != null) { - cartMapper.updateById(new TradeCartDO().setId(cart.getId()).setCount(count)); + // 特殊情况,如果 count 小于等于 0,说明前端想要删除 + if (count <= 0) { + cartMapper.deleteById(cart.getId()); + } else { + cartMapper.updateById(new TradeCartDO().setId(cart.getId()).setCount(count)); + } return cart.getId(); // 情况二:不存在,则进行插入 } else {