package cn.pluss.platform.entity;

import cn.pluss.platform.util.StringUtil;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 订单详情表
 * </p>
 *
 * @author Djh
 * @since 2022-03-17
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("tb_pluss_merc_order_detail")
public class MercOrderDetail implements Serializable {

    /** 待付款 */
    public static final String STATUS_NO_PAY = "00";

    /** 已付款 */
    public static final String STATUS_PAYED = "01";

    /** 退款中 */
    public static final String STATUS_REFUND_REQ = "02";

    /** 同意退款，需填写退货订单号 */
    public static final String STATUS_REFUNDING = "12";

    /** 退款申请中，已填写快递单号 */
    public static final String STATUS_REFUND_AGREE = "13";

    /** 已退款 */
    public static final String STATUS_REFUND_SUCCESS = "03";

    /** 退款失败 */
    public static final String STATUS_REFUND_FAIL = "04";

    /** 待收货 */
    public static final String STATUS_UN_RECEIVED = "05";

    /** 已完成 */
    public static final String STATUS_COMPLETE = "06";

    private static final long serialVersionUID = 1L;

    /**
     * id
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @TableField("shopTrolleyId")
    private Long shopTrolleyId;

    /**
     * 订单号
     */
    @TableField("orderNo")
    private String orderNo;


    /**
     * 设备商品code
     */
    @TableField("code")
    private String code;


    /**
     * 设备商品名称
     */
    @TableField("name")
    private String name;


    @TableField("`desc`")
    private String desc;


    @TableField("deviceLogo")
    private String deviceLogo;


    /**
     * 设备类型
     */
    @TableField("type")
    private String type;

    /**
     * 价格
     */
    private BigDecimal price;

    /**
     * 个数
     */
    @TableField("num")
    private Long num;


    /**
     * 用户id
     */
    @TableField("userId")
    private Long userId;

    /**
     * 上送物流单号
     */
    @TableField("logistNo")
    private String logistNo;

    /**
     * 订单状态00：待支付 01：已支付 02：退款中 03：退款成功 04：退款失败  05：待收货 06：已完成
     */
    @TableField("status")
    private String status;

    /**
     * 退款原因
     */
    @TableField("refundReason")
    private String refundReason;

    /**
     * 退款驳回备注
     */
    @TableField("rejectRemark")
    private String rejectRemark;

    /**
     * 退款方式
     */
    @TableField("refundType")
    private String refundType;

    /**
     * 物流单号
     */
    @TableField("expressNo")
    private String expressNo;

    /**
     * 退款物流单号
     */
    @TableField("refundExpressNo")
    private String refundExpressNo;

    /**
     * 退款金额
     */
    @TableField("refundAmt")
    private BigDecimal refundAmt;

    /**
     * 退款单号
     */
    @TableField("refundNo")
    private String refundNo;

    /**
     * 退款时间
     */
    @TableField("refundTime")
    private Date refundTime;

    /**
     * 退款备注
     */
    @TableField("refundRemark")
    private String refundRemark;

    /**
     * 单件邮费
     */
    @TableField("postage")
    private BigDecimal postage;

    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "createTime", fill = FieldFill.INSERT)
    private Date createTime;


    @TableField(exist = false)
    private String statusDesc;

    @TableField(exist = false)
    private String phone;

    @TableField(exist = false)
    private String verifyCode;

    @TableField(exist = false)
    private List<String> picList;

    /**
     * 物流状态
     */
    @TableField(exist = false)
    private String expressStatus;

    @TableField(exist = false)
    private String expressStatusDesc;

    @TableField(exist = false)
    private MercOrderNew order;

    @TableField(exist = false)
    private MerchantBaseInfo merchant;

    @TableField(exist = false)
    private String roleCode;

    /**
     * 规格名称
     */
    @TableField(exist = false)
    private String specName;

    public String getExpressStatusDesc() {
        String expressStatus = this.getExpressStatus();
        if(StringUtil.isEmpty(expressStatus)){
            this.expressStatusDesc = "待发货";
        }else{
            switch (expressStatus){
                case "00":
                    this.expressStatusDesc = "待发货";
                    break;
                case "01":
                    this.expressStatusDesc = "已发货";
                    break;
                case "02":
                    this.expressStatusDesc = "已揽收";
                    break;
                case "03":
                    this.expressStatusDesc = "已收入";
                    break;
                case "04":
                    this.expressStatusDesc = "已发出";
                    break;
                case "05":
                    this.expressStatusDesc = "已发出";
                    break;
                case "06":
                    this.expressStatusDesc = "派件中";
                    break;
                case "07":
                    this.expressStatusDesc = "自提柜入库";
                    break;
                case "08":
                    this.expressStatusDesc = "已签收";
                    break;
                case "90":
                    this.expressStatusDesc = "揽收失败";
                    break;
                case "99":
                    this.expressStatusDesc = "签收失败";
                    break;
                default:
                    this.expressStatusDesc = "未知";
                    break;
            }
        }
        return expressStatusDesc;
    }

    public String getStatusDesc() {
        switch (this.getStatus()){
            case "00":
                this.statusDesc = "待支付";
                break;
            case "01":
                this.statusDesc = "已支付";
                break;
            case "02":
                this.statusDesc = "发起退款中";
                break;
            case "03":
                this.statusDesc = "退款成功";
                break;
            case "04":
                this.statusDesc = "退款失败";
                break;
            case "05":
                this.statusDesc = "待收货";
                break;
            case "06":
                this.statusDesc = "已完成";
                break;
            case "12":
                statusDesc = "已同意退货";
                break;
            case "13":
                statusDesc = "退款中";
                break;
            default:
                this.statusDesc = "未知";
                break;
        }
        return statusDesc;
    }
}