From f28cb1b4e59305480ef1effee38b1dc411f775a4 Mon Sep 17 00:00:00 2001
From: 喻健 <Administrator@Admin>
Date: 星期二, 25 十二月 2018 17:50:25 +0800
Subject: [PATCH] 奖金统计

---
 fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderMapper.xml |  242 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 208 insertions(+), 34 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderMapper.xml b/fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderMapper.xml
index ab4ef73..a6c58c8 100644
--- a/fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderMapper.xml
+++ b/fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderMapper.xml
@@ -158,9 +158,9 @@
 		<if test="endTime != null">
 			AND <![CDATA[tc.co_create_time < #{endTime}]]>
 		</if>
-	GROUP BY tc.`co_order_no`
+	GROUP BY tc.`co_order_no`,tc.co_source_type
 	ORDER BY tc.co_create_time DESC
-	LIMIT #{start},#{count}
+	LIMIT ${start},${count}
   </select>
   
    <select id="countGroupOrderNoByUid" resultType="java.lang.Long">
@@ -243,32 +243,6 @@
 	)A
   </select>
   
-  
-  <select id="countOrder" resultType="java.lang.Long">
-	SELECT IFNULL(COUNT(DISTINCT tc.`co_order_no`,tc.`co_source_type`),0) 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 1=1 
-		<if test="uid != null">
-		   AND th.`hb_uid` = ${uid}
-		</if>
-		<if test ="isToday == 1">
-			AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
-		</if>
-  </select>
-
-  <select id="countOrderMoney" resultType="java.lang.Long">
-	SELECT  IFNULL(SUM(th.`hb_money`),0)AS totalmoney 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 <![CDATA[tc.`co_state` <> 4]]>
-		<if test ="isToday == 1">
-		   AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
-		</if>
-	GROUP BY tc.`co_order_no`,tc.`co_source_type`
-  </select>
-  
   <select id="countByUidAndOrderState" 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
@@ -276,8 +250,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} AND (tc.`co_state` = 1 OR tc.`co_state` = 2)
-			<if test="type != null">
-				AND th.hb_type = #{type}
+			<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="startTime != null">
 				AND <![CDATA[tc.co_create_time >= #{startTime}]]>
@@ -293,8 +273,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} AND  tc.`co_state` =3
-			<if test="type != null">
-				AND th.hb_type = #{type}
+			<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="startTime != null">
 				AND <![CDATA[tc.co_create_time >= #{startTime}]]>
@@ -310,8 +296,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} AND tc.`co_state` = 4 
-			<if test="type != null">
-				AND th.hb_type = #{type}
+			<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="startTime != null">
 				AND <![CDATA[tc.co_create_time >= #{startTime}]]>
@@ -322,4 +314,186 @@
 		)A
   </select>
   
+  
+  <select id="countBonusOrder" resultType="java.lang.Long">
+	SELECT COALESCE(COUNT(DISTINCT tc.`co_order_no`,tc.`co_source_type`),0) 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 1=1
+		<if test="uid != null">
+		   AND th.`hb_uid` = ${uid}
+		</if> 
+		<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>
+  </select>
+
+  <select id="countBonusOrderMoney" resultType="java.math.BigDecimal">
+	SELECT  COALESCE(SUM(th.`hb_money`),0)AS totalmoney 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 <![CDATA[tc.`co_state` <> 4]]>
+	 	 <if test="uid != null">
+		   AND th.`hb_uid` = ${uid}
+		 </if> 
+		<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>
+  </select>
+  
+   <select id="listBonusOrder" resultMap="ResultMap" >
+  	SELECT COALESCE(SUM(th.`hb_money`),0)AS totalMoney,tc.*,th.hb_state AS hongBaoState, th.hb_type AS hongBaoType,
+  		th.hb_get_time AS accountTime,th.hb_get_time AS accountTime,th.hb_pre_get_time AS preAccountTime
+    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}
+		<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>
+	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>

--
Gitblit v1.8.0