<?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.hzs.report.order.mapper.OrderReportMapper">

    <!-- 查询业绩国家来源 -->
    <select id="listCountryAchieve" resultType="com.hzs.report.order.vo.OrderCountryAchieveVO">
        select bc.name, so.order_achieve, #{param.memberCode} member_code
        from (select so.pk_country, sum(so.order_achieve) order_achieve
        from sa_order so
        inner join cu_member cm
        on cm.pk_id = so.pk_member
        and cm.del_flag = 0
        and cm.category = 0
        where so.del_flag = 0
        and so.order_achieve != 0
        and so.order_status = 1
        <if test="param.startDate != null">
            and so.pay_time >= #{param.startDate}
        </if>
        <if test="param.endDate != null">
            and #{param.endDate} >= so.pay_time
        </if>
        and so.pk_member in
        (select cm.pk_id
        from cu_member cm
        where cm.del_flag = 0
        start with cm.member_code = #{param.memberCode}
        connect by prior cm.pk_id = cm.pk_place_parent)
        group by so.pk_country) so
        left join bd_country bc
        on bc.pk_id = so.pk_country
        order by so.order_achieve desc
    </select>

</mapper>
