<?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.qs.mp.channel.mapper.ChannelOrderMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qs.mp.channel.domain.ChannelOrder">
        <id column="order_id" property="orderId" />
        <result column="channel_id" property="channelId" />
        <result column="title" property="title" />
        <result column="order_amt" property="orderAmt" />
        <result column="discount_amt" property="discountAmt" />
        <result column="freight_amt" property="freightAmt" />
        <result column="pay_amt" property="payAmt" />
        <result column="status" property="status" />
        <result column="pkg_num" property="pkgNum" />
        <result column="memo" property="memo" />
        <result column="receiver" property="receiver" />
        <result column="tel" property="tel" />
        <result column="province" property="province" />
        <result column="city" property="city" />
        <result column="area" property="area" />
        <result column="address" property="address" />
        <result column="delivery_id" property="deliveryId" />
        <result column="delivery_flow_id" property="deliveryFlowId" />
        <result column="delivery_time" property="deliveryTime" />
        <result column="created_time" property="createdTime" />
        <result column="updated_time" property="updatedTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        order_id, channel_id, title, order_amt, discount_amt, freight_amt, pay_amt, status, pkg_num, memo, receiver, tel, province, city, area, address, delivery_id, delivery_flow_id, delivery_time, created_time, updated_time
    </sql>
    
    <!-- 查询经销商订单列表 -->
    <select id="selectChannelOrderVoList" resultType="com.qs.mp.channel.domain.vo.ChannelOrderVO">
		select DISTINCT t1.* , t2.name channelName, t3.name parentName
		from mp_channel_order t1
		left join mp_channel t2 on t1.channel_id = t2.channel_id
		left join mp_channel t3 on t2.parent_id = t3.channel_id
		${ew.customSqlSegment}
	</select>
	
	
	<!-- 查询经销商订单数量 -->
    <select id="selectChannelOrderCount" resultType="integer">
		select count(DISTINCT t1.order_id) 
		from mp_channel_order t1
		left join mp_channel t2 on t1.channel_id = t2.channel_id
		left join mp_channel t3 on t2.parent_id = t3.channel_id
		${ew.customSqlSegment}
	</select>

</mapper>
