admin
2019-01-19 0e5e21d2f3693dc993b3f49d88a275f7b226eba5
fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderCountMapper.xml
@@ -5,37 +5,37 @@
   <sql id="Column_DateType">
      <if test="dateType == 1">
         DATE_FORMAT(t.`co_create_time`,'%Y-%m-%d') AS 'showDate'
         DATE_FORMAT(t.`co_third_create_time`,'%Y-%m-%d') AS 'showDate'
      </if>
      <if test="dateType == 2">
         DATE_FORMAT(t.`co_create_time`,'%m') AS 'showDate'
         DATE_FORMAT(t.`co_third_create_time`,'%m') AS 'showDate'
      </if>
      <if test="dateType == 3">
         DATE_FORMAT(t.`co_create_time`,'%Y') AS 'showDate'
         DATE_FORMAT(t.`co_third_create_time`,'%Y') AS 'showDate'
      </if>
   </sql>
   <sql id="Count_Select_DateType">
      <if test="startTime != null and startTime != '' ">
         AND DATE_FORMAT(t.`co_create_time`,'%Y-%m-%d')<![CDATA[ >= ]]>'${startTime}'
         AND DATE_FORMAT(t.`co_third_create_time`,'%Y-%m-%d')<![CDATA[ >= ]]>'${startTime}'
      </if>
      <if test="endTime != null and endTime != '' ">
         AND DATE_FORMAT(t.`co_create_time`,'%Y-%m-%d') <![CDATA[ <= ]]>'${endTime}'
         AND DATE_FORMAT(t.`co_third_create_time`,'%Y-%m-%d') <![CDATA[ <= ]]>'${endTime}'
      </if>
      <if test="year != null and year != '' ">
         AND DATE_FORMAT(t.`co_create_time`,'%Y') = '${year}'
         AND DATE_FORMAT(t.`co_third_create_time`,'%Y') = '${year}'
      </if>
   </sql>
   <sql id="Count_Group_DateType">
      <if test="dateType == 1">
         GROUP BY DATE_FORMAT(t.`co_create_time`,'%Y-%m-%d')
         GROUP BY DATE_FORMAT(t.`co_third_create_time`,'%Y-%m-%d')
      </if>
      <if test="dateType == 2">
         GROUP BY DATE_FORMAT(t.`co_create_time`,'%Y-%m')
         GROUP BY DATE_FORMAT(t.`co_third_create_time`,'%Y-%m')
      </if>
      <if test="dateType == 3">
         GROUP BY DATE_FORMAT(t.`co_create_time`,'%Y')
         GROUP BY DATE_FORMAT(t.`co_third_create_time`,'%Y')
      </if>
   </sql>
