<?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.bonus.order.mapper.BonusOrderMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="SaOrder" type="com.hzs.common.domain.sale.order.SaOrder">
        <id column="PK_ID" property="pkId"/>
        <result column="ORDER_CODE" property="orderCode"/>
        <result column="ORDER_TYPE" property="orderType"/>
        <result column="PK_RATE" property="pkRate"/>
        <result column="ORDER_AMOUNT" property="orderAmount"/>
        <result column="ORDER_ACHIEVE" property="orderAchieve"/>
        <result column="POSTAGE" property="postage"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="REC_NAME" property="recName"/>
        <result column="REC_PHONE" property="recPhone"/>
        <result column="REC_PROVINCE" property="recProvince"/>
        <result column="REC_CITY" property="recCity"/>
        <result column="REC_COUNTY" property="recCounty"/>
        <result column="REC_ADDRESS" property="recAddress"/>
        <result column="PAY_TIME" property="payTime"/>
        <result column="REMARK" property="remark"/>
        <result column="PK_REFERENCE" property="pkReference"/>
        <result column="PK_PLACEMENT" property="pkPlacement"/>
        <result column="TRAN_TYPE" property="tranType"/>
        <result column="DELIVERY_WAY" property="deliveryWay"/>
        <result column="ORDER_STATUS" property="orderStatus"/>
        <result column="PK_VERTEX" property="pkVertex"/>
        <result column="PAY_TYPE" property="payType"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_MEMBER_STORE" property="pkMemberStore"/>
        <result column="PK_STOREHOUSE" property="pkStorehouse"/>
        <result column="PK_MEMBER_STORE" property="pkMemberStore"/>
        <result column="PK_ORIGINAL_ORDER" property="pkOriginalOrder"/>
        <result column="UPLOAD_ACHIEVE" property="uploadAchieve"/>
        <result column="ORDER_TYPE_EXTEND" property="orderTypeExtend"/>
        <result column="CONSUME_AMOUNT" property="consumeAmount"/>
        <result column="SYSTEM_TYPE" property="systemType"/>
        <result column="BOX_NUM" property="boxNum"/>
    </resultMap>

    <resultMap id="orderExtResultMap" type="com.hzs.common.domain.sale.ext.SaOrderExt" extends="SaOrder">
        <result column="MEMBER_CODE" property="memberCode"/>
        <result column="MEMBER_NAME" property="memberName"/>
        <result column="CREATOR_CODE" property="creatorCode"/>
        <result column="PK_SETTLE_COUNTRY" property="pkSettleCountry"/>
        <result column="PK_CENTER_CODE" property="pkCenterCode"/>
        <result column="PK_STORE_LEVEL" property="pkStoreLevel"/>
        <result column="IN_EXCHANGE_RATE" property="inExchangeRate"/>
    </resultMap>

    <select id="listRetailSaOrder" resultMap="orderExtResultMap">
        select so.pk_id,
        so.pk_member,
        so.order_code,
        so.order_type,
        so.pk_rate,
        so.rec_province,
        so.rec_city,
        so.rec_county,
        so.order_amount,
        so.order_achieve,
        so.order_ass_achieve,
        so.upload_achieve,
        so.pk_reference,
        so.pk_vertex,
        so.pk_country,
        so.pay_time,
        so.pk_creator,
        so.consume_amount,
        bc.in_exchange_rate
        from sa_order so
        left join bd_currency bc
        on so.pk_rate = bc.pk_id
        where so.del_flag = 0
        and so.order_status = 1
        <if test="orderCode != null and orderCode != ''">
            and so.order_code=#{orderCode}
        </if>
        <if test="orderTypeList != null and orderTypeList.size > 0">
            and so.order_type in
            <foreach collection="orderTypeList" item="items" open="(" close=")" separator=",">
                #{items}
            </foreach>
        </if>
        and so.pay_time >= #{startDate}
        and so.pay_time &lt; #{endDate}
        order by pay_time
    </select>


</mapper>
