From 0ca854587e3b4cbd659ffcaa20ef4157aefdd3ae Mon Sep 17 00:00:00 2001 From: sin <2943460818@qq.com> Date: Sun, 14 Apr 2019 18:15:53 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=B7=BB=E5=8A=A0=E8=AE=A2=E5=8D=95=20info?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../users/OrderLogisticsController.java | 3 +- .../users/UsersOrderController.java | 28 +++- .../iocoder/mall/order/api/OrderService.java | 9 ++ .../mall/order/api/bo/OrderInfoBO.java | 148 ++++++++++++++++++ .../order/api/constant/DictKeysConstants.java | 15 ++ .../iocoder/mall/order/biz/OrderCommon.java | 19 ++- .../mall/order/biz/OrderCommonImpl.java | 24 +++ .../mall/order/biz/convert/OrderConvert.java | 4 + .../convert/OrderLogisticsDetailConvert.java | 4 + .../biz/convert/OrderRecipientConvert.java | 4 + .../biz/dao/OrderLogisticsDetailMapper.java | 10 ++ .../mall/order/biz/dataobject/OrderDO.java | 8 + .../order/biz/dataobject/OrderItemDO.java | 4 + .../service/OrderLogisticsServiceImpl.java | 6 +- .../biz/service/OrderReturnServiceImpl.java | 1 + .../order/biz/service/OrderServiceImpl.java | 64 +++++++- .../mapper/OrderLogisticsDetailMapper.xml | 15 ++ .../src/main/resources/mapper/OrderMapper.xml | 18 ++- 18 files changed, 362 insertions(+), 22 deletions(-) create mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderInfoBO.java create mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeysConstants.java diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderLogisticsController.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderLogisticsController.java index d979fbfd..edab5e74 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderLogisticsController.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderLogisticsController.java @@ -4,6 +4,7 @@ import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.order.api.OrderLogisticsService; import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoBO; import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder; +import com.alibaba.dubbo.config.annotation.Reference; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; @@ -23,7 +24,7 @@ import org.springframework.web.bind.annotation.RestController; @Api(description = "订单物流信息") public class OrderLogisticsController { - @Autowired + @Reference(validation = "true") private OrderLogisticsService orderLogisticsService; @GetMapping("logistics_info") diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersOrderController.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersOrderController.java index f042c168..dbd2bf63 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersOrderController.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/UsersOrderController.java @@ -3,12 +3,12 @@ package cn.iocoder.mall.order.application.controller.users; import cn.iocoder.common.framework.util.HttpUtil; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; +import cn.iocoder.mall.admin.api.DataDictService; +import cn.iocoder.mall.admin.api.bo.DataDictBO; import cn.iocoder.mall.order.api.CartService; import cn.iocoder.mall.order.api.OrderService; -import cn.iocoder.mall.order.api.bo.CalcOrderPriceBO; -import cn.iocoder.mall.order.api.bo.CartItemBO; -import cn.iocoder.mall.order.api.bo.OrderCreateBO; -import cn.iocoder.mall.order.api.bo.OrderPageBO; +import cn.iocoder.mall.order.api.bo.*; +import cn.iocoder.mall.order.api.constant.DictKeysConstants; import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum; import cn.iocoder.mall.order.api.dto.CalcOrderPriceDTO; import cn.iocoder.mall.order.api.dto.OrderCreateDTO; @@ -20,6 +20,7 @@ import cn.iocoder.mall.order.application.vo.UsersOrderConfirmCreateVO; import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder; import com.alibaba.dubbo.config.annotation.Reference; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -43,8 +44,11 @@ public class UsersOrderController { private OrderService orderService; @Reference(validation = "true") private CartService cartService; + @Reference(validation = "true") + private DataDictService dataDictService; @GetMapping("order_page") + @ApiOperation("订单分页") public CommonResult getOrderPage(@Validated OrderQueryDTO orderQueryDTO) { Integer userId = UserSecurityContextHolder.getContext().getUserId(); orderQueryDTO.setUserId(userId); @@ -52,6 +56,7 @@ public class UsersOrderController { } @PostMapping("create_order") + @ApiOperation("创建订单") public CommonResult createOrder(@RequestBody @Validated OrderCreatePO orderCreatePO) { Integer userId = UserSecurityContextHolder.getContext().getUserId(); OrderCreateDTO orderCreateDTO = OrderConvertAPP.INSTANCE.convert(orderCreatePO); @@ -60,6 +65,7 @@ public class UsersOrderController { } @PostMapping("create_order_from_cart") + @ApiOperation("创建订单购物车") public CommonResult createOrderFromCart(@RequestParam("userAddressId") Integer userAddressId, @RequestParam(value = "remark", required = false) String remark, HttpServletRequest request) { @@ -85,6 +91,7 @@ public class UsersOrderController { } @GetMapping("confirm_create_order") + @ApiOperation("确认创建订单") public CommonResult getConfirmCreateOrder(@RequestParam("skuId") Integer skuId, @RequestParam("quantity") Integer quantity) { // 创建 CalcOrderPriceDTO 对象,并执行价格计算 @@ -99,9 +106,22 @@ public class UsersOrderController { } @PostMapping("confirm_receiving") + @ApiOperation("确认收货") public CommonResult confirmReceiving(@RequestParam("orderId") Integer orderId) { Integer userId = UserSecurityContextHolder.getContext().getUserId(); return orderService.confirmReceiving(userId, orderId); } + @GetMapping("info") + @ApiOperation("订单详情") + public CommonResult orderInfo(@RequestParam("orderId") Integer orderId) { + Integer userId = UserSecurityContextHolder.getContext().getUserId(); + CommonResult commonResult = orderService.info(userId, orderId); + + OrderInfoBO orderInfoBO = commonResult.getData(); + CommonResult dictResult = dataDictService + .getDataDict(DictKeysConstants.ORDER_STATUS_KEY, orderInfoBO.getStatus()); + orderInfoBO.setStatusText(dictResult.getData().getDisplayName()); + return commonResult; + } } diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderService.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderService.java index 32a540ed..29b4b16a 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderService.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderService.java @@ -38,6 +38,15 @@ public interface OrderService { */ CommonResult getOrderRecipientBO(Integer orderId); + /** + * 订单info + * + * @param userId + * @param orderId + * @return + */ + CommonResult info(Integer userId, Integer orderId); + /** * 订单 - 创建 * diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderInfoBO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderInfoBO.java new file mode 100644 index 00000000..e244f830 --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderInfoBO.java @@ -0,0 +1,148 @@ +package cn.iocoder.mall.order.api.bo; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.Date; + +/** + * 订单 info + * + * @author Sin + * @time 2019-04-14 15:36 + */ +@Data +@Accessors(chain = true) +public class OrderInfoBO implements Serializable { + + /** + * 订单编号 + */ + private String orderNo; + /** + * 价格(分) + */ + private Integer price; + /** + * 交易金额 + */ + private Integer payAmount; + /** + * 物流金额 (分) + */ + private Integer logisticsPrice; + /** + * 付款时间(待发货) + */ + private Date paymentTime; + /** + * 发货时间(待收货) + */ + private Date deliveryTime; + /** + * 收货时间(已签收) + */ + private Date receiverTime; + /** + * 成交时间(用户确认收货 -> status = 已完成) + */ + private Date closingTime; + /** + * 是否退货 + * + * - 1、没有 + * - 2、换货 + * - 3、退货 + * - 4、换货 + 退货 + */ + private Integer hasReturnExchange; + /** + * 状态(如果有多个商品分开发货需要全部商品发完才会改变状态) + * + * - 1、待付款 + * - 2、待发货 + * - 3、待收获 + * - 4、已完成 + * - 5、已关闭 + */ + private Integer status; + /** + * 转换的字典值 + */ + private String statusText; + /** + * 备注 + */ + private String remark; + + /// + /// 其他信息 + + /** + * 手机人信息 + */ + private Recipient recipient; + /** + * 最新物流信息 + */ + private LogisticsDetail latestLogisticsDetail; + + @Data + @Accessors(chain = true) + public static class Recipient { + + /** + * 编号 + */ + private Integer id; + /** + * 订单id + */ + private Integer orderId; + /** + * 收件区域编号 + */ + private String areaNo; + /** + * 收件人名称 + */ + private String name; + /** + * 收件手机号 + */ + private String mobile; + /** + * 配送类型 + * + * - 1 快递 + */ + private Integer type; + /** + * 收件详细地址 + */ + private String address; + } + + @Data + @Accessors(chain = true) + public static class LogisticsDetail { + + /** + * id + */ + private Integer id; + /** + * 物流id + */ + private Integer orderLogisticsId; + /** + * 物流时间 + */ + private Date logisticsTime; + /** + * 物流信息 + */ + private String logisticsInformation; + } +} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeysConstants.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeysConstants.java new file mode 100644 index 00000000..a51a4d53 --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeysConstants.java @@ -0,0 +1,15 @@ +package cn.iocoder.mall.order.api.constant; + +/** + * 字典 keys 定义 + * + * @author Sin + * @time 2019-04-14 17:46 + */ +public class DictKeysConstants { + + /** + * 订单 - status + */ + public static final String ORDER_STATUS_KEY = "order_status"; +} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/OrderCommon.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/OrderCommon.java index df28d22e..1099d060 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/OrderCommon.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/OrderCommon.java @@ -12,11 +12,28 @@ import java.util.List; */ public interface OrderCommon { + /** - * 计算订单金额 + * 计算总价格 + * + * @param items + * @return + */ + Integer calculatedPrice(List items); + + /** + * 计算订单实付金额 * * @param items * @return */ Integer calculatedAmount(List items); + + /** + * 计算物流金额 + * + * @param items + * @return + */ + Integer calculatedLogisticsPrice(List items); } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/OrderCommonImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/OrderCommonImpl.java index b3e9fdc1..fb549061 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/OrderCommonImpl.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/OrderCommonImpl.java @@ -16,6 +16,18 @@ import java.util.concurrent.atomic.AtomicInteger; @Component public class OrderCommonImpl implements OrderCommon { + @Override + public Integer calculatedPrice(List items) { + if (CollectionUtils.isEmpty(items)) { + return 0; + } + AtomicInteger totalPrice = new AtomicInteger(0); + items.forEach(orderItemDO -> { + totalPrice.addAndGet(orderItemDO.getPrice() * orderItemDO.getQuantity()); + }); + return totalPrice.get(); + } + @Override public Integer calculatedAmount(List items) { if (CollectionUtils.isEmpty(items)) { @@ -27,4 +39,16 @@ public class OrderCommonImpl implements OrderCommon { }); return totalAmount.get(); } + + @Override + public Integer calculatedLogisticsPrice(List items) { + if (CollectionUtils.isEmpty(items)) { + return 0; + } + AtomicInteger totalAmount = new AtomicInteger(0); + items.forEach(orderItemDO -> { + totalAmount.addAndGet(orderItemDO.getLogisticsPrice()); + }); + return totalAmount.get(); + } } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderConvert.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderConvert.java index cf375c95..6917a876 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderConvert.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderConvert.java @@ -1,6 +1,7 @@ package cn.iocoder.mall.order.biz.convert; import cn.iocoder.mall.order.api.bo.OrderBO; +import cn.iocoder.mall.order.api.bo.OrderInfoBO; import cn.iocoder.mall.order.biz.dataobject.OrderDO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; @@ -21,4 +22,7 @@ public interface OrderConvert { @Mappings({}) List convertPageBO(List orderDOList); + + @Mappings({}) + OrderInfoBO convert(OrderDO orderDO); } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderLogisticsDetailConvert.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderLogisticsDetailConvert.java index eccb4ca1..e2b90e63 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderLogisticsDetailConvert.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderLogisticsDetailConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.mall.order.biz.convert; +import cn.iocoder.mall.order.api.bo.OrderInfoBO; import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoBO; import cn.iocoder.mall.order.biz.dataobject.OrderLogisticsDetailDO; import org.mapstruct.Mapper; @@ -21,4 +22,7 @@ public interface OrderLogisticsDetailConvert { @Mappings({}) List convertLogisticsDetail(List orderLogisticsDOList); + + @Mappings({}) + OrderInfoBO.LogisticsDetail convertLogisticsDetail(OrderLogisticsDetailDO orderLogisticsDetailDO); } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderRecipientConvert.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderRecipientConvert.java index 9e832df3..1229f468 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderRecipientConvert.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderRecipientConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.mall.order.biz.convert; +import cn.iocoder.mall.order.api.bo.OrderInfoBO; import cn.iocoder.mall.order.api.bo.OrderRecipientBO; import cn.iocoder.mall.order.api.dto.OrderCreateDTO; import cn.iocoder.mall.order.biz.dataobject.OrderRecipientDO; @@ -32,4 +33,7 @@ public interface OrderRecipientConvert { @Mappings({}) List convert(List orderRecipientDOList); + + @Mappings({}) + OrderInfoBO.Recipient convertOrderInfoRecipient(OrderRecipientDO orderRecipientDO); } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderLogisticsDetailMapper.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderLogisticsDetailMapper.java index f022bb49..8851f738 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderLogisticsDetailMapper.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderLogisticsDetailMapper.java @@ -43,4 +43,14 @@ public interface OrderLogisticsDetailMapper { List selectByOrderLogisticsIds( @Param("orderLogisticsIds") Collection orderLogisticsIds ); + + /** + * 查询 - 获取最新的物流信息 + * + * @param orderLogisticsIds + * @return + */ + OrderLogisticsDetailDO selectLatest( + @Param("orderLogisticsIds") Collection orderLogisticsIds + ); } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderDO.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderDO.java index 40d1bbbd..37dc7a3b 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderDO.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderDO.java @@ -28,6 +28,14 @@ public class OrderDO extends DeletableDO { * 订单编号 */ private String orderNo; + /** + * 价格(分) + */ + private Integer price; + /** + * 物流金额 (分) + */ + private Integer logisticsPrice; /** * 交易金额 */ diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderItemDO.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderItemDO.java index ad4338c9..295a7588 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderItemDO.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderItemDO.java @@ -56,6 +56,10 @@ public class OrderItemDO extends DeletableDO { * 支付金额(实付金额) */ private Integer payAmount; + /** + * 物流金额 (分) + */ + private Integer logisticsPrice; /// /// 时间信息 diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderLogisticsServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderLogisticsServiceImpl.java index 0c2f0d0a..d1f87c49 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderLogisticsServiceImpl.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderLogisticsServiceImpl.java @@ -5,7 +5,6 @@ import cn.iocoder.common.framework.util.DateUtil; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.order.api.OrderLogisticsService; -import cn.iocoder.mall.order.api.bo.OrderLogisticsBO; import cn.iocoder.mall.order.api.bo.OrderLogisticsInfoBO; import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum; import cn.iocoder.mall.order.biz.convert.OrderLogisticsConvert; @@ -34,6 +33,7 @@ import java.util.stream.Collectors; * @time 2019-04-12 21:32 */ @Service +@com.alibaba.dubbo.config.annotation.Service(validation = "true") public class OrderLogisticsServiceImpl implements OrderLogisticsService { @Autowired @@ -63,7 +63,9 @@ public class OrderLogisticsServiceImpl implements OrderLogisticsService { // 获取物流 信息 Set orderLogisticsIds = orderItemDOList.stream() - .map(o -> o.getOrderLogisticsId()).collect(Collectors.toSet()); + .filter(o -> o.getOrderLogisticsId() != null) + .map(o -> o.getOrderLogisticsId()) + .collect(Collectors.toSet()); List orderLogisticsDOList = orderLogisticsMapper.selectByIds(orderLogisticsIds); 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 b57eecbf..b24c44d7 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 @@ -19,6 +19,7 @@ import java.util.Date; * @time 2019-03-30 15:35 */ @Service +@com.alibaba.dubbo.config.annotation.Service(validation = "true") public class OrderReturnServiceImpl implements OrderReturnService { @Autowired 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 6bbfd469..f85655c5 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 @@ -12,10 +12,7 @@ import cn.iocoder.mall.order.api.dto.*; import cn.iocoder.mall.order.biz.OrderCommon; import cn.iocoder.mall.order.biz.constants.OrderDeliveryTypeEnum; import cn.iocoder.mall.order.biz.constants.OrderRecipientTypeEnum; -import cn.iocoder.mall.order.biz.convert.OrderConvert; -import cn.iocoder.mall.order.biz.convert.OrderItemConvert; -import cn.iocoder.mall.order.biz.convert.OrderLogisticsConvert; -import cn.iocoder.mall.order.biz.convert.OrderRecipientConvert; +import cn.iocoder.mall.order.biz.convert.*; import cn.iocoder.mall.order.biz.dao.*; import cn.iocoder.mall.order.biz.dataobject.*; import cn.iocoder.mall.pay.api.PayTransactionService; @@ -55,6 +52,8 @@ public class OrderServiceImpl implements OrderService { @Autowired private OrderLogisticsMapper orderLogisticsMapper; @Autowired + private OrderLogisticsDetailMapper orderLogisticsDetailMapper; + @Autowired private OrderRecipientMapper orderRecipientMapper; @Autowired private OrderCancelMapper orderCancelMapper; @@ -152,6 +151,41 @@ public class OrderServiceImpl implements OrderService { return CommonResult.success(orderRecipientBO); } + @Override + public CommonResult info(Integer userId, Integer orderId) { + OrderDO orderDO = orderMapper.selectById(orderId); + if (orderDO == null) { + return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_NOT_EXISTENT.getCode()); + } + + List itemDOList = orderItemMapper + .selectByDeletedAndOrderId(orderId, DeletedStatusEnum.DELETED_NO.getValue()); + + Set orderLogisticsIds = itemDOList.stream() + .filter(o -> o.getOrderLogisticsId() != null) + .map(o -> o.getOrderLogisticsId()) + .collect(Collectors.toSet()); + + // 收件人信息 + OrderRecipientDO orderRecipientDO = orderRecipientMapper.selectByOrderId(orderId); + + // 订单物流信息 + OrderLogisticsDetailDO orderLogisticsDetailDO = null; + if (!CollectionUtils.isEmpty(orderLogisticsIds)) { + orderLogisticsDetailDO = orderLogisticsDetailMapper.selectLatest(orderLogisticsIds); + } + + // convert 信息 + OrderInfoBO.LogisticsDetail logisticsDetail + = OrderLogisticsDetailConvert.INSTANCE.convertLogisticsDetail(orderLogisticsDetailDO); + + OrderInfoBO.Recipient recipient = OrderRecipientConvert.INSTANCE.convertOrderInfoRecipient(orderRecipientDO); + OrderInfoBO orderInfoBO = OrderConvert.INSTANCE.convert(orderDO); + orderInfoBO.setRecipient(recipient); + orderInfoBO.setLatestLogisticsDetail(logisticsDetail); + return CommonResult.success(orderInfoBO); + } + @Override @Transactional public CommonResult createOrder(OrderCreateDTO orderCreateDTO) { @@ -196,6 +230,7 @@ public class OrderServiceImpl implements OrderService { orderItemDO.setSkuImage(Optional.ofNullable(productSkuDetailBO.getSpu().getPicUrls().get(0)).get()); orderItemDO.setSkuName(productSkuDetailBO.getSpu().getName()); orderItemDO.setPrice(productSkuDetailBO.getPrice()); + orderItemDO.setLogisticsPrice(0); int payAmount = orderItemDO.getQuantity() * orderItemDO.getPrice(); orderItemDO.setPayAmount(payAmount); @@ -206,10 +241,14 @@ public class OrderServiceImpl implements OrderService { // TODO: 2019-04-11 Sin 订单号需要生成规则 String orderNo = UUID.randomUUID().toString().replace("-", "").substring(0, 16); Integer totalAmount = orderCommon.calculatedAmount(orderItemDOList); + Integer totalPrice = orderCommon.calculatedPrice(orderItemDOList); + Integer totalLogisticsPrice = orderCommon.calculatedLogisticsPrice(orderItemDOList); OrderDO orderDO = new OrderDO() .setUserId(userId) .setOrderNo(orderNo) + .setPrice(totalPrice) .setPayAmount(totalAmount) + .setLogisticsPrice(totalLogisticsPrice) .setClosingTime(null) .setDeliveryTime(null) .setPaymentTime(null) @@ -223,7 +262,9 @@ public class OrderServiceImpl implements OrderService { orderMapper.insert(orderDO); // 收件人信息 - CommonResult userAddressResult = userAddressService.getAddress(userId, orderCreateDTO.getUserAddressId()); + CommonResult userAddressResult + = userAddressService.getAddress(userId, orderCreateDTO.getUserAddressId()); + if (userAddressResult.isError()) { return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_GET_USER_ADDRESS_FAIL.getCode()); } @@ -310,9 +351,16 @@ public class OrderServiceImpl implements OrderService { orderItemMapper.updateById(new OrderItemDO().setId(orderItemId).setPayAmount(payAmount)); // 再重新计算订单金额 - List orderItemDOList = orderItemMapper.selectByDeletedAndOrderId(orderId, DeletedStatusEnum.DELETED_NO.getValue()); - Integer orderPayAmount = orderCommon.calculatedAmount(orderItemDOList); - orderMapper.updateById(new OrderDO().setId(orderId).setPayAmount(orderPayAmount)); + List orderItemDOList = orderItemMapper + .selectByDeletedAndOrderId(orderId, DeletedStatusEnum.DELETED_NO.getValue()); + Integer price = orderCommon.calculatedPrice(orderItemDOList); + Integer amount = orderCommon.calculatedAmount(orderItemDOList); + orderMapper.updateById( + new OrderDO() + .setId(orderId) + .setPrice(price) + .setPayAmount(amount) + ); return CommonResult.success(null); } diff --git a/order/order-service-impl/src/main/resources/mapper/OrderLogisticsDetailMapper.xml b/order/order-service-impl/src/main/resources/mapper/OrderLogisticsDetailMapper.xml index 695f9b5e..4e8836b7 100644 --- a/order/order-service-impl/src/main/resources/mapper/OrderLogisticsDetailMapper.xml +++ b/order/order-service-impl/src/main/resources/mapper/OrderLogisticsDetailMapper.xml @@ -46,4 +46,19 @@ #{orderLogisticsId} + + + diff --git a/order/order-service-impl/src/main/resources/mapper/OrderMapper.xml b/order/order-service-impl/src/main/resources/mapper/OrderMapper.xml index 14dea171..1a66e6c4 100644 --- a/order/order-service-impl/src/main/resources/mapper/OrderMapper.xml +++ b/order/order-service-impl/src/main/resources/mapper/OrderMapper.xml @@ -3,8 +3,8 @@ - id, user_id, order_no, pay_amount, payment_time, - delivery_time, receiver_time, closing_time, + id, user_id, order_no, price, pay_amount, logistics_price, + payment_time, delivery_time, receiver_time, closing_time, has_return_exchange, status, remark, create_time, update_time, `deleted` @@ -14,13 +14,13 @@ --> INSERT INTO `order` ( - user_id, order_no, pay_amount, payment_time, - delivery_time, receiver_time, closing_time, + user_id, order_no, price, pay_amount, logistics_price, + payment_time, delivery_time, receiver_time, closing_time, has_return_exchange, status, remark, create_time, update_time, `deleted` ) VALUES ( - #{userId}, #{orderNo}, #{payAmount}, #{paymentTime}, - #{deliveryTime}, #{receiverTime}, #{closingTime}, + #{userId}, #{orderNo}, #{price}, #{payAmount}, #{logisticsPrice}, + #{paymentTime}, #{deliveryTime}, #{receiverTime}, #{closingTime}, #{hasReturnExchange}, #{status}, #{remark}, #{createTime}, #{updateTime}, #{deleted} ) @@ -34,9 +34,15 @@ , order_no = #{orderNo} + + , price = #{price} + , pay_amount = #{payAmount} + + , logistics_price = #{logisticsPrice} + , payment_time = #{paymentTime}