<?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.zhongzheng.modules.order.mapper.OrderMapper">

    <resultMap type="com.zhongzheng.modules.order.domain.Order" id="OrderResult">
        <result property="orderId" column="order_id"/>
        <result property="oderSn" column="oder_sn"/>
        <result property="userId" column="user_id"/>
        <result property="orderPrice" column="order_price"/>
        <result property="orderGeneral" column="order_general"/>
        <result property="orderStatus" column="order_status"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="payTime" column="pay_time"/>
        <result property="payType" column="pay_type"/>
        <result property="transid" column="transid"/>
        <result property="cancelTime" column="cancel_time"/>
        <result property="finishTime" column="finish_time"/>
        <result property="orderType" column="order_type"/>
        <result property="telphone" column="telphone"/>
        <result property="nickname" column="nickname"/>
        <result property="payPrice" column="pay_price"/>
        <collection property="goodsList" ofType="com.zhongzheng.modules.order.domain.OrderGoods" column="orderSn">
            <result property="goodsType" column="goods_type"/>
            <result property="goodsId" column="goods_id"/>
            <result property="goodsPrice" column="goods_price"/>
            <result property="num" column="num"/>
        </collection>

    </resultMap>

    <select id="getOrderGoodsList" resultMap="OrderResult">
        SELECT
            o.*,
            og.goods_id,
            og.goods_type,
            og.goods_price,
            og.num ,
            u.telphone,
            u.nickname
        FROM
            `order` o
                LEFT JOIN order_goods og ON o.oder_sn = og.order_sn
                LEFT JOIN user u on o.user_id = u.user_id
        WHERE
            1 = 1
        <if test="oderSn != null and oderSn != ''" >
            AND o.oder_sn = #{oderSn}
        </if>
        <if test="orderStatus != null and orderStatus != ''" >
            AND o.order_status = #{orderStatus}
        </if>
        <if test="nickname != null and nickname != ''" >
            AND u.nickname like concat('%', #{nickname}, '%')
        </if>
        <if test="telphone != null and telphone != ''" >
            AND u.telphone = #{telphone}
        </if>
        <if test="payPrice != null and payPrice != ''" >
            AND o.pay_price = #{payPrice}
        </if>
        <if test="startTime != null and startTime != ''" >
            AND o.pay_time > #{startTime}
        </if>
        <if test="endTime != null and endTime != ''" >
            AND #{endTime} > o.pay_time
        </if>
        ORDER BY
            order_id DESC
    </select>
</mapper>
