<?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.kym.mapper.miniapp.RefundLogMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.kym.entity.miniapp.RefundLog">
        <result column="user_id" property="userId" />
        <result column="refund_id" property="refundId" />
        <result column="out_refund_no" property="outRefundNo" />
        <result column="transaction_id" property="transactionId" />
        <result column="out_trade_no" property="outTradeNo" />
        <result column="channel" property="channel" />
        <result column="user_received_account" property="userReceivedAccount" />
        <result column="success_time" property="successTime" />
        <result column="status" property="status" />
        <result column="funds_account" property="fundsAccount" />
        <result column="total" property="total" />
        <result column="refund" property="refund" />
        <result column="currency" property="currency" />
        <result column="reason" property="reason" />
    </resultMap>

    <resultMap id="RefundVoMap" type="com.kym.entity.miniapp.vo.RefundVo">
        <result column="id" property="refundLogId" />
        <result column="user_id" property="userId" />
        <result column="mobile_phone" property="mobilePhone" />
        <result column="balance" property="balance" />
        <result column="frozenAmount" property="frozenAmount" />
        <result column="out_refund_no" property="outRefundNo" />
        <result column="out_trade_no" property="outTradeNo" />
        <result column="channel" property="channel" />
        <result column="user_received_account" property="userReceivedAccount" />
        <result column="success_time" property="successTime" />
        <result column="status" property="status" />
        <result column="total" property="total" />
        <result column="refund" property="refund" />
        <result column="currency" property="currency" />
        <result column="reason" property="reason" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,user_id, refund_id, out_refund_no, transaction_id, out_trade_no, channel, user_received_account, success_time, status, funds_account, total, refund, currency,reason,create_time,update_time
    </sql>


    <select id="listRefundLog" resultMap="RefundVoMap" parameterType="com.kym.entity.admin.queryParams.CommonQueryParam">
        SELECT
            t1.id,
            t4.user_id,
            t4.mobile_phone,
            t4.balance,
            t4.frozen_amount,
            t1.out_refund_no,
            t1.out_trade_no,
            t1.channel,
            t1.user_received_account,
            t1.success_time,
            t1.`status`,
            t1.`total`,
            t1.`refund`,
            t1.`channel`,
            t1.`currency`,
            t1.`reason`
        FROM
            t_refund_log t1
                LEFT JOIN
            (SELECT
                 t2.id user_id,
                 t2.mobile_phone,
                 t3.balance,
                 t3.frozen_amount
             FROM
                 t_user t2
                     LEFT JOIN t_account t3
                               ON t2.id = t3.user_id) t4
            ON t1.user_id = t4.user_id
        <where>
            <if test="params.mobilePhone != null">
                and t4.mobile_phone = #{params.mobilePhone}
            </if>
            <if test="params.status != null">
                and t1.status = #{params.status}
            </if>
            <if test="params.id != null">
                and t1.id = #{params.id}
            </if>
        </where>
    </select>

</mapper>
