<?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.PayLogMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.kym.entity.miniapp.PayLog">
        <id column="id" property="id"/>
        <result column="company_id" property="companyId" />
        <result column="user_id" property="userId"/>
        <result column="openid" property="openid"/>
        <result column="bank_type" property="bankType"/>
        <result column="mch_id" property="mchId"/>
        <result column="out_trade_no" property="outTradeNo"/>
        <result column="transaction_id" property="transactionId"/>
        <result column="success_time" property="successTime"/>
        <result column="trade_type" property="tradeType"/>
        <result column="trade_state" property="tradeState"/>
        <result column="attach" property="attach"/>
        <result column="total" property="total"/>
        <result column="currency" property="currency"/>
        <result column="payer_total" property="payerTotal"/>
        <result column="payer_currency" property="payerCurrency"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <resultMap id="CustomRechargeMap" type="com.kym.entity.admin.vo.CustomRechargeVo">
        <result column="user_id" property="userId"/>
        <result column="mobile_phone" property="mobilePhone"/>
        <result column="recharge_amount" property="rechargeAmount"/>
        <result column="currency" property="currency"/>
        <result column="out_trade_no" property="outTradeNo"/>
        <result column="transaction_id" property="transactionId"/>
        <result column="transaction_time" property="transactionTime"/>
        <result column="trade_state" property="tradeState"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, company_id,user_id, openid, bank_type, mch_id, out_trade_no, transaction_id, success_time, trade_type, trade_state, attach, total, currency, payer_total, payer_currency, create_time, update_time
    </sql>

    <select id="listRecharge" parameterType="com.kym.entity.admin.queryParams.CommonQueryParam"
            resultMap="CustomRechargeMap">
        SELECT
        t1.user_id,
        t2.`mobile_phone`,
        t1.total AS recharge_amount,
        t1.currency,
        t1.out_trade_no,
        t1.transaction_id,
        CONVERT(t1.success_time,DATETIME) AS transaction_time,
        t1.trade_state
        FROM
        t_pay_log t1
        LEFT JOIN t_user t2
        ON t1.`user_id` = t2.`id`
        <if test="params.mobilePhone != null and params.mobilePhone!=''">
            where t2.mobile_phone = #{params.mobilePhone}
        </if>
        <if test="params.transactionId != null and params.transactionId!=''">
            where t1.transaction_id = #{params.transactionId}
        </if>
        <if test="params.outTradeNo != null and params.outTradeNo!=''">
            where t1.out_trade_no = #{params.outTradeNo}
        </if>
        order by t1.create_time desc
    </select>

</mapper>
