yujian
2018-12-26 f0f94a69b05dd6049e1b3dff2ef3f7a9ac8332fb
fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderMapper.xml
@@ -137,8 +137,14 @@
       LEFT JOIN  yeshi_ec_hongbao_order tr ON tr.`ho_order_id` = tc.`co_id`
         LEFT JOIN yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id` OR  th.`hb_pid` = tr.`ho_hongbao_id` )
   WHERE th.`hb_uid` = #{uid}
      <if test="state != null">
         AND th.hb_state = #{state}
      <if test="state != null and state == 1">  <!-- 未到账 -->
         AND (th.hb_state = 1 or th.hb_state = 2)
      </if>
      <if test="state != null and state == 2"> <!-- 已到账 -->
         AND th.hb_state = 3
      </if>
      <if test="state != null and state == 3">  <!-- 红包已失效 -->
         AND th.hb_state =4
      </if>
      <if test="type != null and type == 1"> <!-- 自购订单 -->
         AND (th.hb_type =1 or th.hb_type =2)
@@ -152,12 +158,33 @@
      <if test="orderNo != null">
         AND tc.co_order_no = #{orderNo}
      </if>
      <if test="orderState != null and orderState ==  1">
         AND (tc.co_state = 1 or tc.co_state = 2) <!-- 有效订单 -->
      </if>
      <if test="orderState != null and orderState ==  2">
         AND tc.co_state = 3 <!-- 维权订单 -->
      </if>
      <if test="orderState != null and orderState ==  3">
         AND tc.co_state = 4 <!-- 失效订单 -->
      </if>
      <if test="startTime != null">
         AND <![CDATA[tc.co_create_time >= #{startTime}]]>
      </if>
      <if test="endTime != null">
         AND <![CDATA[tc.co_create_time < #{endTime}]]>
      </if>
      <if test ="day != null and day == 1"> <!-- 今天 -->
          AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
      </if>
      <if test="day != null and day == 2">  <!-- 昨天 -->
           AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
       </if>
       <if test="day != null and day == 3">  <!-- 本月 -->
           AND DATE_FORMAT(tc.`co_create_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(tc.`co_create_time`, '%Y%m')) = 1
       </if>
   GROUP BY tc.`co_order_no`,tc.co_source_type
   ORDER BY tc.co_create_time DESC
   LIMIT ${start},${count}
@@ -168,8 +195,14 @@
       LEFT JOIN  yeshi_ec_hongbao_order tr ON tr.`ho_order_id` = tc.`co_id`
         LEFT JOIN yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id` OR  th.`hb_pid` = tr.`ho_hongbao_id` )
   WHERE  th.`hb_uid` = #{uid}
      <if test="state != null">
         AND th.hb_state = #{state}
      <if test="state != null and state == 1">  <!-- 未到账 -->
         AND (th.hb_state = 1 or th.hb_state = 2)
      </if>
      <if test="state != null and state == 2">  <!-- 已到账 -->
         AND th.hb_state = 3
      </if>
      <if test="state != null and state == 3"> <!-- 红包已失效 -->
         AND th.hb_state =4
      </if>
      <if test="type != null and type == 1"> <!-- 自购订单 -->
         AND (th.hb_type =1 or th.hb_type =2)
@@ -180,6 +213,17 @@
      <if test="type != null and type == 3"> <!-- 邀请订单 -->
         AND  (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
      </if>
      <if test="orderState != null and orderState = 1">
         AND (tc.co_state = 1 or tc.co_state = 2) <!-- 有效订单 -->
      </if>
      <if test="orderState != null and orderState = 2">
         AND tc.co_state = 3 <!-- 维权订单 -->
      </if>
      <if test="orderState != null and orderState = 3">
         AND tc.co_state = 4 <!-- 失效订单 -->
      </if>
      <if test="orderNo != null">
         AND tc.co_order_no = #{orderNo}
      </if>
@@ -189,6 +233,18 @@
      <if test="endTime != null">
         AND <![CDATA[tc.co_create_time < #{endTime}]]>
      </if>
      <if test ="day != null and day == 1"> <!-- 今天 -->
          AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
      </if>
      <if test="day != null and day == 2">  <!-- 昨天 -->
           AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
       </if>
       <if test="day != null and day == 3">  <!-- 本月 -->
           AND DATE_FORMAT(tc.`co_create_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(tc.`co_create_time`, '%Y%m')) = 1
       </if>
  </select>
  
   <select id="listByOrderNoAndType" resultMap="ResultMap"  parameterType="java.util.List">
@@ -332,6 +388,7 @@
      <if test="type != null and type == 3"> <!-- 邀请订单 -->
         AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
      </if>
      <if test ="day != null and day == 1"> <!-- 今天 -->
          AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
      </if>
