package cn.pluss.platform.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

@Data
@ApiModel("会员订单实体类")
public class MemberOrder {

	@TableId
	@ApiModelProperty("id")
	private Integer id;
	@ApiModelProperty("商户code")
	private String merchantCode;
	@ApiModelProperty("商户名称")
	private String merchantName;
	@ApiModelProperty("店铺id")
	private String storeId;
	@ApiModelProperty("店铺名称")
	private String storeName;
	@ApiModelProperty("订单编码")
	private String orderNumber;
	@ApiModelProperty("会员code，会员id")
	private String memberCode;
	@ApiModelProperty("会员昵称")
	private String nickName;
	@ApiModelProperty("创建时间")
	@DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss")
	private Date createDt;
	@ApiModelProperty("订单类型 ： 0：会员消费，1：会员充值")
	private String orderType;
	@ApiModelProperty("订单金额")
	private String orderFee;
	@ApiModelProperty("订单状态： 0：交易失败，1：交易成功")
	private String orderStatus;
	@ApiModelProperty("充值类型： 0：会员线上充值，1：现金充值 2：APP扫码会员充值")
	private String rechargeType;
	@ApiModelProperty("员工id")
	private String staffCode;
	@ApiModelProperty("员工名称")
	private String staffName;
	@ApiModelProperty("支付宝交易流水号")
	private String aliPayTransNo;
	@ApiModelProperty("微信支付交易流水号")
	private String weChatTransNo;
	@ApiModelProperty("乐刷交易流水号")
	private String leshuaTransNo;
	@ApiModelProperty("备注")
	private String remark;
	@ApiModelProperty("通道流水号")
	private String channelNo;

	@TableField(exist = false)
	private String orderTypeDesc;

	@TableField(exist = false)
	@ApiModelProperty("顾客头像url")
	private String logo;

	@TableField(exist = false)
	@ApiModelProperty("赠送金额，消费返或者充值送")
	private String giveMoney;

	@TableField(exist = false)
	@ApiModelProperty("别名。")
	private String alias;

	/**
	 * 查询添加数据
	 */
	@TableField(exist = false)
	private String startTime;
	@TableField(exist = false)
	private String endTime;
	@TableField(exist = false)
	private Integer size;
	@TableField(exist = false)
	private Integer page;

	@Override
	public String toString() {
		return "MemberOrder [id=" + id + ", merchantCode=" + merchantCode + ", merchantName=" + merchantName
				+ ", storeId=" + storeId + ", storeName=" + storeName + ", orderNumber=" + orderNumber + ", memberCode="
				+ memberCode + ", nickName=" + nickName + ", createDt=" + createDt + ", orderType=" + orderType
				+ ", orderFee=" + orderFee + ", orderStatus=" + orderStatus + ", rechargeType=" + rechargeType
				+ ", staffCode=" + staffCode + ", staffName=" + staffName + ", aliPayTransNo=" + aliPayTransNo
				+ ", weChatTransNo=" + weChatTransNo + ", startTime=" + startTime + ", endTime=" + endTime + ", size="
				+ size + ", page=" + page + "]";
	}

	public static void updateOrderTypeDesc(MemberOrder order) {
		if ("0".equals(order.getOrderType())) {
			order.setOrderTypeDesc("会员消费");
			return;
		}

		if (order.getRechargeType() == null) {
			return;
		}

		switch (order.getRechargeType()) {
			case "0":
				order.setOrderTypeDesc("H5-会员充值");
				break;
			case "1":
				order.setOrderTypeDesc("现金充值");
				break;
			case "2":
				order.setOrderTypeDesc("APP扫码-会员充值");
				break;
			case "3":
				order.setOrderTypeDesc("小程序-会员充值");
				break;
			default:
				order.setOrderTypeDesc("未知订单类型");
				break;
		}
	}

	public static void updateStaffName(MemberOrder order, UserApp userApp) {
		// 充值的收银员都为老板
		if (!"0".equals(order.getOrderType())) {
			order.setStaffName(userApp.getUserName());
		}
	}
}
