From f152a58fc41d7baa8a923ddadcb47979fdcf94aa Mon Sep 17 00:00:00 2001 From: sin <2943460818@qq.com> Date: Wed, 8 May 2019 21:33:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=80=E6=AC=BE=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/AdminOrderReturnController.java | 8 ++- .../mall/order/api/OrderReturnService.java | 2 +- .../api/constant/OrderErrorCodeEnum.java | 1 + .../api/constant/OrderReturnStatusEnum.java | 4 +- .../biz/service/OrderReturnServiceImpl.java | 50 ++++++++++++++++++- 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/admins/AdminOrderReturnController.java b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/admins/AdminOrderReturnController.java index f373c390c..c2e1bd906 100644 --- a/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/admins/AdminOrderReturnController.java +++ b/order/order-application/src/main/java/cn/iocoder/mall/order/application/controller/admins/AdminOrderReturnController.java @@ -1,5 +1,6 @@ package cn.iocoder.mall.order.application.controller.admins; +import cn.iocoder.common.framework.util.HttpUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.order.api.OrderReturnService; import cn.iocoder.mall.order.api.bo.OrderReturnListBO; @@ -12,6 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; + /** * 订单退货 * @@ -49,7 +52,8 @@ public class AdminOrderReturnController { } @PostMapping("confirm_order") - public CommonResult confirmOrder(@RequestParam("id") Integer id) { - return orderReturnService.refund(id); + public CommonResult confirmOrder(HttpServletRequest request, @RequestParam("id") Integer id) { + String ip = HttpUtil.getIp(request); + return orderReturnService.refund(id, ip); } } 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 55870b084..5d3efaad0 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 @@ -81,5 +81,5 @@ public interface OrderReturnService { * @param id * @return */ - CommonResult refund(Integer id); + CommonResult refund(Integer id, String ip); } 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 382e851fd..c6806757a 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 @@ -35,6 +35,7 @@ public enum OrderErrorCodeEnum { // 订单退货 ORDER_RETURN_NO_RETURN_APPLY(1008000400, "未退货申请"), ORDER_RETURN_NOT_EXISTENT(1008000401, "退货订单不存在"), + ORDER_RETURN_REFUND_FAILED(1008000402, "退款失败"), // ========== 购物车 ========== CARD_ITEM_NOT_FOUND(1008003000, "购物车项不存在"), diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderReturnStatusEnum.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderReturnStatusEnum.java index 383e6fcca..b1b9f0e8f 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderReturnStatusEnum.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderReturnStatusEnum.java @@ -17,15 +17,13 @@ public enum OrderReturnStatusEnum { * - 4、退货中 * - 5、已收货 * - 6、拒绝退款 - * - 7、退货成功 */ RETURN_APPLICATION(1, "退货申请"), APPLICATION_SUCCESSFUL(2, "申请成功"), APPLICATION_FAIL(3, "申请失败"), RETURN_IN(4, "退货中"), ORDER_RECEIPT(5, "确认收货"), - REFUSE_REFUND(6, "拒绝退款"), - RETURN_SUCCESS(7, "退货成功"), + RETURN_SUCCESS(6, "退货成功"), ; private final int value; 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 0568ca75b..428203e8b 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 @@ -10,6 +10,8 @@ import cn.iocoder.mall.order.api.bo.OrderReturnInfoBO; import cn.iocoder.mall.order.api.bo.OrderReturnListBO; import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum; import cn.iocoder.mall.order.api.constant.OrderReturnStatusEnum; +import cn.iocoder.mall.order.api.constant.OrderStatusEnum; +import cn.iocoder.mall.order.api.constant.PayAppId; import cn.iocoder.mall.order.api.dto.OrderReturnApplyDTO; import cn.iocoder.mall.order.api.dto.OrderReturnQueryDTO; import cn.iocoder.mall.order.biz.convert.OrderReturnConvert; @@ -19,9 +21,12 @@ 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 cn.iocoder.mall.pay.api.PayRefundService; +import cn.iocoder.mall.pay.api.dto.PayRefundSubmitDTO; import org.apache.dubbo.config.annotation.Reference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.Collections; @@ -48,6 +53,8 @@ public class OrderReturnServiceImpl implements OrderReturnService { @Reference(validation = "true") private OrderLogisticsService orderLogisticsService; + @Reference(validation = "true") + private PayRefundService payRefundService; @Override public CommonResult orderReturnApply(OrderReturnApplyDTO orderReturnDTO) { @@ -188,12 +195,51 @@ public class OrderReturnServiceImpl implements OrderReturnService { } @Override - public CommonResult refund(Integer id) { + @Transactional + public CommonResult refund(Integer id, String ip) { + OrderReturnDO orderReturnDO = orderReturnMapper.selectById(id); + if (orderReturnDO == null) { + return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_RETURN_NOT_EXISTENT.getCode()); + } // TODO: 2019/5/8 sin, 发送 MQ 消息,申请退货成功! // TODO: 2019/5/8 sin 退款:支付系统退款 // TODO: 2019/5/8 sin 退货+退款:退回商品签收后,支付系统退款 + // TODO: 2019/5/8 sin 事务一致性 [重要] - return null; + // 支付退款 + CommonResult payResult = payRefundService.submitRefund( + new PayRefundSubmitDTO() + .setAppId(PayAppId.APP_ID_SHOP_ORDER) + .setOrderId(String.valueOf(orderReturnDO.getOrderId())) + .setPrice(orderReturnDO.getRefundPrice()) + .setOrderDescription("") + .setCreateIp(ip) + ); + + if (!payResult.isSuccess()) { + return ServiceExceptionUtil.error(OrderErrorCodeEnum.ORDER_RETURN_REFUND_FAILED.getCode()); + } + + // 更新 订单退货 信息 + orderReturnMapper.updateByOrderId( + new OrderReturnDO() + .setId(id) + .setStatus(OrderReturnStatusEnum.RETURN_SUCCESS.getValue()) + ); + + // 更新订单 + orderMapper.updateById( + new OrderDO() + .setId(orderReturnDO.getOrderId()) + .setStatus(OrderStatusEnum.COMPLETED.getValue()) + ); + + // 更新订单 + orderItemMapper.updateByOrderId( + orderReturnDO.getOrderId(), + new OrderItemDO().setStatus(OrderStatusEnum.COMPLETED.getValue()) + ); + return CommonResult.success(null); } }