<?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="cn.pluss.platform.mapper.FansMapper">

    <insert id="saveFans" parameterType="cn.pluss.platform.entity.Fans">
        	insert into tb_pluss_fans(userId,logo,nickName,consumMoney,merchantCode,merchantName,consumAddress,consumTime,orderNumber,createDt,lastMerchantCode,shareMoney,lastconsumTime,lastOrderNumber,payWay,isUse)VALUES(#{userId},#{logo},#{nickName},#{consumMoney},#{merchantCode},#{merchantName},#{consumAddress},#{consumTime},#{orderNumber},now(),#{lastMerchantCode},#{shareMoney},#{lastconsumTime},#{lastOrderNumber},#{payWay},#{isUse})
    	</insert>


    <select id="queryFans" parameterType="cn.pluss.platform.entity.Fans" resultType="cn.pluss.platform.entity.Fans">
        SELECT * from tb_pluss_fans
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="userId!= null">
                and userId = #{userId}
            </if>
            <if test="logo!= null">
                and logo = #{logo}
            </if>
            <if test="nickName!= null">
                and nickName = #{nickName}
            </if>
            <if test="consumMoney!= null">
                and consumMoney = #{consumMoney}
            </if>
            <if test="merchantCode!= null">
                and merchantCode = #{merchantCode}
            </if>
            <if test="merchantName!= null">
                and merchantName = #{merchantName}
            </if>
            <if test="consumAddress!= null">
                and consumAddress = #{consumAddress}
            </if>
            <if test="consumTime!= null">
                and consumTime = #{consumTime}
            </if>
            <if test="orderNumber!= null">
                and orderNumber = #{orderNumber}
            </if>
            <if test="createDt!= null">
                and createDt = #{createDt}
            </if>

            <if test="lastMerchantCode!= null">
                and lastMerchantCode = #{lastMerchantCode}
            </if>
            <if test="shareMoney!= null">
                and shareMoney = #{shareMoney}
            </if>
            <if test="lastconsumTime!= null">
                and lastconsumTime = #{lastconsumTime}
            </if>
            <if test="lastOrderNumber!= null">
                and lastOrderNumber = #{lastOrderNumber}
            </if>
            <if test="payWay!= null">
                and payWay = #{payWay}
            </if>
            <if test="isUse!= null">
                and isUse = #{isUse}
            </if>
        </where>
    </select>

    <!-- queryFansTodayCount -->
    <select id="queryFansTodayCount" parameterType="cn.pluss.platform.entity.Fans" resultType="java.lang.Double">
        select sum(shareMoney) from tb_pluss_fans
        <where>
            <if test="merchantCode!= null">
                and merchantCode = #{merchantCode}
            </if>
            <if test="stTime!= null">
                and createDt &gt;= #{stTime}
            </if>
            <if test="endTime!= null">
                and createDt &lt;= #{endTime}
            </if>

        </where>
        <!-- <where>

             <if test="stTime!= null">
                     and createDt &gt;= #{stTime}
             </if>
             <if test="endTime!= null">
                     and createDt &lt;= #{endTime}
             </if>
        </where> -->
    </select>


    <select id="queryFansList" parameterType="cn.pluss.platform.entity.Fans" resultType="cn.pluss.platform.entity.Fans">
        SELECT * from tb_pluss_fans
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="userId!= null">
                and userId = #{userId}
            </if>
            <if test="logo!= null">
                and logo = #{logo}
            </if>
            <if test="nickName!= null">
                and nickName like concat("%",#{nickName},"%")
            </if>
            <if test="consumMoney!= null">
                and consumMoney = #{consumMoney}
            </if>
            <if test="merchantCode!= null">
                and merchantCode = #{merchantCode}
            </if>
            <if test="merchantName!= null">
                and merchantName = #{merchantName}
            </if>
            <if test="consumAddress!= null">
                and consumAddress = #{consumAddress}
            </if>
            <if test="consumTime!= null">
                and consumTime = #{consumTime}
            </if>
            <if test="orderNumber!= null">
                and orderNumber = #{orderNumber}
            </if>
            <if test="createDt!= null">
                and createDt = #{createDt}
            </if>
            <if test="stTime!= null">
                and createDt &gt;= #{stTime}
            </if>
            <if test="endTime!= null">
                and createDt &lt;= #{endTime}
            </if>
            <if test="lastMerchantCode!= null">
                and lastMerchantCode = #{lastMerchantCode}
            </if>
            <if test="shareMoney!= null">
                and shareMoney = #{shareMoney}
            </if>
            <if test="lastconsumTime!= null">
                and lastconsumTime = #{lastconsumTime}
            </if>
            <if test="lastOrderNumber!= null">
                and lastOrderNumber = #{lastOrderNumber}
            </if>
            <if test="payWay!= null">
                and payWay = #{payWay}
            </if>
            <if test="isUse!= null">
                and isUse = #{isUse}
            </if>

        </where>
    </select>

    <update id="updateFans" parameterType="cn.pluss.platform.entity.Fans">
        update tb_pluss_fans
        <set>
            <if test="userId!= null">
                userId = #{userId},
            </if>
            <if test="logo!= null">
                logo = #{logo},
            </if>
            <if test="nickName!= null">
                nickName = #{nickName},
            </if>
            <if test="consumMoney!= null">
                consumMoney = #{consumMoney},
            </if>
            <if test="merchantCode!= null">
                merchantCode = #{merchantCode},
            </if>
            <if test="merchantName!= null">
                merchantName = #{merchantName},
            </if>
            <if test="consumAddress!= null">
                consumAddress = #{consumAddress},
            </if>
            <if test="consumTime!= null">
                consumTime = #{consumTime},
            </if>
            <if test="orderNumber!= null">
                orderNumber = #{orderNumber},
            </if>
            <if test="createDt!= null">
                createDt = #{createDt},
            </if>

            <if test="lastMerchantCode!= null">
                lastMerchantCode = #{lastMerchantCode},
            </if>
            <if test="shareMoney!= null">
                shareMoney = #{shareMoney},
            </if>
            <if test="lastconsumTime!= null">
                lastconsumTime = #{lastconsumTime},
            </if>
            <if test="lastOrderNumber!= null">
                lastOrderNumber = #{lastOrderNumber},
            </if>
            <if test="payWay!= null">
                payWay = #{payWay},
            </if>
            <if test="isUse!= null">
                isUse = #{isUse}
            </if>

        </set>
        where id=#{id}
    </update>

    <delete id="deleteFans" parameterType="cn.pluss.platform.entity.Fans">
			DELETE FROM tb_pluss_fans where id=#{id}
		</delete>

    <select id="queryFansPage" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.Fans">
        SELECT * from tb_pluss_fans
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="userId!= null">
                and userId = #{userId}
            </if>
            <if test="logo!= null">
                and logo = #{logo}
            </if>
            <if test="nickName!= null">
                and nickName like CONCAT("%",#{nickName},"%")
            </if>
            <if test="consumMoney!= null">
                and consumMoney = #{consumMoney}
            </if>
            <if test="merchantCode!= null">
                and merchantCode = #{merchantCode}
            </if>
            <if test="merchantName!= null">
                and merchantName = #{merchantName}
            </if>
            <if test="consumAddress!= null">
                and consumAddress = #{consumAddress}
            </if>
            <if test="orderNumber!= null">
                and orderNumber = #{orderNumber}
            </if>
            <if test="createDt!= null">
                and createDt = #{createDt}
            </if>

            <if test="lastMerchantCode!= null">
                and lastMerchantCode = #{lastMerchantCode}
            </if>
            <if test="shareMoney!= null">
                and shareMoney = #{shareMoney}
            </if>
            <if test="lastconsumTime!= null">
                and lastconsumTime = #{lastconsumTime}
            </if>
            <if test="lastOrderNumber!= null">
                and lastOrderNumber = #{lastOrderNumber}
            </if>
            <if test="payWay!= null">
                and payWay = #{payWay}
            </if>
            <if test="payWay!= null">
                and payWay = #{payWay}
            </if>
            <if test="startTime!= null">
                and createDt &gt; #{startTime}
            </if>
            <if test="endTime!= null">
                and createDt &lt; #{endTime}
            </if>
            <if test="isUse!= null">
                and isUse = #{isUse}
            </if>
        </where>
        order by id desc limit #{pageSize} offset #{offset}
    </select>

    <select id="queryFansPageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT count(*) from tb_pluss_fans
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="userId!= null">
                and userId = #{userId}
            </if>
            <if test="logo!= null">
                and logo = #{logo}
            </if>
            <if test="nickName!= null and nickName!= ''">
                and nickName like CONCAT("%",#{nickName},"%")
            </if>
            <if test="consumMoney!= null">
                and consumMoney = #{consumMoney}
            </if>
            <if test="merchantCode!= null">
                and merchantCode = #{merchantCode}
            </if>
            <if test="merchantName!= null">
                and merchantName = #{merchantName}
            </if>
            <if test="consumAddress!= null">
                and consumAddress = #{consumAddress}
            </if>
            <if test="orderNumber!= null">
                and orderNumber = #{orderNumber}
            </if>
            <if test="createDt!= null">
                and createDt = #{createDt}
            </if>

            <if test="lastMerchantCode!= null">
                and lastMerchantCode = #{lastMerchantCode}
            </if>
            <if test="shareMoney!= null">
                and shareMoney = #{shareMoney}
            </if>
            <if test="lastconsumTime!= null">
                and lastconsumTime = #{lastconsumTime}
            </if>
            <if test="lastOrderNumber!= null">
                and lastOrderNumber = #{lastOrderNumber}
            </if>
            <if test="payWay!= null">
                and payWay = #{payWay}
            </if>
            <if test="isUse!= null">
                and isUse = #{isUse}
            </if>
            <if test="startTime != null ">
                <![CDATA[
                            and  DATE_FORMAT(consumTime, '%Y-%m-%d %H:%i:%S')>=DATE_FORMAT(#{startTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
            <if test="endTime != null ">
                <![CDATA[
                            and  DATE_FORMAT(consumTime, '%Y-%m-%d %H:%i:%S')<=DATE_FORMAT(#{endTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
        </where>
    </select>

    <select id="queryFansNoPageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT count(*) from tb_pluss_fans
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="userId!= null">
                and userId = #{userId}
            </if>
            <if test="logo!= null">
                and logo = #{logo}
            </if>
            <if test="nickName!= null and nickName!= ''">
                and nickName like CONCAT("%",#{nickName},"%")
            </if>
            <if test="consumMoney!= null">
                and consumMoney = #{consumMoney}
            </if>
            <if test="merchantCode!= null">
                and merchantCode IN (SELECT merchantCode
                FROM tb_pluss_merchant_base_info
                WHERE bindingCode = (SELECT bindingCode
                FROM tb_pluss_merchant_base_info
                where merchantCode = #{merchantCode}))
            </if>
            <if test="merchantName!= null">
                and merchantName = #{merchantName}
            </if>
            <if test="consumAddress!= null">
                and consumAddress = #{consumAddress}
            </if>
            <if test="orderNumber!= null">
                and orderNumber = #{orderNumber}
            </if>
            <if test="createDt!= null">
                and createDt = #{createDt}
            </if>
            <if test="lastMerchantCode!= null">
                and lastMerchantCode = #{lastMerchantCode}
            </if>
            <if test="shareMoney!= null">
                and shareMoney = #{shareMoney}
            </if>
            <if test="lastconsumTime!= null">
                and lastconsumTime = #{lastconsumTime}
            </if>
            <if test="lastOrderNumber!= null">
                and lastOrderNumber = #{lastOrderNumber}
            </if>
            <if test="payWay!= null">
                and payWay = #{payWay}
            </if>
            <if test="isUse!= null">
                and isUse = #{isUse}
            </if>
            <if test="startTime != null ">
                <![CDATA[
                            and  DATE_FORMAT(consumTime, '%Y-%m-%d %H:%i:%S')>=DATE_FORMAT(#{startTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
            <if test="endTime != null ">
                <![CDATA[
                            and  DATE_FORMAT(consumTime, '%Y-%m-%d %H:%i:%S')<=DATE_FORMAT(#{endTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
        </where>
    </select>

    <select id="sumConsumMoneyByMerchantCode" parameterType="java.util.Map" resultType="java.lang.Double">
		  select sum(consumMoney) from tb_pluss_fans
		  where merchantCode=#{merchantCode} and consumTime &gt; #{startTime} and consumTime &lt; #{endTime}
		</select>

    <!--获取当天的粉丝集合  -->
    <select id="queryNowDateFansList" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.Fans">
           select * From tb_pluss_fans where userId = #{userId} and date(consumTime) = curdate() order by consumTime desc
        </select>


    <select id="queryFansPageManage" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.Fans">
        SELECT * from tb_pluss_fans
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="userId!= null">
                and userId = #{userId}
            </if>
            <if test="logo!= null">
                and logo = #{logo}
            </if>
            <if test="nickName!= null">
                and nickName like CONCAT("%",#{nickName},"%")
            </if>
            <if test="consumMoney!= null">
                and consumMoney = #{consumMoney}
            </if>
            <if test="merchantCode!= null">
                and merchantCode = #{merchantCode}
            </if>
            <if test="merchantName!= null">
                and merchantName = #{merchantName}
            </if>
            <if test="consumAddress!= null">
                and consumAddress = #{consumAddress}
            </if>
            <if test="orderNumber!= null">
                and orderNumber = #{orderNumber}
            </if>
            <if test="createDt!= null">
                and createDt = #{createDt}
            </if>

            <if test="lastMerchantCode!= null">
                and lastMerchantCode = #{lastMerchantCode}
            </if>
            <if test="shareMoney!= null">
                and shareMoney = #{shareMoney}
            </if>
            <if test="lastconsumTime!= null">
                and lastconsumTime = #{lastconsumTime}
            </if>
            <if test="lastOrderNumber!= null">
                and lastOrderNumber = #{lastOrderNumber}
            </if>
            <if test="payWay!= null">
                and payWay = #{payWay}
            </if>
            <if test="isUse!= null">
                and isUse = #{isUse}
            </if>

        </where>
        order by id desc limit #{pageSize} offset #{offset}
    </select>


    <select id="queryFansPageCountManage" parameterType="java.util.Map" resultType="java.lang.Integer">
        SELECT count(*) from tb_pluss_fans
        <where>
            <if test="id!= null">
                and id = #{id}
            </if>
            <if test="userId!= null">
                and userId = #{userId}
            </if>
            <if test="logo!= null">
                and logo = #{logo}
            </if>
            <if test="nickName!= null">
                and nickName like CONCAT("%",#{nickName},"%")
            </if>
            <if test="consumMoney!= null">
                and consumMoney = #{consumMoney}
            </if>
            <if test="merchantCode!= null">
                and merchantCode = #{merchantCode}
            </if>
            <if test="merchantName!= null">
                and merchantName = #{merchantName}
            </if>
            <if test="consumAddress!= null">
                and consumAddress = #{consumAddress}
            </if>
            <if test="orderNumber!= null">
                and orderNumber = #{orderNumber}
            </if>
            <if test="createDt!= null">
                and createDt = #{createDt}
            </if>

            <if test="lastMerchantCode!= null">
                and lastMerchantCode = #{lastMerchantCode}
            </if>
            <if test="shareMoney!= null">
                and shareMoney = #{shareMoney}
            </if>
            <if test="lastconsumTime!= null">
                and lastconsumTime = #{lastconsumTime}
            </if>
            <if test="lastOrderNumber!= null">
                and lastOrderNumber = #{lastOrderNumber}
            </if>
            <if test="payWay!= null">
                and payWay = #{payWay}
            </if>
            <if test="isUse!= null">
                and isUse = #{isUse}
            </if>

        </where>
    </select>

    <!--查询某一粉丝最后一次的消费记录  -->
    <select id="queryLastFansByUserId" resultType="cn.pluss.platform.entity.Fans">
		 select * from tb_pluss_fans WHERE  userId=#{userId} ORDER BY consumTime desc limit 1
		</select>


    <select id="queryFansConsumPage" parameterType="java.util.Map" resultType="cn.pluss.platform.vo.FansConsumVO">
        select pf.id as id,pf.userId as userId,pf.logo as logo,pf.nickName as nickName,pf.consumMoney as
        consumMoney,pf.merchantCode as merchantCode,mbi.merchantName as
        lastMerchantName,pf.lastMerchantCode,pf.merchantName as
        merchantName,pf.shareMoney,pf.consumTime,pf.lastconsumTime,pf.orderNumber,pf.lastOrderNumber,pf.createDt,pf.payWay
        from tb_pluss_fans pf left join tb_pluss_merchant_base_info mbi on mbi.merchantCode=pf.lastMerchantCode
        <where>
            <if test="merchantName!=null and merchantName!=''">
                and pf.merchantName like concat("%",#{merchantName},"%")
            </if>
            <if test="nickName!=null and nickName!=''">
                and pf.nickName like concat("%",#{nickName},"%")
            </if>
            <if test="merchantCode!=null and merchantCode!=''">
                and pf.merchantCode like concat("%",#{merchantCode},"%")
            </if>
            <if test="lastMerchantName!=null and lastMerchantName!=''">
                and mbi.merchantName like concat("%",#{lastMerchantName},"%")
            </if>
            <if test="orderNumber!=null and orderNumber!=''">
                and pf.orderNumber like concat("%",#{orderNumber},"%")
            </if>
            <if test="lastOrderNumber!=null and lastOrderNumber!=''">
                and pf.lastOrderNumber like concat("%",#{lastOrderNumber},"%")
            </if>
            <if test="startTime!= null">
                <![CDATA[
                            and  DATE_FORMAT(pf.consumTime, '%Y-%m-%d %H:%i:%S')>=DATE_FORMAT(#{startTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
            <if test="endTime!= null">
                <![CDATA[
                            and  DATE_FORMAT(pf.consumTime, '%Y-%m-%d %H:%i:%S')<=DATE_FORMAT(#{endTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
        </where>
        order by pf.id DESC limit #{pageSize} offset #{offset}
    </select>

    <select id="queryFansNoConsumPage" parameterType="java.util.Map" resultType="cn.pluss.platform.vo.FansConsumVO">
        select pf.id as id,pf.userId as userId,pf.logo as logo,pf.nickName as nickName,pf.consumMoney as
        consumMoney,pf.merchantCode as merchantCode,mbi.merchantName as
        lastMerchantName,pf.lastMerchantCode,pf.merchantName as
        merchantName,pf.shareMoney,pf.consumTime,pf.lastconsumTime,pf.orderNumber,pf.lastOrderNumber,pf.createDt,pf.payWay
        from tb_pluss_fans pf left join tb_pluss_merchant_base_info mbi on mbi.merchantCode=pf.lastMerchantCode
        <where>
            <if test="merchantName!=null and merchantName!=''">
                and pf.merchantName like concat("%",#{merchantName},"%")
            </if>
            <if test="nickName!=null and nickName!=''">
                and pf.nickName like concat("%",#{nickName},"%")
            </if>
            <if test="merchantCode!=null and merchantCode!=''">
                and pf.merchantCode IN (SELECT merchantCode
                FROM tb_pluss_merchant_base_info
                WHERE bindingCode = (SELECT bindingCode
                FROM tb_pluss_merchant_base_info
                where merchantCode = #{merchantCode}))
            </if>
            <if test="lastMerchantName!=null and lastMerchantName!=''">
                and mbi.merchantName like concat("%",#{lastMerchantName},"%")
            </if>
            <if test="orderNumber!=null and orderNumber!=''">
                and pf.orderNumber like concat("%",#{orderNumber},"%")
            </if>
            <if test="lastOrderNumber!=null and lastOrderNumber!=''">
                and pf.lastOrderNumber like concat("%",#{lastOrderNumber},"%")
            </if>
            <if test="startTime!= null">
                <![CDATA[
                            and  DATE_FORMAT(pf.consumTime, '%Y-%m-%d %H:%i:%S')>=DATE_FORMAT(#{startTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
            <if test="endTime!= null">
                <![CDATA[
                            and  DATE_FORMAT(pf.consumTime, '%Y-%m-%d %H:%i:%S')<=DATE_FORMAT(#{endTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
        </where>
        order by pf.id DESC limit #{pageSize} offset #{offset}
    </select>

    <select id="queryFansConsumPageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
        select count(pf.id) from tb_pluss_fans pf left join tb_pluss_merchant_base_info mbi on
        mbi.merchantCode=pf.lastMerchantCode
        <where>
            <if test="merchantName!=null and merchantName!=''">
                and pf.merchantName like concat("%",#{merchantName},"%")
            </if>
            <if test="nickName!=null and nickName!=''">
                and pf.nickName like concat("%",#{nickName},"%")
            </if>
            <if test="merchantCode!=null and merchantCode!=''">
                and pf.merchantCode like concat("%",#{merchantCode},"%")
            </if>
            <if test="lastMerchantName!=null and lastMerchantName!=''">
                and mbi.merchantName like concat("%",#{lastMerchantName},"%")
            </if>
            <if test="orderNumber!=null and orderNumber!=''">
                and pf.orderNumber like concat("%",#{orderNumber},"%")
            </if>
            <if test="lastOrderNumber!=null and lastOrderNumber!=''">
                and pf.lastOrderNumber like concat("%",#{lastOrderNumber},"%")
            </if>
            <if test="startTime!= null">
                <![CDATA[
                            and  DATE_FORMAT(pf.consumTime, '%Y-%m-%d %H:%i:%S')>=DATE_FORMAT(#{startTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
            <if test="endTime!= null">
                <![CDATA[
                            and  DATE_FORMAT(pf.consumTime, '%Y-%m-%d %H:%i:%S')<=DATE_FORMAT(#{endTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
        </where>
    </select>

    <select id="queryFansNoConsumPageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
        select count(pf.id) from tb_pluss_fans pf left join tb_pluss_merchant_base_info mbi on
        mbi.merchantCode=pf.lastMerchantCode
        <where>
            <if test="merchantName!=null and merchantName!=''">
                and pf.merchantName like concat("%",#{merchantName},"%")
            </if>
            <if test="nickName!=null and nickName!=''">
                and pf.nickName like concat("%",#{nickName},"%")
            </if>
            <if test="merchantCode!=null and merchantCode!=''">
                and pf.merchantCode IN (SELECT merchantCode
                FROM tb_pluss_merchant_base_info
                WHERE bindingCode = (SELECT bindingCode
                FROM tb_pluss_merchant_base_info
                where merchantCode = #{merchantCode}))
            </if>
            <if test="lastMerchantName!=null and lastMerchantName!=''">
                and mbi.merchantName like concat("%",#{lastMerchantName},"%")
            </if>
            <if test="orderNumber!=null and orderNumber!=''">
                and pf.orderNumber like concat("%",#{orderNumber},"%")
            </if>
            <if test="lastOrderNumber!=null and lastOrderNumber!=''">
                and pf.lastOrderNumber like concat("%",#{lastOrderNumber},"%")
            </if>
            <if test="startTime!= null">
                <![CDATA[
                            and  DATE_FORMAT(pf.consumTime, '%Y-%m-%d %H:%i:%S')>=DATE_FORMAT(#{startTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
            <if test="endTime!= null">
                <![CDATA[
                            and  DATE_FORMAT(pf.consumTime, '%Y-%m-%d %H:%i:%S')<=DATE_FORMAT(#{endTime}, '%Y-%m-%d %H:%i:%S')
                         ]]>
            </if>
        </where>
    </select>

    <select id="queryFansSumConsumMoney" parameterType="java.util.Map" resultType="java.lang.Double">
        SELECT sum(consumMoney) from tb_pluss_fans
        <where>
            <if test="lastMerchantCode!= null">
                and lastMerchantCode = #{lastMerchantCode}
            </if>
            <if test="startTime!= null">
                and createDt &gt; #{startTime}
            </if>
            <if test="endTime!= null">
                and createDt &lt; #{endTime}
            </if>
        </where>
    </select>


    <select id="queryFansSumShareMoney" parameterType="java.util.Map" resultType="java.lang.Double">
        SELECT sum(shareMoney) from tb_pluss_fans
        <where>
            <if test="lastMerchantCode!= null">
                and lastMerchantCode = #{lastMerchantCode}
            </if>
            <if test="startTime!= null">
                and createDt &gt; #{startTime}
            </if>
            <if test="endTime!= null">
                and createDt &lt; #{endTime}
            </if>
        </where>
    </select>

    <select id="selectGroupData" resultType="cn.pluss.platform.entity.Fans">
        SELECT
            SUM( shareMoney ) shareMoney,
            lastMerchantCode
        FROM
            tb_pluss_fans
        where lastMerchantCode IN
        <foreach collection="lastMerchantCodeList" close=")" separator="," open="(" item="item">
            #{item}
        </foreach>
        GROUP BY lastMerchantCode
    </select>


</mapper>
