<?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.yc.ship.module.trade.dal.mysql.refund.RefundRecordMapper">

    <select id="selectRefundRecordTotalAmount" resultType="java.util.Map">
        select sum(trr.refund_amount) totalRefundAmount
        from trade_refund_record trr
        where trr.refund_id = #{refundId} and trr.refund_status = 6
    </select>

    <select id="selectRefundRecordFailCount" resultType="java.util.Map">
        select count(*) totalCount,count(if(trr.refund_status=7,1,null)) failCount
        from trade_refund_record trr
        where trr.refund_id = #{refundId}
    </select>

    <select id="selectMarketRefundAmount" resultType="java.math.BigDecimal">
        select sum(trr.refund_amount) totalAmount
        from trade_refund_record trr
        inner join trade_order_pay top on trr.order_pay_id = top.id
        where (top.order_id = #{orderId}
            <if test="changeOrderId!=null">
               or top.order_id =  #{changeOrderId}
            </if>
            ) and trr.refund_status = 6 and trr.refund_type = 2
    </select>

    <select id="selectMarketRefundRecordList" resultType="com.yc.ship.module.trade.dal.dataobject.refund.RefundRecordDO">
        select trr.*
        from trade_refund_record trr
                 inner join trade_order_pay top on trr.order_pay_id = top.id
        where (top.order_id = #{orderId}
        <if test="changeOrderId!=null">
            or top.order_id =  #{changeOrderId}
        </if>
        ) and trr.refund_status = 6 and trr.refund_type = 2
    </select>
</mapper>