<?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.fdkankan.platform.order.mapper.IOrderMapper">


    <select id="getListByParam" resultType="com.fdkankan.platform.user.vo.ResponseOrder">
        SELECT o.*, u.user_name FROM  t_order o
        LEFT JOIN t_user u on o.user_id = u.id
        <if test=" param.expressNum != null and param.expressNum !='' " >
            LEFT JOIN t_order_item oi on oi.order_id = o.id
        </if>
        where o.rec_status = 'A'
        <if test=" param.phoneNum != null and param.phoneNum !='' " >
            and u.user_name like concat('%',#{param.phoneNum},'%')
        </if>
        <if test=" param.expressNum != null and param.expressNum !='' " >
            and oi.express_num like concat('%',#{param.expressNum},'%')
        </if>
        <if test=" param.orderSn != null and param.orderSn !='' " >
            and o.orderSn like concat('%',#{param.orderSn},'%')
        </if>
        <if test=" param.tradeNum != null and param.tradeNum !='' " >
            and o.tradeNum like concat('%',#{param.tradeNum},'%')
        </if>
        <if test="param.startDate != null and param.startDate !='' " >
            and o.order_time &gt;= ${param.startDate} '00:00:00'
        </if>
        <if test=" param.endDate != null and param.endDate !='' " >
            and o.order_time &lt;= ${param.endDate} '23:59:59'
        </if>
        <if test=" param.type != null and param.type !='' and param.type == 0" >
            and o.payment_status = 'unpaid'
        </if>
        <if test=" param.type != null and param.type !='' and param.type == 1" >
            and o.shipping_status = 'unshipped' and o.payment_status = 'paid'
        </if>
        <if test=" param.type != null and param.type !='' and param.type == 2" >
            and o.shipping_status = 'shipped'
        </if>
        <if test=" param.type != null and param.type !='' and param.type == 3" >
            and o.order_status = 'completed'
        </if>

        <if test="orderBy != null">
            order by ${orderBy}
        </if>
        <if test="start != null and pageSize!=null">
            limit ${start}, ${pageSize}
        </if>
    </select>


    <select id="getCountByParam" resultType="integer">
        SELECT count(*) FROM  t_order o
        LEFT JOIN t_user u on o.user_id = u.id
        <if test=" param.expressNum != null and param.expressNum !='' " >
            LEFT JOIN t_order_item oi on oi.order_id = o.id
        </if>
        where o.rec_status = 'A'
        <if test=" param.phoneNum != null and param.phoneNum !='' " >
            and u.user_name like concat('%',#{param.phoneNum},'%')
        </if>
        <if test=" param.expressNum != null and param.expressNum !='' " >
            and oi.express_num like concat('%',#{param.expressNum},'%')
        </if>
        <if test=" param.orderSn != null and param.orderSn !='' " >
            and o.orderSn like concat('%',#{param.orderSn},'%')
        </if>
        <if test=" param.tradeNum != null and param.tradeNum !='' " >
            and o.tradeNum like concat('%',#{param.tradeNum},'%')
        </if>
        <if test="param.startDate != null and param.startDate !='' " >
            and o.order_time &gt;= ${param.startDate} '00:00:00'
        </if>
        <if test=" param.endDate != null and param.endDate !='' " >
            and o.order_time &lt;= ${param.endDate} '23:59:59'
        </if>
        <if test=" param.type != null and param.type !='' and param.type == 0" >
            and o.payment_status = 'unpaid'
        </if>
        <if test=" param.type != null and param.type !='' and param.type == 1" >
            and o.shipping_status = 'unshipped' and o.payment_status = 'paid'
        </if>
        <if test=" param.type != null and param.type !='' and param.type == 2" >
            and o.shipping_status = 'shipped'
        </if>
        <if test=" param.type != null and param.type !='' and param.type == 3" >
            and o.order_status = 'completed'
        </if>
    </select>
</mapper>
