package com.ruoyi.web.controller.utils;

import com.ruoyi.mall.domain.MallOrderBack;
import com.ruoyi.mall.domain.MallOrderOrder;
import com.ruoyi.mall.mapper.MallOrderOrderMapper;
import com.ruoyi.mall.service.IMallOrderBackService;
import com.ruoyi.mall.service.IMallOrderOrderService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @ClassName LinOrderUtil
 * @Description 查看订单状态是否异常
 * @Author linlinee
 * @Date 2021/12/2 3:59 PM
 * @Version 1.0
 **/

public class LinOrderUtil {

    private static IMallOrderOrderService orderOrderService;

    private static IMallOrderBackService orderBackService;

    /**
     * 订单状态0=待支付,1=待发货,2=待收货,3=待评论,4=已完成,5=退货中,6=退货成功,7=换货中,8=已取消
     * @param nowStatus
     * @param orderId
     * @return
     */
    public static Boolean orderStatusRoute(int nowStatus, String orderId){

        MallOrderOrder order = orderOrderService.selectMallOrderOrderById(Long.parseLong(orderId));
        switch (nowStatus) {
            case 1:
                return  "0".equals(order.getStatus()) ? true : false;
            case 2:
                if ("1".equals(order.getStatus()) || "5".equals(order.getStatus())){
                    return true;
                }else {
                    return false;
                }
            case 3:
                if ("2".equals(order.getStatus()) || "5".equals(order.getStatus())){
                    return true;
                }else {
                    return false;
                }
            case 4:
                return  "3".equals(order.getStatus()) ? true : false;
            case 5:
                if ("1".equals(order.getStatus()) || "2".equals(order.getStatus())){
                    return true;
                }else {
                    return false;
                }
            case 6:
                return  "5".equals(order.getStatus()) ? true : false;
            case 7:
                return  "0".equals(order.getStatus()) ? true : false;
            default: return false;
        }
    }

    /**
     * 状态: 0=退款中,1=退款成功,2=取消退款,3=拒绝退款
     * @param nowStatus
     * @param refundId
     * @return
     */
    public static Boolean refundStatusRoute(int nowStatus, String refundId){
        //订单状态0=待支付,1=待发货,2=待收货,3=待评论,4=已完成,5=退货中,6=退货成功,7=换货中,8=已取消
        MallOrderBack back = orderBackService.selectMallOrderBackById(Long.parseLong(refundId));
        MallOrderOrder order = orderOrderService.selectMallOrderOrderById(back.getOrderId());

        switch (nowStatus) {
            case 0:
                if ("1".equals(order.getStatus()) || "2".equals(order.getStatus())) {
                    return true;
                }else {
                    return false;
                }
            case 1:
                if ("5".equals(order.getStatus()) && "0".equals(back.getStatus())) {
                    return true;
                }else {
                    return false;
                }
            case 2:
                if ("5".equals(order.getStatus()) && "0".equals(back.getStatus())) {
                    return true;
                }else {
                    return false;
                }
            case 3:
                if ("5".equals(order.getStatus()) && "0".equals(back.getStatus())) {
                    return true;
                }else {
                    return false;
                }
            default: return false;
        }
    }
}
