添加退款操作
This commit is contained in:
parent
87574d5e7b
commit
f152a58fc4
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,5 +81,5 @@ public interface OrderReturnService {
|
|||
* @param id
|
||||
* @return
|
||||
*/
|
||||
CommonResult refund(Integer id);
|
||||
CommonResult refund(Integer id, String ip);
|
||||
}
|
||||
|
|
|
@ -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, "购物车项不存在"),
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue