package com.cyksj.model.views;

import com.ejlchina.searcher.bean.DbField;
import com.ejlchina.searcher.bean.DbIgnore;
import com.ejlchina.searcher.bean.SearchBean;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;

/*
 *项目名: yhlxj
 *文件名: YhShopDistributeBusinessView
 *创建者: JavaZou
 *创建时间:2023/9/22 10:56
 */
@Getter
@Setter
@SearchBean(tables = "(select distinct business_id from yh_shop where business_id != 0) ys left join yh_shop_user_distribute_business_order_don_record ubr on ubr.business_id = ys.business_id and :time:" +
		" left join cms_user cu on cu.id = ys.business_id",
		groupBy = "ys.business_id,cu.nickname,date_format(ubr.order_created_time,'%Y-%m')")
public class YhShopDistributeBusinessView {
	@DbField("ys.business_id")
	private Long businessId;

	@DbField("cu.nickname")
	private String businessName;

	/**
	 * 关联人数
	 */
	@DbIgnore
	private Integer numOfRelation;

	@DbField("count(if(ubr.order_type = 1 and ubr.status = 'success',1,NULL))")
	private Integer numOfFirstOrderThisMonth;

	@DbField("cast(sum(if(ubr.order_type = 1 and ubr.status = 'success',ubr.take_money,0))/100 as decimal(10,2))")
	private BigDecimal moneyOfFirstOrderThisMonth;

	@DbField("count(if(ubr.order_type = 2 and ubr.status = 'success',1,NULL))")
	private Integer numOfRenewOrderThisMonth;

	@DbField("cast(sum(if(ubr.order_type = 2 and ubr.status = 'success',ubr.take_money,0))/100 as decimal(10,2))")
	private BigDecimal moneyOfRenewOrderThisMonth;

	@DbField("cast(sum(if(ubr.status = 'success',ubr.take_money,0))/100 as decimal(10,2))")
	private BigDecimal takeMoney;

	@DbField("cast(sum(if(ubr.status = 'refund', ubr.take_money,0))/100 as decimal(10,2))")
	private BigDecimal refundMoney;

	@DbField("date_format(ubr.order_created_time,'%Y-%m')")
	private String monthDate;
}
