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

import com.tmerclub.cloud.api.platform.vo.OfflineHandleEventVO;
import com.tmerclub.cloud.common.order.dto.OrderDTO;
import com.tmerclub.cloud.common.product.vo.app.CategoryAppVO;
import com.tmerclub.cloud.coupon.vo.CouponVO;
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.marketing.CouponApi;
import com.moyuer.cloud.systemtest.api.order.MyOrderApi;
import com.moyuer.cloud.systemtest.api.store.ShopWalletApi;
import com.moyuer.cloud.systemtest.api.supplier.SupplierProductApi;
import com.moyuer.cloud.systemtest.data.amount.OfflineHandleEventDtoData;
import com.moyuer.cloud.systemtest.data.amount.PreSaleSpuData;
import com.moyuer.cloud.systemtest.data.amount.SpuData;
import com.moyuer.cloud.systemtest.data.marketing.CouponData;
import com.moyuer.cloud.systemtest.data.order.OrderDtoData;
import com.moyuer.cloud.systemtest.data.order.SubmitOrderDtoData;
import com.moyuer.cloud.systemtest.data.store.DeliveryData;
import com.moyuer.cloud.systemtest.data.supplier.SupplierProductData;
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;

/**
 * @author lpj
 */
public class CouponTest {
    @DataProvider(name = "realProduct")
    private Object[][] realProduct() {
        List<CategoryAppVO> categoryAppVOList = CategoryApi.listShopCategory(true);
        Long shopCategoryId = categoryAppVOList.get(categoryAppVOList.size() - 1).getCategoryId();
        Long categoryId = CategoryApi.listSigningCategory(true).get(0).getCategoryId();
        Long productId = ProductApi.createProduct(SpuData.getRealSpu(categoryId,shopCategoryId, DeliveryData.getFreeFeeDelivery(true),8800L), true);
        return new Object[][]{{productId}};
    }

    @DataProvider(name = "virtualProduct")
    private Object[][] virtualProduct() {
        List<CategoryAppVO> categoryAppVOList = CategoryApi.listShopCategory(true);
        Long shopCategoryId = categoryAppVOList.get(categoryAppVOList.size() - 1).getCategoryId();
        Long categoryId = CategoryApi.listSigningCategory(true).get(0).getCategoryId();
        Long productId = ProductApi.createProduct(SpuData.getUnRealSpu(categoryId, shopCategoryId, 8800L, 1), true);
        return new Object[][]{{productId}};
    }

    @DataProvider(name = "fullPreSaleProduct")
    private Object[][] fullPreSaleProduct() {
        List<CategoryAppVO> categoryAppVOList = CategoryApi.listShopCategory(true);
        Long shopCategoryId = categoryAppVOList.get(categoryAppVOList.size() - 1).getCategoryId();
        Long categoryId = CategoryApi.listSigningCategory(true).get(0).getCategoryId();
        Long productId = ProductApi.createProduct(PreSaleSpuData.getFullPreSaleSpu(categoryId,shopCategoryId, DeliveryData.getFreeFeeDelivery(true),8800L), true);
        return new Object[][]{{productId}};
    }

    @DataProvider(name = "depositPreSaleProduct")
    private Object[][] depositPreSaleProduct() {
        List<CategoryAppVO> categoryAppVOList = CategoryApi.listShopCategory(true);
        Long shopCategoryId = categoryAppVOList.get(categoryAppVOList.size() - 1).getCategoryId();
        Long categoryId = CategoryApi.listSigningCategory(true).get(0).getCategoryId();
        Long productId = ProductApi.createProduct(PreSaleSpuData.getDepositPreSaleSpu(categoryId,shopCategoryId, DeliveryData.getFreeFeeDelivery(true),8800L), true);
        return new Object[][]{{productId}};
    }

    @DataProvider(name = "supplierProduct")
    private Object[][] supplierProduct() {
        Long supplierProductId = SupplierProductData.getSupplierProductId(6600L, DeliveryData.getSupplierFreeFeeDelivery(true), true);
        Long productId = SupplierProductData.getProductId(supplierProductId, 8800L, 1, null, true, true);
        return new Object[][]{{productId, supplierProductId}};
    }