@@ -50,9 +50,107 @@
   <select id="countOrderNumber" resultType="java.util.HashMap">
      SELECT IFNULL(COUNT(t.`co_id`),0) AS showValue,<include refid="Column_DateType"/>
      FROM `yeshi_ec_common_order` t 
      WHERE t.`co_create_time` IS NOT NULL <include refid="Count_Select_DateType"/>
      WHERE t.`co_third_create_time` IS NOT NULL <include refid="Count_Select_DateType"/>
      <include refid="Count_Group_DateType"/>
      ORDER BY t.`co_create_time`
      ORDER BY t.`co_third_create_time`
   </select>
   <select id="countOrderNumberBySettleTime" resultType="java.util.HashMap">
      <!-- 统计历史订单数量  根据结算时间 -->
      SELECT SUM(A.self)AS totalSelf,SUM(A.shared)AS totalShared,SUM(A.invite)AS totalInvite
      FROM (
         <!-- 返利订单 -->
         SELECT IFNULL(COUNT(ho_id),0) AS self,0 AS shared,0 AS invite
         FROM  (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho
            LEFT JOIN (
               SELECT * FROM yeshi_ec_hongbao_v2 v2
               WHERE v2.`hb_uid`= ${uid} AND (v2.`hb_type` = 1 OR v2.`hb_type` = 2)
               ) hb  ON hb.hb_id=ho.`ho_hongbao_id` <!-- 自购订单 -->
         LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
         WHERE hb.hb_id IS NOT NULL
             <if test="state != null">
               AND co.`co_state` = ${state}
            </if>
            <if test="day != null and day == 1"> <!-- 今天 -->
               AND TO_DAYS(co.`co_settle_time`) = TO_DAYS(NOW())
            </if>
            <if test="day != null and day == 2">  <!-- 昨天 -->
               AND TO_DAYS(NOW()) - TO_DAYS(co.co_settle_time) = 1
            </if>
            <if test="day != null and day == 3">  <!-- 本月 -->
               AND DATE_FORMAT(co.`co_settle_time`,'%Y%m') =
               DATE_FORMAT(CURDATE(),'%Y%m')
            </if>
            <if test="day != null and day == 4">  <!-- 上月 -->
               AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
               DATE_FORMAT(co.`co_settle_time`, '%Y%m')) = 1
            </if>
         GROUP BY co.`co_order_no`, co.`co_source_type`)YX
         UNION ALL
         <!-- 分享订单 -->
         SELECT 0 AS self,IFNULL(COUNT(ho_id),0) AS shared,0 AS invite
         FROM  (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho
               LEFT JOIN (
                  SELECT * FROM yeshi_ec_hongbao_v2 v2
                  WHERE v2.`hb_uid`= ${uid} AND v2.`hb_type` = 20
               ) hb  ON hb.hb_id=ho.`ho_hongbao_id`  <!-- 分享订单 -->
            LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
            WHERE hb.hb_id IS NOT NULL
               <if test="state != null">
                  AND co.`co_state` = ${state}
               </if>
               <if test="day != null and day == 1"> <!-- 今天 -->
                  AND TO_DAYS(co.`co_settle_time`) = TO_DAYS(NOW())
               </if>
               <if test="day != null and day == 2">  <!-- 昨天 -->
                  AND TO_DAYS(NOW()) - TO_DAYS(co.`co_settle_time`) = 1
               </if>
               <if test="day != null and day == 3">  <!-- 本月 -->
                  AND DATE_FORMAT(co.`co_settle_time`,'%Y%m') =
                  DATE_FORMAT(CURDATE(),'%Y%m')
               </if>
               <if test="day != null and day == 4">  <!-- 上月 -->
                  AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
                  DATE_FORMAT(co.`co_settle_time`, '%Y%m')) = 1
               </if>
            GROUP BY co.`co_order_no`, co.`co_source_type`)WQ
         UNION ALL
         <!-- 邀请订单 -->
         SELECT 0 AS self,0 AS shared,IFNULL(COUNT(ho_id),0) AS invite
         FROM  (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho
            LEFT JOIN (
               SELECT * FROM yeshi_ec_hongbao_v2 v2
               WHERE v2.`hb_uid`= ${uid}
                   AND (v2.`hb_type` = 5 OR v2.`hb_type` = 6 OR v2.`hb_type` = 7
                        OR v2.`hb_type` = 21 OR v2.`hb_type` = 22 )
               ) hbp  ON hbp.hb_pid=ho.`ho_hongbao_id`
            LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
            WHERE  hbp.hb_id IS NOT NULL
               <if test="state != null">
                  AND co.`co_state` = ${state}
               </if>
               <if test="day != null and day == 1"> <!-- 今天 -->
                  AND TO_DAYS(co.`co_settle_time`) = TO_DAYS(NOW())
               </if>
               <if test="day != null and day == 2">  <!-- 昨天 -->
                  AND TO_DAYS(NOW()) - TO_DAYS(co.`co_settle_time`) = 1
               </if>
               <if test="day != null and day == 3">  <!-- 本月 -->
                  AND DATE_FORMAT(co.`co_settle_time`,'%Y%m') =
                  DATE_FORMAT(CURDATE(),'%Y%m')
               </if>
               <if test="day != null and day == 4">  <!-- 上月 -->
                  AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
                  DATE_FORMAT(co.`co_settle_time`, '%Y%m')) = 1
               </if>
            GROUP BY co.`co_order_no`, co.`co_source_type`)SX
      )A
   </select>
   
</mapper>