package com.sqx.modules.order.dto;

import com.sqx.common.query.PageQuery;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.Pattern;

@Data
public class OrderQueryDto extends PageQuery {

    @ApiModelProperty("操作人id 导出用")
    private String userId;
    @ApiModelProperty("订单状态 0待结算 1待支付 2直接购买（未支付） 7商家待接单 8商家拒绝接单 6制作中  3待取餐/派送中 4已完成 5已取消 13外卖待接单,14已退款，15已支付")
    private Integer status;
    @ApiModelProperty("用户手机号")
    private String phone;
    @ApiModelProperty("商铺id")
    private Long shopId;
    @ApiModelProperty("用户姓名")
    private String userName;
    @ApiModelProperty("订单号")
    private String orderNumber;
    @ApiModelProperty("跑腿订单状态（0：已下单未支付1：超时关闭未支付订单2：已支付3：骑手已接单4：骑手已取货/购买6：订单已完成8：用户取消订单" +
            "9：骑手取消订单10：平台下架订单 11：外卖订单下单后生成跑腿订单，只参与群聊，无法被接单")
    private String indentStatus;
    @ApiModelProperty("预约单标识;1是、0否")
    private String reservationFlag;
    @ApiModelProperty("订单类型 实际匹配的字段为order_type_extra 1上门 2骑手配送 3商家配送 不传查所有")
    private Integer orderType;
    @ApiModelProperty("商铺名称")
    private String shopName;
    @ApiModelProperty("骑手电话")
    private String riderPhone;
    @ApiModelProperty("订单创建开始时间")
    private String startTime;
    @ApiModelProperty("订单创建结束时间")
    private String endTime;
    @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$", message = "订单支付查询开始时间格式必须为yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("订单支付开始时间")
    private String payStartTime;
    @Pattern(regexp = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$", message = "订单支付查询结束时间格式必须为yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty("订单支付结束时间")
    private String payEndTime;
    @ApiModelProperty("骑手站点id")
    private Integer riderStationId;
    @ApiModelProperty("商铺类型id")
    private String shopTypeId;
    @ApiModelProperty("第三方支付系统交易号")
    private String transactionId;
    @ApiModelProperty("优惠券类型 0 平台 1商家 不选查所有")
    private String couponType;
    @ApiModelProperty("退款开始时间")
    private String refundStartTime;
    @ApiModelProperty("退款结束时间")
    private String refundEndTime;

    public String toStrMessage() {
        StringBuilder stringBuffer=new StringBuilder();
        if(status!=null){stringBuffer.append("状态："+getStateStr(status)+";");}
        if(phone!=null&&!phone.trim().equals("")){stringBuffer.append("手机号："+phone+";");}
//        if(shopId!=null){stringBuffer.append("："+shopId+";");}
        if(userName!=null&&!userName.trim().equals("")){stringBuffer.append("昵称："+userName+";");}
        if(orderNumber!=null&&!orderNumber.trim().equals("")){stringBuffer.append("订单号："+orderNumber+";");}
        if(orderType!=null){stringBuffer.append("订单类型："+(orderType==1?"到店取餐":(orderType==2?"骑手配送":"商家配送"))+";");}
        if(shopName!=null&&!shopName.trim().equals("")){stringBuffer.append("商铺名称："+shopName+";");}
        if(riderPhone!=null&&!riderPhone.trim().equals("")){stringBuffer.append("骑手手机号："+riderPhone+";");}
        if(startTime!=null&&!startTime.trim().equals("")){stringBuffer.append("开始时间："+startTime+";");}
        if(endTime!=null&&!endTime.trim().equals("")){stringBuffer.append("结束时间："+endTime+";");}
        if(payStartTime!=null&&!payStartTime.trim().equals("")){stringBuffer.append("支付开始时间："+payStartTime+";");}
        if(payEndTime!=null&&!payEndTime.trim().equals("")){stringBuffer.append("支付结束时间："+payEndTime+";");}
        if(shopTypeId!=null&&!shopTypeId.trim().equals("")){stringBuffer.append("商铺类型id："+shopTypeId+";");}
        if(couponType!=null&&!couponType.trim().equals("")){stringBuffer.append(couponType.equals("0")?"优惠券类型:平台;":"优惠券类型:商家;");}
        if(indentStatus!=null&&!indentStatus.trim().equals("")){stringBuffer.append("跑腿订单状态："+getIndentStateStr(indentStatus)+";");}
        if(refundStartTime!=null&&!refundStartTime.trim().equals("")){stringBuffer.append("退款开始时间："+refundStartTime+";");}
        if(refundEndTime!=null&&!refundEndTime.trim().equals("")){stringBuffer.append("退款结束时间："+refundEndTime+";");}
        return stringBuffer.toString();
    }

    private String getIndentStateStr(String indentStatus) {
        switch (indentStatus){
            case "1": return "超时关闭未支付订单";
            case "2": return "已支付";
            case "3": return "骑手已接单";
            case "4": return "骑手已取货";
            case "6": return "订单已完成";
            case "8": return "用户取消订单";
            case "9": return "骑手取消订单";
            case "10": return "平台下架订单";
            case "11": return "外卖订单下单后生成跑腿订单，只参与群聊，无法被接单";
            case "0": return "已下单未支付";
            default: return indentStatus+"";
        }
    }

    public String toStrCode() {
        return ","+(status==null?"":status)+
                ","+(phone==null?"":phone)+
                ","+(shopId==null?"":shopId)+
                ","+(userName==null?"":userName)+
                ","+(orderNumber==null?"":orderNumber)+
                ","+(orderType==null?"":orderType)+
                ","+(shopName==null?"":shopName)+
                ","+(riderPhone==null?"":riderPhone)+
                ","+(startTime==null?"":startTime)+
                ","+(endTime==null?"":endTime)+
                ","+(payStartTime ==null?"":payStartTime)+
                ","+(payEndTime==null?"":payEndTime)+
                ","+(riderStationId==null?"":riderStationId)+
                ","+(shopTypeId==null?"":shopTypeId)+
                ","+(couponType==null?"":couponType)+
                ","+(indentStatus==null?"":indentStatus)+
                ","+(refundEndTime==null?"":refundEndTime)+
                ","+(refundEndTime==null?"":refundEndTime)+
                ",";
    }

    // '订单状态 0待结算 1待支付 2直接购买（未支付） 7商家待接单 8商家拒绝接单 6制作中  3待取餐/派送中 4已完成 5已取消 ',
    private String getStateStr(Integer state){
        switch (state){
            case 1: return "待支付";
            case 2: return "未支付";
            case 3: return "待取餐";
            case 4: return "已完成";
            case 5: return "已取消";
            case 6: return "制作中";
            case 7: return "商家待接单";
            case 8: return "商家拒绝接单";
            case 0: return "待结算";
            case 14: return "已退款";
            case 15: return "已支付";
            default: return state+"";
        }
    }
}
