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 o.id,o.user_id,o.goods_id,o.money,o.refund_money,o.status,o.is_dp,o.ori_money from order_don o inner join (select user_id from user_distribute_shared where :sharedId:) us on us.user_id = o.user_id where o.is_fixed_distribute is true and o.status not in ('close','noPayment') :time:) od left join goods_don g on g.id = od.goods_id" +
		" inner join distribute_waiting_send_points dp on dp.order_id = od.id",
		groupBy = "od.goods_id,g.title")
public class UserDistributeOrdersStatisticsView {

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

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

	@DbField("count(od.id)")
	private Integer orders;

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

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

	@DbField("cast(sum(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;
}
