<?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.zsElectric.boot.business.mapper.UserRefundsOrderInfoMapper">

    <!-- 获取退款订单分页列表 -->
    <select id="getUserRefundsOrderInfoPage" resultType="com.zsElectric.boot.business.model.vo.UserRefundsOrderInfoVO">
        SELECT
                id,
                order_id,
                order_no,
                user_id,
                type,
                out_refund_no,
                refund_id,
                transaction_id,
                reason,
                accepted_time,
                success_time,
                amount,
                notify_request,
                status,
                create_time,
                update_time,
                is_deleted
        FROM
            c_user_refunds_order_info
        <where>
            is_deleted = 0
            <if test="queryParams.userId != null">
                AND user_id = #{queryParams.userId}
            </if>
            <if test="queryParams.startTime != null">
                AND create_time <![CDATA[  >=  ]]> #{queryParams.startTime,jdbcType=DATE}
            </if>
            <if test="queryParams.endTime != null">
                AND create_time <![CDATA[  <=  ]]> #{queryParams.endTime,jdbcType=DATE}
            </if>
        </where>
        ORDER BY
        create_time DESC
    </select>

    <!-- 导出退款订单数据（success_time为空） -->
    <select id="listExportUserRefundsOrderInfo" resultType="com.zsElectric.boot.business.model.dto.UserRefundsOrderInfoExportDTO">
        SELECT
            order_no,
            CASE type WHEN 1 THEN '主动退款' WHEN 2 THEN '用户申请退款' ELSE '未知' END AS type_name,
            out_refund_no,
            refund_id,
            transaction_id,
            reason,
            accepted_time,
            amount,
            status,
            create_time
        FROM
            c_user_refunds_order_info
        <where>
            is_deleted = 0
            AND success_time IS NULL
            <if test="queryParams.startTime != null">
                AND create_time <![CDATA[  >=  ]]> #{queryParams.startTime,jdbcType=DATE}
            </if>
            <if test="queryParams.endTime != null">
                AND create_time <![CDATA[  <=  ]]> #{queryParams.endTime,jdbcType=DATE}
            </if>
        </where>
        ORDER BY
        create_time DESC
    </select>

</mapper>
