<?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.com.xingxi.store.data.mapper.WxaStoreChangeOrderMapper">

    <select id="selectChangeOrderListByStatus" resultType="ChangeOrderDTO">
        SELECT t_change_order.*,t_change_order_detail.expressName,
               t_change_order_detail.expressNo,
               t_change_order_detail.returnExpressNo
        FROM t_change_order
        INNER JOIN t_order ON t_order.orderId = t_change_order.orderId
        INNER JOIN t_change_order_detail ON t_change_order_detail.changeId = t_change_order.changeId
        <where>
            t_change_order.delFlag = '0'
            AND t_order.buyerId = #{userId}
            AND t_order.sellerId = #{mercId}
            <if test="status !=null and status != ''">
                AND t_change_order.changeStatus = #{status}
            </if>
        </where>
--         GROUP BY t_change_order.changeId
        ORDER BY t_change_order.changeTime desc
    </select>



    <update id="updateChangeOrderDetailByChangeId" parameterType="ChangeOrderDetail">
        update t_change_order_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderId != null">orderId = #{orderId},</if>
            <if test="orderNo != null and orderNo != ''">orderNo = #{orderNo},</if>
            <if test="orderDetailId != null">orderDetailId = #{orderDetailId},</if>
            <if test="suiteId != null and suiteId != ''">suiteId = #{suiteId},</if>
            <if test="prodId != null">prodId = #{prodId},</if>
            <if test="prodName != null and prodName != ''">prodName = #{prodName},</if>
            <if test="pprId != null">pprId = #{pprId},</if>
            <if test="pprName != null and pprName != ''">pprName = #{pprName},</if>
            <if test="prodType != null and prodType != ''">prodType = #{prodType},</if>
            <if test="vendorId != null">vendorId = #{vendorId},</if>
            <if test="changeQty != null">changeQty = #{changeQty},</if>
            <if test="changeDetailStatus != null and changeDetailStatus != ''">changeDetailStatus = #{changeDetailStatus},</if>
            <if test="expressName != null and expressName != ''">expressName = #{expressName},</if>
            <if test="expressNo != null and expressNo != ''">expressNo = #{expressNo},</if>
            <if test="returnExpressName != null and returnExpressName != ''">returnExpressName = #{returnExpressName},</if>
            <if test="returnExpressNo != null and returnExpressNo != ''">returnExpressNo = #{returnExpressNo},</if>
            <if test="sendTime != null">sendTime = #{sendTime},</if>
            <if test="returnId != null">returnId = #{returnId},</if>
            <if test="returnNo != null and returnNo != ''">returnNo = #{returnNo},</if>
            <if test="returnDetailId != null">returnDetailId = #{returnDetailId},</if>
            <if test="delFlag != null and delFlag != ''">delFlag = #{delFlag},</if>
            <if test="createUser != null and createUser != ''">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null and updateUser != ''">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where changeId = #{changeId}
    </update>
</mapper>
