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.product.vo.app.CategoryAppVO;
import com.tmerclub.cloud.multishop.mongo.MongoShopWalletLogBO;
import com.tmerclub.cloud.order.dto.OrderStationDTO;
import com.tmerclub.cloud.order.vo.OrderDetailVO;
import com.moyuer.cloud.systemtest.api.amount.CategoryApi;
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.SameCityApi;
import com.moyuer.cloud.systemtest.api.store.ShopWalletApi;
import com.moyuer.cloud.systemtest.api.store.TransportApi;
import com.moyuer.cloud.systemtest.data.amount.SpuData;
import com.moyuer.cloud.systemtest.data.order.*;
import com.moyuer.cloud.systemtest.data.platform.CategoryDtoData;
import com.moyuer.cloud.systemtest.data.store.DeliveryData;
import com.moyuer.cloud.systemtest.data.store.SameCityDtoData;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;

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

    private List<Long> getCategoryId() {
        List<CategoryAppVO> categoryAppVOList = CategoryApi.listShopCategory(true);
        Long shopCategoryId = categoryAppVOList.get(categoryAppVOList.size() - 1).getCategoryId();
        Long categoryId = CategoryApi.listSigningCategory(true).get(0).getCategoryId();
        CategoryApi.update(CategoryDtoData.getCategoryDTO(categoryId));
        return Stream.of(categoryId, shopCategoryId).collect(Collectors.toList());
    }

    /**
     * 无运费商品
     * */
    @DataProvider(name = "realProductDeliveryFree")
    private Object[][] realProductDeliveryFree() {
        List<Long> categoryIds = getCategoryId();
        Long transportId = DeliveryData.getFreeFeeDelivery(true);
        Long productId = ProductApi.createProduct(SpuData.getRealSpu(categoryIds.get(0), categoryIds.get(1), transportId, 1000L), true);
        return new Object[][]{{productId}};
    }
    /**
     * 广东可配送，8元运费商品
     * */
    @DataProvider(name = "realProductDelivery")
    private Object[][] realProductDeliveryNoFree() {
        List<Long> categoryIds = getCategoryId();
        TransportApi.addTransport(DeliveryData.getTransportDTO(), true);
        Long transportId = TransportApi.infoTransport(true).get(0).getTransportId();
        Long productId = ProductApi.createProduct(SpuData.getRealSpu(categoryIds.get(0), categoryIds.get(1), transportId, 8800L), true);
        return new Object[][]{{productId}};
    }

    @Test(description = "JK_01,实物商品订单取消删除", dataProvider = "realProductDeliveryFree")
    public void realOrderCancel(Long productId) {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        MyOrderApi.cancel(orderNum);
        ProductApi.delete(productId, true);
        MyOrderApi.delete(orderNum);
    }

    @Test(description = "JK_02,实物商品订单发货完整流程", dataProvider = "realProductDeliveryFree")
    public void realProductDeliveryOrderTestCase(Long productId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNum);

        TimeUnit.SECONDS.sleep(2L);
        OrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNum));
        MyOrderApi.receipt(orderNum);
        CommentApi.addComment(SpuCommDtoData.getSpuCommDtoData(OrderApi.getOrderItemAndAddress(orderNum).getOrderItems().get(0).getOrderItemId()));
        ProductApi.delete(productId, true);

        //验证运行后数据是否正确
        TimeUnit.SECONDS.sleep(2L);
        List<MongoShopWalletLogBO> mongoShopWalletLogBOList = ShopWalletApi.getMongoShopWalletLogBO(orderNum, true);
        Assert.assertEquals(mongoShopWalletLogBOList.size(), 1);
        WalletAssert.shopWalletLogAssert(mongoShopWalletLogBOList.get(0), 0, 1, 980L, 1000L, 0L, 0L, 0L, 20L, 0);
    }

    @Test(description = "JK_03,修改订单金额、用户收货信息和物流信息完整流程", dataProvider = "realProductDeliveryFree")
    public void orderChangeAmountDeliveryTestCase(Long productId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);

        OrderApi.infoOrder(orderNum);
        OrderApi.changeOrderAmount(OrderAdminDtoData.getOrderAdminDto(orderNum));

        OrderApi.infoOrderAddr(orderNum);
        OrderApi.changeOrderAddrCheck(orderNum);
        OrderApi.changeOrderAddr(OrderAddrDtoData.getChangeOrderAddrDTO(orderNum));
        PayApi.orderPay(orderNum);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNum));
        List<DeliveryOrderFeignVO> delivery = OrderApi.infoOrderDelivery(orderNum);

        List<DeliveryOrderDTO> deliveryOrderDtos = JSON.parseArray(JSON.toJSONString(delivery), DeliveryOrderDTO.class);
        deliveryOrderDtos.forEach(s -> s.setDeliveryNo("xgh123123123123"));
        OrderApi.updateOrderDelivery(deliveryOrderDtos);
        MyOrderApi.receipt(orderNum);
        CommentApi.addComment(SpuCommDtoData.getSpuCommDtoData(OrderApi.getOrderItemAndAddress(orderNum).getOrderItems().get(0).getOrderItemId()));
        ProductApi.delete(productId, true);

        //验证运行后数据是否正确
        TimeUnit.SECONDS.sleep(2L);
        List<MongoShopWalletLogBO> mongoShopWalletLogBOList = ShopWalletApi.getMongoShopWalletLogBO(orderNum, true);
        Assert.assertEquals(mongoShopWalletLogBOList.size(), 1);
        WalletAssert.shopWalletLogAssert(mongoShopWalletLogBOList.get(0), 0, 1, 4999L, 5100L, 0L, 0L, 0L, 101L, 0);
    }

    @Test(description = "JK_04,无需快递发货订单完整流程", dataProvider = "realProductDeliveryFree")
    public void noDeliveryOrderTestCase(Long productId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNum);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.delivery(DeliveryOrderDtoData.getNoDeliveryOrderDtoData(orderNum));
        MyOrderApi.receipt(orderNum);
        CommentApi.addComment(SpuCommDtoData.getSpuCommDtoData(OrderApi.getOrderItemAndAddress(orderNum).getOrderItems().get(0).getOrderItemId()));
        ProductApi.delete(productId, true);

        //验证运行后数据是否正确
        TimeUnit.SECONDS.sleep(2L);
        List<MongoShopWalletLogBO> mongoShopWalletLogBOList = ShopWalletApi.getMongoShopWalletLogBO(orderNum, true);
        Assert.assertEquals(mongoShopWalletLogBOList.size(), 1);
        WalletAssert.shopWalletLogAssert(mongoShopWalletLogBOList.get(0), 0, 1, 980L, 1000L, 0L, 0L, 0L, 20L, 0);
    }

    @Test(description = "JK_05,多次退款失败，退货成功订单", dataProvider = "realProductDeliveryFree")
    public void multiRefundOrderTestCase(Long productId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        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);

        //验证运行后数据是否正确
        TimeUnit.SECONDS.sleep(2L);
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNum).size(), 6);
        List<MongoShopWalletLogBO> mongoShopWalletLogBOList = ShopWalletApi.getMongoShopWalletLogBO(orderNum, true);
        Assert.assertEquals(mongoShopWalletLogBOList.size(), 2);
        WalletAssert.shopWalletLogAssert(mongoShopWalletLogBOList.get(0), 0, 0, 980L, 1000L, 0L, 0L, 0L, 20L, 2);
        WalletAssert.shopWalletLogAssert(mongoShopWalletLogBOList.get(1), 0, 1, 980L, 1000L, 0L, 0L, 0L, 20L, 0);

        OrderDetailVO orderDetailVO = ShopWalletApi.getOrderDetailVO(orderNum, refundIdSixth, true);
