package com.cyksj.model.views;

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

import java.math.BigDecimal;

/*
 *项目名: netflix
 *文件名: UserDistributeOrdersStatisticsView
 *创建者: JavaZou
 *创建时间:2023/5/15 11:32
 */
@Getter
@Setter
@SearchBean(tables = "(select * from distribute_waiting_send_points where :sharedId: :time:) dw left join order_don od on od.id = dw.order_id and dw.is_vip = false and od.status not in ('close','noPayment')" +
		" left join vip_order_don vod on vod.id = dw.order_id and dw.is_vip = true and vod.status not in ('close','noPayment')" +
		" left join goods_don g on g.id = ifnull(od.goods_id,vod.goods_id)",
		groupBy = "ifnull(od.goods_id,vod.goods_id),g.title")
public class UserDistributeOrdersStatisticsView {

	@DbField("g.title")
	private String title;

	@DbField("cast(sum(if(od.id is null,vod.money,if(od.is_dp and od.ori_money != 0,od.ori_money,od.money))/100) as decimal(10,2))")
	private BigDecimal distributeOrderMoney;

	@DbField("count(dw.order_id)")
	private Integer orders;

	@DbField("TRUNCATE(sum(if(dw.send_status != 'close',dw.points,0))/1000,2)")
	private BigDecimal takeMoney;

	@DbField("count(if(ifnull(od.status,vod.status) = 'refund',1,NULL))")
	private Integer refundOrders;

	@DbField("cast(sum(if(od.id is null,vod.refund_money,ifnull(if(od.is_dp and od.ori_money != 0 and od.refund_money > od.ori_money,od.ori_money,od.refund_money),0)))/100 as decimal(10,2))")
	private BigDecimal refundMoney;
}
