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;
import java.util.Date;

/**
 * @author chan
 * @date 2022/12/13 2:54 PM
 */
@Getter
@Setter
@SearchBean(tables = "channel c " +
        " LEFT JOIN channel_popularize cp on c.id = cp.channel_id " +
        " LEFT JOIN order_don o on cp.id = o.popularize_id :time: " +
        " LEFT JOIN order_don o1 on o.id = o1.id and o1.`status` not in ('close','noPayment') " +
        " LEFT JOIN order_don o2 on o.id = o2.id and o2.`status` = 'refund' "
        , where = ":condition:"
        , groupBy = " c.id,c.`name`,c.wx_shop_id,c.host,c.zfb_shop_id,c.created_time,c.update_time"
        ,distinct = true
)
public class ChannelView {

    @DbField("c.id")
    private Long id;

    @DbField("c.name")
    private String name;

    /**
     * 域名
     */
    @DbField("c.host")
    private String host;

    /**
     * 链接数
     */
    @DbField("count(DISTINCT(cp.id))")
    private Integer popularizeCount;

    @DbField("c.wx_shop_id")
    private String wxShopId;

    @DbField("c.zfb_shop_id")
    private String zfbShopId;

    /**
     * 浏览数
     */
    @DbField("select count(v.id) from channel_popularize_visit v,channel_popularize cp  where v.popularize_id = cp.id and cp.id = c.id ")
    private Integer visit;

    /**
     * 订单数
     */
    @DbField("count(o1.id)")
    private Integer orderCount;

    /**
     * 订单金额
     */
    @DbField("IFNULL(sum(o1.money),0)")
    private BigDecimal orderMoney;

    /**
     * 退款订单数
     */
    @DbField("count(o2.id)")
    private Integer refundCount;

    /**
     * 退款金额
     */
    @DbField("IFNULL(sum(o2.money),0)")
    private BigDecimal refundMoney;

    @DbField("c.remark")
    private String remark;

    @DbField("c.creator")
    private String creator;


    @DbField("c.created_time")
    private Date createdTime;

    @DbField("c.update_time")
    private Date updateTime;

}
