diff --git a/mobile-web/src/api/order.js b/mobile-web/src/api/order.js index 1658558ee..0663873e6 100644 --- a/mobile-web/src/api/order.js +++ b/mobile-web/src/api/order.js @@ -45,3 +45,24 @@ export function createOrder(params) { }); } +// Cart + +export function addCart(skuId, quantity) { + return request({ + url: '/order-api/users/cart/add', + method: 'post', + params: { + skuId, + quantity, + } + }); +} + +export function countCart() { + return request({ + url: '/order-api/users/cart/count', + method: 'get', + params: { + } + }); +} diff --git a/mobile-web/src/components/common/productcard.vue b/mobile-web/src/components/common/productcard.vue index 51692d9d7..c5be62b2a 100644 --- a/mobile-web/src/components/common/productcard.vue +++ b/mobile-web/src/components/common/productcard.vue @@ -8,8 +8,7 @@ style="background:#fff" > diff --git a/mobile-web/src/config/request.js b/mobile-web/src/config/request.js index 6bdbe764f..becd9ca02 100644 --- a/mobile-web/src/config/request.js +++ b/mobile-web/src/config/request.js @@ -208,6 +208,7 @@ service.interceptors.response.use( // this.$router.push({ path: '/login' }) // TODO 跳转到登陆页.不是很优雅 location.replace('/#login'); + location.reload(); } } }); diff --git a/mobile-web/src/config/router.js b/mobile-web/src/config/router.js index 7c9960599..759f7183b 100644 --- a/mobile-web/src/config/router.js +++ b/mobile-web/src/config/router.js @@ -58,7 +58,8 @@ const routes = [ component: () => import('../page/user/info/detail'), name: 'user', meta: { - title: '个人信息' + title: '个人信息', + requireAuth: true, } }, { @@ -178,7 +179,8 @@ const routes = [ path: '/order', component: () => import('../page/shipping/order'), meta: { - title: '确认订单' + title: '确认订单', + requireAuth: true, } }, { diff --git a/mobile-web/src/page/cart/index.vue b/mobile-web/src/page/cart/index.vue index d846f423d..3f25a72cb 100644 --- a/mobile-web/src/page/cart/index.vue +++ b/mobile-web/src/page/cart/index.vue @@ -6,74 +6,36 @@ 全选 - + - +
-
+
- - + + + + + + + + +
-
- -
- - - - - - -
- - - - -
- - - -
- - - - - -
-
+ + + + + + + + + - +
\ No newline at end of file + + diff --git a/mobile-web/src/page/product/detail.vue b/mobile-web/src/page/product/detail.vue index fd858bab5..adda364b3 100644 --- a/mobile-web/src/page/product/detail.vue +++ b/mobile-web/src/page/product/detail.vue @@ -74,7 +74,7 @@ 收藏 - + 购物车 @@ -167,6 +167,8 @@ diff --git a/mobile-web/src/page/shipping/order.vue b/mobile-web/src/page/shipping/order.vue index 25c8a83d6..c12ffbe1d 100644 --- a/mobile-web/src/page/shipping/order.vue +++ b/mobile-web/src/page/shipping/order.vue @@ -16,12 +16,22 @@
{{addressData.address}}
-
+
-
- + + + + + +
+
+ +
+
+ +
add(@Param("skuId") Integer skuId, + @Param("quantity") Integer quantity) { + // 添加到购物车 + CommonResult addResult = cartService.add(UserSecurityContextHolder.getContext().getUserId(), + skuId, quantity); + // 添加失败,则直接返回错误 + if (addResult.isError()) { + return CommonResult.error(addResult); + } + // 获得目前购物车商品总数量 + return cartService.count(UserSecurityContextHolder.getContext().getUserId()); + } + + @PostMapping("update_quantity") + public CommonResult updateQuantity(@Param("skuId") Integer skuId, + @Param("quantity") Integer quantity) { + // 添加到购物车 + CommonResult updateQuantityResult = cartService.updateQuantity(UserSecurityContextHolder.getContext().getUserId(), + skuId, quantity); + // 添加失败,则直接返回错误 + if (updateQuantityResult.isError()) { + return CommonResult.error(updateQuantityResult); + } + // 获得目前购物车商品总数量 + // TODO 芋艿,需要改成价格计算 + return cartService.count(UserSecurityContextHolder.getContext().getUserId()); + } + + @PostMapping("update_selected") + public CommonResult updateSelected(@Param("skuId") Integer skuId, + @Param("selected") Boolean selected) { + // 添加到购物车 + CommonResult updateSelectedResult = cartService.updateSelected(UserSecurityContextHolder.getContext().getUserId(), + skuId, selected); + // 添加失败,则直接返回错误 + if (updateSelectedResult.isError()) { + return CommonResult.error(updateSelectedResult); + } + // 获得目前购物车商品总数量 + // TODO 芋艿,需要改成价格计算 + return cartService.count(UserSecurityContextHolder.getContext().getUserId()); + } + + @GetMapping("count") + public CommonResult count() { + return cartService.count(UserSecurityContextHolder.getContext().getUserId()); + } + + @GetMapping("/list") + public CommonResult list() { + // 获得购物车中所有的 + List cartItems = cartService.list(UserSecurityContextHolder.getContext().getUserId(), null); + // 购物车为空时,构造空的 UsersOrderConfirmCreateVO 返回 + if (cartItems.isEmpty()) { + UsersOrderConfirmCreateVO result = new UsersOrderConfirmCreateVO(); + result.setItemGroups(Collections.emptyList()); + result.setFee(new UsersOrderConfirmCreateVO.Fee(0, 0, 0, 0)); + return CommonResult.success(result); + } + // 购物车非空时,获得具体结果 + + return null; + } + + @GetMapping("/confirm_create_order") + public CommonResult getConfirmCreateOrder() { + // 获得购物车中选中的 + List cartItems = cartService.list(UserSecurityContextHolder.getContext().getUserId(), true); + // 购物车为空时,构造空的 UsersOrderConfirmCreateVO 返回 + if (cartItems.isEmpty()) { + UsersOrderConfirmCreateVO result = new UsersOrderConfirmCreateVO(); + result.setItemGroups(Collections.emptyList()); + result.setFee(new UsersOrderConfirmCreateVO.Fee(0, 0, 0, 0)); + return CommonResult.success(result); + } + // 购物车非空时,获得具体结果 +// return CommonResult.success(CartConvert.INSTANCE.convert(calcOrderPriceResult.getData())); + return null; + } + public CommonResult confirmOrder() { // 查询购物车列表(选中的) // cartService.list(userId, true); diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/vo/UsersOrderConfirmCreateVO.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/vo/UsersOrderConfirmCreateVO.java index bf847feef..a735cec4f 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/vo/UsersOrderConfirmCreateVO.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/vo/UsersOrderConfirmCreateVO.java @@ -133,6 +133,15 @@ public class UsersOrderConfirmCreateVO { */ private Integer presentTotal; + public Fee() { + } + + public Fee(Integer originalTotal, Integer discountTotal, Integer postageTotal, Integer presentTotal) { + this.originalTotal = originalTotal; + this.discountTotal = discountTotal; + this.postageTotal = postageTotal; + this.presentTotal = presentTotal; + } } /** diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/CartService.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/CartService.java index bb7222510..0a09bd899 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/CartService.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/CartService.java @@ -39,9 +39,10 @@ public interface CartService { * * @param userId 用户编号 * @param skuId 商品 SKU 编号 + * @param selected 是否选中 * @return 是否成功 */ - CommonResult updateSelected(Integer userId, Integer skuId); + CommonResult updateSelected(Integer userId, Integer skuId, Boolean selected); /** * 购物车删除商品 @@ -67,7 +68,7 @@ public interface CartService { * @param userId 用户编号 * @return 商品数量 */ - CommonResult count(Integer userId, String nobody, Integer shopId); + CommonResult count(Integer userId); /** * 显示买家购物车中的商品列表,并根据 selected 进行过滤。 diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/CartItemStatusEnum.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/CartItemStatusEnum.java new file mode 100644 index 000000000..cc9a96dd5 --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/CartItemStatusEnum.java @@ -0,0 +1,46 @@ +package cn.iocoder.mall.order.api.constant; + +import java.util.Arrays; + +public enum CartItemStatusEnum { + + ENABLE(1, "正常"), + DELETE_BY_MANUAL(2, "主动删除"), + DELETE_BY_(3, "下单删除"), + ; + + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CartItemStatusEnum::getValue).toArray(); + + /** + * 状态值 + */ + private Integer value; + /** + * 状态名 + */ + private String name; + + CartItemStatusEnum(Integer value, String name) { + this.value = value; + this.name = name; + } + + public Integer getValue() { + return value; + } + + public CartItemStatusEnum setValue(Integer value) { + this.value = value; + return this; + } + + public String getName() { + return name; + } + + public CartItemStatusEnum setName(String name) { + this.name = name; + return this; + } + +} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java index cc42d1c99..00bb00fe8 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderErrorCodeEnum.java @@ -27,6 +27,12 @@ public enum OrderErrorCodeEnum { ORDER_ITEM_ONLY_ONE(1008000004, "订单Item只有一个!"), ORDER_ITEM_SOME_NOT_EXISTS(-1, "有不存在的商品"), // TODO 芋艿 后面改下错误码 + + // ========== 购物车 ========== + CARD_ITEM_NOT_FOUND(1008003000, "购物车项不存在"), + CARD_ITEM_SKU_NOT_FOUND(1008003001, "商品不存在"), + CARD_ITEM_SKU_QUANTITY_NOT_ENOUGH(1008003002, "商品库存不足"), + ; private final int code; diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/CartMapper.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/CartMapper.java new file mode 100644 index 000000000..fe73b4f54 --- /dev/null +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/CartMapper.java @@ -0,0 +1,39 @@ +package cn.iocoder.mall.order.biz.dao; + +import cn.iocoder.mall.order.biz.dataobject.CartItemDO; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.Collection; +import java.util.List; + +@Repository +public interface CartMapper { + + CartItemDO selectById(@Param("id") Integer id); + + List selectByIds(@Param("ids") Collection ids); + + CartItemDO selectByUserIdAndSkuIdAndStatus(@Param("userId") Integer userId, + @Param("skuId") Integer skuId, + @Param("status") Integer status); + + Integer selectQuantitySumByUserIdAndStatus(@Param("userId") Integer userId, + @Param("status") Integer status); + +// List selectListByStatus(@Param("status") Integer status); +// +// List selectListByTitleLike(@Param("title") String title, +// @Param("offset") Integer offset, +// @Param("limit") Integer limit); + +// Integer selectCountByTitleLike(@Param("title") String title); + + void insert(CartItemDO cartItemDO); + + int update(CartItemDO cartItemDO); + + int updateQuantity(@Param("id") Integer id, + @Param("quantityIncr") Integer quantityIncr); + +} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderCancelMapper.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderCancelMapper.java index 31a89df90..66563e679 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderCancelMapper.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderCancelMapper.java @@ -13,4 +13,5 @@ import org.springframework.stereotype.Repository; public interface OrderCancelMapper { int insert(OrderCancelDO orderCancelDO); + } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/CartItemDO.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/CartItemDO.java index 9f164a553..122caccf6 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/CartItemDO.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/CartItemDO.java @@ -76,7 +76,7 @@ public class CartItemDO extends BaseDO { /** * 订单编号 */ - private String orderId; + private Integer orderId; /** * 订单创建时间 */ diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/mock/ProductSpuServiceMock.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/mock/ProductSpuServiceMock.java deleted file mode 100644 index 280ca5a36..000000000 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/mock/ProductSpuServiceMock.java +++ /dev/null @@ -1,57 +0,0 @@ -package cn.iocoder.mall.order.biz.mock; - -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.product.api.ProductSpuService; -import cn.iocoder.mall.product.api.bo.ProductSkuDetailBO; -import cn.iocoder.mall.product.api.bo.ProductSpuBO; -import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO; -import cn.iocoder.mall.product.api.bo.ProductSpuPageBO; -import cn.iocoder.mall.product.api.dto.ProductSpuAddDTO; -import cn.iocoder.mall.product.api.dto.ProductSpuPageDTO; -import cn.iocoder.mall.product.api.dto.ProductSpuUpdateDTO; - -import java.util.Collection; -import java.util.List; - -/** - * @author Sin - * @time 2019-03-24 15:24 - */ -public class ProductSpuServiceMock implements ProductSpuService { - - @Override - public CommonResult getProductSpuDetail(Integer id) { - return null; - } - - @Override - public CommonResult addProductSpu(Integer adminId, ProductSpuAddDTO productSpuAddDTO) { - return null; - } - - @Override - public CommonResult updateProductSpu(Integer adminId, ProductSpuUpdateDTO productSpuUpdateDTO) { - return null; - } - - @Override - public CommonResult updateProductSpuSort(Integer adminId, Integer spuId, Integer sort) { - return null; - } - - @Override - public CommonResult getProductSpuPage(ProductSpuPageDTO productSpuPageDTO) { - return null; - } - - @Override - public CommonResult> getProductSpuList(Collection ids) { - return null; - } - - @Override - public CommonResult> getProductSkuDetailList(Collection ids) { - return null; - } - -} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java index 67f45dfd8..da3e6cb1b 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/CartServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.mall.order.biz.service; +import cn.iocoder.common.framework.constant.CommonStatusEnum; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.order.api.CartService; @@ -7,12 +8,17 @@ import cn.iocoder.mall.order.api.bo.CalcOrderPriceBO; import cn.iocoder.mall.order.api.bo.CartBO; import cn.iocoder.mall.order.api.bo.CartItemBO; import cn.iocoder.mall.order.api.bo.OrderCreateBO; +import cn.iocoder.mall.order.api.constant.CartItemStatusEnum; import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum; import cn.iocoder.mall.order.api.dto.CalcOrderPriceDTO; import cn.iocoder.mall.order.biz.convert.CartConvert; +import cn.iocoder.mall.order.biz.dao.CartMapper; +import cn.iocoder.mall.order.biz.dataobject.CartItemDO; import cn.iocoder.mall.product.api.ProductSpuService; +import cn.iocoder.mall.product.api.bo.ProductSkuBO; import cn.iocoder.mall.product.api.bo.ProductSkuDetailBO; import com.alibaba.dubbo.config.annotation.Reference; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.*; @@ -28,19 +34,97 @@ public class CartServiceImpl implements CartService { @Reference(validation = "true") private ProductSpuService productSpuService; + @Autowired + private CartMapper cartMapper; + @Override + @SuppressWarnings("Duplicates") public CommonResult add(Integer userId, Integer skuId, Integer quantity) { - return null; + // 查询 SKU 是否合法 + CommonResult skuResult = productSpuService.getProductSku(skuId); + if (skuResult.isError()) { + return CommonResult.error(skuResult); + } + ProductSkuBO sku = skuResult.getData(); + if (sku == null + || CommonStatusEnum.DISABLE.getValue().equals(sku.getStatus())) { // sku 被禁用 + return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); + } + // TODO 芋艿,后续基于商品是否上下架进一步完善。 + // 查询 CartItemDO + CartItemDO item = cartMapper.selectByUserIdAndSkuIdAndStatus(userId, skuId, CartItemStatusEnum.ENABLE.getValue()); + // 存在,则进行数量更新 + if (item != null) { + return updateQuantity0(item, sku, quantity); + } + // 不存在,则进行插入 + return add0(userId, sku, quantity); + } + + private CommonResult add0(Integer userId, ProductSkuBO sku, Integer quantity) { + // 校验库存 + if (quantity > sku.getQuantity()) { + return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); + } + // 创建 CartItemDO 对象,并进行保存。 + CartItemDO item = new CartItemDO() + // 基础字段 + .setStatus(CartItemStatusEnum.ENABLE.getValue()).setSelected(true) + // 买家信息 + .setUserId(userId) + // 商品信息 + .setSpuId(sku.getSpuId()).setSkuId(sku.getId()).setQuantity(quantity); + item.setCreateTime(new Date()); + cartMapper.insert(item); + // 返回成功 + return CommonResult.success(true); } @Override + @SuppressWarnings("Duplicates") public CommonResult updateQuantity(Integer userId, Integer skuId, Integer quantity) { - return null; + // 查询 SKU 是否合法 + CommonResult skuResult = productSpuService.getProductSku(skuId); + if (skuResult.isError()) { + return CommonResult.error(skuResult); + } + ProductSkuBO sku = skuResult.getData(); + if (sku == null + || CommonStatusEnum.DISABLE.getValue().equals(sku.getStatus())) { // sku 被禁用 + return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); + } + // 查询 CartItemDO + CartItemDO item = cartMapper.selectByUserIdAndSkuIdAndStatus(userId, skuId, CartItemStatusEnum.ENABLE.getValue()); + if (item == null) { + return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_NOT_FOUND.getCode()); + } + // TODO 芋艿,后续基于商品是否上下架进一步完善。 + return updateQuantity0(item, sku, quantity); + } + + private CommonResult updateQuantity0(CartItemDO item, ProductSkuBO sku, Integer quantity) { + // 校验库存 + if (item.getQuantity() + quantity > sku.getQuantity()) { + return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); + } + // 更新 CartItemDO + cartMapper.updateQuantity(item.getId(), quantity); + // 返回成功 + return CommonResult.success(true); } @Override - public CommonResult updateSelected(Integer userId, Integer skuId) { - return null; + public CommonResult updateSelected(Integer userId, Integer skuId, Boolean selected) { + // 查询 CartItemDO + CartItemDO item = cartMapper.selectByUserIdAndSkuIdAndStatus(userId, skuId, CartItemStatusEnum.ENABLE.getValue()); + if (item == null) { + return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_NOT_FOUND.getCode()); + } + // 更新 CartItemDO + CartItemDO updateCartItem = new CartItemDO().setId(item.getId()).setSelected(selected); + cartMapper.update(updateCartItem); + // 返回成功 + return CommonResult.success(true); } @Override @@ -54,8 +138,8 @@ public class CartServiceImpl implements CartService { } @Override - public CommonResult count(Integer userId, String nobody, Integer shopId) { - return null; + public CommonResult count(Integer userId) { + return CommonResult.success(cartMapper.selectQuantitySumByUserIdAndStatus(userId, CartItemStatusEnum.ENABLE.getValue())); } @Override diff --git a/order/order-service-impl/src/main/resources/mapper/CartMapper.xml b/order/order-service-impl/src/main/resources/mapper/CartMapper.xml new file mode 100644 index 000000000..bcad82e5a --- /dev/null +++ b/order/order-service-impl/src/main/resources/mapper/CartMapper.xml @@ -0,0 +1,99 @@ + + + + + + id, status, delete_time, selected, user_id, + spu_id, sku_id, quantity, order_id, order_create_time, + create_time + + + + + + + + + + + + INSERT INTO cart_item ( + status, delete_time, selected, user_id, + spu_id, sku_id, quantity, order_id, order_create_time, + create_time + ) VALUES ( + #{status}, #{deleteTime}, #{selected}, #{userId}, + #{spuId}, #{skuId}, #{quantity}, #{orderId}, #{orderCreateTime}, + #{createTime} + ) + + + + UPDATE cart_item + + + status = #{status}, + + + delete_time = #{deleteTime}, + + + selected = #{selected}, + + + quantity = #{quantity}, + + + order_id = #{orderId}, + + + order_create_time = #{orderCreateTime}, + + + price = #{price}, + + + quantity = #{quantity}, + + + WHERE id = #{id} + + + + UPDATE cart_item + SET quantity = quantity + #{quantityIncr} + WHERE id = #{id} + + + diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductSpuService.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductSpuService.java index 5f431d9db..30b4a70ff 100644 --- a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductSpuService.java +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/ProductSpuService.java @@ -17,6 +17,8 @@ public interface ProductSpuService { CommonResult> getProductSpuList(Collection ids); + CommonResult getProductSku(Integer id); + CommonResult> getProductSkuDetailList(Collection ids); CommonResult addProductSpu(Integer adminId, ProductSpuAddDTO productSpuAddDTO); diff --git a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductSkuBO.java b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductSkuBO.java index e26e85d44..6114be470 100644 --- a/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductSkuBO.java +++ b/product/product-service-api/src/main/java/cn/iocoder/mall/product/api/bo/ProductSkuBO.java @@ -6,15 +6,40 @@ import lombok.experimental.Accessors; import java.io.Serializable; /** - * 商品 SKU BOA + * 商品 SKU BO */ @Data @Accessors(chain = true) public class ProductSkuBO implements Serializable { /** - * SKU 编号 + * sku 编号 */ private Integer id; + /** + * 商品编号 + */ + private Integer spuId; + /** + * 状态 + */ + private Integer status; + /** + * 图片地址 + */ + private String picURL; +// /** +// * 规格值数组 +// */ +// // TODO 芋艿,这个属性目前未进行设置 +// private List attrs; + /** + * 价格,单位:分 + */ + private Integer price; + /** + * 库存数量 + */ + private Integer quantity; } diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductSpuConvert.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductSpuConvert.java index f2d8cc094..a869fd877 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductSpuConvert.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/convert/ProductSpuConvert.java @@ -1,10 +1,7 @@ package cn.iocoder.mall.product.convert; import cn.iocoder.common.framework.util.StringUtil; -import cn.iocoder.mall.product.api.bo.ProductAttrAndValuePairBO; -import cn.iocoder.mall.product.api.bo.ProductSkuDetailBO; -import cn.iocoder.mall.product.api.bo.ProductSpuBO; -import cn.iocoder.mall.product.api.bo.ProductSpuDetailBO; +import cn.iocoder.mall.product.api.bo.*; import cn.iocoder.mall.product.api.dto.ProductSkuAddOrUpdateDTO; import cn.iocoder.mall.product.api.dto.ProductSpuAddDTO; import cn.iocoder.mall.product.api.dto.ProductSpuUpdateDTO; @@ -73,6 +70,11 @@ public interface ProductSpuConvert { }) ProductSkuDetailBO convert3(ProductSkuDO sku); + @Mappings({ +// @Mapping(source = "attrs", target = "attrs", ignore = true) // TODO 芋艿 后续补充 + }) + ProductSkuBO convert4(ProductSkuDO sku); + @Mappings({}) // TODO 芋艿,后续细看下 mapstruct 的 API ,优化这块 default ProductSpuDetailBO convert2(ProductSpuDO spu, List skus, List productAttrDetailBOs) { // 创建并转换 ProductSpuDetailBO 对象 diff --git a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductSpuServiceImpl.java b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductSpuServiceImpl.java index 1a25c186c..c785fd09a 100644 --- a/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductSpuServiceImpl.java +++ b/product/product-service-impl/src/main/java/cn/iocoder/mall/product/service/ProductSpuServiceImpl.java @@ -213,6 +213,12 @@ public class ProductSpuServiceImpl implements ProductSpuService { return CommonResult.success(ProductSpuConvert.INSTANCE.convert(spus)); } + @Override + public CommonResult getProductSku(Integer id) { + ProductSkuDO sku = productSkuMapper.selectById(id); + return CommonResult.success(ProductSpuConvert.INSTANCE.convert4(sku)); + } + @Override public CommonResult> getProductSkuDetailList(Collection ids) { // 查询 SKU 数组