yujian
2019-01-22 88b54772dbcf5ecab1e2316e4e4626ac901b8908
fanli/src/main/java/com/yeshi/fanli/mapping/UserInfoMapper.xml
@@ -322,14 +322,13 @@
   
   
   <select id="countNewUser" resultType="java.lang.Long">
      <!--  自购订单 -->
         SELECT COALESCE(count(id),0) FROM `yeshi_ec_user` 
          WHERE 1 > 0
         WHERE 1=1
             <if test="isToday != null and isToday == 1">
             AND  TO_DAYS(FROM_UNIXTIME(createtime/1000)) = TO_DAYS(NOW())
             AND TO_DAYS(FROM_UNIXTIME(createtime/1000)) = TO_DAYS(NOW())
           </if>
           <if test="isMonth != null and isMonth == 1">
             AND DATE_FORMAT( FROM_UNIXTIME(createtime/1000), '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )
             AND DATE_FORMAT( FROM_UNIXTIME(createtime/1000), '%Y%m' ) = DATE_FORMAT(CURDATE() , '%Y%m' )
          </if>
   </select>
   
@@ -371,31 +370,38 @@
   <select id="countLoseUser" resultType="java.lang.Long">
      SELECT  COUNT(DISTINCT t.`id` ) FROM `yeshi_ec_user` t 
      LEFT JOIN `yeshi_ec_user_money_detail` d ON d.`umd_uid` = t.`id` 
      WHERE DATE_SUB(CURDATE(), INTERVAL ${num} DAY) > DATE(FROM_UNIXTIME( t.`last_logintime`/1000))
             AND DATE_SUB(CURDATE(), INTERVAL ${num} DAY) > DATE(d.`umd_createtime`)
      WHERE DATE_SUB(CURDATE(), INTERVAL ${num} DAY)<![CDATA[> ]]> DATE(FROM_UNIXTIME( t.`last_logintime`/1000))
             AND DATE_SUB(CURDATE(), INTERVAL ${num} DAY) <![CDATA[> ]]> DATE(d.`umd_createtime`)
   </select>
   
   <select id="countHasOrderUser" resultType="java.lang.Long">
      SELECT COUNT(DISTINCT h.`uid`) FROM yeshi_ec_hongbao_v2 h
      WHERE h.`hb_type`=1 or  h.`hb_type`=2
      SELECT COUNT(DISTINCT h.`hb_uid`) FROM yeshi_ec_hongbao_v2 h
      WHERE (h.`hb_type`=1 or  h.`hb_type`=2 or h.`hb_type`= 20)
   </select>
   
   
   <select id="countNewUserByDate" resultType="java.util.HashMap">
      SELECT COUNT(h.`id`) AS total,
      SELECT COUNT(DISTINCT h.`id`) AS showValue,
         <if test="type == 1">
             FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m-%d') AS 'createDate'
             FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m-%d') AS 'showDate'
         </if>
         <if test="type == 2">
             FROM_UNIXTIME(h.`createtime`/1000,'%m') AS 'createDate'
             FROM_UNIXTIME(h.`createtime`/1000,'%m') AS 'showDate'
         </if>
         <if test="type == 3">
             FROM_UNIXTIME(h.`createtime`/1000,'%Y') AS 'createDate'
             FROM_UNIXTIME(h.`createtime`/1000,'%Y') AS 'showDate'
         </if>
      FROM yeshi_ec_user h 
         <if test="channel != null and  channel != 'all' ">
            left join (SELECT a.`lua_uid` AS uid FROM `yeshi_ec_log_user_active`  a
             WHERE a.`lua_channel`='${channel}' GROUP BY a.`lua_uid`)a ON h.`id`=a.uid
          </if>
      WHERE 1=1
         <if test="channel != null and  channel != 'all' ">
            AND a.uid is not null
         </if>
         <if test="startTime != null and startTime != '' ">
          AND FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m-%d')<![CDATA[ >= ]]>'${startTime}'
             AND FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m-%d')<![CDATA[ >= ]]>'${startTime}'
         </if>
         <if test="endTime != null and endTime != '' ">
             AND FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m-%d') <![CDATA[ <= ]]> '${endTime}'
@@ -414,4 +420,81 @@
      </if>      
      ORDER BY h.`createtime`
   </select>
   <select id="getTodayHasOrder" resultType="java.util.HashMap">
      SELECT COALESCE(COUNT(DISTINCT u.`id`),0) AS 'showValue',
         <if test="type == 1">
             FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') AS 'showDate'
         </if>
         <if test="type == 2">
             FROM_UNIXTIME(u.`createtime`/1000,'%m') AS 'showDate'
         </if>
         <if test="type == 3">
             FROM_UNIXTIME(u.`createtime`/1000,'%Y') AS 'showDate'
         </if>
      FROM  yeshi_ec_user u
      <if test="channel != null and channel != 'all' ">
         LEFT JOIN  (SELECT a.`lua_uid` AS uid FROM `yeshi_ec_log_user_active`  a
             WHERE a.`lua_channel`='${channel}' GROUP BY a.`lua_uid`) a ON u.`id`=a.uid
      </if>
      LEFT JOIN `yeshi_ec_hongbao_v2` h ON h.`hb_uid`= u.`id`
      WHERE (h.`hb_type`=1 OR h.`hb_type`=20)
         <if test="channel != null and  channel != 'all' ">
            AND a.uid is not null
         </if>
         <!-- 当日下单 -->
         AND FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') = DATE_FORMAT(h.hb_create_time,'%Y-%m-%d')
         <if test="startTime != null and startTime != '' ">
             AND FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d')<![CDATA[ >= ]]>'${startTime}'
         </if>
         <if test="endTime != null and endTime != '' ">
             AND FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') <![CDATA[ <= ]]> '${endTime}'
         </if>
         <if test="years != null and years != '' ">
             AND FROM_UNIXTIME(u.`createtime`/1000,'%Y') = '${years}'
         </if>
      <if test="type == 1">
         GROUP BY FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d')
      </if>
      <if test="type == 2">
          GROUP BY FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m')
      </if>
      <if test="type == 3">
          GROUP BY FROM_UNIXTIME(u.`createtime`/1000,'%Y')
      </if>
      ORDER BY u.`createtime`
   </select>
   <select id="getWeekHasOrder" resultType="java.util.HashMap">
      SELECT COUNT(DISTINCT hb.uid) AS showValue,FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') AS 'showDate'
      FROM (SELECT COUNT(v2.`hb_id`) AS num,v2.hb_uid  AS uid
              FROM yeshi_ec_hongbao_v2 v2
              WHERE   (v2.`hb_type`=1 OR v2.`hb_type`=20)
                 AND DATE_FORMAT(v2.`hb_create_time`,'%Y-%m-%d') <![CDATA[ >= ]]>'${startTime}'
                 AND DATE_FORMAT(v2.`hb_create_time`,'%Y-%m-%d') <![CDATA[ <= ]]>'${endTime}'
              GROUP BY v2.hb_uid HAVING num >= ${orderNum})hb
      LEFT JOIN yeshi_ec_user u  ON u.id = hb.uid
      <if test="channel != null and channel != 'all' ">
         LEFT JOIN  (SELECT a.`lua_uid` AS uid FROM `yeshi_ec_log_user_active`  a
             WHERE a.`lua_channel`='${channel}' GROUP BY a.`lua_uid`) a ON u.`id`=a.uid
      </if>
      WHERE FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') = '${startTime}'
         <if test="channel != null and  channel != 'all' ">
            AND a.uid is not null
         </if>
         GROUP BY FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d')
      ORDER BY u.`createtime`
   </select>
   <select id="getInfoByPhoneOrInviteCode" resultMap="BaseResultMap">
      SELECT * FROM yeshi_ec_user u
      LEFT JOIN yeshi_ec_user_info_extra uf ON uf.`uie_uid` = u.`id`
      WHERE uf.`uie_invite_code` IS NOT NULL
           AND (u.`phone` =#{phone} OR uf.`uie_invite_code` = #{inviteCode})
      LIMIT 1
   </select>
</mapper>