From 3220e8db7867b3478fef135c10b030d6f7033730 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 8 May 2019 19:33:06 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=90=8E=E7=AB=AF=EF=BC=9AOrder=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=EF=BC=8C=E8=A7=A3=E5=86=B3=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/users/OrderController.java | 14 +--- .../controller/users/UsersCartController.java | 62 +++++---------- .../iocoder/mall/order/api/CartService.java | 23 +++--- .../order/biz/service/CartServiceImpl.java | 76 +++++++++---------- .../biz/service/OrderReturnServiceImpl.java | 2 +- .../order/biz/service/OrderServiceImpl.java | 18 +---- 6 files changed, 74 insertions(+), 121 deletions(-) diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderController.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderController.java index 3b3bff303..08e83a2a2 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderController.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderController.java @@ -13,17 +13,14 @@ import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum; import cn.iocoder.mall.order.api.dto.CalcOrderPriceDTO; import cn.iocoder.mall.order.api.dto.OrderCreateDTO; import cn.iocoder.mall.order.api.dto.OrderQueryDTO; -import cn.iocoder.mall.order.api.dto.OrderReturnApplyDTO; import cn.iocoder.mall.order.application.convert.CartConvert; import cn.iocoder.mall.order.application.convert.OrderConvertAPP; -import cn.iocoder.mall.order.application.convert.OrderReturnConvert; import cn.iocoder.mall.order.application.po.user.OrderCreatePO; -import cn.iocoder.mall.order.application.po.user.OrderReturnApplyPO; import cn.iocoder.mall.order.application.vo.UsersOrderConfirmCreateVO; import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder; -import org.apache.dubbo.config.annotation.Reference; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.dubbo.config.annotation.Reference; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -76,7 +73,7 @@ public class OrderController { HttpServletRequest request) { Integer userId = UserSecurityContextHolder.getContext().getUserId(); // 获得购物车中选中的商品 - List cartItems = cartService.list(userId, true).getData(); + List cartItems = cartService.list(userId, true); if (cartItems.isEmpty()) { return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_CREATE_CART_IS_EMPTY.getCode()); } @@ -105,12 +102,9 @@ public class OrderController { .setUserId(UserSecurityContextHolder.getContext().getUserId()) .setItems(Collections.singletonList(new CalcOrderPriceDTO.Item(skuId, quantity, true))) .setCouponCardId(couponCardId); - CommonResult calcOrderPriceResult = cartService.calcOrderPrice(calcOrderPriceDTO); - if (calcOrderPriceResult.isError()) { - return CommonResult.error(calcOrderPriceResult); - } + CalcOrderPriceBO calcOrderPrice = cartService.calcOrderPrice(calcOrderPriceDTO); // 执行数据拼装 - return CommonResult.success(CartConvert.INSTANCE.convert(calcOrderPriceResult.getData())); + return CommonResult.success(CartConvert.INSTANCE.convert(calcOrderPrice)); } @PostMapping("confirm_receiving") diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersCartController.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersCartController.java index 46d3ca5c5..059923790 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersCartController.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersCartController.java @@ -23,6 +23,8 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import static cn.iocoder.common.framework.vo.CommonResult.success; + @RestController @RequestMapping("users/cart") public class UsersCartController { @@ -38,26 +40,17 @@ public class UsersCartController { public CommonResult add(@RequestParam("skuId") Integer skuId, @RequestParam("quantity") Integer quantity) { // 添加到购物车 - CommonResult addResult = cartService.add(UserSecurityContextHolder.getContext().getUserId(), - skuId, quantity); - // 添加失败,则直接返回错误 - if (addResult.isError()) { - return CommonResult.error(addResult); - } + cartService.add(UserSecurityContextHolder.getContext().getUserId(), skuId, quantity); // 获得目前购物车商品总数量 - return cartService.count(UserSecurityContextHolder.getContext().getUserId()); + return success(cartService.count(UserSecurityContextHolder.getContext().getUserId())); } @PostMapping("update_quantity") public CommonResult updateQuantity(@RequestParam("skuId") Integer skuId, // TODO 芋艿,先暂用这个 VO 。等促销活动出来后,做调整 @RequestParam("quantity") Integer quantity) { // 添加到购物车 - CommonResult updateQuantityResult = cartService.updateQuantity(UserSecurityContextHolder.getContext().getUserId(), + cartService.updateQuantity(UserSecurityContextHolder.getContext().getUserId(), skuId, quantity); - // 添加失败,则直接返回错误 - if (updateQuantityResult.isError()) { - return CommonResult.error(updateQuantityResult); - } // 获得目前购物车明细 return getCartDetail(); } @@ -66,19 +59,14 @@ public class UsersCartController { public CommonResult updateSelected(@RequestParam("skuIds") Set skuIds, // TODO 芋艿,先暂用这个 VO 。等促销活动出来后,做调整 @RequestParam("selected") Boolean selected) { // 添加到购物车 - CommonResult updateSelectedResult = cartService.updateSelected(UserSecurityContextHolder.getContext().getUserId(), - skuIds, selected); - // 添加失败,则直接返回错误 - if (updateSelectedResult.isError()) { - return CommonResult.error(updateSelectedResult); - } + cartService.updateSelected(UserSecurityContextHolder.getContext().getUserId(), skuIds, selected); // 获得目前购物车明细 return getCartDetail(); } @GetMapping("count") public CommonResult count() { - return cartService.count(UserSecurityContextHolder.getContext().getUserId()); + return success(cartService.count(UserSecurityContextHolder.getContext().getUserId())); } @GetMapping("/list") @@ -88,50 +76,42 @@ public class UsersCartController { private CommonResult getCartDetail() { // 获得购物车中选中的 - List cartItems = cartService.list(UserSecurityContextHolder.getContext().getUserId(), null).getData(); + List cartItems = cartService.list(UserSecurityContextHolder.getContext().getUserId(), null); // 购物车为空时,构造空的 UsersOrderConfirmCreateVO 返回 if (cartItems.isEmpty()) { UsersCartDetailVO result = new UsersCartDetailVO(); result.setItemGroups(Collections.emptyList()); result.setFee(new UsersCartDetailVO.Fee(0, 0, 0, 0)); - return CommonResult.success(result); + return success(result); } // 计算商品价格 - CommonResult calcOrderPriceResult = list0(cartItems, null); - if (calcOrderPriceResult.isError()) { - return CommonResult.error(calcOrderPriceResult); - } + CalcOrderPriceBO calcOrder = list0(cartItems, null); // 执行数据拼装 - return CommonResult.success(CartConvert.INSTANCE.convert2(calcOrderPriceResult.getData())); + return success(CartConvert.INSTANCE.convert2(calcOrder)); } @GetMapping("/confirm_create_order") public CommonResult getConfirmCreateOrder(@RequestParam(value = "couponCardId", required = false) Integer couponCardId) { Integer userId = UserSecurityContextHolder.getContext().getUserId(); // 获得购物车中选中的 - List cartItems = cartService.list(userId, true).getData(); + List cartItems = cartService.list(userId, 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 success(result); } // 计算商品价格 - CommonResult calcOrderPriceResult = list0(cartItems, couponCardId); - if (calcOrderPriceResult.isError()) { - return CommonResult.error(calcOrderPriceResult); - } + CalcOrderPriceBO calcOrderPrice = list0(cartItems, couponCardId); // 获得优惠劵 - CalcOrderPriceBO calcOrderPrice = calcOrderPriceResult.getData(); List couponCards = couponService.getCouponCardList(userId, - CartConvert.INSTANCE.convertList(calcOrderPrice.getItemGroups())).getData(); + CartConvert.INSTANCE.convertList(calcOrderPrice.getItemGroups())); // 执行数据拼装 - return CommonResult.success(CartConvert.INSTANCE.convert(calcOrderPrice) - .setCouponCards(couponCards)); + return success(CartConvert.INSTANCE.convert(calcOrderPrice).setCouponCards(couponCards)); } - private CommonResult list0(List cartItems, Integer couponCardId) { + private CalcOrderPriceBO list0(List cartItems, Integer couponCardId) { // 创建计算的 DTO CalcOrderPriceDTO calcOrderPriceDTO = new CalcOrderPriceDTO() .setUserId(UserSecurityContextHolder.getContext().getUserId()) @@ -148,12 +128,8 @@ public class UsersCartController { @PermitAll public CommonResult calcSkuPrice(@RequestParam("skuId") Integer skuId) { // 计算 sku 的价格 - CommonResult calcSkuPriceResult = cartService.calcSkuPrice(skuId); - // 返回结果 - if (calcSkuPriceResult.isError()) { - return CommonResult.error(calcSkuPriceResult); - } - return CommonResult.success(CartConvert.INSTANCE.convert2(calcSkuPriceResult.getData())); + CalcSkuPriceBO calcSkuPrice = cartService.calcSkuPrice(skuId); + return success(CartConvert.INSTANCE.convert2(calcSkuPrice)); } public CommonResult confirmOrder() { 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 aed88c4ee..6a07d63cd 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 @@ -1,7 +1,8 @@ package cn.iocoder.mall.order.api; -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.mall.order.api.bo.*; +import cn.iocoder.mall.order.api.bo.CalcOrderPriceBO; +import cn.iocoder.mall.order.api.bo.CalcSkuPriceBO; +import cn.iocoder.mall.order.api.bo.CartItemBO; import cn.iocoder.mall.order.api.dto.CalcOrderPriceDTO; import org.springframework.lang.Nullable; @@ -20,7 +21,7 @@ public interface CartService { * @param quantity 数量 * @return 是否成功 */ - CommonResult add(Integer userId, Integer skuId, Integer quantity); + Boolean add(Integer userId, Integer skuId, Integer quantity); /** * 购物车更新商品数量 @@ -30,7 +31,7 @@ public interface CartService { * @param quantity 数量 * @return 是否成功 */ - CommonResult updateQuantity(Integer userId, Integer skuId, Integer quantity); + Boolean updateQuantity(Integer userId, Integer skuId, Integer quantity); /** * 购物车更新商品是否选中 @@ -40,7 +41,7 @@ public interface CartService { * @param selected 是否选中 * @return 是否成功 */ - CommonResult updateSelected(Integer userId, Collection skuIds, Boolean selected); + Boolean updateSelected(Integer userId, Collection skuIds, Boolean selected); /** * 购物车删除商品 @@ -50,7 +51,7 @@ public interface CartService { * * @return 是否成功 */ - CommonResult deleteList(Integer userId, List skuIds); + Boolean deleteList(Integer userId, List skuIds); /** * 清空购物车 @@ -58,7 +59,7 @@ public interface CartService { * @param userId 用户编号 * @return 是否成功 */ - CommonResult deleteAll(Integer userId); + Boolean deleteAll(Integer userId); /** * 查询用户在购物车中的商品数量 @@ -66,7 +67,7 @@ public interface CartService { * @param userId 用户编号 * @return 商品数量 */ - CommonResult count(Integer userId); + Integer count(Integer userId); /** * 显示买家购物车中的商品列表,并根据 selected 进行过滤。 @@ -75,7 +76,7 @@ public interface CartService { * @param selected 是否选中。若为空,则不进行筛选 * @return 购物车中商品列表信息 */ - CommonResult> list(Integer userId, @Nullable Boolean selected); + List list(Integer userId, @Nullable Boolean selected); // ========== 购物车与订单相关的逻辑 ========== @@ -85,7 +86,7 @@ public interface CartService { * @param calcOrderPriceDTO 计算订单金额 DTO * @return 计算订单金额结果 */ - CommonResult calcOrderPrice(CalcOrderPriceDTO calcOrderPriceDTO); + CalcOrderPriceBO calcOrderPrice(CalcOrderPriceDTO calcOrderPriceDTO); /** * 计算指定商品 SKU 的金额,并返回计算结果 @@ -95,6 +96,6 @@ public interface CartService { * @param skuId 商品 SKU 编号 * @return 计算订单金额结果 */ - CommonResult calcSkuPrice(Integer skuId); + CalcSkuPriceBO calcSkuPrice(Integer skuId); } 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 51203a125..7f354f7bf 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 @@ -2,7 +2,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; import cn.iocoder.mall.order.api.bo.CalcOrderPriceBO; import cn.iocoder.mall.order.api.bo.CalcSkuPriceBO; @@ -48,12 +47,12 @@ public class CartServiceImpl implements CartService { @Override @SuppressWarnings("Duplicates") - public CommonResult add(Integer userId, Integer skuId, Integer quantity) { + public Boolean add(Integer userId, Integer skuId, Integer quantity) { // 查询 SKU 是否合法 ProductSkuBO sku = productSpuService.getProductSku(skuId); if (sku == null || CommonStatusEnum.DISABLE.getValue().equals(sku.getStatus())) { // sku 被禁用 - return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); + throw ServiceExceptionUtil.exception(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); } // TODO 芋艿,后续基于商品是否上下架进一步完善。 // 查询 CartItemDO @@ -66,10 +65,10 @@ public class CartServiceImpl implements CartService { return add0(userId, sku, quantity); } - private CommonResult add0(Integer userId, ProductSkuBO sku, Integer quantity) { + private Boolean add0(Integer userId, ProductSkuBO sku, Integer quantity) { // 校验库存 if (quantity > sku.getQuantity()) { - return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); + throw ServiceExceptionUtil.exception(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); } // 创建 CartItemDO 对象,并进行保存。 CartItemDO item = new CartItemDO() @@ -82,79 +81,79 @@ public class CartServiceImpl implements CartService { item.setCreateTime(new Date()); cartMapper.insert(item); // 返回成功 - return CommonResult.success(true); + return true; } @Override @SuppressWarnings("Duplicates") - public CommonResult updateQuantity(Integer userId, Integer skuId, Integer quantity) { + public Boolean updateQuantity(Integer userId, Integer skuId, Integer quantity) { // 查询 SKU 是否合法 ProductSkuBO sku = productSpuService.getProductSku(skuId); if (sku == null || CommonStatusEnum.DISABLE.getValue().equals(sku.getStatus())) { // sku 被禁用 - return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); + throw ServiceExceptionUtil.exception(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()); + throw ServiceExceptionUtil.exception(OrderErrorCodeEnum.CARD_ITEM_NOT_FOUND.getCode()); } // TODO 芋艿,后续基于商品是否上下架进一步完善。 return updateQuantity0(item, sku, quantity); } - private CommonResult updateQuantity0(CartItemDO item, ProductSkuBO sku, Integer quantity) { + private Boolean updateQuantity0(CartItemDO item, ProductSkuBO sku, Integer quantity) { // 校验库存 if (item.getQuantity() + quantity > sku.getQuantity()) { - return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); + throw ServiceExceptionUtil.exception(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); } // 更新 CartItemDO cartMapper.updateQuantity(item.getId(), quantity); // 返回成功 - return CommonResult.success(true); + return true; } @Override - public CommonResult updateSelected(Integer userId, Collection skuIds, Boolean selected) { + public Boolean updateSelected(Integer userId, Collection skuIds, Boolean selected) { // 更新 CartItemDO 们 cartMapper.updateListByUserIdAndSkuId(userId, skuIds, selected, null); // 返回成功 - return CommonResult.success(true); + return true; } @Override - public CommonResult deleteList(Integer userId, List skuIds) { + public Boolean deleteList(Integer userId, List skuIds) { // 更新 CartItemDO 们 cartMapper.updateListByUserIdAndSkuId(userId, skuIds, null, CartItemStatusEnum.DELETE_BY_MANUAL.getValue()); // 返回成功 - return CommonResult.success(true); + return true; } @Override - public CommonResult deleteAll(Integer userId) { + public Boolean deleteAll(Integer userId) { return null; } @Override - public CommonResult count(Integer userId) { - return CommonResult.success(cartMapper.selectQuantitySumByUserIdAndStatus(userId, CartItemStatusEnum.ENABLE.getValue())); + public Integer count(Integer userId) { + return cartMapper.selectQuantitySumByUserIdAndStatus(userId, CartItemStatusEnum.ENABLE.getValue()); } @Override - public CommonResult> list(Integer userId, Boolean selected) { + public List list(Integer userId, Boolean selected) { List items = cartMapper.selectByUserIdAndStatusAndSelected(userId, CartItemStatusEnum.ENABLE.getValue(), selected); - return CommonResult.success(CartConvert.INSTANCE.convert(items)); + return CartConvert.INSTANCE.convert(items); } @Override - public CommonResult calcOrderPrice(CalcOrderPriceDTO calcOrderPriceDTO) { + public CalcOrderPriceBO calcOrderPrice(CalcOrderPriceDTO calcOrderPriceDTO) { // TODO 芋艿,补充一些表单校验。例如说,需要传入用户编号。 // 校验商品都存在 Map calcOrderItemMap = calcOrderPriceDTO.getItems().stream() .collect(Collectors.toMap(CalcOrderPriceDTO.Item::getSkuId, item -> item)); // KEY:skuId List skus = productSpuService.getProductSkuDetailList(calcOrderItemMap.keySet()); if (skus.size() != calcOrderPriceDTO.getItems().size()) { - return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_ITEM_SOME_NOT_EXISTS.getCode()); + throw ServiceExceptionUtil.exception(OrderErrorCodeEnum.ORDER_ITEM_SOME_NOT_EXISTS.getCode()); } // TODO 库存相关 // 查询促销活动 @@ -172,11 +171,8 @@ public class CartServiceImpl implements CartService { calcOrderPriceBO.setItemGroups(itemGroups); // 4. 计算优惠劵 if (calcOrderPriceDTO.getCouponCardId() != null) { - CommonResult result = modifyPriceByCouponCard(calcOrderPriceDTO.getUserId(), calcOrderPriceDTO.getCouponCardId(), itemGroups); - if (result.isError()) { - return CommonResult.error(result); - } - calcOrderPriceBO.setCouponCardDiscountTotal(result.getData()); + Integer result = modifyPriceByCouponCard(calcOrderPriceDTO.getUserId(), calcOrderPriceDTO.getCouponCardId(), itemGroups); + calcOrderPriceBO.setCouponCardDiscountTotal(result); } // 5. 计算最终的价格 int buyTotal = 0; @@ -191,31 +187,31 @@ public class CartServiceImpl implements CartService { String.format("价格合计( %d - %d == %d )不正确", buyTotal, discountTotal, presentTotal)); calcOrderPriceBO.setFee(new CalcOrderPriceBO.Fee(buyTotal, discountTotal, 0, presentTotal)); // 返回 - return CommonResult.success(calcOrderPriceBO); + return calcOrderPriceBO; } @Override @SuppressWarnings("Duplicates") - public CommonResult calcSkuPrice(Integer skuId) { + public CalcSkuPriceBO calcSkuPrice(Integer skuId) { // 查询 SKU 是否合法 ProductSkuBO sku = productSpuService.getProductSku(skuId); if (sku == null || CommonStatusEnum.DISABLE.getValue().equals(sku.getStatus())) { // sku 被禁用 - return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); + throw ServiceExceptionUtil.exception(OrderErrorCodeEnum.CARD_ITEM_SKU_NOT_FOUND.getCode()); } // 查询促销活动 List activityList = promotionActivityService.getPromotionActivityListBySpuId(sku.getSpuId(), Arrays.asList(PromotionActivityStatusEnum.WAIT.getValue(), PromotionActivityStatusEnum.RUN.getValue())); if (activityList.isEmpty()) { // 如果无促销活动,则直接返回默认结果即可 - return CommonResult.success(new CalcSkuPriceBO().setOriginalPrice(sku.getPrice()).setBuyPrice(sku.getPrice())); + return new CalcSkuPriceBO().setOriginalPrice(sku.getPrice()).setBuyPrice(sku.getPrice()); } // 如果有促销活动,则开始做计算 TODO 芋艿,因为现在暂时只有限时折扣 + 满减送。所以写的比较简单先 PromotionActivityBO fullPrivilege = findPromotionActivityByType(activityList, PromotionActivityTypeEnum.FULL_PRIVILEGE); PromotionActivityBO timeLimitedDiscount = findPromotionActivityByType(activityList, PromotionActivityTypeEnum.TIME_LIMITED_DISCOUNT); Integer presentPrice = calcSkuPriceByTimeLimitDiscount(sku, timeLimitedDiscount); // 返回结果 - return CommonResult.success(new CalcSkuPriceBO().setFullPrivilege(fullPrivilege).setTimeLimitedDiscount(timeLimitedDiscount) - .setOriginalPrice(sku.getPrice()).setBuyPrice(presentPrice)); + return new CalcSkuPriceBO().setFullPrivilege(fullPrivilege).setTimeLimitedDiscount(timeLimitedDiscount) + .setOriginalPrice(sku.getPrice()).setBuyPrice(presentPrice); } private List initCalcOrderPriceItems(List skus, @@ -306,14 +302,10 @@ public class CartServiceImpl implements CartService { return itemGroups; } - private CommonResult modifyPriceByCouponCard(Integer userId, Integer couponCardId, List itemGroups) { + private Integer modifyPriceByCouponCard(Integer userId, Integer couponCardId, List itemGroups) { Assert.isTrue(couponCardId != null, "优惠劵编号不能为空"); // 查询优惠劵 - CommonResult couponCardResult = couponService.getCouponCardDetail(userId, couponCardId); - if (couponCardResult.isError()) { - return CommonResult.error(couponCardResult); - } - CouponCardDetailBO couponCard = couponCardResult.getData(); + CouponCardDetailBO couponCard = couponService.getCouponCardDetail(userId, couponCardId); // 获得匹配的商品 List items = new ArrayList<>(); if (RangeTypeEnum.ALL.getValue().equals(couponCard.getRangeType())) { @@ -347,7 +339,7 @@ public class CartServiceImpl implements CartService { // 判断是否符合条件 int originalTotal = items.stream().mapToInt(CalcOrderPriceBO.Item::getPresentTotal).sum(); // 此处,指的是以优惠劵视角的原价 if (originalTotal == 0 || originalTotal < couponCard.getPriceAvailable()) { - return ServiceExceptionUtil.error(PromotionErrorCodeEnum.COUPON_CARD_NOT_MATCH.getCode()); // TODO 芋艿,这种情况,会出现错误码的提示,无法格式化出来。另外,这块的最佳实践,找人讨论下。 + throw ServiceExceptionUtil.exception(PromotionErrorCodeEnum.COUPON_CARD_NOT_MATCH.getCode()); // TODO 芋艿,这种情况,会出现错误码的提示,无法格式化出来。另外,这块的最佳实践,找人讨论下。 } // 计算价格 // 获得到优惠信息,进行价格计算 @@ -370,7 +362,7 @@ public class CartServiceImpl implements CartService { // 按比例,拆分 presentTotal splitDiscountPriceToItems(items, discountTotal, presentTotal); // 返回优惠金额 - return CommonResult.success(originalTotal - presentTotal); + return originalTotal - presentTotal; } /** diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderReturnServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderReturnServiceImpl.java index 4e354e14c..c5bc3d275 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderReturnServiceImpl.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderReturnServiceImpl.java @@ -141,7 +141,7 @@ public class OrderReturnServiceImpl implements OrderReturnService { ); } - @Override +// @Override public CommonResult agree(Integer id) { OrderReturnDO orderReturnDO = orderReturnMapper.selectById(id); if (orderReturnDO == null) { diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderServiceImpl.java index ce73c0c19..67f330c4d 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderServiceImpl.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderServiceImpl.java @@ -224,11 +224,7 @@ public class OrderServiceImpl implements OrderService { } // 价格计算 - CommonResult calcOrderPriceResult = calcOrderPrice(productList, orderCreateDTO); - if (calcOrderPriceResult.isError()) { - return CommonResult.error(calcOrderPriceResult); - } - CalcOrderPriceBO calcOrderPrice = calcOrderPriceResult.getData(); + CalcOrderPriceBO calcOrderPrice = calcOrderPrice(productList, orderCreateDTO); // 设置 orderItem Map productSpuBOMap = productList @@ -261,10 +257,7 @@ public class OrderServiceImpl implements OrderService { // 标记优惠劵已使用 if (orderCreateDTO.getCouponCardId() != null) { - CommonResult useCouponCardResult = couponService.useCouponCard(userId, orderCreateDTO.getCouponCardId()); - if (useCouponCardResult.isError()) { - return CommonResult.error(useCouponCardResult); - } + couponService.useCouponCard(userId, orderCreateDTO.getCouponCardId()); } // TODO 芋艿,扣除库存 @@ -329,10 +322,7 @@ public class OrderServiceImpl implements OrderService { orderItemMapper.insert(orderItemDOList); // 创建预订单 - CommonResult createPayTransactionResult = createPayTransaction(orderDO, orderItemDOList, orderCreateDTO.getIp()); - if (calcOrderPriceResult.isError()) { - return CommonResult.error(calcOrderPriceResult); - } + createPayTransaction(orderDO, orderItemDOList, orderCreateDTO.getIp()); // if (commonResult.isError()) { // //手动开启事务回滚 @@ -349,7 +339,7 @@ public class OrderServiceImpl implements OrderService { ); } - private CommonResult calcOrderPrice(List skus, OrderCreateDTO orderCreateDTO) { + private CalcOrderPriceBO calcOrderPrice(List skus, OrderCreateDTO orderCreateDTO) { // 创建计算的 DTO CalcOrderPriceDTO calcOrderPriceDTO = new CalcOrderPriceDTO() .setUserId(orderCreateDTO.getUserId())