package com.tmerclub.cloud.systemtest.test.order;

import com.alibaba.fastjson2.JSON;
import com.tmerclub.cloud.api.delivery.dto.DeliveryOrderDTO;
import com.tmerclub.cloud.api.delivery.vo.DeliveryOrderFeignVO;
import com.tmerclub.cloud.common.order.dto.OrderDTO;
import com.tmerclub.cloud.common.order.vo.OrderAddrVO;
import com.tmerclub.cloud.order.dto.OrderAddrDTO;
import com.moyuer.cloud.systemtest.api.amount.PayApi;
import com.moyuer.cloud.systemtest.api.amount.ProductApi;
import com.moyuer.cloud.systemtest.api.order.*;
import com.moyuer.cloud.systemtest.api.store.TransportApi;
import com.moyuer.cloud.systemtest.api.supplier.SupplierOrderApi;
import com.moyuer.cloud.systemtest.api.supplier.SupplierProductApi;
import com.moyuer.cloud.systemtest.api.supplier.SupplierRefundApi;
import com.moyuer.cloud.systemtest.data.order.*;
import com.moyuer.cloud.systemtest.data.store.DeliveryData;
import com.moyuer.cloud.systemtest.data.supplier.SupplierOrderRefundDtoData;
import com.moyuer.cloud.systemtest.data.supplier.SupplierProductData;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;



/**
 * @author Tu
 */
public class SupplierOrderTest {