@@ -339,10 +396,10 @@
           AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
       </if>
       <if test="day != null and day == 3">  <!-- 本月 -->
           AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') = DATE_FORMAT(CURDATE( ),'%Y%m')
           AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')
       </if>
       <if test="day != null and day == 4">  <!-- 上月 -->
           AND ERIOD_DIFF( DATE_FORMAT( now( ), '%Y%m'), DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
           AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'), DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
       </if>
  </select>
@@ -370,10 +427,10 @@
           AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
       </if>
       <if test="day != null and day == 3">  <!-- 本月 -->
           AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') = DATE_FORMAT(CURDATE( ),'%Y%m')
           AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')
       </if>
       <if test="day != null and day == 4">  <!-- 上月 -->
           AND ERIOD_DIFF( DATE_FORMAT( now( ), '%Y%m'), DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
           AND PERIOD_DIFF( DATE_FORMAT(NOW(), '%Y%m'), DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
       </if>
  </select>
  
@@ -393,6 +450,15 @@
      <if test="type != null and type == 3"> <!-- 邀请订单 -->
         AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
      </if>
      <if test="orderState != null and orderState == 1">
         AND (tc.co_state = 1 or tc.co_state = 2) <!-- 有效订单 -->
      </if>
      <if test="orderState != null and orderState == 2">
         AND tc.co_state = 3 <!-- 维权订单 -->
      </if>
      <if test="orderState != null and orderState == 3">
         AND tc.co_state = 4 <!-- 失效订单 -->
      </if>
      <if test ="day != null and day == 1"> <!-- 今天 -->
          AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
      </if>
@@ -400,100 +466,14 @@
           AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
       </if>
       <if test="day != null and day == 3">  <!-- 本月 -->
           AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') = DATE_FORMAT(CURDATE( ),'%Y%m')
           AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')
       </if>
       <if test="day != null and day == 4">  <!-- 上月 -->
           AND ERIOD_DIFF( DATE_FORMAT( now( ), '%Y%m'), DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
           AND PERIOD_DIFF( DATE_FORMAT(NOW(), '%Y%m'), DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
       </if>
   GROUP BY tc.`co_order_no`,tc.co_source_type
   ORDER BY tc.co_create_time DESC
   LIMIT ${start},${count}
  </select>
  <select id="countBonusOrderByState" resultType="java.util.HashMap">
     SELECT SUM(valid)AS totalValid, SUM(proces)AS totalProces ,SUM(Invalid)AS totalInvite
     FROM (SELECT IFNULL(COUNT(DISTINCT tc.`co_order_no`,tc.`co_source_type`),0) AS valid,0 AS proces,0 AS  Invalid
        FROM yeshi_ec_common_order tc
          LEFT JOIN  yeshi_ec_hongbao_order tr ON tr.`ho_order_id` = tc.`co_id`
            LEFT JOIN yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id` OR  th.`hb_pid` = tr.`ho_hongbao_id` )
      WHERE th.`hb_uid` = #{uid} AND (tc.`co_state` = 1 OR tc.`co_state` = 2)
         <if test="type != null and type == 1"> <!-- 自购订单 -->
            AND (th.hb_type =1 or th.hb_type =2)
         </if>
         <if test="type != null and type == 2"> <!-- 分享订单 -->
            AND (th.`hb_type` = 20 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
         </if>
         <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
         </if>
         <if test ="day != null and day == 1"> <!-- 今天 -->
             AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
         </if>
         <if test="day != null and day == 2">  <!-- 昨天 -->
              AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
          </if>
          <if test="day != null and day == 3">  <!-- 本月 -->
              AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') = DATE_FORMAT(CURDATE( ),'%Y%m')
          </if>
          <if test="day != null and day == 4">  <!-- 上月 -->
              AND ERIOD_DIFF( DATE_FORMAT( now( ), '%Y%m'), DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
          </if>
      UNION
      SELECT 0 AS valid,IFNULL(COUNT(DISTINCT tc.`co_order_no`,tc.`co_source_type`),0) AS proces,0 AS Invalid
      FROM yeshi_ec_common_order tc
          LEFT JOIN  yeshi_ec_hongbao_order tr ON tr.`ho_order_id` = tc.`co_id`
            LEFT JOIN yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id` OR  th.`hb_pid` = tr.`ho_hongbao_id` )
      WHERE th.`hb_uid` = #{uid} AND  tc.`co_state` =3
         <if test="type != null and type == 1"> <!-- 自购订单 -->
            AND (th.hb_type =1 or th.hb_type =2)
         </if>
         <if test="type != null and type == 2"> <!-- 分享订单 -->
            AND (th.`hb_type` = 20 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
         </if>
         <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
         </if>
         <if test ="day != null and day == 1"> <!-- 今天 -->
             AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
         </if>
         <if test="day != null and day == 2">  <!-- 昨天 -->
              AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
          </if>
          <if test="day != null and day == 3">  <!-- 本月 -->
              AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') = DATE_FORMAT(CURDATE( ),'%Y%m')
          </if>
          <if test="day != null and day == 4">  <!-- 上月 -->
              AND ERIOD_DIFF( DATE_FORMAT( now( ), '%Y%m'), DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
          </if>
      UNION
      SELECT 0 AS valid,0 AS proces,IFNULL(COUNT(DISTINCT tc.`co_order_no`,tc.`co_source_type`),0) AS Invalid
      FROM yeshi_ec_common_order tc
          LEFT JOIN  yeshi_ec_hongbao_order tr ON tr.`ho_order_id` = tc.`co_id`
            LEFT JOIN yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id` OR  th.`hb_pid` = tr.`ho_hongbao_id` )
      WHERE th.`hb_uid`= #{uid} AND tc.`co_state` = 4
         <if test="type != null and type == 1"> <!-- 自购订单 -->
            AND (th.hb_type =1 or th.hb_type =2)
         </if>
         <if test="type != null and type == 2"> <!-- 分享订单 -->
            AND (th.`hb_type` = 20 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
         </if>
         <if test="type != null and type == 3"> <!-- 邀请订单 -->
            AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
         </if>
         <if test ="day != null and day == 1"> <!-- 今天 -->
             AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
         </if>
         <if test="day != null and day == 2">  <!-- 昨天 -->
              AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
          </if>
          <if test="day != null and day == 3">  <!-- 本月 -->
              AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') = DATE_FORMAT(CURDATE( ),'%Y%m')
          </if>
          <if test="day != null and day == 4">  <!-- 上月 -->
              AND ERIOD_DIFF( DATE_FORMAT( now( ), '%Y%m'), DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
          </if>
      )A
  </select>
</mapper>