<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.cyksj.mapper.vip.VipOrderDonMapper">


    <select id="countPopularizeOrderDetail" resultType="com.cyksj.model.views.ChannelPopularizeView">
        select *
        from (select count(*) as orderCount, ifnull(sum(money),0) as orderMoney
        from vip_order_don
        where popularize_id = #{popularizeId}
        <if test="startTime != null and startTime != ''">
            and created_time >= #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            and created_time &lt; #{endTime}
        </if>
        <if test="goodsId != null">
            and goods_id = #{goodsId}
        </if>
        and status not in ('close', 'noPayment')) s1
        ,
        (select count(*) as refundCount, ifnull(sum(money),0) as refundMoney
        from vip_order_don
        where popularize_id = #{popularizeId}
        <if test="startTime != null and startTime != ''">
            and created_time >= #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            and created_time &lt; #{endTime}
        </if>
        <if test="goodsId != null">
            and goods_id = #{goodsId}
        </if>
        and status = 'refund')
        s2
    </select>

    <select id="getOrderDataByCid" resultType="com.cyksj.model.views.ChannelView">
        select count(vod.id) as orderCount, IFNULL(sum(vod.money), 0) as orderMoney
        from channel c
        LEFT JOIN channel_popularize cp on c.id = cp.channel_id
        LEFT JOIN vip_order_don vod on vod.popularize_id = cp.id
        where c.id = #{channelId}
        and vod.status not in ('close', 'noPayment')
        <if test="st != null and st != ''">
            and vod.created_time >= #{st}
        </if>
        <if test="et != null and et != ''">
            and vod.created_time &lt; #{et}
        </if>
    </select>
</mapper>