<?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.crm.ucard.dao.mapper.CardWithdrawMapper">

    <select id="countList" resultType="integer"
            parameterType="com.crm.rely.backend.core.entity.ucard.CardWithdrawPageEntity">
        SELECT COUNT(*)
        FROM
        ucard_withdraw a
        LEFT JOIN ucard_merchant_user b ON a.unique_id = b.unique_id
        <where>
            <if test="type != null and type != ''">
                and a.`type` = #{type}
            </if>
            <if test="status != null and status != ''">
                and a.status = #{status}
            </if>
            <if test="cardNumber != null and cardNumber != ''">
                and a.`card_number` = #{cardNumber}
            </if>
            <if test="email != null and email != ''">
                and b.`email` like concat(#{email},'%')
            </if>
            <if test="mobile != null and mobile != ''">
                and b.`mobile` like concat(#{mobile},'%')
            </if>
            <if test="cId != null and cId > 0">
                and b.`c_id` = #{cId}
            </if>
            <if test="beginDate != null and beginDate != '' and beginDate > 0">
                and a.transaction_time <![CDATA[ >= ]]> #{beginDate}
            </if>
            <if test="endDate != null and endDate != '' and endDate > 0">
                and a.transaction_time <![CDATA[ <= ]]> #{endDate}
            </if>
        </where>
    </select>

    <select id="pageList" resultType="com.crm.rely.backend.core.dto.ucard.CardWithdrawDto"
            parameterType="com.crm.rely.backend.core.entity.ucard.CardWithdrawPageEntity">
        SELECT
        a.*,
        b.c_id,
        b.area_code,
        b.mobile,
        b.email,
        b.`last_name`,
        b.first_name,
        b.`country`
        FROM
        ucard_withdraw a
        LEFT JOIN ucard_merchant_user b ON a.unique_id = b.unique_id
        <where>
            <if test="type != null and type != ''">
                and a.`type` = #{type}
            </if>
            <if test="status != null and status != ''">
                and a.status = #{status}
            </if>
            <if test="cardNumber != null and cardNumber != ''">
                and a.`card_number` = #{cardNumber}
            </if>
            <if test="email!=null and email!=''">
                and b.`email` like concat(#{email},'%')
            </if>
            <if test="mobile!=null and mobile!=''">
                and b.`mobile` like concat(#{mobile},'%')
            </if>
            <if test="cId!=null and cId > 0">
                and b.`c_id` = #{cId}
            </if>
            <if test="beginDate != null and beginDate != '' and beginDate > 0">
                and a.transaction_time <![CDATA[ >= ]]> #{beginDate}
            </if>
            <if test="endDate != null and endDate != '' and endDate > 0">
                and a.transaction_time <![CDATA[ <= ]]> #{endDate}
            </if>
        </where>
        ORDER BY a.id DESC
        <if test="page != null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

</mapper>