//        WalletAssert.shopOrderDetailAssert(orderDetailVO.getOrderItemDetailList().get(0), 100);
    }
    @Test(description = "JK_06,未发货订单申请退款成功", dataProvider = "realProductDeliveryFree")
    public void unDeliveryRefundTest(Long productId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        //部分退款成功
        Long orderNumFirst = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNumFirst);
        TimeUnit.SECONDS.sleep(2L);
        Long refundIdFirst = OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundDTO(orderNumFirst,0L));
        ShopOrderRefundApi.infoByRefundSn(refundIdFirst);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundIdFirst));
        //整单退款成功
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        Long orderNumSec = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNumSec);
        TimeUnit.SECONDS.sleep(2L);
        Long refundIdSec = OrderRefundApi.apply(OrderRefundDtoData.getAllOrderRefundDTO(orderNumSec));
        ShopOrderRefundApi.infoByRefundSn(refundIdSec);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundIdSec));

        ProductApi.delete(productId, true);

        //第一个下单验证运行后数据是否正确
        TimeUnit.SECONDS.sleep(2L);
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNumFirst).size(), 1);
        List<MongoShopWalletLogBO> mongoShopWalletLogBOListFirst = ShopWalletApi.getMongoShopWalletLogBO(orderNumFirst, true);
        Assert.assertEquals(mongoShopWalletLogBOListFirst.size(), 2);
        WalletAssert.shopWalletLogAssert(mongoShopWalletLogBOListFirst.get(0), 0, 0, 980L, 1000L, 0L, 0L, 0L, 20L, 2);
        WalletAssert.shopWalletLogAssert(mongoShopWalletLogBOListFirst.get(1), 0, 1, 980L, 1000L, 0L, 0L, 0L, 20L, 0);

        OrderDetailVO orderDetailVOFirst = ShopWalletApi.getOrderDetailVO(orderNumFirst, refundIdFirst, true);
