<?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.kiisoo.ic.customer.mapper.OpVipDOMapper">

    <!--会员list-->
    <select id="selectVipList" resultType="com.kiisoo.ic.customer.entity.OpVip">
        select t1.id as id, t1.register_time as registerTime, t1.phone as phone, t2.register_store_id as shopId
        from op_vip t1,op_vip_attr t2
        where t1.id = t2.vip_id
        <if test="shopIds != null and shopIds.size > 0">
            and t2.register_store_id in
            <foreach collection="shopIds" separator="," item="item" index="index" close=")" open="(">
                #{item}
            </foreach>
        </if>
        <if test="startDate != null">
            and t1.register_time <![CDATA[ >= ]]> #{startDate}
        </if>
        <if test="endDate != null">
            and t1.register_time <![CDATA[ <= ]]> #{endDate}
        </if>
    </select>

    <!--会员总数-->
    <select id="selectVipCount" resultType="Long">
        select count(t1.id)
        from op_vip t1,op_customer t2
        <where>
            <if test="shopIds != null and shopIds.size > 0">
                and t2.register_store_id in
                <foreach collection="shopIds" separator="," item="item" index="index" close=")" open="(">
                    #{item}
                </foreach>
            </if>
            <if test="startDate != null">
                and t1.register_time <![CDATA[ >= ]]> #{startDate}
            </if>
            <if test="endDate != null">
                and t1.register_time <![CDATA[ <= ]]> #{endDate}
            </if>

        </where>

    </select>

    <!--会员总数-->
    <select id="selectVipCountByStoreIds" resultType="Long">
        select count(t1.id)
        from op_vip t1,op_customer t2,op_seller_customer_relation t3
        where t2.id = t3.customer_id
        <if test="shopIds != null and shopIds.size > 0">
            and t3.store_id in
            <foreach collection="shopIds" separator="," item="item" index="index" close=")" open="(">
                #{item}
            </foreach>
        </if>
        and t1.id = t2.member_id
        and t3.type != 3
    </select>

    <select id="selectVipCountNew" resultType="Long">
        select count(t1.id)
        from op_vip t1
    </select>

</mapper>
