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

    <select id="countList" resultType="integer"
            parameterType="com.crm.rely.backend.core.entity.ucard.GlobalPaymentPageEntity">
        SELECT COUNT(*) FROM ucard_global_payment_order g
        LEFT JOIN ucard_merchant_user uc ON g.unique_id = uc.unique_id
        <where>
            <if test="uniqueId!=null and uniqueId!=''">
                and g.`unique_id` = #{cardNo}
            </if>
            <if test="originOrderNo!=null and originOrderNo!=''">
                and g.`origin_order_no` = #{originOrderNo}
            </if>
            <if test="orderNo!=null">
                and g.`order_no` = #{orderNo}
            </if>
            <if test="beginDate!=null and beginDate!=''">
                and DATE_FORMAT(g.add_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{beginDate}
            </if>
            <if test="endDate!=null and endDate!=''">
                and DATE_FORMAT(g.add_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{endDate}
            </if>
            <if test="email!=null and email!=''">
                and uc.`email` like concat(#{email},'%')
            </if>
            <if test="mobile!=null and mobile!=''">
                and uc.`mobile` like concat(#{mobile},'%')
            </if>
            <if test="cId!=null">
                and uc.`c_id` = #{cId}
            </if>
        </where>
    </select>

    <select id="pageList" resultType="com.crm.rely.backend.core.dto.ucard.GlobalPaymentOrderDto"
            parameterType="com.crm.rely.backend.core.entity.ucard.GlobalPaymentPageEntity">
        select g.* ,uc.c_id,uc.mobile,uc.email ,uc.last_name,uc.first_name from ucard_global_payment_order g
        LEFT JOIN ucard_merchant_user uc ON g.unique_id = uc.unique_id
        <where>
            <if test="uniqueId!=null and uniqueId!=''">
                and g.`unique_id` = #{cardNo}
            </if>
            <if test="originOrderNo!=null and originOrderNo!=''">
                and g.`origin_order_no` = #{originOrderNo}
            </if>
            <if test="orderNo!=null">
                and g.`order_no` = #{orderNo}
            </if>
            <if test="beginDate!=null and beginDate!=''">
                and DATE_FORMAT(g.add_time,'%Y-%m-%d') <![CDATA[ >= ]]> #{beginDate}
            </if>
            <if test="endDate!=null and endDate!=''">
                and DATE_FORMAT(g.add_time,'%Y-%m-%d') <![CDATA[ <= ]]> #{endDate}
            </if>
            <if test="email!=null and email!=''">
                and uc.`email` like concat(#{email},'%')
            </if>
            <if test="mobile!=null and mobile!=''">
                and uc.`mobile` like concat(#{mobile},'%')
            </if>
            <if test="cId!=null">
                and uc.`c_id` = #{cId}
            </if>
        </where>
        order by id desc
        limit #{page.offset},#{page.row}
    </select>
    
</mapper> 