Commit 5a788af084e6e1f493e908a4f8ab5710432457b7
1 parent
cc71aabd
购物车:简化 cart 表命名
Showing
17 changed files
with
141 additions
and
159 deletions
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/TradeCartController.http renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/AppCartController.http
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/TradeCartController.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/AppCartController.java
| @@ -2,11 +2,8 @@ package cn.iocoder.yudao.module.trade.controller.app.cart; | @@ -2,11 +2,8 @@ package cn.iocoder.yudao.module.trade.controller.app.cart; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; | 4 | import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; |
| 5 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartAddReqVO; | ||
| 6 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartListRespVO; | ||
| 7 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartResetReqVO; | ||
| 8 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartUpdateReqVO; | ||
| 9 | -import cn.iocoder.yudao.module.trade.service.cart.TradeCartService; | 5 | +import cn.iocoder.yudao.module.trade.controller.app.cart.vo.*; |
| 6 | +import cn.iocoder.yudao.module.trade.service.cart.CartService; | ||
| 10 | import io.swagger.v3.oas.annotations.Operation; | 7 | import io.swagger.v3.oas.annotations.Operation; |
| 11 | import io.swagger.v3.oas.annotations.Parameter; | 8 | import io.swagger.v3.oas.annotations.Parameter; |
| 12 | import io.swagger.v3.oas.annotations.tags.Tag; | 9 | import io.swagger.v3.oas.annotations.tags.Tag; |
| @@ -29,30 +26,38 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti | @@ -29,30 +26,38 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti | ||
| 29 | @RequiredArgsConstructor | 26 | @RequiredArgsConstructor |
| 30 | @Validated | 27 | @Validated |
| 31 | @Slf4j | 28 | @Slf4j |
| 32 | -public class TradeCartController { | 29 | +public class AppCartController { |
| 33 | 30 | ||
| 34 | @Resource | 31 | @Resource |
| 35 | - private TradeCartService cartService; | 32 | + private CartService cartService; |
| 36 | 33 | ||
| 37 | @PostMapping("/add") | 34 | @PostMapping("/add") |
| 38 | @Operation(summary = "添加购物车商品") | 35 | @Operation(summary = "添加购物车商品") |
| 39 | @PreAuthenticated | 36 | @PreAuthenticated |
| 40 | - public CommonResult<Long> addCart(@Valid @RequestBody AppTradeCartAddReqVO addCountReqVO) { | 37 | + public CommonResult<Long> addCart(@Valid @RequestBody AppCartAddReqVO addCountReqVO) { |
| 41 | return success(cartService.addCart(getLoginUserId(), addCountReqVO)); | 38 | return success(cartService.addCart(getLoginUserId(), addCountReqVO)); |
| 42 | } | 39 | } |
| 43 | 40 | ||
| 44 | - @PutMapping("/update") | ||
| 45 | - @Operation(summary = "更新购物车商品") | 41 | + @PutMapping("/update-count") |
| 42 | + @Operation(summary = "更新购物车商品数量") | ||
| 46 | @PreAuthenticated | 43 | @PreAuthenticated |
| 47 | - public CommonResult<Boolean> updateCart(@Valid @RequestBody AppTradeCartUpdateReqVO updateReqVO) { | ||
| 48 | - cartService.updateCart(getLoginUserId(), updateReqVO); | 44 | + public CommonResult<Boolean> updateCartCount(@Valid @RequestBody AppCartUpdateCountReqVO updateReqVO) { |
| 45 | + cartService.updateCartCount(getLoginUserId(), updateReqVO); | ||
| 46 | + return success(true); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @PutMapping("/update-selected") | ||
| 50 | + @Operation(summary = "更新购物车商品选中") | ||
| 51 | + @PreAuthenticated | ||
| 52 | + public CommonResult<Boolean> updateCartSelected(@Valid @RequestBody AppCartUpdateSelectedReqVO updateReqVO) { | ||
| 53 | + cartService.updateCartSelected(getLoginUserId(), updateReqVO); | ||
| 49 | return success(true); | 54 | return success(true); |
| 50 | } | 55 | } |
| 51 | 56 | ||
| 52 | @PutMapping("/reset") | 57 | @PutMapping("/reset") |
| 53 | @Operation(summary = "重置购物车商品") | 58 | @Operation(summary = "重置购物车商品") |
| 54 | @PreAuthenticated | 59 | @PreAuthenticated |
| 55 | - public CommonResult<Boolean> resetCart(@Valid @RequestBody AppTradeCartResetReqVO updateReqVO) { | 60 | + public CommonResult<Boolean> resetCart(@Valid @RequestBody AppCartResetReqVO updateReqVO) { |
| 56 | cartService.resetCart(getLoginUserId(), updateReqVO); | 61 | cartService.resetCart(getLoginUserId(), updateReqVO); |
| 57 | return success(true); | 62 | return success(true); |
| 58 | } | 63 | } |
| @@ -83,7 +88,7 @@ public class TradeCartController { | @@ -83,7 +88,7 @@ public class TradeCartController { | ||
| 83 | @GetMapping("/list") | 88 | @GetMapping("/list") |
| 84 | @Operation(summary = "查询用户的购物车列表") | 89 | @Operation(summary = "查询用户的购物车列表") |
| 85 | @PreAuthenticated | 90 | @PreAuthenticated |
| 86 | - public CommonResult<AppTradeCartListRespVO> getCartList() { | 91 | + public CommonResult<AppCartListRespVO> getCartList() { |
| 87 | return success(cartService.getCartList(getLoginUserId())); | 92 | return success(cartService.getCartList(getLoginUserId())); |
| 88 | } | 93 | } |
| 89 | 94 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartAddReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartAddReqVO.java
| @@ -7,7 +7,7 @@ import javax.validation.constraints.NotNull; | @@ -7,7 +7,7 @@ import javax.validation.constraints.NotNull; | ||
| 7 | 7 | ||
| 8 | @Schema(description = "用户 App - 购物车添加购物项 Request VO") | 8 | @Schema(description = "用户 App - 购物车添加购物项 Request VO") |
| 9 | @Data | 9 | @Data |
| 10 | -public class AppTradeCartAddReqVO { | 10 | +public class AppCartAddReqVO { |
| 11 | 11 | ||
| 12 | @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED,example = "1024") | 12 | @Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED,example = "1024") |
| 13 | @NotNull(message = "商品 SKU 编号不能为空") | 13 | @NotNull(message = "商品 SKU 编号不能为空") |
| @@ -17,8 +17,4 @@ public class AppTradeCartAddReqVO { | @@ -17,8 +17,4 @@ public class AppTradeCartAddReqVO { | ||
| 17 | @NotNull(message = "数量不能为空") | 17 | @NotNull(message = "数量不能为空") |
| 18 | private Integer count; | 18 | private Integer count; |
| 19 | 19 | ||
| 20 | - @Schema(description = "是否添加到购物车", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | ||
| 21 | - @NotNull(message = "是否添加购物车不能为空") | ||
| 22 | - private Boolean addStatus; | ||
| 23 | - | ||
| 24 | } | 20 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartDetailRespVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartDetailRespVO.java
| @@ -8,7 +8,7 @@ import java.util.List; | @@ -8,7 +8,7 @@ import java.util.List; | ||
| 8 | 8 | ||
| 9 | @Schema(description = "用户 App - 用户的购物车明细 Response VO") | 9 | @Schema(description = "用户 App - 用户的购物车明细 Response VO") |
| 10 | @Data | 10 | @Data |
| 11 | -public class AppTradeCartDetailRespVO { | 11 | +public class AppCartDetailRespVO { |
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * 商品分组数组 | 14 | * 商品分组数组 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartListRespVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartListRespVO.java
| @@ -9,7 +9,7 @@ import java.util.List; | @@ -9,7 +9,7 @@ import java.util.List; | ||
| 9 | 9 | ||
| 10 | @Schema(description = "用户 App - 用户的购物列表 Response VO") | 10 | @Schema(description = "用户 App - 用户的购物列表 Response VO") |
| 11 | @Data | 11 | @Data |
| 12 | -public class AppTradeCartListRespVO { | 12 | +public class AppCartListRespVO { |
| 13 | 13 | ||
| 14 | /** | 14 | /** |
| 15 | * 有效的购物项数组 | 15 | * 有效的购物项数组 |
| @@ -31,6 +31,9 @@ public class AppTradeCartListRespVO { | @@ -31,6 +31,9 @@ public class AppTradeCartListRespVO { | ||
| 31 | @Schema(description = "商品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | 31 | @Schema(description = "商品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 32 | private Integer count; | 32 | private Integer count; |
| 33 | 33 | ||
| 34 | + @Schema(description = "是否选中", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | ||
| 35 | + private Boolean selected; | ||
| 36 | + | ||
| 34 | /** | 37 | /** |
| 35 | * 商品 SPU | 38 | * 商品 SPU |
| 36 | */ | 39 | */ |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartResetReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartResetReqVO.java
| @@ -8,7 +8,7 @@ import javax.validation.constraints.NotNull; | @@ -8,7 +8,7 @@ import javax.validation.constraints.NotNull; | ||
| 8 | 8 | ||
| 9 | @Schema(description = "用户 App - 购物车重置 Request VO") | 9 | @Schema(description = "用户 App - 购物车重置 Request VO") |
| 10 | @Data | 10 | @Data |
| 11 | -public class AppTradeCartResetReqVO { | 11 | +public class AppCartResetReqVO { |
| 12 | 12 | ||
| 13 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | 13 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 14 | @NotNull(message = "编号不能为空") | 14 | @NotNull(message = "编号不能为空") |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartUpdateReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartUpdateCountReqVO.java
| @@ -6,9 +6,9 @@ import lombok.Data; | @@ -6,9 +6,9 @@ import lombok.Data; | ||
| 6 | import javax.validation.constraints.Min; | 6 | import javax.validation.constraints.Min; |
| 7 | import javax.validation.constraints.NotNull; | 7 | import javax.validation.constraints.NotNull; |
| 8 | 8 | ||
| 9 | -@Schema(description = "用户 App - 购物车更新 Request VO") | 9 | +@Schema(description = "用户 App - 购物车更新数量 Request VO") |
| 10 | @Data | 10 | @Data |
| 11 | -public class AppTradeCartUpdateReqVO { | 11 | +public class AppCartUpdateCountReqVO { |
| 12 | 12 | ||
| 13 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | 13 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 14 | @NotNull(message = "编号不能为空") | 14 | @NotNull(message = "编号不能为空") |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppTradeCartItemUpdateSelectedReqVO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/cart/vo/AppCartUpdateSelectedReqVO.java
| @@ -8,11 +8,11 @@ import java.util.Collection; | @@ -8,11 +8,11 @@ import java.util.Collection; | ||
| 8 | 8 | ||
| 9 | @Schema(description = "用户 App - 购物车更新是否选中 Request VO") | 9 | @Schema(description = "用户 App - 购物车更新是否选中 Request VO") |
| 10 | @Data | 10 | @Data |
| 11 | -public class AppTradeCartItemUpdateSelectedReqVO { | 11 | +public class AppCartUpdateSelectedReqVO { |
| 12 | 12 | ||
| 13 | - @Schema(description = "商品 SKU 编号列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024,2048") | ||
| 14 | - @NotNull(message = "商品 SKU 编号列表不能为空") | ||
| 15 | - private Collection<Long> skuIds; | 13 | + @Schema(description = "编号列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024,2048") |
| 14 | + @NotNull(message = "编号列表不能为空") | ||
| 15 | + private Collection<Long> ids; | ||
| 16 | 16 | ||
| 17 | @Schema(description = "是否选中", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | 17 | @Schema(description = "是否选中", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") |
| 18 | @NotNull(message = "是否选中不能为空") | 18 | @NotNull(message = "是否选中不能为空") |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/cart/TradeCartConvert.java
| @@ -5,8 +5,8 @@ import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | @@ -5,8 +5,8 @@ import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | ||
| 5 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; | 5 | import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum; |
| 6 | import cn.iocoder.yudao.module.trade.controller.app.base.sku.AppProductSkuBaseRespVO; | 6 | import cn.iocoder.yudao.module.trade.controller.app.base.sku.AppProductSkuBaseRespVO; |
| 7 | import cn.iocoder.yudao.module.trade.controller.app.base.spu.AppProductSpuBaseRespVO; | 7 | import cn.iocoder.yudao.module.trade.controller.app.base.spu.AppProductSpuBaseRespVO; |
| 8 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartListRespVO; | ||
| 9 | -import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; | 8 | +import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppCartListRespVO; |
| 9 | +import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; | ||
| 10 | import org.mapstruct.Mapper; | 10 | import org.mapstruct.Mapper; |
| 11 | import org.mapstruct.factory.Mappers; | 11 | import org.mapstruct.factory.Mappers; |
| 12 | 12 | ||
| @@ -21,16 +21,16 @@ public interface TradeCartConvert { | @@ -21,16 +21,16 @@ public interface TradeCartConvert { | ||
| 21 | 21 | ||
| 22 | TradeCartConvert INSTANCE = Mappers.getMapper(TradeCartConvert.class); | 22 | TradeCartConvert INSTANCE = Mappers.getMapper(TradeCartConvert.class); |
| 23 | 23 | ||
| 24 | - default AppTradeCartListRespVO convertList(List<TradeCartDO> carts, | ||
| 25 | - List<ProductSpuRespDTO> spus, List<ProductSkuRespDTO> skus) { | 24 | + default AppCartListRespVO convertList(List<CartDO> carts, |
| 25 | + List<ProductSpuRespDTO> spus, List<ProductSkuRespDTO> skus) { | ||
| 26 | Map<Long, ProductSpuRespDTO> spuMap = convertMap(spus, ProductSpuRespDTO::getId); | 26 | Map<Long, ProductSpuRespDTO> spuMap = convertMap(spus, ProductSpuRespDTO::getId); |
| 27 | Map<Long, ProductSkuRespDTO> skuMap = convertMap(skus, ProductSkuRespDTO::getId); | 27 | Map<Long, ProductSkuRespDTO> skuMap = convertMap(skus, ProductSkuRespDTO::getId); |
| 28 | // 遍历,开始转换 | 28 | // 遍历,开始转换 |
| 29 | - List<AppTradeCartListRespVO.Cart> validList = new ArrayList<>(carts.size()); | ||
| 30 | - List<AppTradeCartListRespVO.Cart> invalidList = new ArrayList<>(); | 29 | + List<AppCartListRespVO.Cart> validList = new ArrayList<>(carts.size()); |
| 30 | + List<AppCartListRespVO.Cart> invalidList = new ArrayList<>(); | ||
| 31 | carts.forEach(cart -> { | 31 | carts.forEach(cart -> { |
| 32 | - AppTradeCartListRespVO.Cart cartVO = new AppTradeCartListRespVO.Cart(); | ||
| 33 | - cartVO.setId(cart.getId()).setCount(cart.getCount()); | 32 | + AppCartListRespVO.Cart cartVO = new AppCartListRespVO.Cart(); |
| 33 | + cartVO.setId(cart.getId()).setCount(cart.getCount()).setSelected(cart.getSelected()); | ||
| 34 | ProductSpuRespDTO spu = spuMap.get(cart.getSpuId()); | 34 | ProductSpuRespDTO spu = spuMap.get(cart.getSpuId()); |
| 35 | ProductSkuRespDTO sku = skuMap.get(cart.getSkuId()); | 35 | ProductSkuRespDTO sku = skuMap.get(cart.getSkuId()); |
| 36 | cartVO.setSpu(convert(spu)).setSku(convert(sku)); | 36 | cartVO.setSpu(convert(spu)).setSku(convert(sku)); |
| @@ -38,13 +38,14 @@ public interface TradeCartConvert { | @@ -38,13 +38,14 @@ public interface TradeCartConvert { | ||
| 38 | if (spu == null | 38 | if (spu == null |
| 39 | || !ProductSpuStatusEnum.isEnable(spu.getStatus()) | 39 | || !ProductSpuStatusEnum.isEnable(spu.getStatus()) |
| 40 | || spu.getStock() <= 0) { | 40 | || spu.getStock() <= 0) { |
| 41 | + cartVO.setSelected(false); // 强制设置成不可选中 | ||
| 41 | invalidList.add(cartVO); | 42 | invalidList.add(cartVO); |
| 42 | } else { | 43 | } else { |
| 43 | // 虽然 SKU 可能也会不存在,但是可以通过购物车重新选择 | 44 | // 虽然 SKU 可能也会不存在,但是可以通过购物车重新选择 |
| 44 | validList.add(cartVO); | 45 | validList.add(cartVO); |
| 45 | } | 46 | } |
| 46 | }); | 47 | }); |
| 47 | - return new AppTradeCartListRespVO().setValidList(validList).setInvalidList(invalidList); | 48 | + return new AppCartListRespVO().setValidList(validList).setInvalidList(invalidList); |
| 48 | } | 49 | } |
| 49 | AppProductSpuBaseRespVO convert(ProductSpuRespDTO spu); | 50 | AppProductSpuBaseRespVO convert(ProductSpuRespDTO spu); |
| 50 | AppProductSkuBaseRespVO convert(ProductSkuRespDTO sku); | 51 | AppProductSkuBaseRespVO convert(ProductSkuRespDTO sku); |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java
| @@ -22,7 +22,7 @@ import cn.iocoder.yudao.module.trade.controller.app.base.property.AppProductProp | @@ -22,7 +22,7 @@ import cn.iocoder.yudao.module.trade.controller.app.base.property.AppProductProp | ||
| 22 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.*; | 22 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.*; |
| 23 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; | 23 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; |
| 24 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemRespVO; | 24 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemRespVO; |
| 25 | -import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; | 25 | +import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; |
| 26 | import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; | 26 | import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; |
| 27 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; | 27 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| 28 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; | 28 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; |
| @@ -221,12 +221,12 @@ public interface TradeOrderConvert { | @@ -221,12 +221,12 @@ public interface TradeOrderConvert { | ||
| 221 | ProductCommentCreateReqDTO convert04(AppTradeOrderItemCommentCreateReqVO createReqVO, TradeOrderItemDO tradeOrderItemDO); | 221 | ProductCommentCreateReqDTO convert04(AppTradeOrderItemCommentCreateReqVO createReqVO, TradeOrderItemDO tradeOrderItemDO); |
| 222 | 222 | ||
| 223 | default TradePriceCalculateReqBO convert(Long userId, AppTradeOrderSettlementReqVO settlementReqVO, | 223 | default TradePriceCalculateReqBO convert(Long userId, AppTradeOrderSettlementReqVO settlementReqVO, |
| 224 | - List<TradeCartDO> cartList) { | 224 | + List<CartDO> cartList) { |
| 225 | TradePriceCalculateReqBO reqBO = new TradePriceCalculateReqBO(); | 225 | TradePriceCalculateReqBO reqBO = new TradePriceCalculateReqBO(); |
| 226 | reqBO.setUserId(userId).setCouponId(settlementReqVO.getCouponId()).setAddressId(settlementReqVO.getAddressId()) | 226 | reqBO.setUserId(userId).setCouponId(settlementReqVO.getCouponId()).setAddressId(settlementReqVO.getAddressId()) |
| 227 | .setItems(new ArrayList<>(settlementReqVO.getItems().size())); | 227 | .setItems(new ArrayList<>(settlementReqVO.getItems().size())); |
| 228 | // 商品项的构建 | 228 | // 商品项的构建 |
| 229 | - Map<Long, TradeCartDO> cartMap = convertMap(cartList, TradeCartDO::getId); | 229 | + Map<Long, CartDO> cartMap = convertMap(cartList, CartDO::getId); |
| 230 | for (AppTradeOrderSettlementReqVO.Item item : settlementReqVO.getItems()) { | 230 | for (AppTradeOrderSettlementReqVO.Item item : settlementReqVO.getItems()) { |
| 231 | // 情况一:skuId + count | 231 | // 情况一:skuId + count |
| 232 | if (item.getSkuId() != null) { | 232 | if (item.getSkuId() != null) { |
| @@ -235,7 +235,7 @@ public interface TradeOrderConvert { | @@ -235,7 +235,7 @@ public interface TradeOrderConvert { | ||
| 235 | continue; | 235 | continue; |
| 236 | } | 236 | } |
| 237 | // 情况二:cartId | 237 | // 情况二:cartId |
| 238 | - TradeCartDO cart = cartMap.get(item.getCartId()); | 238 | + CartDO cart = cartMap.get(item.getCartId()); |
| 239 | if (cart == null) { | 239 | if (cart == null) { |
| 240 | continue; | 240 | continue; |
| 241 | } | 241 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/cart/TradeCartDO.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/cart/CartDO.java
| @@ -17,7 +17,7 @@ import lombok.experimental.Accessors; | @@ -17,7 +17,7 @@ import lombok.experimental.Accessors; | ||
| 17 | @Data | 17 | @Data |
| 18 | @EqualsAndHashCode(callSuper = true) | 18 | @EqualsAndHashCode(callSuper = true) |
| 19 | @Accessors(chain = true) | 19 | @Accessors(chain = true) |
| 20 | -public class TradeCartDO extends BaseDO { | 20 | +public class CartDO extends BaseDO { |
| 21 | 21 | ||
| 22 | // ========= 基础字段 BEGIN ========= | 22 | // ========= 基础字段 BEGIN ========= |
| 23 | 23 | ||
| @@ -33,27 +33,7 @@ public class TradeCartDO extends BaseDO { | @@ -33,27 +33,7 @@ public class TradeCartDO extends BaseDO { | ||
| 33 | */ | 33 | */ |
| 34 | private Long userId; | 34 | private Long userId; |
| 35 | 35 | ||
| 36 | - /** | ||
| 37 | - * 是否添加到购物车 | ||
| 38 | - * | ||
| 39 | - * false - 未添加:用户点击【立即购买】 | ||
| 40 | - * true - 已添加:用户点击【添加购物车】 | ||
| 41 | - * | ||
| 42 | - * 为什么要设计这个字段? | ||
| 43 | - * 配合 orderStatus 字段,可以知道有多少商品,用户点击了【立即购买】,最终多少【确认下单】 | ||
| 44 | - */ | ||
| 45 | - private Boolean addStatus; | ||
| 46 | - /** | ||
| 47 | - * 是否提交订单 | ||
| 48 | - * | ||
| 49 | - * false - 未下单:立即购买,或者添加到购物车,此时设置为 false | ||
| 50 | - * true - 已下单:确认下单,此时设置为 true | ||
| 51 | - */ | ||
| 52 | - private Boolean orderStatus; | ||
| 53 | - | ||
| 54 | - // ========= 基础字段 END ========= | ||
| 55 | - | ||
| 56 | - // ========= 商品信息 BEGIN ========= | 36 | + // ========= 商品信息 ========= |
| 57 | 37 | ||
| 58 | /** | 38 | /** |
| 59 | * 商品 SPU 编号 | 39 | * 商品 SPU 编号 |
| @@ -71,16 +51,9 @@ public class TradeCartDO extends BaseDO { | @@ -71,16 +51,9 @@ public class TradeCartDO extends BaseDO { | ||
| 71 | * 商品购买数量 | 51 | * 商品购买数量 |
| 72 | */ | 52 | */ |
| 73 | private Integer count; | 53 | private Integer count; |
| 74 | - | ||
| 75 | - // ========= 商品信息 END ========= | ||
| 76 | - | ||
| 77 | - // ========= 优惠信息 BEGIN ========= | ||
| 78 | - | ||
| 79 | - // TODO 芋艿:combination_id 拼团 ID | ||
| 80 | - // TODO 芋艿:seckill_id 秒杀产品 ID | ||
| 81 | - // TODO 芋艿:bargain_id 砍价 ID | ||
| 82 | - // TODO 芋艿:pinkId 团长拼团 ID | ||
| 83 | - | ||
| 84 | - // ========= 优惠信息 END ========= | 54 | + /** |
| 55 | + * 是否选中 | ||
| 56 | + */ | ||
| 57 | + private Boolean selected; | ||
| 85 | 58 | ||
| 86 | } | 59 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderItemDO.java
| @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.trade.dal.dataobject.order; | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.trade.dal.dataobject.order; | ||
| 3 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 3 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO; | 5 | import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.TradeAfterSaleDO; |
| 6 | -import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; | 6 | +import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; |
| 7 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; | 7 | import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; |
| 8 | import com.baomidou.mybatisplus.annotation.TableField; | 8 | import com.baomidou.mybatisplus.annotation.TableField; |
| 9 | import com.baomidou.mybatisplus.annotation.TableName; | 9 | import com.baomidou.mybatisplus.annotation.TableName; |
| @@ -46,7 +46,7 @@ public class TradeOrderItemDO extends BaseDO { | @@ -46,7 +46,7 @@ public class TradeOrderItemDO extends BaseDO { | ||
| 46 | /** | 46 | /** |
| 47 | * 购物车项编号 | 47 | * 购物车项编号 |
| 48 | * | 48 | * |
| 49 | - * 关联 {@link TradeCartDO#getId()} | 49 | + * 关联 {@link CartDO#getId()} |
| 50 | */ | 50 | */ |
| 51 | private Long cartId; | 51 | private Long cartId; |
| 52 | 52 |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/cart/TradeCartMapper.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/cart/CartMapper.java
| @@ -4,7 +4,7 @@ import cn.hutool.core.collection.CollUtil; | @@ -4,7 +4,7 @@ import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.hutool.core.map.MapUtil; | 4 | import cn.hutool.core.map.MapUtil; |
| 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 6 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | 6 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 7 | -import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; | 7 | +import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; |
| 8 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 8 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| 9 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 9 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| 10 | import org.apache.ibatis.annotations.Mapper; | 10 | import org.apache.ibatis.annotations.Mapper; |
| @@ -15,19 +15,16 @@ import java.util.Map; | @@ -15,19 +15,16 @@ import java.util.Map; | ||
| 15 | import java.util.Set; | 15 | import java.util.Set; |
| 16 | 16 | ||
| 17 | @Mapper | 17 | @Mapper |
| 18 | -public interface TradeCartMapper extends BaseMapperX<TradeCartDO> { | 18 | +public interface CartMapper extends BaseMapperX<CartDO> { |
| 19 | 19 | ||
| 20 | - default TradeCartDO selectByUserIdAndSkuId(Long userId, Long skuId, | ||
| 21 | - Boolean addStatus, Boolean orderStatus) { | ||
| 22 | - return selectOne(new LambdaQueryWrapper<TradeCartDO>().eq(TradeCartDO::getUserId, userId) | ||
| 23 | - .eq(TradeCartDO::getSkuId, skuId) | ||
| 24 | - .eq(TradeCartDO::getAddStatus, addStatus) | ||
| 25 | - .eq(TradeCartDO::getOrderStatus, orderStatus)); | 20 | + default CartDO selectByUserIdAndSkuId(Long userId, Long skuId) { |
| 21 | + return selectOne(CartDO::getUserId, userId, | ||
| 22 | + CartDO::getSkuId, skuId); | ||
| 26 | } | 23 | } |
| 27 | 24 | ||
| 28 | default Integer selectSumByUserId(Long userId) { | 25 | default Integer selectSumByUserId(Long userId) { |
| 29 | // SQL sum 查询 | 26 | // SQL sum 查询 |
| 30 | - List<Map<String, Object>> result = selectMaps(new QueryWrapper<TradeCartDO>() | 27 | + List<Map<String, Object>> result = selectMaps(new QueryWrapper<CartDO>() |
| 31 | .select("SUM(count) AS sumCount") | 28 | .select("SUM(count) AS sumCount") |
| 32 | .eq("user_id", userId) | 29 | .eq("user_id", userId) |
| 33 | .eq("add_status", true) // 只计算添加到购物车中的 | 30 | .eq("add_status", true) // 只计算添加到购物车中的 |
| @@ -38,7 +35,7 @@ public interface TradeCartMapper extends BaseMapperX<TradeCartDO> { | @@ -38,7 +35,7 @@ public interface TradeCartMapper extends BaseMapperX<TradeCartDO> { | ||
| 38 | 35 | ||
| 39 | default Map<Long, Integer> selectSumMapByUserId(Long userId) { | 36 | default Map<Long, Integer> selectSumMapByUserId(Long userId) { |
| 40 | // SQL sum 查询 | 37 | // SQL sum 查询 |
| 41 | - List<Map<String, Object>> result = selectMaps(new QueryWrapper<TradeCartDO>() | 38 | + List<Map<String, Object>> result = selectMaps(new QueryWrapper<CartDO>() |
| 42 | .select("spu_id, SUM(count) AS sumCount") | 39 | .select("spu_id, SUM(count) AS sumCount") |
| 43 | .eq("user_id", userId) | 40 | .eq("user_id", userId) |
| 44 | .eq("add_status", true) // 只计算添加到购物车中的 | 41 | .eq("add_status", true) // 只计算添加到购物车中的 |
| @@ -49,32 +46,32 @@ public interface TradeCartMapper extends BaseMapperX<TradeCartDO> { | @@ -49,32 +46,32 @@ public interface TradeCartMapper extends BaseMapperX<TradeCartDO> { | ||
| 49 | item -> MapUtil.getInt(item, "sumCount")); | 46 | item -> MapUtil.getInt(item, "sumCount")); |
| 50 | } | 47 | } |
| 51 | 48 | ||
| 52 | - default TradeCartDO selectById(Long id, Long userId) { | ||
| 53 | - return selectOne(TradeCartDO::getId, id, | ||
| 54 | - TradeCartDO::getUserId, userId); | 49 | + default CartDO selectById(Long id, Long userId) { |
| 50 | + return selectOne(CartDO::getId, id, | ||
| 51 | + CartDO::getUserId, userId); | ||
| 55 | } | 52 | } |
| 56 | 53 | ||
| 57 | - default List<TradeCartDO> selectListByIds(Collection<Long> ids, Long userId) { | ||
| 58 | - return selectList(new LambdaQueryWrapper<TradeCartDO>() | ||
| 59 | - .in(TradeCartDO::getId, ids) | ||
| 60 | - .eq(TradeCartDO::getUserId, userId)); | 54 | + default List<CartDO> selectListByIds(Collection<Long> ids, Long userId) { |
| 55 | + return selectList(new LambdaQueryWrapper<CartDO>() | ||
| 56 | + .in(CartDO::getId, ids) | ||
| 57 | + .eq(CartDO::getUserId, userId)); | ||
| 61 | } | 58 | } |
| 62 | 59 | ||
| 63 | - default List<TradeCartDO> selectListByUserId(Long userId, Boolean addStatus, Boolean orderStatus) { | ||
| 64 | - return selectList(new LambdaQueryWrapper<TradeCartDO>() | ||
| 65 | - .eq(TradeCartDO::getUserId, userId) | ||
| 66 | - .eq(TradeCartDO::getAddStatus, addStatus) | ||
| 67 | - .eq(TradeCartDO::getOrderStatus, orderStatus)); | 60 | + default List<CartDO> selectListByUserId(Long userId) { |
| 61 | + return selectList(new LambdaQueryWrapper<CartDO>() | ||
| 62 | + .eq(CartDO::getUserId, userId)); | ||
| 68 | } | 63 | } |
| 69 | 64 | ||
| 70 | - default void updateByIds(Collection<Long> ids, TradeCartDO updateObject) { | ||
| 71 | - update(updateObject, new LambdaQueryWrapper<TradeCartDO>().in(TradeCartDO::getId, ids)); | 65 | + default List<CartDO> selectListByUserId(Long userId, Set<Long> ids) { |
| 66 | + return selectList(new LambdaQueryWrapper<CartDO>() | ||
| 67 | + .eq(CartDO::getUserId, userId) | ||
| 68 | + .in(CartDO::getId, ids)); | ||
| 72 | } | 69 | } |
| 73 | 70 | ||
| 74 | - default List<TradeCartDO> selectListByUserId(Long userId, Set<Long> ids) { | ||
| 75 | - return selectList(new LambdaQueryWrapper<TradeCartDO>() | ||
| 76 | - .eq(TradeCartDO::getUserId, userId) | ||
| 77 | - .in(TradeCartDO::getId, ids)); | 71 | + default void updateByIds(Collection<Long> ids, Long userId, CartDO updateObj) { |
| 72 | + update(updateObj, new LambdaQueryWrapper<CartDO>() | ||
| 73 | + .in(CartDO::getId, ids) | ||
| 74 | + .eq(CartDO::getUserId, userId)); | ||
| 78 | } | 75 | } |
| 79 | 76 | ||
| 80 | } | 77 | } |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/cart/TradeCartService.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/cart/CartService.java
| 1 | package cn.iocoder.yudao.module.trade.service.cart; | 1 | package cn.iocoder.yudao.module.trade.service.cart; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartAddReqVO; | ||
| 4 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartListRespVO; | ||
| 5 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartResetReqVO; | ||
| 6 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartUpdateReqVO; | ||
| 7 | -import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; | 3 | +import cn.iocoder.yudao.module.trade.controller.app.cart.vo.*; |
| 4 | +import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; | ||
| 8 | 5 | ||
| 9 | import javax.validation.Valid; | 6 | import javax.validation.Valid; |
| 10 | import java.util.Collection; | 7 | import java.util.Collection; |
| @@ -17,7 +14,7 @@ import java.util.Set; | @@ -17,7 +14,7 @@ import java.util.Set; | ||
| 17 | * | 14 | * |
| 18 | * @author 芋道源码 | 15 | * @author 芋道源码 |
| 19 | */ | 16 | */ |
| 20 | -public interface TradeCartService { | 17 | +public interface CartService { |
| 21 | 18 | ||
| 22 | /** | 19 | /** |
| 23 | * 添加商品到购物车 | 20 | * 添加商品到购物车 |
| @@ -26,7 +23,7 @@ public interface TradeCartService { | @@ -26,7 +23,7 @@ public interface TradeCartService { | ||
| 26 | * @param addReqVO 添加信息 | 23 | * @param addReqVO 添加信息 |
| 27 | * @return 购物项的编号 | 24 | * @return 购物项的编号 |
| 28 | */ | 25 | */ |
| 29 | - Long addCart(Long userId, @Valid AppTradeCartAddReqVO addReqVO); | 26 | + Long addCart(Long userId, @Valid AppCartAddReqVO addReqVO); |
| 30 | 27 | ||
| 31 | /** | 28 | /** |
| 32 | * 更新购物车商品数量 | 29 | * 更新购物车商品数量 |
| @@ -34,7 +31,15 @@ public interface TradeCartService { | @@ -34,7 +31,15 @@ public interface TradeCartService { | ||
| 34 | * @param userId 用户编号 | 31 | * @param userId 用户编号 |
| 35 | * @param updateCountReqVO 更新信息 | 32 | * @param updateCountReqVO 更新信息 |
| 36 | */ | 33 | */ |
| 37 | - void updateCart(Long userId, AppTradeCartUpdateReqVO updateCountReqVO); | 34 | + void updateCartCount(Long userId, AppCartUpdateCountReqVO updateCountReqVO); |
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 更新购物车选中状态 | ||
| 38 | + * | ||
| 39 | + * @param userId 用户编号 | ||
| 40 | + * @param updateSelectedReqVO 更新信息 | ||
| 41 | + */ | ||
| 42 | + void updateCartSelected(Long userId, @Valid AppCartUpdateSelectedReqVO updateSelectedReqVO); | ||
| 38 | 43 | ||
| 39 | /** | 44 | /** |
| 40 | * 重置购物车商品 | 45 | * 重置购物车商品 |
| @@ -44,7 +49,7 @@ public interface TradeCartService { | @@ -44,7 +49,7 @@ public interface TradeCartService { | ||
| 44 | * @param userId 用户编号 | 49 | * @param userId 用户编号 |
| 45 | * @param updateReqVO 重置信息 | 50 | * @param updateReqVO 重置信息 |
| 46 | */ | 51 | */ |
| 47 | - void resetCart(Long userId, AppTradeCartResetReqVO updateReqVO); | 52 | + void resetCart(Long userId, AppCartResetReqVO updateReqVO); |
| 48 | 53 | ||
| 49 | /** | 54 | /** |
| 50 | * 删除购物车商品 | 55 | * 删除购物车商品 |
| @@ -68,7 +73,7 @@ public interface TradeCartService { | @@ -68,7 +73,7 @@ public interface TradeCartService { | ||
| 68 | * @param userId 用户编号 | 73 | * @param userId 用户编号 |
| 69 | * @return 购物车列表 | 74 | * @return 购物车列表 |
| 70 | */ | 75 | */ |
| 71 | - AppTradeCartListRespVO getCartList(Long userId); | 76 | + AppCartListRespVO getCartList(Long userId); |
| 72 | 77 | ||
| 73 | /** | 78 | /** |
| 74 | * 查询用户的购物车列表 | 79 | * 查询用户的购物车列表 |
| @@ -77,7 +82,7 @@ public interface TradeCartService { | @@ -77,7 +82,7 @@ public interface TradeCartService { | ||
| 77 | * @param ids 购物项的编号 | 82 | * @param ids 购物项的编号 |
| 78 | * @return 购物车列表 | 83 | * @return 购物车列表 |
| 79 | */ | 84 | */ |
| 80 | - List<TradeCartDO> getCartList(Long userId, Set<Long> ids); | 85 | + List<CartDO> getCartList(Long userId, Set<Long> ids); |
| 81 | 86 | ||
| 82 | /** | 87 | /** |
| 83 | * 获得用户的购物车商品 SPU 数量的 Map | 88 | * 获得用户的购物车商品 SPU 数量的 Map |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/cart/TradeCartServiceImpl.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/cart/CartServiceImpl.java
| @@ -5,13 +5,10 @@ import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; | @@ -5,13 +5,10 @@ import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; | ||
| 5 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; | 5 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; |
| 6 | import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; | 6 | import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; |
| 7 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; | 7 | import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; |
| 8 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartAddReqVO; | ||
| 9 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartListRespVO; | ||
| 10 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartResetReqVO; | ||
| 11 | -import cn.iocoder.yudao.module.trade.controller.app.cart.vo.AppTradeCartUpdateReqVO; | 8 | +import cn.iocoder.yudao.module.trade.controller.app.cart.vo.*; |
| 12 | import cn.iocoder.yudao.module.trade.convert.cart.TradeCartConvert; | 9 | import cn.iocoder.yudao.module.trade.convert.cart.TradeCartConvert; |
| 13 | -import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; | ||
| 14 | -import cn.iocoder.yudao.module.trade.dal.mysql.cart.TradeCartMapper; | 10 | +import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; |
| 11 | +import cn.iocoder.yudao.module.trade.dal.mysql.cart.CartMapper; | ||
| 15 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 16 | import org.springframework.transaction.annotation.Transactional; | 13 | import org.springframework.transaction.annotation.Transactional; |
| 17 | import org.springframework.validation.annotation.Validated; | 14 | import org.springframework.validation.annotation.Validated; |
| @@ -29,17 +26,16 @@ import static java.util.Collections.emptyList; | @@ -29,17 +26,16 @@ import static java.util.Collections.emptyList; | ||
| 29 | /** | 26 | /** |
| 30 | * 购物车 Service 实现类 | 27 | * 购物车 Service 实现类 |
| 31 | * | 28 | * |
| 32 | - * // TODO 芋艿:秒杀、拼团、砍价对购物车的影响 | ||
| 33 | - * // TODO 芋艿:未来优化:购物车的价格计算,支持营销信息 | 29 | + * // TODO 芋艿:未来优化:购物车的价格计算,支持营销信息;目前不支持的原因,前端界面需要前端 pr 支持下; |
| 34 | * | 30 | * |
| 35 | * @author 芋道源码 | 31 | * @author 芋道源码 |
| 36 | */ | 32 | */ |
| 37 | @Service | 33 | @Service |
| 38 | @Validated | 34 | @Validated |
| 39 | -public class TradeCartServiceImpl implements TradeCartService { | 35 | +public class CartServiceImpl implements CartService { |
| 40 | 36 | ||
| 41 | @Resource | 37 | @Resource |
| 42 | - private TradeCartMapper cartMapper; | 38 | + private CartMapper cartMapper; |
| 43 | 39 | ||
| 44 | @Resource | 40 | @Resource |
| 45 | private ProductSpuApi productSpuApi; | 41 | private ProductSpuApi productSpuApi; |
| @@ -47,13 +43,11 @@ public class TradeCartServiceImpl implements TradeCartService { | @@ -47,13 +43,11 @@ public class TradeCartServiceImpl implements TradeCartService { | ||
| 47 | private ProductSkuApi productSkuApi; | 43 | private ProductSkuApi productSkuApi; |
| 48 | 44 | ||
| 49 | @Override | 45 | @Override |
| 50 | - public Long addCart(Long userId, AppTradeCartAddReqVO addReqVO) { | 46 | + public Long addCart(Long userId, AppCartAddReqVO addReqVO) { |
| 51 | // 查询 TradeCartDO | 47 | // 查询 TradeCartDO |
| 52 | - TradeCartDO cart = cartMapper.selectByUserIdAndSkuId(userId, addReqVO.getSkuId(), | ||
| 53 | - addReqVO.getAddStatus(), false); | 48 | + CartDO cart = cartMapper.selectByUserIdAndSkuId(userId, addReqVO.getSkuId()); |
| 54 | // 校验 SKU | 49 | // 校验 SKU |
| 55 | - Integer count = cart != null && addReqVO.getAddStatus() ? | ||
| 56 | - cart.getCount() + addReqVO.getCount() : addReqVO.getCount(); | 50 | + Integer count = addReqVO.getCount(); |
| 57 | ProductSkuRespDTO sku = checkProductSku(addReqVO.getSkuId(), count); | 51 | ProductSkuRespDTO sku = checkProductSku(addReqVO.getSkuId(), count); |
| 58 | 52 | ||
| 59 | // 情况零:特殊,count 小于等于 0,说明前端项目删除 | 53 | // 情况零:特殊,count 小于等于 0,说明前端项目删除 |
| @@ -63,23 +57,22 @@ public class TradeCartServiceImpl implements TradeCartService { | @@ -63,23 +57,22 @@ public class TradeCartServiceImpl implements TradeCartService { | ||
| 63 | if (count <= 0) { | 57 | if (count <= 0) { |
| 64 | cartMapper.deleteById(cart.getId()); | 58 | cartMapper.deleteById(cart.getId()); |
| 65 | } else { | 59 | } else { |
| 66 | - cartMapper.updateById(new TradeCartDO().setId(cart.getId()).setCount(count)); | 60 | + cartMapper.updateById(new CartDO().setId(cart.getId()).setCount(count)); |
| 67 | } | 61 | } |
| 68 | return cart.getId(); | 62 | return cart.getId(); |
| 69 | // 情况二:不存在,则进行插入 | 63 | // 情况二:不存在,则进行插入 |
| 70 | } else { | 64 | } else { |
| 71 | - cart = new TradeCartDO().setUserId(userId) | ||
| 72 | - .setSpuId(sku.getSpuId()).setSkuId(sku.getId()).setCount(count) | ||
| 73 | - .setAddStatus(addReqVO.getAddStatus()).setOrderStatus(false); | 65 | + cart = new CartDO().setUserId(userId) |
| 66 | + .setSpuId(sku.getSpuId()).setSkuId(sku.getId()).setCount(count); | ||
| 74 | cartMapper.insert(cart); | 67 | cartMapper.insert(cart); |
| 75 | } | 68 | } |
| 76 | return cart.getId(); | 69 | return cart.getId(); |
| 77 | } | 70 | } |
| 78 | 71 | ||
| 79 | @Override | 72 | @Override |
| 80 | - public void updateCart(Long userId, AppTradeCartUpdateReqVO updateReqVO) { | 73 | + public void updateCartCount(Long userId, AppCartUpdateCountReqVO updateReqVO) { |
| 81 | // 校验 TradeCartDO 存在 | 74 | // 校验 TradeCartDO 存在 |
| 82 | - TradeCartDO cart = cartMapper.selectById(updateReqVO.getId(), userId); | 75 | + CartDO cart = cartMapper.selectById(updateReqVO.getId(), userId); |
| 83 | if (cart == null) { | 76 | if (cart == null) { |
| 84 | throw exception(CARD_ITEM_NOT_FOUND); | 77 | throw exception(CARD_ITEM_NOT_FOUND); |
| 85 | } | 78 | } |
| @@ -87,29 +80,35 @@ public class TradeCartServiceImpl implements TradeCartService { | @@ -87,29 +80,35 @@ public class TradeCartServiceImpl implements TradeCartService { | ||
| 87 | checkProductSku(cart.getSkuId(), updateReqVO.getCount()); | 80 | checkProductSku(cart.getSkuId(), updateReqVO.getCount()); |
| 88 | 81 | ||
| 89 | // 更新数量 | 82 | // 更新数量 |
| 90 | - cartMapper.updateById(new TradeCartDO().setId(cart.getId()) | 83 | + cartMapper.updateById(new CartDO().setId(cart.getId()) |
| 91 | .setCount(updateReqVO.getCount())); | 84 | .setCount(updateReqVO.getCount())); |
| 92 | } | 85 | } |
| 93 | 86 | ||
| 94 | @Override | 87 | @Override |
| 88 | + public void updateCartSelected(Long userId, AppCartUpdateSelectedReqVO updateSelectedReqVO) { | ||
| 89 | + cartMapper.updateByIds(updateSelectedReqVO.getIds(), userId, | ||
| 90 | + new CartDO().setSelected(updateSelectedReqVO.getSelected())); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + @Override | ||
| 95 | @Transactional(rollbackFor = Exception.class) | 94 | @Transactional(rollbackFor = Exception.class) |
| 96 | - public void resetCart(Long userId, AppTradeCartResetReqVO resetReqVO) { | 95 | + public void resetCart(Long userId, AppCartResetReqVO resetReqVO) { |
| 97 | // 第一步:删除原本的购物项 | 96 | // 第一步:删除原本的购物项 |
| 98 | - TradeCartDO oldCart = cartMapper.selectById(resetReqVO.getId(), userId); | 97 | + CartDO oldCart = cartMapper.selectById(resetReqVO.getId(), userId); |
| 99 | if (oldCart == null) { | 98 | if (oldCart == null) { |
| 100 | throw exception(CARD_ITEM_NOT_FOUND); | 99 | throw exception(CARD_ITEM_NOT_FOUND); |
| 101 | } | 100 | } |
| 102 | cartMapper.deleteById(oldCart.getId()); | 101 | cartMapper.deleteById(oldCart.getId()); |
| 103 | 102 | ||
| 104 | // 第二步:添加新的购物项 | 103 | // 第二步:添加新的购物项 |
| 105 | - TradeCartDO newCart = cartMapper.selectByUserIdAndSkuId(userId, resetReqVO.getSkuId(), | ||
| 106 | - true, false); | 104 | + // TODO 芋艿:直接改成 addCart 貌似就行 |
| 105 | + CartDO newCart = cartMapper.selectByUserIdAndSkuId(userId, resetReqVO.getSkuId()); | ||
| 107 | if (newCart != null) { | 106 | if (newCart != null) { |
| 108 | - updateCart(userId, new AppTradeCartUpdateReqVO() | 107 | + updateCartCount(userId, new AppCartUpdateCountReqVO() |
| 109 | .setId(newCart.getId()).setCount(resetReqVO.getCount())); | 108 | .setId(newCart.getId()).setCount(resetReqVO.getCount())); |
| 110 | } else { | 109 | } else { |
| 111 | - addCart(userId, new AppTradeCartAddReqVO().setAddStatus(true) | ||
| 112 | - .setSkuId(resetReqVO.getSkuId()).setCount(resetReqVO.getCount())); | 110 | + addCart(userId, new AppCartAddReqVO().setSkuId(resetReqVO.getSkuId()) |
| 111 | + .setCount(resetReqVO.getCount())); | ||
| 113 | } | 112 | } |
| 114 | } | 113 | } |
| 115 | 114 | ||
| @@ -122,7 +121,7 @@ public class TradeCartServiceImpl implements TradeCartService { | @@ -122,7 +121,7 @@ public class TradeCartServiceImpl implements TradeCartService { | ||
| 122 | @Override | 121 | @Override |
| 123 | public void deleteCart(Long userId, Collection<Long> ids) { | 122 | public void deleteCart(Long userId, Collection<Long> ids) { |
| 124 | // 查询 TradeCartDO 列表 | 123 | // 查询 TradeCartDO 列表 |
| 125 | - List<TradeCartDO> carts = cartMapper.selectListByIds(ids, userId); | 124 | + List<CartDO> carts = cartMapper.selectListByIds(ids, userId); |
| 126 | if (CollUtil.isEmpty(carts)) { | 125 | if (CollUtil.isEmpty(carts)) { |
| 127 | return; | 126 | return; |
| 128 | } | 127 | } |
| @@ -133,30 +132,33 @@ public class TradeCartServiceImpl implements TradeCartService { | @@ -133,30 +132,33 @@ public class TradeCartServiceImpl implements TradeCartService { | ||
| 133 | 132 | ||
| 134 | @Override | 133 | @Override |
| 135 | public Integer getCartCount(Long userId) { | 134 | public Integer getCartCount(Long userId) { |
| 135 | + // TODO 芋艿:需要算上 selected | ||
| 136 | return cartMapper.selectSumByUserId(userId); | 136 | return cartMapper.selectSumByUserId(userId); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | @Override | 139 | @Override |
| 140 | public Map<Long, Integer> getCartCountMap(Long userId) { | 140 | public Map<Long, Integer> getCartCountMap(Long userId) { |
| 141 | + // TODO 芋艿:需要算上 selected | ||
| 141 | return cartMapper.selectSumMapByUserId(userId); | 142 | return cartMapper.selectSumMapByUserId(userId); |
| 142 | } | 143 | } |
| 143 | 144 | ||
| 144 | @Override | 145 | @Override |
| 145 | - public AppTradeCartListRespVO getCartList(Long userId) { | ||
| 146 | - // 获得购物车的商品,只查询未下单的 | ||
| 147 | - List<TradeCartDO> carts = cartMapper.selectListByUserId(userId, true, false); | ||
| 148 | - carts.sort(Comparator.comparing(TradeCartDO::getId).reversed()); | 146 | + public AppCartListRespVO getCartList(Long userId) { |
| 147 | + // 获得购物车的商品 | ||
| 148 | + List<CartDO> carts = cartMapper.selectListByUserId(userId); | ||
| 149 | + carts.sort(Comparator.comparing(CartDO::getId).reversed()); | ||
| 149 | // 如果未空,则返回空结果 | 150 | // 如果未空,则返回空结果 |
| 150 | if (CollUtil.isEmpty(carts)) { | 151 | if (CollUtil.isEmpty(carts)) { |
| 151 | - return new AppTradeCartListRespVO().setValidList(emptyList()) | 152 | + return new AppCartListRespVO().setValidList(emptyList()) |
| 152 | .setInvalidList(emptyList()); | 153 | .setInvalidList(emptyList()); |
| 153 | } | 154 | } |
| 154 | 155 | ||
| 155 | // 查询 SPU、SKU 列表 | 156 | // 查询 SPU、SKU 列表 |
| 156 | - List<ProductSpuRespDTO> spus = productSpuApi.getSpuList(convertSet(carts, TradeCartDO::getSpuId)); | ||
| 157 | - List<ProductSkuRespDTO> skus = productSkuApi.getSkuList(convertSet(carts, TradeCartDO::getSkuId)); | 157 | + List<ProductSpuRespDTO> spus = productSpuApi.getSpuList(convertSet(carts, CartDO::getSpuId)); |
| 158 | + List<ProductSkuRespDTO> skus = productSkuApi.getSkuList(convertSet(carts, CartDO::getSkuId)); | ||
| 158 | 159 | ||
| 159 | // 如果 SPU 被删除,则删除购物车对应的商品。延迟删除 | 160 | // 如果 SPU 被删除,则删除购物车对应的商品。延迟删除 |
| 161 | + // 为什么不是 SKU 被删除呢?因为 SKU 被删除时,还可以通过 SPU 选择其它 SKU | ||
| 160 | deleteCartIfSpuDeleted(carts, spus); | 162 | deleteCartIfSpuDeleted(carts, spus); |
| 161 | 163 | ||
| 162 | // 拼接数据 | 164 | // 拼接数据 |
| @@ -164,14 +166,14 @@ public class TradeCartServiceImpl implements TradeCartService { | @@ -164,14 +166,14 @@ public class TradeCartServiceImpl implements TradeCartService { | ||
| 164 | } | 166 | } |
| 165 | 167 | ||
| 166 | @Override | 168 | @Override |
| 167 | - public List<TradeCartDO> getCartList(Long userId, Set<Long> ids) { | 169 | + public List<CartDO> getCartList(Long userId, Set<Long> ids) { |
| 168 | if (CollUtil.isEmpty(ids)) { | 170 | if (CollUtil.isEmpty(ids)) { |
| 169 | return Collections.emptyList(); | 171 | return Collections.emptyList(); |
| 170 | } | 172 | } |
| 171 | return cartMapper.selectListByUserId(userId, ids); | 173 | return cartMapper.selectListByUserId(userId, ids); |
| 172 | } | 174 | } |
| 173 | 175 | ||
| 174 | - private void deleteCartIfSpuDeleted(List<TradeCartDO> carts, List<ProductSpuRespDTO> spus) { | 176 | + private void deleteCartIfSpuDeleted(List<CartDO> carts, List<ProductSpuRespDTO> spus) { |
| 175 | // 如果 SPU 被删除,则删除购物车对应的商品。延迟删除 | 177 | // 如果 SPU 被删除,则删除购物车对应的商品。延迟删除 |
| 176 | carts.removeIf(cart -> { | 178 | carts.removeIf(cart -> { |
| 177 | if (spus.stream().noneMatch(spu -> spu.getId().equals(cart.getSpuId()))) { | 179 | if (spus.stream().noneMatch(spu -> spu.getId().equals(cart.getSpuId()))) { |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| @@ -43,7 +43,7 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettle | @@ -43,7 +43,7 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettle | ||
| 43 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; | 43 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; |
| 44 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; | 44 | import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; |
| 45 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; | 45 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; |
| 46 | -import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; | 46 | +import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; |
| 47 | import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; | 47 | import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; |
| 48 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; | 48 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; |
| 49 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; | 49 | import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; |
| @@ -53,7 +53,7 @@ import cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants; | @@ -53,7 +53,7 @@ import cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants; | ||
| 53 | import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; | 53 | import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; |
| 54 | import cn.iocoder.yudao.module.trade.enums.order.*; | 54 | import cn.iocoder.yudao.module.trade.enums.order.*; |
| 55 | import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; | 55 | import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; |
| 56 | -import cn.iocoder.yudao.module.trade.service.cart.TradeCartService; | 56 | +import cn.iocoder.yudao.module.trade.service.cart.CartService; |
| 57 | import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; | 57 | import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; |
| 58 | import cn.iocoder.yudao.module.trade.service.message.TradeMessageService; | 58 | import cn.iocoder.yudao.module.trade.service.message.TradeMessageService; |
| 59 | import cn.iocoder.yudao.module.trade.service.message.bo.TradeOrderMessageWhenDeliveryOrderReqBO; | 59 | import cn.iocoder.yudao.module.trade.service.message.bo.TradeOrderMessageWhenDeliveryOrderReqBO; |
| @@ -93,7 +93,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -93,7 +93,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 93 | private TradeOrderItemMapper tradeOrderItemMapper; | 93 | private TradeOrderItemMapper tradeOrderItemMapper; |
| 94 | 94 | ||
| 95 | @Resource | 95 | @Resource |
| 96 | - private TradeCartService tradeCartService; | 96 | + private CartService tradeCartService; |
| 97 | @Resource | 97 | @Resource |
| 98 | private TradePriceService tradePriceService; | 98 | private TradePriceService tradePriceService; |
| 99 | @Resource | 99 | @Resource |
| @@ -168,7 +168,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | @@ -168,7 +168,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { | ||
| 168 | */ | 168 | */ |
| 169 | private TradePriceCalculateRespBO calculatePrice(Long userId, AppTradeOrderSettlementReqVO settlementReqVO) { | 169 | private TradePriceCalculateRespBO calculatePrice(Long userId, AppTradeOrderSettlementReqVO settlementReqVO) { |
| 170 | // 1. 如果来自购物车,则获得购物车的商品 | 170 | // 1. 如果来自购物车,则获得购物车的商品 |
| 171 | - List<TradeCartDO> cartList = tradeCartService.getCartList(userId, | 171 | + List<CartDO> cartList = tradeCartService.getCartList(userId, |
| 172 | convertSet(settlementReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCartId)); | 172 | convertSet(settlementReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCartId)); |
| 173 | 173 | ||
| 174 | // 2. 计算价格 | 174 | // 2. 计算价格 |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java
| @@ -168,7 +168,7 @@ public class MemberUserServiceImpl implements MemberUserService { | @@ -168,7 +168,7 @@ public class MemberUserServiceImpl implements MemberUserService { | ||
| 168 | 168 | ||
| 169 | @Override | 169 | @Override |
| 170 | public boolean isPasswordMatch(String rawPassword, String encodedPassword) { | 170 | public boolean isPasswordMatch(String rawPassword, String encodedPassword) { |
| 171 | - if (true) { | 171 | + if(true) { |
| 172 | return true; | 172 | return true; |
| 173 | } | 173 | } |
| 174 | return passwordEncoder.matches(rawPassword, encodedPassword); | 174 | return passwordEncoder.matches(rawPassword, encodedPassword); |