//        WalletAssert.shopOrderDetailAssert(orderDetailVOFirst, 1000L, 1, 0L, 0L, 0L);

        //第二个下单验证运行后数据是否正确
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNumSec).size(), 1);
        List<MongoShopWalletLogBO> mongoShopWalletLogBOListSec = ShopWalletApi.getMongoShopWalletLogBO(orderNumSec, true);
        Assert.assertEquals(mongoShopWalletLogBOListSec.size(), 2);
        WalletAssert.shopWalletLogAssert(mongoShopWalletLogBOListSec.get(0), 0, 0, 980L, 1000L, 0L, 0L, 0L, 20L, 2);
        WalletAssert.shopWalletLogAssert(mongoShopWalletLogBOListSec.get(1), 0, 1, 980L, 1000L, 0L, 0L, 0L, 20L, 0);

        OrderDetailVO orderDetailVOSec = ShopWalletApi.getOrderDetailVO(orderNumSec, refundIdSec, true);
//        WalletAssert.shopOrderDetailAssert(orderDetailVOSec, 1000L, 1, 0L, 0L, 0L);
    }

    @Test(description = "JK_07,已发货订单申请仅退款成功", dataProvider = "realProductDeliveryFree")
    public void deliveryRefundTest(Long productId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));

        //部分退款成功
        Long orderNumFirst = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNumFirst);

        TimeUnit.SECONDS.sleep(2L);
        OrderApi.delivery(DeliveryOrderDtoData.getNoDeliveryOrderDtoData(orderNumFirst));

        TimeUnit.SECONDS.sleep(2L);
        Long refundIdFirst= OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundDTO(orderNumFirst,0L));
        ShopOrderRefundApi.infoByRefundSn(refundIdFirst);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundIdFirst));
        //整单退款成功
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        Long orderNumSec = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNumSec);

        TimeUnit.SECONDS.sleep(2L);
        OrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumSec));

        TimeUnit.SECONDS.sleep(2L);
        Long refundIdSec= OrderRefundApi.apply(OrderRefundDtoData.getAllOrderRefundDTO(orderNumSec));
        ShopOrderRefundApi.infoByRefundSn(refundIdSec);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundIdSec));

        ProductApi.delete(productId, true);

        //第一个下单验证运行后数据是否正确
        TimeUnit.SECONDS.sleep(2L);
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNumFirst).size(), 1);
        List<MongoShopWalletLogBO> mongoShopWalletLogBOListFirst = ShopWalletApi.getMongoShopWalletLogBO(orderNumFirst, true);
        Assert.assertEquals(mongoShopWalletLogBOListFirst.size(), 2);
        WalletAssert.shopWalletLogAssert(mongoShopWalletLogBOListFirst.get(0), 0, 0, 980L, 1000L, 0L, 0L, 0L, 20L, 2);
        WalletAssert.shopWalletLogAssert(mongoShopWalletLogBOListFirst.get(1), 0, 1, 980L, 1000L, 0L, 0L, 0L, 20L, 0);

        OrderDetailVO orderDetailVOFirst = ShopWalletApi.getOrderDetailVO(orderNumFirst, refundIdFirst, true);
