package cn.pluss.platform.entity;

import  java.util.Date;

import cn.pluss.platform.dto.MemberScanPayDTO;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import cn.pluss.platform.util.StringUtil;

@Data
public class MerchantMenberComsume {

    @TableId
    private Integer id;
    private String merchantCode;
    private String merchantName;
    private String storeId;
    private String storeName;
    private String  orderNumber;

    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
	@JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createDt;
    private String logo;
    private String memberCode;
    private String nickName;
    private String phone;
    private Double comsumeMoney;
    private Double giveMoney;
    private Integer payType;

    @TableField(exist = false)
    private String alias;
	/**
	 * 返现金额
	 */
	@TableField(exist = false)
    private Double returnMoney;


	public MerchantMenberComsume eval(String orderNumber, Double giveMoney, MemberScanPayDTO memberScanPayDTO, MerchantMenber merchantMenber) {
		MerchantMenberComsume m=new MerchantMenberComsume();
		m.setCreateDt(new Date());
		m.setGiveMoney(giveMoney);
		m.setComsumeMoney(memberScanPayDTO.getConsumeFee());
		m.setMemberCode(memberScanPayDTO.getAuthCode());
		m.setMerchantCode(memberScanPayDTO.getMerchantCode());
		m.setMerchantName(memberScanPayDTO.getMerchantName());
		m.setNickName(merchantMenber.getNickName());
		m.setPhone(merchantMenber.getPhone());
		m.setStoreId(memberScanPayDTO.getStoreId());
		m.setStoreName(memberScanPayDTO.getStoreName());
		m.setLogo(merchantMenber.getLogo());
		m.setOrderNumber(orderNumber);
		return m;
	}
	
	public MerchantMenberComsume convert(String orderNumber,Double giveMoney,MerchantMenber merchantMenber,MerchantStore merchantStore,Double comsumeFee,String merchantCode) {
		MerchantMenberComsume m=new MerchantMenberComsume();
		m.setCreateDt(new Date());
		m.setGiveMoney(giveMoney);
		m.setComsumeMoney(comsumeFee);
		m.setMemberCode(merchantMenber.getMemberCode());
		m.setMerchantCode(merchantCode);
		if(StringUtil.isNotEmpty(merchantStore.getMerchantName())) {
			m.setMerchantName(merchantStore.getMerchantName());
		}
		if(StringUtil.isNotEmpty(merchantMenber.getNickName())) {
			m.setNickName(merchantMenber.getNickName());
		}
		m.setPhone(merchantMenber.getPhone());
		m.setStoreId(merchantStore.getStoreId());
		if(StringUtil.isNotEmpty(merchantStore.getStoreName())) {
			m.setStoreName(merchantStore.getStoreName());
		}
		if(StringUtil.isNotEmpty(merchantMenber.getLogo())) {
			m.setLogo(merchantMenber.getLogo());
		}
	 m.setOrderNumber(orderNumber);
		return m;
	}
    
}