    @Test(description = "JK_20,取消删除订单流程",dataProvider = "freeProductId")
    public void cancelOrderTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        TimeUnit.SECONDS.sleep(2L);
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        MyOrderApi.cancel(orderNum);
        deleteProduct(productId,supplierProductId,transportId);
        MyOrderApi.delete(orderNum);

    }

    @Test(description = "JK_21,商家修改订单金额，供应商修改用户收货信息和修改物流信息完成流程",dataProvider = "freeProductId")
    public void changeAmountOrderTest(Long productId,Long supplierProductId,Long transportId)throws InterruptedException{
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        TimeUnit.SECONDS.sleep(2L);
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);

        OrderApi.changeOrderAmount(OrderAdminDtoData.getOrderAdminDto(orderNum));
        PayApi.orderPay(orderNum);
        OrderAddrVO orderAddrVO = SupplierOrderApi.info(orderNum).getOrderAddr();
        orderAddrVO.setAddr("供应商修改收货地址");
        OrderAddrDTO orderAddrDTO = JSON.parseObject(JSON.toJSONString(orderAddrVO), OrderAddrDTO.class);
        orderAddrDTO.setOrderId(orderNum);
        SupplierOrderApi.updateOrderDelivery(orderAddrDTO);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNum));

        List<DeliveryOrderFeignVO> delivery = OrderApi.infoOrderDelivery(orderNum);
        List<DeliveryOrderDTO> deliveryOrderDTOList = JSON.parseArray(JSON.toJSONString(delivery), DeliveryOrderDTO.class);
        deliveryOrderDTOList.forEach(s -> s.setDeliveryNo("xgh123123123123"));
        SupplierOrderApi.updateOrderDelivery(deliveryOrderDTOList);

        deleteProduct(productId,supplierProductId,transportId);
        MyOrderApi.receipt(orderNum);
    }

    @Test(description = "JK_22,无需快递发货订单完整流程",dataProvider = "freeTransportOrderNum")
    public void noDeliveryOrderTest(Long orderNum,Long productId,Long supplierProductId,Long transportId)throws InterruptedException{
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getNoDeliveryOrderDtoData(orderNum));
        TimeUnit.SECONDS.sleep(2L);
        MyOrderApi.receipt(orderNum);

        deleteProduct(productId,supplierProductId,transportId);
        CommentApi.addComment(SpuCommDtoData.getSpuCommDtoData(OrderApi.getOrderItemAndAddress(orderNum).getOrderItems().get(0).getOrderItemId()));
    }

    @Test(description = "JK_23,多次退款失败，退货成功订单",dataProvider = "freeTransportOrderNum")
    public void multiRefundOrderTest(Long orderNum,Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        TimeUnit.SECONDS.sleep(2L);
        //第一次 整单退款，商家直接拒绝
        refuseRefund(orderNum,false,1L,0L);

        //第二次 部分退款，供应商拒绝后发货
        refuseRefund(orderNum,true,2L,0L);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNum));
        //第三次 部分退款仅退款，商家直接拒绝
        refuseRefund(orderNum,true,1L,0L);
        //第四次 整单退款仅退款，供应商拒绝
        refuseRefund(orderNum,false,2L,0L);
        TimeUnit.SECONDS.sleep(2L);
        //第五次 部分退款 退货退货退款，商家自行处理，同意退款后用户发货，拒绝退款
        shopRefundDeliveryRefuse(orderNum,true,2L,0L);

        TimeUnit.SECONDS.sleep(2L);
        //第六次 整单退款 退货退款，转移供应商，同意退款后用户发货，拒绝退款,用户确认收货
        supplierRefundDeliveryRefuse(orderNum,false,2L,0L);

        MyOrderApi.receipt(orderNum);

        //第七次 整单退款 仅退款，商家直接拒绝
        refuseRefund(orderNum,false,1L,0L);
        //第八次 部分退款仅退款，供应商拒绝
        refuseRefund(orderNum,true,2L,0L);
        //第九次 整单退款 退货退款，商家自行处理，同意退款后用户发货，拒绝退款
        shopRefundDeliveryRefuse(orderNum,true,1L,0L);
        //第十次 部分退款 退货退款，转移供应商，退货退款成功
        receiveDeliveryRefund(orderNum,true,2L,0L);

        deleteProduct(productId,supplierProductId,transportId);
    }
    @Test(description = "JK_24,未发货订单申请退款成功-商家自行处理",dataProvider = "productId")
    public void unDeliveryShopReceiveRefundOrderTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        //第一笔订单整单退款
        Long orderNumFirst = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumFirst,false,1L,0L);

        //第二笔订单部分退款
        Long orderNumSec = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumSec,true,1L,0L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_25,未发货订单申请退款成功-移交供应商处理",dataProvider = "productId")
    public void unDeliverySupplierReceiveRefundOrderTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        //第一笔订单整单退款
        Long orderNumFirst = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumFirst,false,2L,0L);

        //第二笔订单部分退款
        Long orderNumSec = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumSec,true,2L,0L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_26,已发货订单申请仅退款成功-商家自行处理",dataProvider = "productId")
    public void deliveredShopReceiveRefundOrderTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        //第一笔订单整单退款
        Long orderNumFirst = payOrder(productId);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumFirst));
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumFirst,false,1L,0L);

        //第二笔订单部分退款
        Long orderNumSec = payOrder(productId);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumSec));
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumSec,true,1L,0L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_27,已发货订单申请仅退款成功-移交供应商处理",dataProvider = "productId")
    public void deliveredSupplierReceiveRefundOrderTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        //第一笔订单整单退款
        Long orderNumFirst = payOrder(productId);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumFirst));
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumFirst,false,2L,0L);

        //第二笔订单部分退款
        Long orderNumSec = payOrder(productId);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumSec));
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumSec,true,2L,0L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_28,已发货订单申请退货退款成功-商家自行处理",dataProvider = "productId")
    public void deliveredShopReceiveRefundDeliveryTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        //第一笔订单整单退款
        Long orderNumFirst = payOrder(productId);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumFirst));
        TimeUnit.SECONDS.sleep(2L);
        receiveDeliveryRefund(orderNumFirst,false,1L,0L);

        //第二笔订单部分退款
        Long orderNumSec = payOrder(productId);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumSec));
        TimeUnit.SECONDS.sleep(2L);
        receiveDeliveryRefund(orderNumSec,true,1L,0L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_29,已发货订单申请退货退款成功-移交供应商处理",dataProvider = "productId")
    public void deliveredSupplierReceiveRefundDeliveryTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        //第一笔订单整单退款
        Long orderNumFirst = payOrder(productId);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumFirst));
        TimeUnit.SECONDS.sleep(2L);
        receiveDeliveryRefund(orderNumFirst,false,2L,0L);

        //第二笔订单部分退款
        Long orderNumSec = payOrder(productId);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumSec));
        TimeUnit.SECONDS.sleep(2L);
        receiveDeliveryRefund(orderNumSec,true,2L,0L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_30,已完成订单申请仅退款成功-商家自行处理",dataProvider = "productId")
    public void receivedShopReceiveRefundTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        //第一笔订单整单退款
        Long orderNumFirst = payOrder(productId);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumFirst));
        TimeUnit.SECONDS.sleep(2L);
        MyOrderApi.receipt(orderNumFirst);
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumFirst,false,1L,0L);

        //第二笔订单部分退款
        Long orderNumSec = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumSec));
        MyOrderApi.receipt(orderNumSec);
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumSec,true,1L,0L);
        TimeUnit.SECONDS.sleep(2L);
        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_31,已完成订单申请仅退款成功-移交供应商处理",dataProvider = "productId")
    public void receivedSupplierReceiveRefundTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        //第一笔订单整单退款
        Long orderNumFirst = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumFirst));
        TimeUnit.SECONDS.sleep(2L);
        MyOrderApi.receipt(orderNumFirst);
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumFirst,false,2L,0L);

        //第二笔订单部分退款
        Long orderNumSec = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumSec));
        TimeUnit.SECONDS.sleep(2L);
        MyOrderApi.receipt(orderNumSec);
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumSec,true,2L,0L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_32,已完成订单申请退货退款成功-商家自行处理",dataProvider = "productId")
    public void receivedShopReceiveRefundDeliveryTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        //第一笔订单整单退款
        Long orderNumFirst = payOrder(productId);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumFirst));
        MyOrderApi.receipt(orderNumFirst);
        TimeUnit.SECONDS.sleep(2L);
        receiveDeliveryRefund(orderNumFirst,false,1L,0L);

        //第二笔订单部分退款
        Long orderNumSec = payOrder(productId);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumSec));
        MyOrderApi.receipt(orderNumSec);
        TimeUnit.SECONDS.sleep(2L);
        receiveDeliveryRefund(orderNumSec,true,1L,0L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_33,已完成订单申请退货退款成功-移交供应商处理",dataProvider = "productId")
    public void receivedSupplierReceiveRefundDeliveryTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        //第一笔订单整单退款
        Long orderNumFirst = payOrder(productId);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumFirst));
        TimeUnit.SECONDS.sleep(2L);
        MyOrderApi.receipt(orderNumFirst);
        TimeUnit.SECONDS.sleep(2L);
        receiveDeliveryRefund(orderNumFirst,false,2L,0L);

        //第二笔订单部分退款
        Long orderNumSec = payOrder(productId);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumSec));
        MyOrderApi.receipt(orderNumSec);
        TimeUnit.SECONDS.sleep(2L);
        receiveDeliveryRefund(orderNumSec,true,2L,0L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_34,未发货有运费订单部分金额退款-商家自行处理",dataProvider = "productId")
    public void unDeliverySupplierDeliveryTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        //第一笔订单整单退款
        Long orderNumFirst = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumFirst,true,1L,2077L);

        //第二笔订单部分退款
        Long orderNumSec = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumSec,true,1L,293L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_35,未发货有运费订单部分金额退款-转移供应商处理",dataProvider = "productId")
    public void unDeliverySupplierReceiveTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        //第一笔订单整单退款
        Long orderNumFirst = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumFirst,true,2L,2077L);

        //第二笔订单部分退款
        Long orderNumSec = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumSec,true,2L,293L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_36,已完成有运费订单部分金额仅退款-商家自行处理",dataProvider = "productId")
    public void completedShopReceiveTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        Long orderNum = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNum));
        TimeUnit.SECONDS.sleep(2L);
        MyOrderApi.receipt(orderNum);
        receiveRefund(orderNum,true,1L,1099L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_37,已完成有运费订单部分金额仅退款-商家自行处理",dataProvider = "productId")
    public void completedSupplierReceiveTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        Long orderNum = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNum));
        TimeUnit.SECONDS.sleep(2L);
        MyOrderApi.receipt(orderNum);
        receiveRefund(orderNum,true,2L,1099L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_38,已完成有运费订单部分金额退货退款-商家自行处理",dataProvider = "productId")
    public void completedRefundDeliveryShopReceiveTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        Long orderNum = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNum));
        TimeUnit.SECONDS.sleep(2L);
        MyOrderApi.receipt(orderNum);
        receiveRefund(orderNum,true,1L,1099L);
        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_39,已完成有运费订单部分金额退货退款-商家自行处理",dataProvider = "productId")
    public void completedRefundDeliverySupplierReceiveTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        Long orderNum = payOrder(productId);
        TimeUnit.SECONDS.sleep(2L);
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNum));
        TimeUnit.SECONDS.sleep(2L);
        MyOrderApi.receipt(orderNum);
        receiveRefund(orderNum,true,2L,1099L);
        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "JK_40,待采购订单采购完整流程",dataProvider = "productId")
    public void unBuySupplierTest(Long productId,Long supplierProductId,Long transportId) throws InterruptedException  {
        Long orderNum = getOrderNum(productId);
        OrderApi.changeOrderAmount(OrderAdminDtoData.getOrderAdminDto(orderNum,877L,800L));
        PayApi.orderPay(orderNum);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.sourcingOrder(OrderAdminDtoData.getSourcingOrderAdminDto(orderNum));
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNum));
        TimeUnit.SECONDS.sleep(2L);
        MyOrderApi.receipt(orderNum);
        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "采购订单退款成功完整流程", dataProvider = "productId")
    public void unBuySupplierRefundTest(Long productId, Long supplierProductId, Long transportId) throws InterruptedException {
        //第一笔订单整单退款
        Long orderNumFirst = getOrderNum(productId);
        OrderApi.changeOrderAmount(OrderAdminDtoData.getOrderAdminDto(orderNumFirst,888L,800L));
        PayApi.orderPay(orderNumFirst);
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumFirst, false, 1L, null);

        //第二笔订单部分退款-修改退款金额为5.33
        Long orderNumSec = getOrderNum(productId);
        OrderApi.changeOrderAmount(OrderAdminDtoData.getOrderAdminDto(orderNumSec,888L,800L));
        PayApi.orderPay(orderNumSec);
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumSec, true, 1L, 533L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "采购订单退款成功-商家自行处理完整流程", dataProvider = "productId")
    public void buySupplierRefundShopReceiveTest(Long productId, Long supplierProductId, Long transportId) throws InterruptedException {
        //第一笔订单整单退款
        Long orderNumFirst = getOrderNum(productId);
        OrderApi.changeOrderAmount(OrderAdminDtoData.getOrderAdminDto(orderNumFirst,888L,800L));
        PayApi.orderPay(orderNumFirst);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.sourcingOrder(OrderAdminDtoData.getSourcingOrderAdminDto(orderNumFirst));
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumFirst, false, 1L, null);

        //第二笔订单部分退款-修改退款金额为5.33
        Long orderNumSec = getOrderNum(productId);
        OrderApi.changeOrderAmount(OrderAdminDtoData.getOrderAdminDto(orderNumSec,888L,800L));
        PayApi.orderPay(orderNumSec);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.sourcingOrder(OrderAdminDtoData.getSourcingOrderAdminDto(orderNumSec));
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumSec, true, 1L, 533L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "采购订单退款成功-移交供应商处理完整流程", dataProvider = "productId")
    public void buySupplierRefundSupplierReceiveTest(Long productId, Long supplierProductId, Long transportId) throws InterruptedException {
        //第一笔订单整单退款
        Long orderNumFirst = getOrderNum(productId);
        OrderApi.changeOrderAmount(OrderAdminDtoData.getOrderAdminDto(orderNumFirst,888L,800L));
        PayApi.orderPay(orderNumFirst);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.sourcingOrder(OrderAdminDtoData.getSourcingOrderAdminDto(orderNumFirst));
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumFirst, false, 2L, null);

        //第二笔订单部分退款-修改退款金额为5.33
        Long orderNumSec = getOrderNum(productId);
        OrderApi.changeOrderAmount(OrderAdminDtoData.getOrderAdminDto(orderNumSec,888L,800L));
        PayApi.orderPay(orderNumSec);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.sourcingOrder(OrderAdminDtoData.getSourcingOrderAdminDto(orderNumSec));
        TimeUnit.SECONDS.sleep(2L);
        receiveRefund(orderNumSec, true, 2L, 533L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "已完成采购订单退货退款成功-商家自行处理完整流程", dataProvider = "productId")
    public void completeBuySupplierRefundShopReceiveTest(Long productId, Long supplierProductId, Long transportId) throws InterruptedException {
        //第一笔订单整单退款
        Long orderNumFirst = getOrderNum(productId);
        OrderApi.changeOrderAmount(OrderAdminDtoData.getOrderAdminDto(orderNumFirst,888L,800L));
        PayApi.orderPay(orderNumFirst);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.sourcingOrder(OrderAdminDtoData.getSourcingOrderAdminDto(orderNumFirst));
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumFirst));
        TimeUnit.SECONDS.sleep(2L);
        MyOrderApi.receipt(orderNumFirst);
        TimeUnit.SECONDS.sleep(2L);
        receiveDeliveryRefund(orderNumFirst, false, 1L, null);

        //第二笔订单部分退款-修改退款金额为5.33
        Long orderNumSec = getOrderNum(productId);
        OrderApi.changeOrderAmount(OrderAdminDtoData.getOrderAdminDto(orderNumSec,888L,800L));
        PayApi.orderPay(orderNumSec);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.sourcingOrder(OrderAdminDtoData.getSourcingOrderAdminDto(orderNumSec));
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumSec));
        TimeUnit.SECONDS.sleep(2L);
        MyOrderApi.receipt(orderNumSec);
        TimeUnit.SECONDS.sleep(2L);
        receiveDeliveryRefund(orderNumSec, true, 1L, 533L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "已完成采购订单退货退款成功-移交供应商处理完整流程", dataProvider = "productId")
    public void completeBuySupplierRefundSupplierReceiveTest(Long productId, Long supplierProductId, Long transportId) throws InterruptedException {
        //第一笔订单整单退款
        Long orderNumFirst = getOrderNum(productId);
        OrderApi.changeOrderAmount(OrderAdminDtoData.getOrderAdminDto(orderNumFirst,888L,800L));
        PayApi.orderPay(orderNumFirst);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.sourcingOrder(OrderAdminDtoData.getSourcingOrderAdminDto(orderNumFirst));
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumFirst));
        TimeUnit.SECONDS.sleep(2L);
        MyOrderApi.receipt(orderNumFirst);
        TimeUnit.SECONDS.sleep(2L);
        receiveDeliveryRefund(orderNumFirst, false, 2L, null);

        //第二笔订单部分退款-修改退款金额为5.33
        Long orderNumSec = getOrderNum(productId);
        OrderApi.changeOrderAmount(OrderAdminDtoData.getOrderAdminDto(orderNumSec,888L,800L));
        PayApi.orderPay(orderNumSec);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.sourcingOrder(OrderAdminDtoData.getSourcingOrderAdminDto(orderNumSec));
        SupplierOrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumSec));
        TimeUnit.SECONDS.sleep(2L);
        MyOrderApi.receipt(orderNumSec);
        TimeUnit.SECONDS.sleep(2L);
        receiveDeliveryRefund(orderNumSec, true, 2L, 533L);

        deleteProduct(productId,supplierProductId,transportId);
    }

    @Test(description = "商家代销供应商多商品订单完整流程")
    public void differentSupplerProductOrderTest() throws InterruptedException {
        Long supplierProductIdA = SupplierProductData.getSupplierProductId(6600L, DeliveryData.getSupplierFreeFeeDelivery(true), true);
        Long supplierProductIdB = SupplierProductData.getSupplierProductId(6600L, DeliveryData.getSupplierFreeFeeDelivery(true), true);

        Long productIdA = SupplierProductData.getProductId(supplierProductIdA, 8800L, 1, null, true, true);
        Long productIdB = SupplierProductData.getProductId(supplierProductIdB, 8800L, 1, null, true, true);

        ShopCartApi.addItem(ShopCartData.getShopCartItem(productIdA));
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productIdB));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productIdA));
        TimeUnit.SECONDS.sleep(2L);
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productIdA)).get(0);
        PayApi.orderPay(orderNum);

        ProductApi.delete(productIdB, true);
        SupplierProductApi.delete(supplierProductIdB, true);
        ProductApi.delete(productIdA, true);
        SupplierProductApi.delete(supplierProductIdA, true);
    }

    @Test(description = "商家发货的供应商商品订单退款完整流程")
    public void shopDeliverySupplierProductOrderTest() throws InterruptedException {
        Long supplierProductId = SupplierProductData.getSupplierProductId(6600L, DeliveryData.getSupplierFreeFeeDelivery(true), true);

        Long productId = SupplierProductData.getProductId(supplierProductId, 8800L, 2, DeliveryData.getFreeFeeDelivery(true), true, true);

        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId, 1));
        TimeUnit.SECONDS.sleep(2L);
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNum);

        //申请第一次退款，部分退款 等待保存
        TimeUnit.SECONDS.sleep(2L);
        Long refundIdFirst= OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundDTO(orderNum,0L));
        ShopOrderRefundApi.infoByRefundSn(refundIdFirst);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getRufuseOrderRefundDTO(refundIdFirst));

        //申请第二次退款，整单退款
        TimeUnit.SECONDS.sleep(2L);
        Long refundIdSec= OrderRefundApi.apply(OrderRefundDtoData.getAllOrderRefundDTO(orderNum));
        ShopOrderRefundApi.infoByRefundSn(refundIdSec);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getRufuseOrderRefundDTO(refundIdSec));
        //发货后对订单进行部分退款仅退款 & 整单退货退款：先同意退款申请，发货后拒绝退款
        OrderApi.delivery(DeliveryOrderDtoData.getNoDeliveryOrderDtoData(orderNum));
        TimeUnit.SECONDS.sleep(2L);
        Long refundIdTir= OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundDTO(orderNum,0L));
        ShopOrderRefundApi.infoByRefundSn(refundIdTir);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getRufuseOrderRefundDTO(refundIdTir));

        TimeUnit.SECONDS.sleep(2L);
        Long refundIdFourth= OrderRefundApi.apply(OrderRefundDtoData.getAllOrderRefundDeliveryDTO(orderNum));
        ShopOrderRefundApi.infoByRefundSn(refundIdFourth);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveRefundDTO(refundIdFourth));
        OrderRefundApi.submitExpress(OrderRefundDeliveryDtoData.getOrderRefundDeliveryDTO(refundIdFourth));
        TimeUnit.SECONDS.sleep(1L);
        ShopOrderRefundApi.returnMoney(ShopOrderRefundDtoData.getRefuseDeliveryRefundDTO(refundIdFourth));
        //确认收货后，对订单进行部分退款仅退款 & 整单退货退款且同意
        MyOrderApi.receipt(orderNum);
        TimeUnit.SECONDS.sleep(2L);
        Long refundIdFirth= OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundDTO(orderNum,0L));
        ShopOrderRefundApi.infoByRefundSn(refundIdFirth);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getRufuseOrderRefundDTO(refundIdFirth));

        TimeUnit.SECONDS.sleep(2L);
        Long refundIdSixth= OrderRefundApi.apply(OrderRefundDtoData.getAllOrderRefundDeliveryDTO(orderNum));
        ShopOrderRefundApi.infoByRefundSn(refundIdSixth);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveRefundDTO(refundIdSixth));
        OrderRefundApi.submitExpress(OrderRefundDeliveryDtoData.getOrderRefundDeliveryDTO(refundIdSixth));
        ShopOrderRefundApi.returnMoney(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundIdSixth));

        ProductApi.delete(productId, true);
        SupplierProductApi.delete(supplierProductId, true);
    }

    @Test(description = "多商家代销同一供应商商品订单完整流程")
    public void multipleShopSameSupplerProductOrderTest() {
        Long transportId = DeliveryData.getSupplierFreeFeeDelivery(true);
        Long supplierProductId = SupplierProductData.getSupplierProductId(6600L, transportId, true);
        //A店铺代销商品A
        Long productIdA = SupplierProductData.getProductId(supplierProductId, 8800L, 1, null, true, true);
        //B店铺代销商品B
        Long productIdB = SupplierProductData.getProductId(supplierProductId, 8800L, 1, null, true, false);

        ShopCartApi.addItem(ShopCartData.getShopCartItem(productIdA, 1));
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productIdB, 1));
        //确认订单数据
        Long shopIdA = ProductApi.getProductInfo(productIdA).getShopId();
        Long shopIdB = ProductApi.getProductInfo(productIdB).getShopId();
        OrderDTO orderDTO = OrderDtoData.getOrderDtoData(Arrays.asList(shopIdA, shopIdB));
        //确认订单
        MyOrderApi.confirm(orderDTO);
        //提交订单
        List<Long> orderNumberList = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(Arrays.asList(shopIdA, shopIdB)));
        //支付订单
        PayApi.orderPay(orderNumberList);

        ProductApi.delete(productIdB, false);
        ProductApi.delete(productIdA, true);
        SupplierProductApi.delete(supplierProductId, true);
    }

    @Test(description = "商家代销多供应商商品订单完整流程")
    public void sameShopMultipleSupplerProductOrderTest() throws InterruptedException {
        Long transportId = DeliveryData.getSupplierFreeFeeDelivery(true);
        //A供应商发布供应商商品A
        Long supplierProductIdA = SupplierProductData.getSupplierProductId(6600L, transportId, true);
        //B供应商发布供应商商品B
        Long supplierProductIdB = SupplierProductData.getSupplierProductId(6600L, transportId, false);
        //A店铺代销商品A
        Long productIdA = SupplierProductData.getProductId(supplierProductIdA, 8800L, 1, null, true, true);
        //A店铺代销商品B
        Long productIdB = SupplierProductData.getProductId(supplierProductIdB, 8800L, 1, null, false, true);

        ShopCartApi.addItem(ShopCartData.getShopCartItem(productIdA, 1));
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productIdB, 1));
        //确认订单数据
        Long shopId = ProductApi.getProductInfo(productIdA).getShopId();
        OrderDTO orderDTO = OrderDtoData.getOrderDtoData(Collections.singletonList(shopId));
        //确认订单
        MyOrderApi.confirm(orderDTO);
        //提交订单
        TimeUnit.SECONDS.sleep(2L);
        List<Long> orderNumberList = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(Collections.singletonList(shopId)));
        //支付订单
        PayApi.orderPay(orderNumberList);

        ProductApi.delete(productIdB, true);
        ProductApi.delete(productIdA, true);
        SupplierProductApi.delete(supplierProductIdB, false);
        SupplierProductApi.delete(supplierProductIdA, true);
    }

    @Test(description = "多商家代销多供应商商品订单完整流程")
    public void multipleShopMultipleSupplerProductOrderTest() throws InterruptedException {
        //A供应商包邮运费模板
        Long feeTransportIdA = DeliveryData.getSupplierFreeFeeDelivery(true);
        //A供应商运费模板8元/件
        TransportApi.addSupplierTransport(DeliveryData.getTransportDTO(0, 1D, 800L, 1D, 800L, 0, null, null, null), true);
        Long transportIdA = TransportApi.supplierTransportPage(true).get(0).getTransportId();
        //A供应商发布包邮商品A1
        Long supplierProductIdA1 = SupplierProductData.getSupplierProductId(6600L, feeTransportIdA, true);
        //A供应商发货有运费商品A2
        Long supplierProductIdA2 = SupplierProductData.getSupplierProductId(6600L, transportIdA, true);

        //B供应商包邮运费模板
        Long feeTransportIdB = DeliveryData.getSupplierFreeFeeDelivery(false);
        //A供应商运费模板8元/件
        TransportApi.addSupplierTransport(DeliveryData.getTransportDTO(0, 1D, 800L, 1D, 800L, 0, null, null, null), false);
        Long transportIdB = TransportApi.supplierTransportPage(false).get(0).getTransportId();
        //A供应商发布包邮商品A1
        Long supplierProductIdB1 = SupplierProductData.getSupplierProductId(6600L, feeTransportIdB, false);
        //A供应商发货有运费商品A2
        Long supplierProductIdB2 = SupplierProductData.getSupplierProductId(6600L, transportIdB, false);


        //A店铺代销商品A1
        Long productIdA1 = SupplierProductData.getProductId(supplierProductIdA1, 8800L, 1, null, true, true);
        //A店铺代销商品A2
        Long productIdA2 = SupplierProductData.getProductId(supplierProductIdA2, 8800L, 1, null, true, true);
        //A店铺代销商品B1
        Long productIdA3 = SupplierProductData.getProductId(supplierProductIdB1, 8800L, 1, null, false, true);
        //A店铺代销商品B2
        Long productIdA4 = SupplierProductData.getProductId(supplierProductIdB2, 8800L, 1, null, false, true);

        //B店铺代销商品A1
        Long productIdB1 = SupplierProductData.getProductId(supplierProductIdA1, 8800L, 1, null, true, false);
        //B店铺代销商品A2
        Long productIdB2 = SupplierProductData.getProductId(supplierProductIdA2, 8800L, 1, null, true, false);
        //B店铺代销商品B1
        Long productIdB3 = SupplierProductData.getProductId(supplierProductIdB1, 8800L, 1, null, false, false);
        //B店铺代销商品B2
        Long productIdB4 = SupplierProductData.getProductId(supplierProductIdB2, 8800L, 1, null, false, false);

        ShopCartApi.addItem(ShopCartData.getShopCartItem(productIdA1, 1));
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productIdA2, 1));
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productIdA3, 1));
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productIdA4, 1));
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productIdB1, 1));
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productIdB2, 1));
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productIdB3, 1));
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productIdB4, 1));
        //确认订单数据
        Long shopIdA = ProductApi.getProductInfo(productIdA1).getShopId();
        Long shopIdB = ProductApi.getProductInfo(productIdB1).getShopId();
        OrderDTO orderDTO = OrderDtoData.getOrderDtoData(Arrays.asList(shopIdA, shopIdB));
        //确认订单
        MyOrderApi.confirm(orderDTO);
        //提交订单
        TimeUnit.SECONDS.sleep(2L);
        List<Long> orderNumberList = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(Arrays.asList(shopIdA, shopIdB)));
        //支付订单
        PayApi.orderPay(orderNumberList);

        ProductApi.delete(productIdB4, false);
        ProductApi.delete(productIdB3, false);
        ProductApi.delete(productIdB2, false);
        ProductApi.delete(productIdB1, false);
        SupplierProductApi.delete(supplierProductIdB2, false);
        SupplierProductApi.delete(supplierProductIdB1, false);
        TransportApi.deleteSupplierTransport(transportIdB, false);
        ProductApi.delete(productIdA4, true);
        ProductApi.delete(productIdA3, true);
        ProductApi.delete(productIdA2, true);
        ProductApi.delete(productIdA1, true);
        SupplierProductApi.delete(supplierProductIdA2, true);
        SupplierProductApi.delete(supplierProductIdA1, true);
        TransportApi.deleteSupplierTransport(transportIdA, true);
    }

    @DataProvider(name = "freeTransportOrderNum")
    private Object[][] freeTransportOrderNum() throws InterruptedException {
        Long transportId = DeliveryData.getSupplierFreeFeeDelivery(true);
        Long supplierProductId = SupplierProductData.getSupplierProductId(1099L, transportId, true);
        Long productId = SupplierProductData.getProductId(supplierProductId, 8888L, 1, null, true, true);
        Long orderNum = payOrder(productId);
        return new Object[][]{{orderNum,productId,supplierProductId,transportId}};
    }
    @DataProvider(name = "orderNum")
    private Object[][] orderNum() throws InterruptedException {
        TransportApi.addSupplierTransport(DeliveryData.getTransportDTO(), true);
        Long transportId = TransportApi.supplierTransportPage(true).get(0).getTransportId();
        Long supplierProductId = SupplierProductData.getSupplierProductId(1099L, transportId, true);
        Long productId = SupplierProductData.getProductId(supplierProductId, 8888L, 1, null, true, true);
        Long orderNum = payOrder(productId);
        return new Object[][]{{orderNum,productId,supplierProductId,transportId}};
    }

    @DataProvider(name = "freeProductId")
    private Object[][] freeProductId(){
        Long transportId = DeliveryData.getSupplierFreeFeeDelivery(true);
        Long supplierProductId = SupplierProductData.getSupplierProductId(1099L, transportId, true);
        Long productId = SupplierProductData.getProductId(supplierProductId, 8888L, 1, null, true, true);
        return new Object[][]{{productId,supplierProductId,transportId}};
    }
    @DataProvider(name = "productId")
    private Object[][] productId(){
        TransportApi.addSupplierTransport(DeliveryData.getTransportDTO(), true);
        Long transportId = TransportApi.supplierTransportPage(true).get(0).getTransportId();
        Long supplierProductId = SupplierProductData.getSupplierProductId(1099L, transportId, true);
        Long productId = SupplierProductData.getProductId(supplierProductId, 8888L, 1, null, true, true);
        return new Object[][]{{productId,supplierProductId,transportId}};
    }

    private Long getOrderNum(Long productId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        TimeUnit.SECONDS.sleep(2L);
        return MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
    }

    private Long payOrder(Long productId) throws InterruptedException {
        Long orderNum = getOrderNum(productId);
        PayApi.orderPay(orderNum);
        TimeUnit.SECONDS.sleep(2L);
        return orderNum;
    }

    private void deleteProduct(Long productId,Long supplierProductId,Long transportId) {
        ProductApi.delete(productId, true);
        SupplierProductApi.delete(supplierProductId, true);
        if (TransportApi.info(transportId, true).getIsFreeFee().equals(0)) {
            TransportApi.deleteSupplierTransport(transportId, true);
        }
    }
    /**
     * type==true时，部分退款,否则为整单退款
     * role==1时，为商家，否者为供应商
     * 仅退款申请
     * */
    private void refuseRefund(Long orderNum,Boolean type,Long role,Long refundAmount) {
        Long refundId;
        if (type){
            refundId = OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundDTO(orderNum,refundAmount));
        } else {
            refundId = OrderRefundApi.apply(OrderRefundDtoData.getAllOrderRefundDTO(orderNum));
        }
        ShopOrderRefundApi.infoByRefundSn(refundId);
        if(role == 1){
            ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getRufuseOrderRefundDTO(refundId));
        }else {
            ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getSupplierRefundDTO(refundId));
            SupplierRefundApi.processRefundOrder(SupplierOrderRefundDtoData.getRufuseOrderRefundDTO(refundId));
        }
    }

    /**
     * type==true时，部分退款,否则为整单退款
     * role==1时，为商家，否者为供应商
     * 仅退款申请
     * */
    private void receiveRefund(Long orderNum,Boolean type,Long role,Long refundAmount) {
        Long refundId;
        if (type){
            refundId = OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundDTO(orderNum,refundAmount));
        } else {
            refundId = OrderRefundApi.apply(OrderRefundDtoData.getAllOrderRefundDTO(orderNum));
        }

        ShopOrderRefundApi.infoByRefundSn(refundId);
        if(role == 1){
            ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveRefundDTO(refundId));
        }else {
            ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getSupplierRefundDTO(refundId));
            SupplierRefundApi.processRefundOrder(SupplierOrderRefundDtoData.getSupplierReceiveRefundDTO(refundId));
        }
    }

    /**
     * type==true时，部分退款,否则为整单退款
     * 商家自行处理退货退款申请
     * */
    private void shopRefundDeliveryRefuse(Long orderNum,Boolean type,Long step,Long refundAmount) {
        Long refundId;
        if (type){
            refundId = OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundDeliveryDTO(orderNum,refundAmount));
        } else {refundId = OrderRefundApi.apply(OrderRefundDtoData.getAllOrderRefundDeliveryDTO(orderNum));
        }
        ShopOrderRefundApi.infoByRefundSn(refundId);
        if (step == 1){
            //商家在第一步拒绝退货退款申请
            ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getRufuseOrderRefundDTO(refundId));
        }else {
            ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundId));
            OrderRefundApi.submitExpress(OrderRefundDeliveryDtoData.getOrderRefundDeliveryDTO(refundId));
            ShopOrderRefundApi.returnMoney(ShopOrderRefundDtoData.getRefuseDeliveryRefundDTO(refundId));
        }
    }
    /**
     * type==true时，部分退款,否则为整单退款
     * step==1时，在申请退货退款的第一步拒绝退款 否则，在申请退货退款的第二步拒绝退款
     * 供应商 在第二步拒绝退货退款申请
     * */
    private void supplierRefundDeliveryRefuse(Long orderNum,Boolean type,Long step,Long refundAmount) {
        Long refundId;
        if (type){
            refundId = OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundDeliveryDTO(orderNum,refundAmount));
        } else {refundId = OrderRefundApi.apply(OrderRefundDtoData.getAllOrderRefundDeliveryDTO(orderNum));
        }
        ShopOrderRefundApi.infoByRefundSn(refundId);
        if (step == 1){
            //供应商在第一步拒绝退货退款申请
            ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getSupplierRefundDTO(refundId));
            SupplierRefundApi.processRefundOrder(SupplierOrderRefundDtoData.getRufuseOrderRefundDTO(refundId));
        }else {
            ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getSupplierRefundDTO(refundId));
            SupplierRefundApi.processRefundOrder(SupplierOrderRefundDtoData.getSupplierReceiveRefundDTO(refundId));
            OrderRefundApi.submitExpress(OrderRefundDeliveryDtoData.getOrderRefundDeliveryDTO(refundId));
            SupplierRefundApi.returnMoneyRefundOrder(SupplierOrderRefundDtoData.getRefuseDeliveryRefundDTO(refundId));
        }}
    /**
     * 同意退货退款
     * type==true时，部分退款,否则为整单退款
     * role=1，商家同意，否则，供应商同意
     * */
    private void receiveDeliveryRefund(Long orderNum,Boolean type,Long role,Long refundAmount){
        Long refundId;
        if (type){
            refundId = OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundDeliveryDTO(orderNum,refundAmount));
        } else {refundId = OrderRefundApi.apply(OrderRefundDtoData.getAllOrderRefundDeliveryDTO(orderNum));
        }
        ShopOrderRefundApi.infoByRefundSn(refundId);
        if (role == 1){
            ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundId));
            OrderRefundApi.submitExpress(OrderRefundDeliveryDtoData.getOrderRefundDeliveryDTO(refundId));
            ShopOrderRefundApi.returnMoney(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundId));
        }else {
            ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getSupplierRefundDTO(refundId));
            SupplierRefundApi.processRefundOrder(SupplierOrderRefundDtoData.getSupplierReceiveRefundDTO(refundId));
            OrderRefundApi.submitExpress(OrderRefundDeliveryDtoData.getOrderRefundDeliveryDTO(refundId));
            SupplierRefundApi.returnMoneyRefundOrder(SupplierOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundId));
        }
    }
}
