<?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.sqx.modules.member.dao.VipPromoRecordDao">

    <select id="pages" resultType="com.sqx.modules.member.vo.VipPromoRecordVO">
        select
            vpr.id,
            vpr.promo_code_id,
            vpc.promo_code,
            vpr.user_id,
            vpr.user_name,
            vpr.user_phone,
            vpr.create_time,
            vpr.create_time,
            vpr.pay_type,
            vpr.pay_amount,
            t.vip_expiration_time expire_time
        from
            vip_promo_record vpr
            left join vip_promo_code vpc on vpc.id = vpr.promo_code_id
            left join tb_user t on vpr.user_id = t.user_id
        <where>
            and vpr.del_flag = 0
            <if test="query.promoCodeId != null">
                and vpr.promo_code_id = #{query.promoCodeId}
            </if>
            <if test="query.userPhone != null and query.userPhone != ''">
                and vpr.user_phone like concat('%', #{query.userPhone}, '%')
            </if>
<!--            <if test="query.payType != null and query.payType != ''">-->
<!--                and vpr.pay_type = #{query.payType}-->
<!--            </if>-->
            <!-- 是否暖心照顾 -->
            <if test="query.specialFlag != null and query.specialFlag == '1'.toString()">
                and vpr.pay_type = '3'
            </if>
            <if test="query.specialFlag != null and query.specialFlag != '1'.toString()">
                and vpr.pay_type != '3'
            </if>
            <if test="query.startTime != null">
                and vpr.create_time >= #{query.startTime}
            </if>
            <if test="query.endTime != null">
                and vpr.create_time <![CDATA[<=]]>  #{query.endTime}
            </if>
        </where>
        order by vpr.create_time desc
    </select>
</mapper>
