package cn.pluss.platform.entity;

import java.math.BigDecimal;
import  java.util.Date;

import cn.pluss.platform.constants.Constant;
import cn.pluss.platform.util.ParametersUtil;
import cn.pluss.platform.util.StringUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

@Data
public class Fans {

    @TableId
    private Integer id;
    private String userId;
    private String logo;
    private String nickName;
    private Double consumMoney;
    private String merchantCode;
    private String merchantName;
    private String consumAddress;
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date consumTime;
    private String orderNumber;
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date createDt;
    
    private String lastMerchantCode;
    private String shareMoney;
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date lastconsumTime;
    private String lastOrderNumber;
    private String payWay;
    private String isUse;

    @TableField(exist = false)
    private String alias;
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @TableField(exist = false)
    private Date stTime;
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @TableField(exist = false)
    private Date endTime;

    /**
     * 这里的支付类型只分两种
     */
    @TableField(exist = false)
    private String orderTypeDesc;

    public static void updateOrderTypeDesc(Fans fans) {
        if (fans == null) {
            return;
        }

        String payWay = fans.getPayWay();
        switch (payWay.substring(payWay.length() - 1)) {
            case "0":
                fans.setOrderTypeDesc("支付宝");
                break;
            case "1":
                fans.setOrderTypeDesc("微信");
                break;
        }
    }

    //初始化粉丝
    public void convert(MerchantOrder order) {
        this.setLogo(order.getLogo());
        this.setNickName(order.getNickName());
        this.setConsumMoney(order.getConsumeFee());
        if(StringUtil.isEmpty(this.getShareMoney())){
            BigDecimal shareMoney = new BigDecimal(order.getConsumeFee()).multiply(new BigDecimal(ParametersUtil.fans_profit));
            this.setShareMoney(shareMoney.setScale(4,BigDecimal.ROUND_HALF_DOWN).toString());
        }
        this.setConsumTime(order.getCreateDt());
        this.setOrderNumber(order.getOrderNumber());
        this.setUserId(order.getMercUserId());
        this.setMerchantCode(order.getMerchantCode());
        this.setMerchantName(order.getMerchantName());
        if(Constant.PAY_TYPE_ALIPAY.equals(order.getPayTypeCode()) || "sxfPay0".equals(order.getPayTypeCode())){
            this.setPayWay("0");
        }else if(Constant.PAY_TYPE_WECHAT.equals(order.getPayTypeCode()) || "sxfPay1".equals(order.getPayTypeCode())){
            this.setPayWay("1");
        }else if(Constant.PAY_TYPE_YSFPAY.equals(order.getPayTypeCode()) || "sxfPay2".equals(order.getPayTypeCode())){
            this.setPayWay("2");
        }else{
            this.setPayWay("3");
        }
    }
}

