package com.cyksj.model.entity;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.ejlchina.searcher.bean.DbIgnore;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

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

/**
 * @author chan
 * @date 2021/10/11 下午4:04
 */
@Getter
@Setter
public class OrderDon extends BaseEntity implements Serializable {

    /**
     * 座位id
     */
    private Long relationId;

    /**
     * 商品id
     */
    private Long skuId;

    /** 订单号 */
    private String orderNo ;

    private Long goodsId;

    /**
     * 买家支付id
     */
    private String buyerId;

    /**
     * 微信订单号
     */
    private String transactionId;


    /** 用户id */
    private Long userId ;

    /**
     * openId
     */
    private String openId;

    /** 金额 */
    private BigDecimal money;

    /**
     * 押金
     */
    private BigDecimal deposit;

    /**
     * 加购商品金额
     */
    @TableField(exist = false)
    @DbIgnore
    private BigDecimal dpMoney;

    /**
     * 主平台订单金额 用于加购订单分销
     */
    private BigDecimal oriMoney;

    @DbIgnore
    @TableField(exist = false)
    private BigDecimal dsMoney;

    /**
     * 海外支付金额
     */
    private BigDecimal abroadMoney;

    /**
     * 手续费
     */
    private BigDecimal abroadTransactionFee;

    /**
     * 退款金额
     */
    private BigDecimal refundMoney;

    /**
     * 退款余额
     */
    private BigDecimal refundBalance;

    /**
     * 礼品卡现金支付金额
     */
    private BigDecimal gcCash;

    /**
     * 退款原因
     */
    private String refundDesc;

    /**
     * 优惠金额
     */
    private BigDecimal realMoney;

    /**
     * 优惠金额
     */
    private BigDecimal couponMoney;

    /**
     * 优惠券用户领取id
     */
    private Long couponUserId;

    /**
     * 优惠券id
     */
    private Long couponId;

    /**
     * 购买数量
     */
    private Integer num;

    /** 支付状态 */
    private Status status ;

    /**
     * 支付类型
     */
    private Type type;

    /**
     * 推广者设置的优惠码
     */
    private String couponExCode;

    /**
     * 订单类型 1普通订单、2续费订单
     * 默认值为1
     */
    private Integer orderType;

    /**
     * 订单来源
     */
    private Source source;

    /**
     * 订单标注来源
     * 用于客服标注订单来源
     */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String labelSource;

    /**
     * 实物电视机类型 1、其他，2索尼 3三星 4东芝 5LG 6海信 7小米
     */
    private Integer tvType;

    /**
     * 支付时间
     */
    private Date payTime;

    /**
     * 是否是分销订单
     */
    private Boolean isDistribute;

    /**
     * 是否是固定推广者分销
     */
    private Boolean isFixedDistribute;

    /**
     * 商户id
     */
    private String shopId;

    /**
     * 渠道链接id
     */
    private Long popularizeId;

    /**
     * 是否是推广未登录用户购买订单
     */
    private Boolean isNoLogin;

    /**
     * 是否是网页端支付 默认0移动端支付
     */
    private Boolean isWebPay;

    /**
     * 关联兑换码
     */
    private String exCode;

    /**
     * 关联推广id
     */
    private Long dsPopularizeId;

    /**
     * cps后台推广id
     */
    private Long cpsPopularizeId;

    /**
     * 自定义订阅节点
     */
    private String subNode;

    /**
     * 续费后 是否需要更换车票
     */
    private Boolean isChangeTicket;

    /**
     * 之前的车票的规格id
     */
    private Long preSkuId;

    /**
     * 是否已踢出
     */
    private Boolean isKickOut;

    /**
     * 余额支付
     */
    private BigDecimal balance;

    /**
     * 付款说明
     */
    @TableField(exist = false)
    @DbIgnore
    private String payDesc;

    /**
     * 虚拟平台特殊类型
     */
    @TableField(exist = false)
    @DbIgnore
    private GoodsDon.SpecialType specialType;

    /**
     * 是否优惠加购规格
     */
    private Boolean isDp;

    private String payTitle;

    /**
     * 是否是额外硬塞车票车位的订单
     */
    private Boolean isOt;

    /**
     * 礼品卡现金使用记录
     */
    @DbIgnore
    @TableField(exist = false)
    @JsonIgnore
    private List<GiftCardOrderUseRecord> gcUseRecords;

    /**
     * 店铺id
     */
    private Long yhsId;

    /**
     * 文章id
     */
    private Long infoId;

    /**
     * 下单手机号
     */
    private String phone;

    @DbIgnore
    @TableField(exist = false)
    private Boolean isMirror;

    @DbIgnore
    @TableField(exist = false)
    @JsonIgnore
    private OrderDonUserDiscountPopularizeRecord discountPopularizeRecord;

    @TableField(exist = false)
    @JsonIgnore
    private Integer goodsDonType;

    public enum Status {
        /**
         * 订单状态
         */
        close("已关闭"),
        noPayment("待付款"),
        hasPayment("已付款"),
        transport("已发货"),
        received("已签收"),
        complete("已完成"),
        refund("已退款"),
        ;

        private String desc;

        Status(String desc) {
            this.desc = desc;
        }

        public String getDesc() {
            return desc;
        }
    }

    @Getter
    @AllArgsConstructor
    public enum Type{
        WeChat("wechat","微信"),
        ALI_PAY("zfb","支付宝"),
        EX_CODE("exchange_code","兑换码"),
        LOTTERY("lottery","抽奖"),
        EQUIPMENT("equipment", "实物设备分销"),
        PAY_EQUIPMENT("pay_equipment", "自购设备"),
        BALANCE("balance", "余额支付"),
        PAYPAL("paypal","paypal支付"),
        STRIPE("stripe","stripe支付"),
        TICKET_REPLACE("ticket_replace", "车票替换"),
        ;
        String type;
        String desc;

        public static Type getType(String type) {
            if (StrUtil.isEmpty(type)) {
                return ALI_PAY;
            }
            return Arrays.stream(Type.values()).filter(tp -> tp.getType().equals(type)).findFirst().orElse(ALI_PAY);
        }
    }

    @Getter
	public enum Source {
        yinHe("银河官网"),
        movies("银河电影"),
        ;
        String desc;

        Source(String desc) {
            this.desc = desc;
        }
    }

    @Getter
    public enum LabelSource {
        red_book("小红书"),
        tik_tok("抖音"),
        bz("B站"),
        py("朋友"),
        yh("银河官网"),
        bd("百度"),
        whf("无回复"),
        ;
        String desc;

        LabelSource(String desc) {
            this.desc = desc;
        }
    }
}
