<?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.ChannelGoodsOrderMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qs.mp.channel.domain.ChannelGoodsOrder">
        <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="type" property="type" />
        <result column="status" property="status" />
        <result column="order_num" property="orderNum" />
        <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="confirm_time" property="confirmTime" />
        <result column="pay_time" property="payTime" />
        <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, type, status, order_num, memo, receiver, tel, province, city, area, address, delivery_id, delivery_flow_id, delivery_time, confirm_time, pay_time, created_time, updated_time
    </sql>
    <select id="selectChannelGoodsOrderVOList" resultType="com.qs.mp.channel.domain.vo.ChannelGoodsOrderVO">
        select DISTINCT t1.* , t3.name as supplierName,t4.name as channelName
        from mp_channel_goods_order t1
                 left join mp_channel_goods_order_item t2 on t1.order_id = t2.order_id
                 left join mp_supplier t3 on t2.supplier_id = t3.id
                 left join mp_channel t4 on t1.channel_id = t4.channel_id
            ${ew.customSqlSegment}
    </select>
    <select id="selectChannelGoodsOrderCount" resultType="java.lang.Integer">
        select count(DISTINCT t1.order_id)
        from mp_channel_goods_order t1
                 left join mp_channel_goods_order_item t2 on t1.order_id = t2.order_id
                 left join mp_supplier t3 on t2.supplier_id = t3.id
                 left join mp_channel t4 on t1.channel_id = t4.channel_id
            ${ew.customSqlSegment}
    </select>
    <select id="selectChannelGoodsSettleList" resultType="com.qs.mp.channel.domain.vo.ChannelGoodsSettleVO">
        select t1.order_id,t1.created_time,t2.name as channelName,t1.tel,t2.mobile
        from mp_channel_goods_order t1
        left join mp_channel t2 on t1.channel_id = t2.channel_id
        left join mp_channel_goods t3 on t1.order_id = t3.order_id
            ${ew.customSqlSegment}
    </select>
    <select id="listChannelGoodsOrder" resultType="com.qs.mp.channel.domain.vo.ChannelGoodsOrderVO">
        select t1.*,t2.name as channelName
        from mp_channel_goods_order t1
        left join mp_channel t2 on t1.channel_id = t2.channel_id
            ${ew.customSqlSegment}
    </select>

</mapper>