From 503c996acdf6c4a4e6ef13aaa243445df7586f16 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 13 Aug 2023 20:12:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=EF=BC=9A=201=E3=80=81?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=20deliverStatus=20=E5=8F=91=E8=B4=A7?= =?UTF-8?q?=E7=8A=B6=E6=80=81=EF=BC=8C=E6=9A=82=E6=97=B6=E6=B2=A1=E4=BD=9C?= =?UTF-8?q?=E7=94=A8=202=E3=80=81=E6=97=A0=E9=9C=80=E5=8F=91=E8=B4=A7?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E4=BD=BF=E7=94=A8=20logisticsId=20=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E5=AE=9E=E7=8E=B0=203=E3=80=81=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=AF=A6=E6=83=85=EF=BC=8C=E5=A2=9E=E5=8A=A0=20logisticsId=20?= =?UTF-8?q?=E5=92=8C=20logisticsName=20=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CombinationActivityServiceImplTest.java | 10 ------- .../order/TradeOrderDeliveryStatusEnum.java | 28 ------------------- .../app/order/AppTradeOrderController.java | 15 +++++++++- .../order/vo/AppTradeOrderDetailRespVO.java | 6 ++++ .../convert/order/TradeOrderConvert.java | 7 ++++- .../dal/dataobject/order/TradeOrderDO.java | 13 +++++---- .../service/order/TradeOrderServiceImpl.java | 18 +++++------- .../service/order/TradeOrderServiceTest.java | 8 ++---- .../src/test/resources/sql/create_tables.sql | 1 - 9 files changed, 42 insertions(+), 64 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderDeliveryStatusEnum.java diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java index 89f73a234..092d79877 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImplTest.java @@ -152,19 +152,9 @@ public class CombinationActivityServiceImplTest extends BaseDbUnitTest { // 准备参数 CombinationActivityPageReqVO reqVO = new CombinationActivityPageReqVO(); reqVO.setName(null); - reqVO.setSpuId(null); - reqVO.setTotalLimitCount(null); - reqVO.setSingleLimitCount(null); reqVO.setStartTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); reqVO.setEndTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); - reqVO.setUserSize(null); - reqVO.setTotalNum(null); - reqVO.setSuccessNum(null); - reqVO.setOrderUserCount(null); - reqVO.setVirtualGroup(null); reqVO.setStatus(null); - reqVO.setLimitDuration(null); - reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); // 调用 PageResult pageResult = combinationActivityService.getCombinationActivityPage(reqVO); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderDeliveryStatusEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderDeliveryStatusEnum.java deleted file mode 100644 index 27b061e37..000000000 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/order/TradeOrderDeliveryStatusEnum.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.trade.enums.order; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -/** - * 交易订单 - 发货状态 - * - * @author 芋道源码 - */ -@RequiredArgsConstructor -@Getter -public enum TradeOrderDeliveryStatusEnum { - - UNDELIVERED(0, "未发货"), - DELIVERED(1, "已发货"), - RECEIVED(2, "已收货"); - - /** - * 状态值 - */ - private final Integer status; - /** - * 状态名 - */ - private final String name; - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index 765ed58c4..c8a3abb6d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -10,10 +10,12 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.*; import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemRespVO; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; +import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderService; import com.google.common.collect.Maps; import io.swagger.v3.oas.annotations.Operation; @@ -42,8 +44,12 @@ public class AppTradeOrderController { @Resource private TradeOrderService tradeOrderService; + @Resource + private DeliveryExpressService deliveryExpressService; + @Resource private ProductPropertyValueApi productPropertyValueApi; + @Resource private TradeOrderProperties tradeOrderProperties; @@ -76,14 +82,21 @@ public class AppTradeOrderController { public CommonResult getOrder(@RequestParam("id") Long id) { // 查询订单 TradeOrderDO order = tradeOrderService.getOrder(getLoginUserId(), id); + if (order == null) { + return success(null); + } + // 查询订单项 List orderItems = tradeOrderService.getOrderItemListByOrderId(order.getId()); // 查询商品属性 List propertyValueDetails = productPropertyValueApi .getPropertyValueDetailList(TradeOrderConvert.INSTANCE.convertPropertyValueIds(orderItems)); + // 查询物流公司 + DeliveryExpressDO express = order.getLogisticsId() != null && order.getLogisticsId() > 0 ? + deliveryExpressService.getDeliveryExpress(order.getLogisticsId()) : null; // 最终组合 return success(TradeOrderConvert.INSTANCE.convert02(order, orderItems, - propertyValueDetails, tradeOrderProperties)); + propertyValueDetails, tradeOrderProperties, express)); } @GetMapping("/page") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderDetailRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderDetailRespVO.java index 7a67190fc..9b417ee74 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderDetailRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderDetailRespVO.java @@ -80,6 +80,12 @@ public class AppTradeOrderDetailRespVO { @Schema(description = "配送方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") private Integer deliveryType; + @Schema(description = "发货物流公司编号", example = "10") + private Long logisticsId; + + @Schema(description = "发货物流名称", example = "顺丰快递") + private String logisticsName; + @Schema(description = "发货物流单号", example = "1024") private String logisticsNo; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index 788b8c413..ac0a47ca5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -25,6 +25,7 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.*; import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.cart.TradeCartDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; @@ -234,7 +235,8 @@ public interface TradeOrderConvert { // TODO 芋艿:可简化 default AppTradeOrderDetailRespVO convert02(TradeOrderDO order, List orderItems, - List propertyValueDetails, TradeOrderProperties tradeOrderProperties) { + List propertyValueDetails, TradeOrderProperties tradeOrderProperties, + DeliveryExpressDO express) { AppTradeOrderDetailRespVO orderVO = convert3(order, orderItems); orderVO.setPayExpireTime(addTime(tradeOrderProperties.getExpireTime())); if (StrUtil.isNotEmpty(order.getPayChannelCode())) { @@ -260,6 +262,9 @@ public interface TradeOrderConvert { } // 处理收货地址 orderVO.setReceiverAreaName(AreaUtils.format(order.getReceiverAreaId())); + if (express != null) { + orderVO.setLogisticsId(express.getId()).setLogisticsName(express.getName()); + } return orderVO; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java index 011e8546f..b9177fb66 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/order/TradeOrderDO.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.dal.dataobject.order; import cn.iocoder.yudao.framework.common.enums.TerminalEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryPickUpStoreDO; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.*; @@ -174,18 +175,18 @@ public class TradeOrderDO extends BaseDO { private Integer deliveryType; /** * 发货物流公司编号 + * + * 如果无需发货,则 logisticsId 设置为 0。原因是,不想再添加额外字段 + * + * 关联 {@link DeliveryExpressDO#getId()} */ private Long logisticsId; /** * 发货物流单号 + * + * 如果无需发货,则 logisticsNo 设置 ""。原因是,不想再添加额外字段 */ private String logisticsNo; - /** - * 发货状态 - * - * 枚举 {@link TradeOrderDeliveryStatusEnum} - */ - private Integer deliveryStatus; /** * 发货时间 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java index 64e90eb52..39eedffb2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceImpl.java @@ -217,8 +217,8 @@ public class TradeOrderServiceImpl implements TradeOrderService { order.setTerminal(TerminalEnum.H5.getTerminal()); // todo 数据来源? // 支付信息 order.setAdjustPrice(0).setPayStatus(false); - // 物流信息 TODO 芋艿:暂时写死物流方式;应该是前端选择的 - order.setDeliveryType(createReqVO.getDeliveryType()).setDeliveryStatus(TradeOrderDeliveryStatusEnum.UNDELIVERED.getStatus()); + // 物流信息 + order.setDeliveryType(createReqVO.getDeliveryType()); // 退款信息 order.setRefundStatus(TradeOrderRefundStatusEnum.NONE.getStatus()).setRefundPrice(0); tradeOrderMapper.insert(order); @@ -412,8 +412,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { } // 更新 TradeOrderDO 状态为已发货,等待收货 - updateOrderObj.setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()) - .setDeliveryStatus(TradeOrderDeliveryStatusEnum.DELIVERED.getStatus()).setDeliveryTime(LocalDateTime.now()); + updateOrderObj.setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()).setDeliveryTime(LocalDateTime.now()); int updateCount = tradeOrderMapper.updateByIdAndStatus(order.getId(), order.getStatus(), updateOrderObj); if (updateCount == 0) { throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED); @@ -422,7 +421,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { // 发送站内信 tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO().setOrderId(order.getId()) - .setUserId(userId).setMessage(TradeOrderDeliveryStatusEnum.DELIVERED.getName())); + .setUserId(userId).setMessage(null)); // TODO 芋艿:OrderLog // TODO 设计:lili:是不是发货后,才支持售后? @@ -453,8 +452,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { throw exception(ORDER_NOT_FOUND); } // 校验订单是否是待发货状态 - if (!TradeOrderStatusEnum.isUndelivered(order.getStatus()) - || ObjectUtil.notEqual(order.getDeliveryStatus(), TradeOrderDeliveryStatusEnum.UNDELIVERED.getStatus())) { + if (!TradeOrderStatusEnum.isUndelivered(order.getStatus())) { throw exception(ORDER_DELIVERY_FAIL_STATUS_NOT_UNDELIVERED); } // 校验订单是否退款 @@ -480,8 +478,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { // 更新 TradeOrderDO 状态为已完成 int updateCount = tradeOrderMapper.updateByIdAndStatus(order.getId(), order.getStatus(), - new TradeOrderDO().setStatus(TradeOrderStatusEnum.COMPLETED.getStatus()) - .setDeliveryStatus(TradeOrderDeliveryStatusEnum.RECEIVED.getStatus()).setReceiveTime(LocalDateTime.now())); + new TradeOrderDO().setStatus(TradeOrderStatusEnum.COMPLETED.getStatus()).setReceiveTime(LocalDateTime.now())); if (updateCount == 0) { throw exception(ORDER_RECEIVE_FAIL_STATUS_NOT_DELIVERED); } @@ -513,8 +510,7 @@ public class TradeOrderServiceImpl implements TradeOrderService { throw exception(ORDER_NOT_FOUND); } // 校验订单是否是待收货状态 - if (!TradeOrderStatusEnum.isDelivered(order.getStatus()) - || ObjectUtil.notEqual(order.getDeliveryStatus(), TradeOrderDeliveryStatusEnum.DELIVERED.getStatus())) { + if (!TradeOrderStatusEnum.isDelivered(order.getStatus())) { throw exception(ORDER_RECEIVE_FAIL_STATUS_NOT_DELIVERED); } return order; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java index 5507f4307..f9dc071dd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderServiceTest.java @@ -177,7 +177,6 @@ public class TradeOrderServiceTest extends BaseDbUnitTest { assertEquals(tradeOrderDO.getPayOrderId(), 1000L); assertNull(tradeOrderDO.getPayChannelCode()); assertNull(tradeOrderDO.getLogisticsId()); - assertEquals(tradeOrderDO.getDeliveryStatus(), TradeOrderDeliveryStatusEnum.UNDELIVERED.getStatus()); assertNull(tradeOrderDO.getDeliveryTime()); assertNull(tradeOrderDO.getReceiveTime()); assertEquals(tradeOrderDO.getReceiverName(), "芋艿"); @@ -274,8 +273,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest { // mock 数据(TradeOrder) TradeOrderDO order = randomPojo(TradeOrderDO.class, o -> { o.setId(1L).setStatus(TradeOrderStatusEnum.UNDELIVERED.getStatus()); - o.setLogisticsId(null).setLogisticsNo(null).setDeliveryTime(null) - .setDeliveryStatus(TradeOrderDeliveryStatusEnum.UNDELIVERED.getStatus()); + o.setLogisticsId(null).setLogisticsNo(null).setDeliveryTime(null); }); tradeOrderMapper.insert(order); // 准备参数 @@ -288,7 +286,6 @@ public class TradeOrderServiceTest extends BaseDbUnitTest { // 断言 TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L); assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.DELIVERED.getStatus()); - assertEquals(dbOrder.getDeliveryStatus(), TradeOrderDeliveryStatusEnum.DELIVERED.getStatus()); assertPojoEquals(dbOrder, deliveryReqVO); assertNotNull(dbOrder.getDeliveryTime()); } @@ -298,7 +295,7 @@ public class TradeOrderServiceTest extends BaseDbUnitTest { // mock 数据(TradeOrder) TradeOrderDO order = randomPojo(TradeOrderDO.class, o -> { o.setId(1L).setUserId(10L).setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()); - o.setDeliveryStatus(TradeOrderDeliveryStatusEnum.DELIVERED.getStatus()).setReceiveTime(null); + o.setReceiveTime(null); }); tradeOrderMapper.insert(order); // 准备参数 @@ -311,7 +308,6 @@ public class TradeOrderServiceTest extends BaseDbUnitTest { // 断言 TradeOrderDO dbOrder = tradeOrderMapper.selectById(1L); assertEquals(dbOrder.getStatus(), TradeOrderStatusEnum.COMPLETED.getStatus()); - assertEquals(dbOrder.getDeliveryStatus(), TradeOrderDeliveryStatusEnum.RECEIVED.getStatus()); assertNotNull(dbOrder.getReceiveTime()); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql index d4ce5cc9f..e30b0d225 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql @@ -25,7 +25,6 @@ CREATE TABLE IF NOT EXISTS "trade_order" ( "delivery_template_id" bigint, "logistics_id" bigint, "logistics_no" varchar, - "delivery_status" smallint NOT NULL, "delivery_time" datetime, "receive_time" datetime, "receiver_name" varchar NOT NULL,