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 92f1b4c44..76da3c6dc 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 @@ -85,7 +85,7 @@ public class OrderController { remark, HttpUtil.getIp(request), cartItems, couponCardId); // 创建订单 - CommonResult createResult= orderService.createOrder(orderCreateDTO); + CommonResult createResult = orderService.createOrder(orderCreateDTO); if (createResult.isError()) { return CommonResult.error(createResult); } @@ -127,7 +127,7 @@ public class OrderController { CommonResult commonResult = orderService.info(userId, orderId); OrderInfoBO orderInfoBO = commonResult.getData(); - if(orderInfoBO != null) { + if (orderInfoBO != null) { CommonResult dictResult = dataDictService .getDataDict(DictKeyConstants.ORDER_STATUS, orderInfoBO.getStatus()); orderInfoBO.setStatusText(dictResult.getData().getDisplayName()); diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderReturnController.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderReturnController.java index 458cca848..113bde6fb 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderReturnController.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/users/OrderReturnController.java @@ -4,6 +4,7 @@ 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.OrderReturnService; +import cn.iocoder.mall.order.api.bo.OrderReturnInfoBO; import cn.iocoder.mall.order.api.constant.DictKeyConstants; import cn.iocoder.mall.order.api.dto.OrderReturnApplyDTO; import cn.iocoder.mall.order.application.convert.OrderReturnConvert; @@ -41,4 +42,23 @@ public class OrderReturnController { OrderReturnApplyDTO applyDTO = OrderReturnConvert.INSTANCE.convert(orderReturnApplyPO); return orderReturnService.orderReturnApply(applyDTO); } + + @GetMapping("info") + @ApiOperation("订单售后详细") + public CommonResult orderApplyInfo(@RequestParam("orderId") Integer orderId) { + CommonResult commonResult = orderReturnService.orderApplyInfo(orderId); + + // 转换 字典值 + if (commonResult.isSuccess()) { + CommonResult dataDictResult = dataDictService.getDataDict( + DictKeyConstants.ORDER_RETURN_SERVICE_TYPE, + commonResult.getData().getReturnInfo().getServiceType()); + + if (dataDictResult.isSuccess()) { + commonResult.getData().getReturnInfo().setServiceTypeText(dataDictResult.getData().getDisplayName()); + } + } + + return commonResult; + } } diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderReturnService.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderReturnService.java index c35c59db5..7d143a428 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderReturnService.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderReturnService.java @@ -32,4 +32,11 @@ public interface OrderReturnService { */ String updateRefundSuccess(String orderId, Integer refundPrice); + /** + * 订单申请信息 + * + * @param orderId + * @return + */ + CommonResult orderApplyInfo(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 index f4e4be21c..61cbae25b 100644 --- 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 @@ -110,6 +110,15 @@ public class OrderInfoBO implements Serializable { */ private List orderItems; + + /// + /// 其他字段 + + /** + * 是否退货 + */ + private Integer hasOrderReturn; + @Data @Accessors(chain = true) public static class OrderItem { diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderReturnInfoBO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderReturnInfoBO.java new file mode 100644 index 000000000..c9efa015d --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderReturnInfoBO.java @@ -0,0 +1,133 @@ +package cn.iocoder.mall.order.api.bo; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * 订单退货 info + * + * @author Sin + * @time 2019-04-27 10:19 + */ +@Data +@Accessors(chain = true) +public class OrderReturnInfoBO implements Serializable { + + /** + * 退货信息 + */ + private ReturnInfo returnInfo; + /** + * 订单 item + */ + private List orderItems; + + @Data + @Accessors(chain = true) + public static class OrderItem { + + /** + * 商品编号 + */ + private Integer skuId; + /** + * 商品名称 + */ + private String skuName; + /** + * 商品图片 + */ + private String skuImage; + /** + * 数量 + */ + private Integer quantity; + /** + * 最终总金额,单位:分。 + */ + private Integer presentTotal; + } + + @Data + @Accessors(chain = true) + public static class ReturnInfo { + + /** + * 编号自动增长 + */ + private Integer id; + /** + * 服务号 + */ + private String serviceNumber; + /** + * 订单编号 + */ + private Integer orderId; + /** + * 订单号 (保存一个冗余) + */ + private String orderNo; + /** + * 物流id + */ + private Integer orderLogisticsId; + + /// + /// 退货原因 + + /** + * 退货原因(字典值) + */ + private Integer reason; + /** + * 问题描述 + */ + private String describe; + + /// + /// 时间信息 + + /** + * 同意时间 + */ + private Date approvalTime; + /** + * 物流时间(填写物流单号时间) + */ + private Date logisticsTime; + /** + * 收货时间 + */ + private Date receiverTime; + /** + * 成交时间(确认时间) + */ + private Date closingTime; + /** + * 退款类型 + * + * - 1、退货退款 + * - 2、退款 + */ + private Integer serviceType; + /** + * 退款类型 转换值 + */ + private String serviceTypeText; + /** + * 状态 + * + * - 1、退货申请 + * - 2、申请成功 + * - 3、申请失败 + * - 4、退货中 + * - 5、退货成功 + */ + private Integer status; + } +} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeyConstants.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeyConstants.java index 73c62cae2..fc7d901d9 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeyConstants.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/DictKeyConstants.java @@ -20,4 +20,8 @@ public class DictKeyConstants { * 订单 - 退货原因 */ public static final String ORDER_RETURN_REASON = "order_return_reason"; + /** + * 订单退货 - 退货类型 + */ + public static final String ORDER_RETURN_SERVICE_TYPE = "order_return_service_type"; } 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 0cca59617..263b1ac1d 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 @@ -32,7 +32,8 @@ public enum OrderErrorCodeEnum { ORDER_ITEM_ONLY_ONE(1008000200, "订单Item只有一个!"), ORDER_ITEM_SOME_NOT_EXISTS(1008000201, "有不存在的商品!"), - + // 订单退货 + ORDER_RETURN_NO_RETURN_APPLY(1008000400, "未退货申请"), // ========== 购物车 ========== CARD_ITEM_NOT_FOUND(1008003000, "购物车项不存在"), @@ -41,6 +42,8 @@ public enum OrderErrorCodeEnum { // 工具类服务 1008004000 DICT_SERVER_INVOKING_FAIL(1008004000, "字典服务调用失败!"), + + ; private final int code; diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderReturnReturnTypeEnum.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderReturnReturnTypeEnum.java new file mode 100644 index 000000000..08e595db9 --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderReturnReturnTypeEnum.java @@ -0,0 +1,36 @@ +package cn.iocoder.mall.order.api.constant; + +/** + * 订单退货 - returnType + * + * @author Sin + * @time 2019-04-27 11:53 + */ +public enum OrderReturnReturnTypeEnum { + + /** + * 状态 + * + * - 1、退货退款 + * - 2、退款 + */ + RETURN_REFUND(1, "退货退款"), + REFUND(2, "退款") + ; + private final int value; + + private final String name; + + OrderReturnReturnTypeEnum(int value, String name) { + this.value = value; + this.name = name; + } + + public int getValue() { + return value; + } + + public String getName() { + return name; + } +} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderReturnConvert.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderReturnConvert.java index 60522c4a4..8b19b1380 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderReturnConvert.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderReturnConvert.java @@ -1,12 +1,16 @@ package cn.iocoder.mall.order.biz.convert; +import cn.iocoder.mall.order.api.bo.OrderReturnInfoBO; import cn.iocoder.mall.order.api.dto.OrderReturnApplyDTO; import cn.iocoder.mall.order.api.dto.OrderReturnCreateDTO; +import cn.iocoder.mall.order.biz.dataobject.OrderItemDO; import cn.iocoder.mall.order.biz.dataobject.OrderReturnDO; import org.mapstruct.Mapper; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; +import java.util.List; + /** * 订单 return * @@ -23,4 +27,10 @@ public interface OrderReturnConvert { @Mappings({}) OrderReturnDO convert(OrderReturnApplyDTO orderReturnApplyDTO); + + @Mappings({}) + OrderReturnInfoBO.ReturnInfo convert(OrderReturnDO orderReturnDO); + + @Mappings({}) + List convert(List orderItemDOList); } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderItemMapper.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderItemMapper.java index d6ad2f35a..9ccf9a3a2 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderItemMapper.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderItemMapper.java @@ -4,7 +4,6 @@ import cn.iocoder.mall.order.biz.dataobject.OrderItemDO; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; -import javax.validation.constraints.NotNull; import java.util.Collection; import java.util.List; @@ -79,7 +78,7 @@ public interface OrderItemMapper { * @return */ List selectByDeletedAndOrderId( - @Param("orderId") Integer orderId, - @Param("deleted") @NotNull Integer deleted + @Param("deleted") Integer deleted, + @Param("orderId") Integer orderId ); } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderReturnDO.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderReturnDO.java index 117323efb..e65bc06e7 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderReturnDO.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dataobject/OrderReturnDO.java @@ -21,6 +21,10 @@ public class OrderReturnDO extends BaseDO { * 编号自动增长 */ private Integer id; + /** + * 服务号 + */ + private String serviceNumber; /** * 订单编号 */ @@ -68,12 +72,12 @@ public class OrderReturnDO extends BaseDO { */ private Date closingTime; /** - * 退款类型 + * 服务类型 * * - 1、退货退款 * - 2、退款 */ - private Integer returnType; + private Integer serviceType; /** * 状态 * 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 f3063fd7d..bfe47518b 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 @@ -59,7 +59,7 @@ public class OrderLogisticsServiceImpl implements OrderLogisticsService { // 获取订单所发货的订单 id List orderItemDOList = orderItemMapper.selectByDeletedAndOrderId( - orderId, DeletedStatusEnum.DELETED_NO.getValue()); + DeletedStatusEnum.DELETED_NO.getValue(), orderId); // 获取物流 信息 Set orderLogisticsIds = orderItemDOList.stream() 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 408cff3b1..7888190da 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 @@ -1,20 +1,28 @@ package cn.iocoder.mall.order.biz.service; +import cn.iocoder.common.framework.constant.DeletedStatusEnum; +import cn.iocoder.common.framework.exception.ServiceException; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.order.api.OrderReturnService; +import cn.iocoder.mall.order.api.bo.OrderReturnInfoBO; import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum; import cn.iocoder.mall.order.api.constant.OrderReturnStatusEnum; import cn.iocoder.mall.order.api.dto.OrderReturnApplyDTO; import cn.iocoder.mall.order.biz.convert.OrderReturnConvert; +import cn.iocoder.mall.order.biz.dao.OrderItemMapper; import cn.iocoder.mall.order.biz.dao.OrderMapper; import cn.iocoder.mall.order.biz.dao.OrderReturnMapper; import cn.iocoder.mall.order.biz.dataobject.OrderDO; +import cn.iocoder.mall.order.biz.dataobject.OrderItemDO; import cn.iocoder.mall.order.biz.dataobject.OrderReturnDO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import java.util.Date; +import java.util.List; +import java.util.UUID; /** * 订单退货 service @@ -29,6 +37,8 @@ public class OrderReturnServiceImpl implements OrderReturnService { @Autowired private OrderMapper orderMapper; @Autowired + private OrderItemMapper orderItemMapper; + @Autowired private OrderReturnMapper orderReturnMapper; @Override @@ -44,6 +54,8 @@ public class OrderReturnServiceImpl implements OrderReturnService { OrderReturnDO orderReturnDO = OrderReturnConvert.INSTANCE.convert(orderReturnDTO); orderReturnDO .setOrderId(checkOrder.getId()) + // TODO: 2019-04-27 Sin 服务号生成规则 + .setServiceNumber(UUID.randomUUID().toString().replaceAll("-", "").substring(0, 16)) .setOrderNo(checkOrder.getOrderNo()) .setStatus(OrderReturnStatusEnum.RETURN_APPLICATION.getValue()) .setCreateTime(new Date()); @@ -57,4 +69,32 @@ public class OrderReturnServiceImpl implements OrderReturnService { public String updateRefundSuccess(String orderId, Integer refundPrice) { return "success"; } + + @Override + public CommonResult orderApplyInfo(Integer orderId) { + + // 检查订单是否退货 + OrderReturnDO orderReturnDO = orderReturnMapper.selectByOrderId(orderId); + if (orderReturnDO == null) { + return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_RETURN_NO_RETURN_APPLY.getCode()); + } + + List orderItemDOList = orderItemMapper + .selectByDeletedAndOrderId(DeletedStatusEnum.DELETED_NO.getValue(), orderId); + + // 订单不存在 + if (CollectionUtils.isEmpty(orderItemDOList)) { + return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_NOT_EXISTENT.getCode()); + } + + // 转换 returnInfo + OrderReturnInfoBO.ReturnInfo returnInfo = OrderReturnConvert.INSTANCE.convert(orderReturnDO); + List itemList = OrderReturnConvert.INSTANCE.convert(orderItemDOList); + + OrderReturnInfoBO orderReturnInfoBO = new OrderReturnInfoBO() + .setOrderItems(itemList) + .setReturnInfo(returnInfo); + + return CommonResult.success(orderReturnInfoBO); + } } 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 1b2628223..277bbd4ac 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 @@ -141,7 +141,7 @@ public class OrderServiceImpl implements OrderService { } List orderItemDOList = orderItemMapper - .selectByDeletedAndOrderId(orderId, DeletedStatusEnum.DELETED_NO.getValue()); + .selectByDeletedAndOrderId(DeletedStatusEnum.DELETED_NO.getValue(), orderId); List orderItemBOList = OrderItemConvert.INSTANCE.convertOrderItemBO(orderItemDOList); return CommonResult.success(orderItemBOList); @@ -166,7 +166,7 @@ public class OrderServiceImpl implements OrderService { } List itemDOList = orderItemMapper - .selectByDeletedAndOrderId(orderId, DeletedStatusEnum.DELETED_NO.getValue()); + .selectByDeletedAndOrderId(DeletedStatusEnum.DELETED_NO.getValue(), orderId); List orderItems = OrderItemConvert.INSTANCE.convertOrderInfoWithOrderItem(itemDOList); @@ -187,6 +187,9 @@ public class OrderServiceImpl implements OrderService { orderLogisticsDetailDO = orderLogisticsDetailMapper.selectLatest(orderLogisticsIds); } + // 检查是否申请退货 + OrderReturnDO orderReturnDO = orderReturnMapper.selectByOrderId(orderId); + // convert 信息 OrderInfoBO.LogisticsDetail logisticsDetail = OrderLogisticsDetailConvert.INSTANCE.convertLogisticsDetail(orderLogisticsDetailDO); @@ -196,6 +199,13 @@ public class OrderServiceImpl implements OrderService { orderInfoBO.setRecipient(recipient); orderInfoBO.setOrderItems(orderItems); orderInfoBO.setLatestLogisticsDetail(logisticsDetail); + + // 是否退货 + if (orderReturnDO != null) { + orderInfoBO.setHasOrderReturn(orderReturnDO.getStatus()); + } else { + orderInfoBO.setHasOrderReturn(-1); + } return CommonResult.success(orderInfoBO); } @@ -405,7 +415,7 @@ public class OrderServiceImpl implements OrderService { // 再重新计算订单金额 List orderItemDOList = orderItemMapper - .selectByDeletedAndOrderId(orderId, DeletedStatusEnum.DELETED_NO.getValue()); + .selectByDeletedAndOrderId(DeletedStatusEnum.DELETED_NO.getValue(), orderId); // Integer price = orderCommon.calculatedPrice(orderItemDOList); // Integer amount = orderCommon.calculatedAmount(orderItemDOList); Integer price = -1; // TODO 芋艿,这里要修改,价格 @@ -522,7 +532,7 @@ public class OrderServiceImpl implements OrderService { // 获取当前有效的订单 item List orderItemDOList = orderItemMapper - .selectByDeletedAndOrderId(orderId, DeletedStatusEnum.DELETED_NO.getValue()); + .selectByDeletedAndOrderId(DeletedStatusEnum.DELETED_NO.getValue(), orderId); List effectiveOrderItems = orderItemDOList.stream() .filter(orderItemDO -> !orderItemIds.contains(orderItemDO.getId())) diff --git a/order/order-service-impl/src/main/resources/mapper/OrderItemMapper.xml b/order/order-service-impl/src/main/resources/mapper/OrderItemMapper.xml index d6aaa4b2f..593332489 100644 --- a/order/order-service-impl/src/main/resources/mapper/OrderItemMapper.xml +++ b/order/order-service-impl/src/main/resources/mapper/OrderItemMapper.xml @@ -147,10 +147,10 @@ diff --git a/order/order-service-impl/src/main/resources/mapper/OrderReturnMapper.xml b/order/order-service-impl/src/main/resources/mapper/OrderReturnMapper.xml index c51b44e22..2b6e82601 100644 --- a/order/order-service-impl/src/main/resources/mapper/OrderReturnMapper.xml +++ b/order/order-service-impl/src/main/resources/mapper/OrderReturnMapper.xml @@ -4,6 +4,7 @@ id, + service_number, order_id, order_no, order_logistics_id, @@ -13,7 +14,7 @@ logistics_time, receiver_time, closing_time, - return_type, + service_type, status, create_time, update_time @@ -24,16 +25,16 @@ --> INSERT INTO `order_return` ( - order_id, order_no, order_logistics_id, + service_number, order_id, order_no, order_logistics_id, reason, `describe`, approval_time, logistics_time, receiver_time, closing_time, - return_type, status, + service_type, status, create_time, update_time) VALUES ( - #{orderId}, #{orderNo}, #{orderLogisticsId}, + #{serviceNumber}, #{orderId}, #{orderNo}, #{orderLogisticsId}, #{reason}, #{describe}, #{approvalTime}, #{logisticsTime}, #{receiverTime}, #{closingTime}, - #{returnType}, #{status}, #{createTime}, #{updateTime}) + #{serviceType}, #{status}, #{createTime}, #{updateTime})