<?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="cn.pluss.platform.mapper.MercOrderDetailMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.pluss.platform.entity.MercOrderDetail">
        <id column="id" property="id" />
        <result column="orderNo" property="orderNo" />
        <result column="code" property="code" />
        <result column="name" property="name" />
        <result column="deviceLogo" property="deviceLogo" />
        <result column="type" property="type" />
        <result column="num" property="num" />
        <result column="userId" property="userId" />
    </resultMap>

    <select id="pageInfo" parameterType="cn.pluss.platform.entity.MercOrderDetail" resultType="cn.pluss.platform.entity.MercOrderDetail">
        SELECT mo.*,
               ua.roleCode,
               ds.specName as specName,
               moe.status as expressStatus,
               mon.receiver as 'order.receiver',
               mon.phone as 'order.phone',
               mon.address as 'order.address',
               mon.payType as 'order.payType',
               mon.orderAmt as 'order.orderAmt',
               mon.areaName as 'order.areaName',
               mbi.alias as 'merchant.alias'
            FROM
            tb_pluss_merc_order_detail mo
            left join tb_pluss_device_spec ds on  mo.code = ds.code and mo.type = ds.spec
            left join tb_pluss_merc_order_express moe on mo.expressNo = moe.expressNo
            left join tb_pluss_merc_order_new mon on mo.orderNo = mon.orderNo
            left join tb_pluss_user_app ua on  mo.userId = ua.userId
            left join tb_pluss_merchant_base_info mbi on mo.userId = mbi.userId
            <where>
                <if test="condition.orderNo != null and condition.orderNo != ''">
                    and mo.orderNo = #{condition.orderNo}
                </if>
                <if test="condition.name != null and condition.name != ''">
                    and mo.name = #{condition.name}
                </if>
                <if test="condition.merchant != null and condition.merchant.alias != null and condition.merchant.alias != ''">
                    and mbi.alias = #{condition.merchant.alias}
                </if>
                <if test="condition.userId != null">
                    and mo.userId = #{condition.userId}
                </if>
                <if test="condition.roleCode != null and condition.roleCode != ''">
                    and ua.roleCode = #{condition.roleCode}
                </if>
                <if test="condition.logistNo != null and condition.logistNo != ''">
                    and mo.logistNo = #{condition.logistNo}
                </if>
                <if test="condition.expressNo != null and condition.expressNo != ''">
                    and mo.expressNo = #{condition.expressNo}
                </if>
                <if test="condition.status != null and condition.status != ''">
                    and mo.status = #{condition.status}
                </if>
                <if test="condition.order != null and condition.order.payType != null">
                    and mon.payType = #{condition.order.payType}
                </if>

                <if test="condition.order != null and condition.order.receiver != null and condition.order.receiver != ''">
                    and mon.receiver = #{condition.order.receiver}
                </if>

                <if test="condition.order != null and condition.order.phone != null and condition.order.phone != ''">
                    and mon.phone = #{condition.order.phone}
                </if>

                <if test="condition.expressStatus != null and condition.expressStatus != ''">
                    <choose>
                        <when test="condition.expressStatus == '00'">
                            and moe.status is null
                        </when>
                        <otherwise>
                            and moe.status != #{condition.expressStatus}
                        </otherwise>
                    </choose>

                </if>
            </where>
            order by mo.createTime desc
    </select>
</mapper>
