Helius
2020-12-22 1de8d61a544e889ef4a8ed86d438f55994216cd1
zq-erp/src/main/resources/mybatis/mapper/hive/SysVipInfoDao.xml
@@ -1219,5 +1219,72 @@
    <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
        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>
        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.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>