mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 17:21:53 +08:00
调整购物车接口,支持 add 商品时,适配前端可能要删除的情况
This commit is contained in:
parent
f7fe9ad7b0
commit
9980b12551
@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.trade.controller.app.cart.vo;
|
|||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.Min;
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
@Schema(description = "用户 App - 购物车添加购物项 Request VO")
|
@Schema(description = "用户 App - 购物车添加购物项 Request VO")
|
||||||
@ -16,7 +15,6 @@ public class AppTradeCartAddReqVO {
|
|||||||
|
|
||||||
@Schema(description = "新增商品数量", required = true, example = "1")
|
@Schema(description = "新增商品数量", required = true, example = "1")
|
||||||
@NotNull(message = "数量不能为空")
|
@NotNull(message = "数量不能为空")
|
||||||
@Min(message = "数量必须大于 0", value = 1L)
|
|
||||||
private Integer count;
|
private Integer count;
|
||||||
|
|
||||||
@Schema(description = "是否添加到购物车", required = true, example = "true")
|
@Schema(description = "是否添加到购物车", required = true, example = "true")
|
||||||
|
@ -58,9 +58,15 @@ public class TradeCartServiceImpl implements TradeCartService {
|
|||||||
cart.getCount() + addReqVO.getCount() : addReqVO.getCount();
|
cart.getCount() + addReqVO.getCount() : addReqVO.getCount();
|
||||||
ProductSkuRespDTO sku = checkProductSku(addReqVO.getSkuId(), count);
|
ProductSkuRespDTO sku = checkProductSku(addReqVO.getSkuId(), count);
|
||||||
|
|
||||||
|
// 情况零:特殊,count 小于等于 0,说明前端项目删除
|
||||||
// 情况一:存在,则进行数量更新
|
// 情况一:存在,则进行数量更新
|
||||||
if (cart != null) {
|
if (cart != null) {
|
||||||
|
// 特殊情况,如果 count 小于等于 0,说明前端想要删除
|
||||||
|
if (count <= 0) {
|
||||||
|
cartMapper.deleteById(cart.getId());
|
||||||
|
} else {
|
||||||
cartMapper.updateById(new TradeCartDO().setId(cart.getId()).setCount(count));
|
cartMapper.updateById(new TradeCartDO().setId(cart.getId()).setCount(count));
|
||||||
|
}
|
||||||
return cart.getId();
|
return cart.getId();
|
||||||
// 情况二:不存在,则进行插入
|
// 情况二:不存在,则进行插入
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user