    @Test(description = "店铺优惠券基本流程", dataProvider = "realProduct")
    public void shopCouponFlow(Long productId) throws InterruptedException {
        //新建代金券
        List<Long> productIds = Collections.singletonList(productId);
        CouponApi.saveShopCoupon(CouponData.getCouponDTO(1, 0, 1, 1000L, 300L, null, 2, 10, 100, 1, productIds));
        //获取优惠券id
        Long couponId = CouponApi.getShopCouponPage().get(0).getCouponId();
        //用户领取优惠券
        CouponApi.receive(couponId);
        //用户使用优惠券购买商品
        OrderDTO orderDTO = OrderDtoData.getOrderDtoData(productId, 1);
        orderDTO.setCouponIds(Collections.singletonList(CouponApi.getUserCouponPage().get(0).getCouponUserId()));
        MyOrderApi.confirm(orderDTO);
        //用户提交订单
        List<Long> orderNumberList = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId));
        //根据订单id支付订单
        PayApi.orderPay(orderNumberList);
        //对订单进行退款
        Long refundId = OrderRefund.realOrderRefund(orderNumberList.get(0));
        TimeUnit.SECONDS.sleep(1L);
        //用户删除领取的优惠券
        CouponApi.deleteUserCoupon(CouponApi.getUserCouponPage().get(0).getCouponUserId());
        //平台违规下架活动
        CouponApi.offline(OfflineHandleEventDtoData.getOfflineHandleEventDTO(null, couponId, "违规下架原因", null, null, null));
        //申请上架，审核失败
        //商家根据活动id获取下架信息
        OfflineHandleEventVO offlineHandleEventVO = CouponApi.shopGetOfflineHandleEvent(couponId);
        //商家申请上架
        CouponApi.apply(OfflineHandleEventDtoData.getOfflineHandleEventDTO(offlineHandleEventVO.getEventId(), offlineHandleEventVO.getHandleId(), null, "申请上架原因", null, null));
        //平台根据活动id获取下架信息
        offlineHandleEventVO = CouponApi.platformGetOfflineHandleEvent(couponId);
        //平台审核失败
        CouponApi.audit(OfflineHandleEventDtoData.getOfflineHandleEventDTO(offlineHandleEventVO.getEventId(), offlineHandleEventVO.getHandleId(), null, null, "审核失败原因", 4));
        //申请上架，审核成功
        //商家根据活动id获取下架信息
        offlineHandleEventVO = CouponApi.shopGetOfflineHandleEvent(couponId);
        //商家申请上架
        CouponApi.apply(OfflineHandleEventDtoData.getOfflineHandleEventDTO(offlineHandleEventVO.getEventId(), offlineHandleEventVO.getHandleId(), null, "申请上架原因", null, null));
        //平台根据活动id获取下架信息
        offlineHandleEventVO = CouponApi.platformGetOfflineHandleEvent(couponId);
        //平台审核成功
        CouponApi.audit(OfflineHandleEventDtoData.getOfflineHandleEventDTO(offlineHandleEventVO.getEventId(), offlineHandleEventVO.getHandleId(), null, null, null, 3));
        //根据优惠券id获取优惠券信息
        CouponVO couponVO = CouponApi.getShopCouponInfo(couponId);
        //修改优惠券为暂不投放
        CouponApi.updateShopCoupon(CouponData.getUpdateCouponDTO(couponVO));
        //删除店铺代金券
        CouponApi.deleteShopCoupon(couponId);
        //新建商家发放折扣券-全部商品适用
        CouponApi.saveShopCoupon(CouponData.getCouponDTO(1, 1, 2, 1000L, null, 8.33, 1, 10, 100, 0, null));
        //获取优惠券id
        couponId = CouponApi.getShopCouponPage().get(0).getCouponId();
        //删除店铺折扣券
        CouponApi.deleteShopCoupon(couponId);
        //删除商品
        ProductApi.delete(productId, true);
        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumberList.get(0), true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), true).getOrderItemDetailList().get(0).getShopCouponAmount(), 300);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), refundId, true).getOrderItemDetailList().get(0).getRefundAmount(), 8500);
    }

    @Test(description = "虚拟商品参与店铺优惠券完整流程", dataProvider = "virtualProduct")
    public void shopCouponFlowWithVirtualProduct(Long productId) throws InterruptedException {
        //新建代金券
        List<Long> productIds = Collections.singletonList(productId);
        CouponApi.saveShopCoupon(CouponData.getCouponDTO(1, 0, 1, 1000L, 300L, null, 2, 10, 100, 1, productIds));
        //获取优惠券id
        Long couponId = CouponApi.getShopCouponPage().get(0).getCouponId();
        //用户领取优惠券
        CouponApi.receive(couponId);
        //用户使用优惠券购买商品
        OrderDTO orderDTO = OrderDtoData.getOrderDtoData(productId, 1);
        orderDTO.setCouponIds(Collections.singletonList(CouponApi.getUserCouponPage().get(0).getCouponUserId()));
        MyOrderApi.confirm(orderDTO);
        //用户提交订单
        List<Long> orderNumberList = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId));
        //根据订单id支付订单
        PayApi.orderPay(orderNumberList);
        //对订单进行退款
        Long refundId = OrderRefund.virtualOrderRefund(orderNumberList.get(0));
        TimeUnit.SECONDS.sleep(1L);
        //用户删除领取的优惠券
        CouponApi.deleteUserCoupon(CouponApi.getUserCouponPage().get(0).getCouponUserId());
       //根据优惠券id获取优惠券信息
        CouponVO couponVO = CouponApi.getShopCouponInfo(couponId);
        //修改优惠券为暂不投放
        CouponApi.updateShopCoupon(CouponData.getUpdateCouponDTO(couponVO));
        //删除店铺代金券
        CouponApi.deleteShopCoupon(couponId);
        //删除商品
        ProductApi.delete(productId, true);
        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumberList.get(0), true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), true).getOrderItemDetailList().get(0).getShopCouponAmount(), 300);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), refundId, true).getOrderItemDetailList().get(0).getRefundAmount(), 8500);
    }

    @Test(description = "全款预售商品参与店铺优惠券完整流程", dataProvider = "fullPreSaleProduct")
    public void shopCouponFlowWithFullPreSaleProduct(Long productId) throws InterruptedException {
        //新建代金券
        List<Long> productIds = Collections.singletonList(productId);
        CouponApi.saveShopCoupon(CouponData.getCouponDTO(1, 0, 1, 1000L, 300L, null, 2, 10, 100, 1, productIds));
        //获取优惠券id
        Long couponId = CouponApi.getShopCouponPage().get(0).getCouponId();
        //用户领取优惠券
        CouponApi.receive(couponId);
        //用户使用优惠券购买商品
        OrderDTO orderDTO = OrderDtoData.getOrderDtoData(productId, 1);
        orderDTO.setCouponIds(Collections.singletonList(CouponApi.getUserCouponPage().get(0).getCouponUserId()));
        MyOrderApi.confirm(orderDTO);
        //用户提交订单
        List<Long> orderNumberList = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId));
        //根据订单id支付订单
        PayApi.orderPay(orderNumberList);
        //对订单进行退款
        Long refundId = OrderRefund.realOrderRefund(orderNumberList.get(0));
        TimeUnit.SECONDS.sleep(1L);
        //用户删除领取的优惠券
        CouponApi.deleteUserCoupon(CouponApi.getUserCouponPage().get(0).getCouponUserId());
        //根据优惠券id获取优惠券信息
        CouponVO couponVO = CouponApi.getShopCouponInfo(couponId);
        //修改优惠券为暂不投放
        CouponApi.updateShopCoupon(CouponData.getUpdateCouponDTO(couponVO));
        //删除店铺代金券
        CouponApi.deleteShopCoupon(couponId);
        //删除商品
        ProductApi.delete(productId, true);
        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumberList.get(0), true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), true).getOrderItemDetailList().get(0).getShopCouponAmount(), 300);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), refundId, true).getOrderItemDetailList().get(0).getRefundAmount(), 8500);
    }

    @Test(description = "定金预售商品参与店铺优惠券完整流程", dataProvider = "depositPreSaleProduct")
    public void shopCouponFlowWithDepositPreSaleProduct(Long productId) throws InterruptedException {
        //新建代金券
        List<Long> productIds = Collections.singletonList(productId);
        CouponApi.saveShopCoupon(CouponData.getCouponDTO(1, 0, 1, 1000L, 300L, null, 2, 10, 100, 1, productIds));
        //获取优惠券id
        Long couponId = CouponApi.getShopCouponPage().get(0).getCouponId();
        //用户领取优惠券
        CouponApi.receive(couponId);
        //用户使用优惠券购买商品
        OrderDTO orderDTO = OrderDtoData.getOrderDtoData(productId, 1);
        orderDTO.setCouponIds(Collections.singletonList(CouponApi.getUserCouponPage().get(0).getCouponUserId()));
        MyOrderApi.confirm(orderDTO);
        //用户提交订单
        List<Long> orderNumberList = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId));
        //根据订单id支付定金
        PayApi.orderPay(orderNumberList);
        //根据订单id支付尾款
        TimeUnit.SECONDS.sleep(2L);
        PayApi.orderPayBalance(orderNumberList.get(0));
        //对订单进行退款
        TimeUnit.SECONDS.sleep(2L);
        Long refundId = OrderRefund.realOrderRefund(orderNumberList.get(0));
        TimeUnit.SECONDS.sleep(1L);
        //用户删除领取的优惠券
        CouponApi.deleteUserCoupon(CouponApi.getUserCouponPage().get(0).getCouponUserId());
        //根据优惠券id获取优惠券信息
        CouponVO couponVO = CouponApi.getShopCouponInfo(couponId);
        //修改优惠券为暂不投放
        CouponApi.updateShopCoupon(CouponData.getUpdateCouponDTO(couponVO));
        //删除店铺代金券
        CouponApi.deleteShopCoupon(couponId);
        //删除商品
        ProductApi.delete(productId, true);
        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumberList.get(0), true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), true).getOrderItemDetailList().get(0).getShopCouponAmount(), 300);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), refundId, true).getOrderItemDetailList().get(0).getRefundAmount(), 7500);
    }

    @Test(description = "供应商发货的供应商商品参与店铺优惠券完整流程", dataProvider = "supplierProduct")
    public void shopCouponFlowWithSupplierProduct(Long productId, Long supplierProductId) throws InterruptedException {
        //新建代金券
        List<Long> productIds = Collections.singletonList(productId);
        CouponApi.saveShopCoupon(CouponData.getCouponDTO(1, 0, 1, 1000L, 300L, null, 2, 10, 100, 1, productIds));
        //获取优惠券id
        Long couponId = CouponApi.getShopCouponPage().get(0).getCouponId();
        //用户领取优惠券
        CouponApi.receive(couponId);
        //用户使用优惠券购买商品
        OrderDTO orderDTO = OrderDtoData.getOrderDtoData(productId, 1);
        orderDTO.setCouponIds(Collections.singletonList(CouponApi.getUserCouponPage().get(0).getCouponUserId()));
        MyOrderApi.confirm(orderDTO);
        //用户提交订单
        TimeUnit.SECONDS.sleep(2L);
        List<Long> orderNumberList = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId));
        //根据订单id支付订单
        PayApi.orderPay(orderNumberList);
        //对订单进行退款
        TimeUnit.SECONDS.sleep(2L);
        Long refundId = OrderRefund.supplierOrderRefund(orderNumberList.get(0));
        TimeUnit.SECONDS.sleep(1L);
        //用户删除领取的优惠券
        CouponApi.deleteUserCoupon(CouponApi.getUserCouponPage().get(0).getCouponUserId());
        //根据优惠券id获取优惠券信息
        CouponVO couponVO = CouponApi.getShopCouponInfo(couponId);
        //修改优惠券为暂不投放
        CouponApi.updateShopCoupon(CouponData.getUpdateCouponDTO(couponVO));
        //删除店铺代金券
        CouponApi.deleteShopCoupon(couponId);
        //删除商品
        ProductApi.delete(productId, true);
        SupplierProductApi.delete(supplierProductId, true);
        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumberList.get(0), true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), true).getOrderItemDetailList().get(0).getShopCouponAmount(), 300);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), refundId, true).getOrderItemDetailList().get(0).getRefundAmount(), 8500);
    }

    /**
     * 平台优惠券基本流程
     */
    @Test(description = "平台优惠券基本流程", dataProvider = "realProduct")
    public void platformCouponFlow(Long productId) throws InterruptedException {
        List<Long> productIds = Collections.singletonList(productId);
        //新建平台代金券
        CouponApi.savePlatformCoupon(CouponData.getCouponDTO(1, 0, 1, 1000L, 300L, null, 2, 10, 100, 0, productIds));
        //获取优惠券id
        Long couponId = CouponApi.getPlatformCouponPage().get(0).getCouponId();
        //用户领取优惠券
        CouponApi.receive(couponId);
        //用户使用优惠券购买商品
        OrderDTO orderDTO = OrderDtoData.getOrderDtoData(productId, 1);
        orderDTO.setCouponIds(Collections.singletonList(CouponApi.getUserCouponPage().get(0).getCouponUserId()));
        MyOrderApi.confirm(orderDTO);
        //用户提交订单
        List<Long> orderNumberList = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId));
        //根据订单id支付订单
        PayApi.orderPay(orderNumberList);
        //对订单进行退款
        Long refundId = OrderRefund.realOrderRefund(orderNumberList.get(0));
        //根据优惠券id获取优惠券信息
        CouponVO couponVO = CouponApi.getPlatformCouponInfo(couponId);
        //修改优惠券为暂不投放
        CouponApi.updatePlatformCoupon(CouponData.getUpdateCouponDTO(couponVO));
        //删除平台代金券券
        CouponApi.deletePlatformCoupon(couponId);
        //新建平台发放的折扣券
        CouponApi.savePlatformCoupon(CouponData.getCouponDTO(1, 1, 2, 1000L, null, 8.33, 1, 10, 100, 0, null));
        //获取优惠券id
        couponId = CouponApi.getPlatformCouponPage().get(0).getCouponId();
        //删除平台折扣券
        CouponApi.deletePlatformCoupon(couponId);
        //删除商品
        ProductApi.delete(productId, true);
        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumberList.get(0), true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), true).getOrderItemDetailList().get(0).getPlatformCouponAmount(), 300);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), refundId, true).getOrderItemDetailList().get(0).getRefundAmount(), 8500);
    }

    @Test(description = "虚拟商品参与平台优惠券", dataProvider = "virtualProduct")
    public void platformCouponFlowWithVirtualProduct(Long productId) throws InterruptedException {
        List<Long> productIds = Collections.singletonList(productId);
        //新建平台代金券
        CouponApi.savePlatformCoupon(CouponData.getCouponDTO(1, 0, 1, 1000L, 300L, null, 2, 10, 100, 0, productIds));
        //获取优惠券id
        Long couponId = CouponApi.getPlatformCouponPage().get(0).getCouponId();
        //用户领取优惠券
        CouponApi.receive(couponId);
        //用户使用优惠券购买商品
        OrderDTO orderDTO = OrderDtoData.getOrderDtoData(productId, 1);
        orderDTO.setCouponIds(Collections.singletonList(CouponApi.getUserCouponPage().get(0).getCouponUserId()));
        MyOrderApi.confirm(orderDTO);
        //用户提交订单
        List<Long> orderNumberList = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId));
        //根据订单id支付订单
        PayApi.orderPay(orderNumberList);
        //对订单进行退款
        Long refundId = OrderRefund.virtualOrderRefund(orderNumberList.get(0));
        //根据优惠券id获取优惠券信息
        CouponVO couponVO = CouponApi.getPlatformCouponInfo(couponId);
        //修改优惠券为暂不投放
        CouponApi.updatePlatformCoupon(CouponData.getUpdateCouponDTO(couponVO));
        //删除平台代金券券
        CouponApi.deletePlatformCoupon(couponId);
        //新建平台发放的折扣券
        CouponApi.savePlatformCoupon(CouponData.getCouponDTO(1, 1, 2, 1000L, null, 8.33, 1, 10, 100, 0, null));
        //获取优惠券id
        couponId = CouponApi.getPlatformCouponPage().get(0).getCouponId();
        //删除平台折扣券
        CouponApi.deletePlatformCoupon(couponId);
        //删除商品
        ProductApi.delete(productId, true);
        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumberList.get(0), true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), true).getOrderItemDetailList().get(0).getPlatformCouponAmount(), 300);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), refundId, true).getOrderItemDetailList().get(0).getRefundAmount(), 8500);
    }

    @Test(description = "全款预售商品参与平台优惠券", dataProvider = "fullPreSaleProduct")
    public void platformCouponFlowWithFullPreSaleProduct(Long productId) throws InterruptedException {
        List<Long> productIds = Collections.singletonList(productId);
        //新建平台代金券
        CouponApi.savePlatformCoupon(CouponData.getCouponDTO(1, 0, 1, 1000L, 300L, null, 2, 10, 100, 0, productIds));
        //获取优惠券id
        Long couponId = CouponApi.getPlatformCouponPage().get(0).getCouponId();
        //用户领取优惠券
        CouponApi.receive(couponId);
        //用户使用优惠券购买商品
        OrderDTO orderDTO = OrderDtoData.getOrderDtoData(productId, 1);
        orderDTO.setCouponIds(Collections.singletonList(CouponApi.getUserCouponPage().get(0).getCouponUserId()));
        MyOrderApi.confirm(orderDTO);
        //用户提交订单
        List<Long> orderNumberList = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId));
        //根据订单id支付订单
        PayApi.orderPay(orderNumberList);
        //对订单进行退款
        Long refundId = OrderRefund.realOrderRefund(orderNumberList.get(0));
        //根据优惠券id获取优惠券信息
        CouponVO couponVO = CouponApi.getPlatformCouponInfo(couponId);
        //修改优惠券为暂不投放
        CouponApi.updatePlatformCoupon(CouponData.getUpdateCouponDTO(couponVO));
        //删除平台代金券券
        CouponApi.deletePlatformCoupon(couponId);
        //新建平台发放的折扣券
        CouponApi.savePlatformCoupon(CouponData.getCouponDTO(1, 1, 2, 1000L, null, 8.33, 1, 10, 100, 0, null));
        //获取优惠券id
        couponId = CouponApi.getPlatformCouponPage().get(0).getCouponId();
        //删除平台折扣券
        CouponApi.deletePlatformCoupon(couponId);
        //删除商品
        ProductApi.delete(productId, true);
        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumberList.get(0), true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), true).getOrderItemDetailList().get(0).getPlatformCouponAmount(), 300);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), refundId, true).getOrderItemDetailList().get(0).getRefundAmount(), 8500);
    }

    @Test(description = "定金预售商品参与平台优惠券", dataProvider = "depositPreSaleProduct")
    public void platformCouponFlowDepositPreSaleProductProduct(Long productId) throws InterruptedException {
        List<Long> productIds = Collections.singletonList(productId);
        //新建平台代金券
        CouponApi.savePlatformCoupon(CouponData.getCouponDTO(1, 0, 1, 1000L, 300L, null, 2, 10, 100, 0, productIds));
        //获取优惠券id
        Long couponId = CouponApi.getPlatformCouponPage().get(0).getCouponId();
        //用户领取优惠券
        CouponApi.receive(couponId);
        //用户使用优惠券购买商品
        OrderDTO orderDTO = OrderDtoData.getOrderDtoData(productId, 1);
        orderDTO.setCouponIds(Collections.singletonList(CouponApi.getUserCouponPage().get(0).getCouponUserId()));
        MyOrderApi.confirm(orderDTO);
        //用户提交订单
        List<Long> orderNumberList = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId));
        //根据订单id支付订单
        PayApi.orderPay(orderNumberList);
        TimeUnit.SECONDS.sleep(2L);
        //根据订单id支付订单尾款
        PayApi.orderPayBalance(orderNumberList.get(0));
        //对订单进行退款
        TimeUnit.SECONDS.sleep(2L);
        Long refundId = OrderRefund.realOrderRefund(orderNumberList.get(0));
        //根据优惠券id获取优惠券信息
        CouponVO couponVO = CouponApi.getPlatformCouponInfo(couponId);
        //修改优惠券为暂不投放
        CouponApi.updatePlatformCoupon(CouponData.getUpdateCouponDTO(couponVO));
        //删除平台代金券券
        CouponApi.deletePlatformCoupon(couponId);
        //新建平台发放的折扣券
        CouponApi.savePlatformCoupon(CouponData.getCouponDTO(1, 1, 2, 1000L, null, 8.33, 1, 10, 100, 0, null));
        //获取优惠券id
        couponId = CouponApi.getPlatformCouponPage().get(0).getCouponId();
        //删除平台折扣券
        CouponApi.deletePlatformCoupon(couponId);
        //删除商品
        ProductApi.delete(productId, true);
        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumberList.get(0), true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), true).getOrderItemDetailList().get(0).getPlatformCouponAmount(), 300);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), refundId, true).getOrderItemDetailList().get(0).getRefundAmount(), 7500);
    }

    @Test(description = "供应商发货的供应商商品参与平台优惠券", dataProvider = "supplierProduct")
    public void platformCouponFlowWithSupplierProduct(Long productId, Long supplierProductId) throws InterruptedException {
        List<Long> productIds = Collections.singletonList(productId);
        //新建平台代金券
        CouponApi.savePlatformCoupon(CouponData.getCouponDTO(1, 0, 1, 1000L, 300L, null, 2, 10, 100, 0, productIds));
        //获取优惠券id
        Long couponId = CouponApi.getPlatformCouponPage().get(0).getCouponId();
        //用户领取优惠券
        CouponApi.receive(couponId);
        //用户使用优惠券购买商品
        OrderDTO orderDTO = OrderDtoData.getOrderDtoData(productId, 1);
        orderDTO.setCouponIds(Collections.singletonList(CouponApi.getUserCouponPage().get(0).getCouponUserId()));
        MyOrderApi.confirm(orderDTO);
        //用户提交订单
        TimeUnit.SECONDS.sleep(2L);
        List<Long> orderNumberList = MyOrderApi.submit(SubmitOrderDtoData.getSubmitOrderDtoData(productId));
        //根据订单id支付订单
        PayApi.orderPay(orderNumberList);
        //对订单进行退款
        Long refundId = OrderRefund.supplierOrderRefund(orderNumberList.get(0));
        //根据优惠券id获取优惠券信息
        CouponVO couponVO = CouponApi.getPlatformCouponInfo(couponId);
        //修改优惠券为暂不投放
        CouponApi.updatePlatformCoupon(CouponData.getUpdateCouponDTO(couponVO));
        //删除平台代金券券
        CouponApi.deletePlatformCoupon(couponId);
        //新建平台发放的折扣券
        CouponApi.savePlatformCoupon(CouponData.getCouponDTO(1, 1, 2, 1000L, null, 8.33, 1, 10, 100, 0, null));
        //获取优惠券id
        couponId = CouponApi.getPlatformCouponPage().get(0).getCouponId();
        //删除平台折扣券
        CouponApi.deletePlatformCoupon(couponId);
        //删除商品
        ProductApi.delete(productId, true);
        SupplierProductApi.delete(supplierProductId, true);
        //验证运行后数据是否正确
        Assert.assertEquals(ShopWalletApi.getMongoShopWalletLogBO(orderNumberList.get(0), true).size(), 2);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), true).getOrderItemDetailList().get(0).getPlatformCouponAmount(), 300);
        Assert.assertEquals(ShopWalletApi.getOrderDetailVO(orderNumberList.get(0), refundId, true).getOrderItemDetailList().get(0).getRefundAmount(), 8500);
    }
}
