<?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.supplier.SupplierRefundMapper">

    <select id="selectSupplierOrderToCreateRefund" resultType="com.yc.ship.module.trade.dal.dataobject.supplier.SupplierRefundDO">
        select sso.*,sum(b.refund_amount) refundAmount,b.plat_supplier_order_id,b.refund_id
        FROM trade_refund_detail_base b
        INNER JOIN trade_supplier_order sso on sso.id = b.plat_supplier_order_id
        WHERE b.refund_id = #{refundId}
        <if test="supplierOrderStatus!=null">
            and sso.order_status = #{supplierOrderStatus}
        </if>
        GROUP BY b.plat_supplier_order_id
    </select>

    <select id="selectSupplierRefundCount" resultType="java.util.Map">
        select count(*) totalCount,count(if(tsr.refund_status=6,1,null)) successCount
        from trade_supplier_refund tsr
        where tsr.refund_id = #{refundId}
    </select>

    <select id="selectSupplierRefundCountBySupplierOrderId" resultType="java.util.Map">
        select tsr.quantity,count(*) as refundCount
        from trade_supplier_refund tsr
        inner join trade_refund_detail_base db on db.plat_supplier_refund_id = tsr.id
        where tsr.plat_supplier_order_id = #{supplierOrderId} and tsr.refund_status = 6
    </select>


</mapper>