Helius
2020-12-22 66a014290fe3f7540ea460467c80bceea03c12a4
zq-erp/src/main/resources/mybatis/mapper/hive/SysVipInfoDao.xml
@@ -1219,5 +1219,90 @@
    <select id="selectVipInfoByVipNo" resultMap="SysVipInfoMapSimple">
        select * from sys_vip_info where company_id=#{companyId} and vip_no=#{vipNo}
    </select>
    <select id="selectVipAddressBookByList" resultType="com.matrix.system.app.vo.VipInfoListVo">
        select
               a.ID id,
               a.VIP_NAME vipName,
               a.PHONE phone,
               a.photo photo,
               b.arriveCnt arriveCnt,
               g.shop_short_name shopName
        from sys_vip_info a
        left join (
            select x.vip_id, count(1) arriveCnt from (
                                                 select vip_id, date_format(datatime, '%Y-%m-%d')
                                                 from achieve_new
                                                 where 1=1
                                                 <!-- 本月到店次数 -->
                                                 <if test="record.sort == 'monthArrived'">
                                                     and date_format(curdate(), '%Y-%m') = date_format(datatime, '%Y-%m')
                                                 </if>
                                                 <!-- 本年到店次数 -->
                                                 <if test="record.sort == 'yearArrived'">
                                                     and date_format(curdate(), '%Y') = date_format(datatime, '%Y')
                                                 </if>
                                                 group by date_format(datatime, '%Y-%m-%d'), vip_id
                                             ) x group by x.vip_id
            ) b on a.ID=b.vip_id
        <!-- 本月消费 -->
        <if test="record.sort == 'used'">
            left join (
            select y.vip_id, sum(IFNULL(card_cash, 0) + IFNULL(proj_cash,0) + IFNULL(goods_cash, 0)) used from achieve_new y where date_format(datatime,'%Y-%m') = date_format(curdate(), '%Y-%m') group by y.vip_id
            ) c on a.id=c.vip_id
        </if>
        <!-- 本月消耗 -->
        <if test="record.sort == 'consume'">
        left join (
            select z.vip_id, SUM(IFNULL(free_consume, 0) + IFNULL(his_consume, 0) + IFNULL(consume, 0)) consume from achieve_new z where date_format(datatime,'%Y-%m') = date_format(curdate(), '%Y-%m') group by z.vip_id
            ) d on a.ID = d.vip_id
        </if>
        <!-- 上次到店时间 -->
        <if test="record.sort == 'arriveTime'">
        left join (
            select m.vip_id, MAX(datatime) arriveTime from achieve_new m group by m.vip_id
            ) e on a.ID=e.vip_id
        </if>
        <!-- 会员级别排序 -->
        <if test="record.sort == 'vipLevel'">
        left join (
            select n.VIP_LEVEL vipLevel, n.ID from sys_vip_level n
            ) f on a.LEVEL_ID = f.ID
        </if>
        left join sys_shop_info g on a.shop_id = g.id
        left join sys_vip_level h on a.level_id=h.id
        where 1=1
        <if test="record.queryKey != null and record.queryKey != ''">
            and (instr(PHONE,#{record.queryKey})
                or instr(VIP_NAME ,#{record.queryKey})
                or instr(zjm ,#{record.queryKey})
                or instr(VIP_NO ,#{record.queryKey}))
        </if>
        <if test="record.shopId != null">
            and a.shop_id=#{record.shopId}
        </if>
        <if test='record.birthType=="1"'>
            and a.BIRTHDAY1 between curdate() and DATE_ADD(CURDATE(), INTERVAL 3 DAY)
        </if>
        <if test='record.birthType=="2"'>
            and date_format(a.BIRTHDAY1, '%Y-%m') = date_format(CURDATE(), '%Y-%m')
        </if>
        <if test='record.birthType=="3"'>
            and PERIOD_DIFF(date_format(now() ,'%Y-%m') , date_format(a.BIRTHDAY1, '%Y-%m')) =1
        </if>
        <if test="record.vipType != null">
            and a.level_id=#{record.vipType}
        </if>
        <if test="record.other != null and record.other!=''">
            and a.is_deal=#{record.other}
        </if>
        <if test="record.sort == 'monthArrived' or record.sort == 'yearArrived'">
            order by arriveCnt ${record.order}
        </if>
        <if test="record.sort != 'monthArrived' and record.sort != 'yearArrived'">
            order by ${record.sort} ${record.order}
        </if>
    </select>
</mapper>