//        WalletAssert.shopOrderDetailAssert(orderDetailVOFirst, 1000L, 1, 0L, 0L, 0L);

        //第二个下单验证运行后数据是否正确
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNumSec).size(), 1);
        List<MongoShopWalletLogBO> mongoShopWalletLogBOListSec = ShopWalletApi.getMongoShopWalletLogBO(orderNumSec, true);
        Assert.assertEquals(mongoShopWalletLogBOListSec.size(), 2);
        WalletAssert.shopWalletLogAssert(mongoShopWalletLogBOListSec.get(0), 0, 0, 980L, 1000L, 0L, 0L, 0L, 20L, 2);
        WalletAssert.shopWalletLogAssert(mongoShopWalletLogBOListSec.get(1), 0, 1, 980L, 1000L, 0L, 0L, 0L, 20L, 0);

        OrderDetailVO orderDetailVOSec = ShopWalletApi.getOrderDetailVO(orderNumSec, refundIdSec, true);
//        WalletAssert.shopOrderDetailAssert(orderDetailVOSec, 1000L, 1, 0L, 0L, 0L);
    }

    @Test(description = "JK_08,已收货订单申请仅退款成功", dataProvider = "realProductDeliveryFree")
    public void receiveRefundTest(Long productId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));

        //部分退款成功
        Long orderNumFirst = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNumFirst);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.delivery(DeliveryOrderDtoData.getNoDeliveryOrderDtoData(orderNumFirst));
        MyOrderApi.receipt(orderNumFirst);

        TimeUnit.SECONDS.sleep(2L);
        Long refundIdFirst= OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundDTO(orderNumFirst,0L));
        ShopOrderRefundApi.infoByRefundSn(refundIdFirst);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundIdFirst));
        //整单退款成功
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        Long orderNumSec = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNumSec);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumSec));
        MyOrderApi.receipt(orderNumSec);

        TimeUnit.SECONDS.sleep(2L);
        Long refundIdSec= OrderRefundApi.apply(OrderRefundDtoData.getAllOrderRefundDTO(orderNumSec));
        ShopOrderRefundApi.infoByRefundSn(refundIdSec);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundIdSec));

        ProductApi.delete(productId, true);

        //第一个下单验证运行后数据是否正确
        TimeUnit.SECONDS.sleep(2L);
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNumFirst).size(), 1);
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumFirst, true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumFirst, true).getOrderItemDetailList().get(0).getActualTotal(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumFirst, refundIdFirst, true).getOrderItemDetailList().get(0).getRefundAmount(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumFirst, true).getOrderItemDetailList().get(0).getPlatformCommission(), 20);

        //第二个下单验证运行后数据是否正确
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNumSec).size(), 1);
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumSec, true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumSec, true).getOrderItemDetailList().get(0).getActualTotal(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumSec, refundIdSec, true).getOrderItemDetailList().get(0).getRefundAmount(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumSec, true).getOrderItemDetailList().get(0).getPlatformCommission(), 20);
    }

    @Test(description = "JK_09,已发货订单申请退货退款成功", dataProvider = "realProductDeliveryFree")
    public void unReceiveRefundDeLiveryTest(Long productId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));

        //部分退货退款成功
        Long orderNumFirst = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNumFirst);
        OrderApi.delivery(DeliveryOrderDtoData.getNoDeliveryOrderDtoData(orderNumFirst));

        TimeUnit.SECONDS.sleep(2L);
        Long refundIdFirst= OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundDeliveryDTO(orderNumFirst,0L));
        ShopOrderRefundApi.infoByRefundSn(refundIdFirst);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundIdFirst));
        OrderRefundApi.submitExpress(OrderRefundDeliveryDtoData.getOrderRefundDeliveryDTO(refundIdFirst));
        ShopOrderRefundApi.returnMoney(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundIdFirst));

        //整单退货退款成功
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        Long orderNumSec = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNumSec);
        OrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumSec));

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

        ProductApi.delete(productId, true);

        //第一个下单验证运行后数据是否正确
        TimeUnit.SECONDS.sleep(2L);
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNumFirst).size(), 1);
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumFirst, true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumFirst, true).getOrderItemDetailList().get(0).getActualTotal(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumFirst, refundIdFirst, true).getOrderItemDetailList().get(0).getRefundAmount(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumFirst, true).getOrderItemDetailList().get(0).getPlatformCommission(), 20);

        //第二个下单验证运行后数据是否正确
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNumSec).size(), 1);
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumSec, true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumSec, true).getOrderItemDetailList().get(0).getActualTotal(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumSec, refundIdSec, true).getOrderItemDetailList().get(0).getRefundAmount(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumSec, true).getOrderItemDetailList().get(0).getPlatformCommission(), 20);
    }

    @Test(description = "JK_10,已收货订单申请退货退款成功", dataProvider = "realProductDeliveryFree")
    public void receivedRefundDeLiveryTest(Long productId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));

        //部分退货退款成功
        Long orderNumFirst = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNumFirst);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.delivery(DeliveryOrderDtoData.getNoDeliveryOrderDtoData(orderNumFirst));
        MyOrderApi.receipt(orderNumFirst);

        TimeUnit.SECONDS.sleep(2L);
        Long refundIdFirst= OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundDeliveryDTO(orderNumFirst,0L));
        ShopOrderRefundApi.infoByRefundSn(refundIdFirst);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundIdFirst));
        OrderRefundApi.submitExpress(OrderRefundDeliveryDtoData.getOrderRefundDeliveryDTO(refundIdFirst));
        ShopOrderRefundApi.returnMoney(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundIdFirst));
        //整单退货退款成功
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        Long orderNumSec = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNumSec);
        OrderApi.delivery(DeliveryOrderDtoData.getDeliveryOrderDtoData(orderNumSec));
        MyOrderApi.receipt(orderNumSec);
        TimeUnit.SECONDS.sleep(2L);
        Long refundIdSec= OrderRefundApi.apply(OrderRefundDtoData.getAllOrderRefundDeliveryDTO(orderNumSec));
        ShopOrderRefundApi.infoByRefundSn(refundIdSec);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundIdSec));
        OrderRefundApi.submitExpress(OrderRefundDeliveryDtoData.getOrderRefundDeliveryDTO(refundIdSec));
        ShopOrderRefundApi.returnMoney(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundIdSec));

        ProductApi.delete(productId, true);

        //第一个下单验证运行后数据是否正确
        TimeUnit.SECONDS.sleep(2L);
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNumFirst).size(), 1);
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumFirst, true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumFirst, true).getOrderItemDetailList().get(0).getActualTotal(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumFirst, refundIdFirst, true).getOrderItemDetailList().get(0).getRefundAmount(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumFirst, true).getOrderItemDetailList().get(0).getPlatformCommission(), 20);

        //第二个下单验证运行后数据是否正确
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNumSec).size(), 1);
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumSec, true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumSec, true).getOrderItemDetailList().get(0).getActualTotal(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumSec, refundIdSec, true).getOrderItemDetailList().get(0).getRefundAmount(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumSec, true).getOrderItemDetailList().get(0).getPlatformCommission(), 20);
    }

    @Test(description = "JK_11,已完成有运费订单部分金额仅退款", dataProvider = "realProductDelivery")
    public void receivedRefundTest(Long productId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));

        //部分退款仅退部分金额
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNum);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.delivery(DeliveryOrderDtoData.getNoDeliveryOrderDtoData(orderNum));
        MyOrderApi.receipt(orderNum);

        TimeUnit.SECONDS.sleep(2L);
        Long refundId= OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundApartAmountDTO(orderNum,1099L));
        ShopOrderRefundApi.infoByRefundSn(refundId);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundId));
        ProductApi.delete(productId, true);
        TransportApi.deleteTransport(TransportApi.infoTransport(true).get(0).getTransportId(), true);

        //验证运行后数据是否正确
        TimeUnit.SECONDS.sleep(2L);
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNum).size(), 1);
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNum, true).size(), 3);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getActualTotal(), 8800);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, refundId, true).getOrderItemDetailList().get(0).getRefundAmount(), 1099);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, refundId, true).getFreightAmount(), 800);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getPlatformCommission(), 175);
    }

    @Test(description = "JK_12,已完成有运费订单部分金额退货退款", dataProvider = "realProductDelivery")
    public void receivedRefundDeliveryTest(Long productId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));

        //部分退货退款仅退部分金额
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNum);
        OrderApi.delivery(DeliveryOrderDtoData.getNoDeliveryOrderDtoData(orderNum));
        MyOrderApi.receipt(orderNum);

        TimeUnit.SECONDS.sleep(2L);
        Long refundId= OrderRefundApi.apply(OrderRefundDtoData.getRefundDeliveryApartAmountDTO(orderNum,1099L));
        ShopOrderRefundApi.infoByRefundSn(refundId);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundId));
        OrderRefundApi.submitExpress(OrderRefundDeliveryDtoData.getOrderRefundDeliveryDTO(refundId));
        ShopOrderRefundApi.returnMoney(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundId));

        ProductApi.delete(productId, true);
        TransportApi.deleteTransport(TransportApi.infoTransport(true).get(0).getTransportId(), true);

        //验证运行后数据是否正确
        TimeUnit.SECONDS.sleep(2L);
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNum).size(), 1);
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNum, true).size(), 3);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getActualTotal(), 8800);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, refundId, true).getOrderItemDetailList().get(0).getRefundAmount(), 1099);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, refundId, true).getFreightAmount(), 800);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getPlatformCommission(), 175);
    }

    @Test(description = "JK_13,未发货有运费订单部分退款", dataProvider = "realProductDelivery")
    public void unDeliveryRefundTransFeeTest(Long productId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));

        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNum);
        //部分退款仅退部分金额
        TimeUnit.SECONDS.sleep(2L);
        Long refundId= OrderRefundApi.apply(OrderRefundDtoData.getOrderRefundApartAmountDTO(orderNum,1099L));
        ShopOrderRefundApi.infoByRefundSn(refundId);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveDeliveryRefundDTO(refundId));

        ProductApi.delete(productId, true);
        TransportApi.deleteTransport(TransportApi.infoTransport(true).get(0).getTransportId(), true);

        //验证运行后数据是否正确
        TimeUnit.SECONDS.sleep(2L);
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNum).size(), 1);
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNum, true).size(), 3);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getActualTotal(), 8800);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, refundId, true).getOrderItemDetailList().get(0).getRefundAmount(), 1899);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, refundId, true).getFreightAmount(), 800);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getPlatformCommission(), 175);
    }

    @Test(description = "JK_14,未发货有运费订单整单退款", dataProvider = "realProductDelivery")
    public void unDeliveryRefundAllTransFeeTest(Long productId) throws InterruptedException {
        ShopCartApi.addItem(ShopCartData.getShopCartItem(productId));
        MyOrderApi.confirm(OrderDtoData.getOrderDtoData(productId));
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNum);

        TimeUnit.SECONDS.sleep(2L);
        Long refundId= OrderRefundApi.apply(OrderRefundDtoData.getAllOrderRefundDTO(orderNum));
        ShopOrderRefundApi.infoByRefundSn(refundId);
        ShopOrderRefundApi.processRefundOrder(ShopOrderRefundDtoData.getReceiveRefundDTO(refundId));

        ProductApi.delete(productId, true);
        TransportApi.deleteTransport(TransportApi.infoTransport(true).get(0).getTransportId(), true);

        //验证运行后数据是否正确
        TimeUnit.SECONDS.sleep(2L);
        Assert.assertEquals(ShopOrderRefundApi.getEsOrderRefundVO(orderNum).size(), 1);
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNum, true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getActualTotal(), 8800);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, refundId, true).getOrderItemDetailList().get(0).getRefundAmount(), 8800);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, refundId, true).getFreightAmount(), 800);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getPlatformCommission(), 175);
    }

    @Test(description = "JK_15, 自提订单通过自提码后台提货", dataProvider = "realProductDeliveryFree")
    public static void pickUpAdminProductOrderByStationCode(Long productId)throws InterruptedException {
        MyOrderApi.confirm(OrderDtoData.getPickUpOrderDtoData(productId, 1));
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getPickUpSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNum);
        Assert.assertEquals(OrderApi.getOrderItemAndStationInfo(orderNum).getStationCode(), MyOrderApi.stationOrderDetail(orderNum).getStationCode());
        OrderApi.changeStatusAndOrderStation(OrderSelfStationDtoData.getOrderSelfStationDTO(orderNum, MyOrderApi.stationOrderDetail(orderNum).getStationId()));
        MyOrderApi.receipt(orderNum);
        CommentApi.addComment(SpuCommDtoData.getSpuCommDtoData(OrderApi.getOrderItemAndAddress(orderNum).getOrderItems().get(0).getOrderItemId()));
        ProductApi.delete(productId, true);

        TimeUnit.SECONDS.sleep(2L);
        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNum, true).size(), 1);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getActualTotal(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getPlatformCommission(), 20);
    }

    @Test(description = "JK_16, 自提订单无需自提码后台提货", dataProvider = "realProductDeliveryFree")
    public static void pickUpAdminProductOrder(Long productId) {
        MyOrderApi.confirm(OrderDtoData.getPickUpOrderDtoData(productId, 1));
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getPickUpSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNum);
        OrderApi.changeStatusAndOrderStation(OrderSelfStationDtoData.getOrderSelfStationDTO(orderNum, MyOrderApi.stationOrderDetail(orderNum).getStationId()));
        MyOrderApi.receipt(orderNum);
        CommentApi.addComment(SpuCommDtoData.getSpuCommDtoData(OrderApi.getOrderItemAndAddress(orderNum).getOrderItems().get(0).getOrderItemId()));
        ProductApi.delete(productId, true);

        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNum, true).size(), 1);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getActualTotal(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getPlatformCommission(), 20);
    }

    @Test(description = "JK_17, 门店提货自提订单", dataProvider = "realProductDeliveryFree")
    public static void stationPickUpAdminProductOrder(Long productId) throws InterruptedException {
        MyOrderApi.confirm(OrderDtoData.getPickUpOrderDtoData(productId, 1));
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getPickUpSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNum);
        TimeUnit.SECONDS.sleep(2L);
        StationApi.getStationOrderByCode(MyOrderApi.stationOrderDetail(orderNum).getStationCode());
        StationApi.orderStationById(orderNum.toString());
        MyOrderApi.receipt(orderNum);
        CommentApi.addComment(SpuCommDtoData.getSpuCommDtoData(OrderApi.getOrderItemAndAddress(orderNum).getOrderItems().get(0).getOrderItemId()));
        ProductApi.delete(productId, true);

        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNum, true).size(), 1);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getActualTotal(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getPlatformCommission(), 20);
    }

    @Test(description = "JK_18, 用户扫商家码核销订单", dataProvider = "realProductDeliveryFree")
    public static void userPickUpAdminProductOrder(Long productId) throws InterruptedException {
        MyOrderApi.confirm(OrderDtoData.getPickUpOrderDtoData(productId, 1));
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getPickUpSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNum);
        TimeUnit.SECONDS.sleep(2L);
        OrderStationDTO orderStationDTO = new OrderStationDTO();
        orderStationDTO.setOrderIds(Collections.singletonList(orderNum));
        orderStationDTO.setStationId(MyOrderApi.stationOrderDetail(orderNum).getStationId());
        MyOrderApi.orderStationByOrderId(orderStationDTO);
        MyOrderApi.receipt(orderNum);
        CommentApi.addComment(SpuCommDtoData.getSpuCommDtoData(OrderApi.getOrderItemAndAddress(orderNum).getOrderItems().get(0).getOrderItemId()));
        ProductApi.delete(productId, true);

        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNum, true).size(), 1);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getActualTotal(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getPlatformCommission(), 20);
    }

    @Test(description = "JK_19, 同城配送订单流程", dataProvider = "realProductDeliveryFree")
    public static void sameCityOrder(Long productId) throws InterruptedException {
        SameCityApi.saveSameCity(SameCityDtoData.getSameCityDTO());
        MyOrderApi.confirm(OrderDtoData.getSameCityOrderDtoData(productId, 1));
        Long orderNum = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId)).get(0);
        PayApi.orderPay(orderNum);
        TimeUnit.SECONDS.sleep(2L);
        OrderApi.delivery(DeliveryOrderDtoData.getSameCityDeliveryOrderDtoData(orderNum));
        MyOrderApi.receipt(orderNum);
        CommentApi.addComment(SpuCommDtoData.getSpuCommDtoData(OrderApi.getOrderItemAndAddress(orderNum).getOrderItems().get(0).getOrderItemId()));
        ProductApi.delete(productId, true);

        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNum, true).size(), 1);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getActualTotal(), 1000);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getFreightAmount(), 100);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNum, true).getOrderItemDetailList().get(0).getPlatformCommission(), 20);
    }
}

