<?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.manage.cps.UserDistributePopularizeMapper">

    <select id="getDefaultPopularizeDetail" resultType="com.cyksj.model.views.UserDistributePopularizeView">
        select count(od.id)                                        orders,
               ifnull(cast(sum(money) / 100 as decimal(11, 2)), 0) ordersMoney,
               ifnull(cast(sum(if(dp.send_status = 'waiting', dp.points, 0)) / 1000 as decimal(11, 2)), 0)
                   as                                              wMoney,
               ifnull(cast(sum(if(dp.send_status = 'success', dp.points, 0)) / 1000 as decimal(11, 2)), 0)
                   as                                              gotMoney
        from (select user_id from user_distribute_shared where shared_id = #{cpsUserId}) us
                 inner join order_don od
                            on od.user_id = us.user_id and od.status not in ('close', 'noPayment') and
                               od.is_fixed_distribute is true and od.cps_popularize_id = 0
                 inner join distribute_waiting_send_points dp on dp.order_id = od.id
            and dp.send_status in ('success', 'waiting')
        <if test="start != null">
            and dp.created_time >= #{start}
        </if>
        <if test="end != null">
            and dp.created_time &lt; #{end}
        </if>
    </select>
</mapper>