From e9ff30e28b975da534d626f27a450d57edcdc9eb Mon Sep 17 00:00:00 2001
From: jyy <935090232@qq.com>
Date: Wed, 17 Mar 2021 15:38:29 +0800
Subject: [PATCH] 解决绑定下级客户bug

---
 zq-erp/src/main/resources/mybatis/mapper/fenxiao/ShopSalesmanApplyDao.xml |   86 +++++++++++++++++++++++++++++--------------
 1 files changed, 58 insertions(+), 28 deletions(-)

diff --git a/zq-erp/src/main/resources/mybatis/mapper/fenxiao/ShopSalesmanApplyDao.xml b/zq-erp/src/main/resources/mybatis/mapper/fenxiao/ShopSalesmanApplyDao.xml
index 60c4479..038ebd0 100644
--- a/zq-erp/src/main/resources/mybatis/mapper/fenxiao/ShopSalesmanApplyDao.xml
+++ b/zq-erp/src/main/resources/mybatis/mapper/fenxiao/ShopSalesmanApplyDao.xml
@@ -60,6 +60,7 @@
 
 	<select id="findShopSalesmanApplyList" resultType="com.matrix.system.fenxiao.vo.ShopSalesmanApplyVo">
 		SELECT
+		a.id id,
 		a.user_id userId,
 		b.avatar_url avatarUrl,
 		b.nick_name nickname,
@@ -67,6 +68,8 @@
 		WHERE s.open_id = a.parent_user_id ) parentUser,
 		( SELECT COUNT(*) FROM biz_user
 		WHERE parent_open_id = a.user_id AND is_sales != 1 ) lowerLevelNum,
+		( SELECT COUNT(*) FROM biz_user
+		WHERE parent_open_id = a.user_id AND is_sales = 1 ) invitedNum,
 		( SELECT IFNULL(sum(IFNULL(amount, 0)), 0) FROM shop_salesman_order
 		WHERE user_id = a.user_id AND order_status = 2 AND sales_user_id = a.user_id ) totalRevenue,
 		( SELECT IFNULL(sum(IFNULL(amount, 0)), 0) FROM shop_salesman_order
@@ -117,15 +120,17 @@
 	</select>
 	<select id="selectBizUserApplyList" resultType="com.matrix.system.fenxiao.vo.ShopSalesmanAppliingVo">
 		SELECT
-		a.open_id userId,
-		a.nick_name nickName
+		a.user_id userId,
+		a.open_id openId,
+		a.nick_name nickName,
+		a.avatar_url avatarUrl,
+		a.create_time createTime,
+		a.phone_number phone
 		FROM
 		biz_user a
-		LEFT JOIN shop_salesman_apply b ON a.open_id = b.user_id
 		<where>
 			a.company_id = #{record.companyId}
 			and a.is_sales != 1
-			and b.apply_status != 1
 			<if test="record.nickName != null and record.nickName != ''">
 				and a.nick_name like concat('%',#{record.nickName},'%')
 			</if>
@@ -144,9 +149,7 @@
 			IFNULL(sum(IFNULL( b.amount, 0 )),0)
 		FROM
 			shop_salesman_order b
-		WHERE
-			b.user_id = a.open_id
-		  and order_status=2
+		WHERE order_status=2
 		  AND b.sales_user_id = #{openId}
 
 	) AS totalRevenue,
@@ -155,9 +158,7 @@
 			IFNULL(sum(IFNULL( b.amount, 0 )),0)
 		FROM
 			shop_salesman_order b
-		WHERE
-			b.user_id = a.open_id
-		  and order_status=2 and revenue_type=1
+		WHERE order_status=2 and revenue_type=1
 		  AND b.sales_user_id = #{openId}
 
 	) AS salesRevenue,
@@ -166,9 +167,7 @@
 			IFNULL(sum(IFNULL( b.amount, 0 )),0)
 		FROM
 			shop_salesman_order b
-		WHERE
-			b.user_id = a.open_id
-		  and order_status=2 and revenue_type=2
+		WHERE order_status=2 and revenue_type=2
 		  AND b.sales_user_id = #{openId}
 
 	) AS invitationRevenue,
@@ -178,13 +177,13 @@
 			IFNULL(sum(IFNULL( b.amount, 0 )),0)
 		FROM
 			shop_salesman_order b
-		WHERE
-			b.user_id = a.open_id
-		  and order_status=1
+		WHERE order_status=1
 		  AND b.sales_user_id = #{openId}
 
 	) AS djsRevenue,
-	( SELECT count( * ) FROM shop_salesman_order c WHERE c.user_id = a.open_id AND c.sales_user_id = #{openId} ) AS orderCount,
+
+	( SELECT count( * ) FROM shop_salesman_order c WHERE c.user_id = a.open_id AND c.sales_user_id = #{openId} and revenue_type =1 ) AS salesorderCount,
+	( SELECT count( * ) FROM shop_salesman_order c WHERE c.user_id = a.open_id AND c.sales_user_id = #{openId} and revenue_type =2 ) AS invitationOrderCount,
 	(select count(*) from biz_user where parent_open_id=#{openId} and is_sales=1) as invitationCount,
 	(select count(*) from biz_user where parent_open_id=#{openId} and is_sales=2) as customerCount
 	from biz_user a where
@@ -206,9 +205,9 @@
 		( SELECT COUNT(*) FROM biz_user
 		WHERE parent_open_id = a.user_id AND is_sales = 1 ) invitedNum,
 		( SELECT IFNULL(sum(IFNULL(amount, 0)), 0) FROM shop_salesman_order
-		WHERE user_id = a.user_id AND order_status = 2 AND sales_user_id = a.user_id ) totalRevenue,
+		WHERE order_status = 2 AND sales_user_id = a.user_id ) totalRevenue,
 		( SELECT IFNULL(sum(IFNULL(amount, 0)), 0) FROM shop_salesman_order
-		WHERE user_id = a.user_id AND order_status = 1 AND sales_user_id = a.user_id ) balance,
+		WHERE order_status = 1 AND sales_user_id = a.user_id ) balance,
 		a.create_time createTime,
 		a.apply_status applyStatus,
 		a.apply_way applyWay
@@ -216,26 +215,25 @@
 		shop_salesman_apply a
 		LEFT JOIN biz_user b ON a.user_id = b.open_id
 		LEFT JOIN shop_salesman_grade g ON a.grade_id = g.id
-		<where>
-			a.company_id=#{companyId} and a.user_id = #{userId}
-		</where>
+		    where a.id = #{applyId}
 	</select>
 
 	<select id="findCustomDetail" resultType="com.matrix.system.fenxiao.vo.ShopCustomDetailVo">
 		SELECT
-		a.user_id userId,
+		b.open_id userId,
 		b.avatar_url avatarUrl,
 		b.nick_name nickname,
 		a.create_time createTime,
-		a.apply_way applyWay
+		a.apply_way applyWay,
+		(select COUNT(*) from shop_salesman_order c where c.order_status = 1 and c.sales_user_id = a.user_id) doneNum
 		FROM
 		shop_salesman_apply a
 		LEFT JOIN biz_user b ON b.parent_open_id = a.user_id
-
 		<where>
 			a.company_id = #{record.companyId}
 			AND b.is_sales != 1
 			and b.parent_open_id = #{record.userId}
+			and a.apply_status = 2
 			<if test="record.userName != null and record.userName != ''">
 				and b.nick_name like concat('%',#{record.userName},'%')
 			</if>
@@ -247,19 +245,51 @@
 	</select>
 	<select id="findCustomLow" resultType="com.matrix.system.fenxiao.vo.ShopCustomDetailVo">
 		SELECT
-		a.user_id userId,
+		b.open_id userId,
 		b.avatar_url avatarUrl,
 		b.nick_name nickname,
 		a.create_time createTime,
 		a.apply_way applyWay
 		FROM
 		shop_salesman_apply a
-		LEFT JOIN biz_user b ON b.parent_open_id = a.user_id
-
+		LEFT JOIN biz_user b ON b.open_id = a.user_id
 		<where>
 			a.company_id = #{record.companyId}
 			AND b.is_sales = 1
 			and b.parent_open_id = #{record.userId}
+			and a.apply_status = 2
+			<if test="record.userName != null and record.userName != ''">
+				and b.nick_name like concat('%',#{record.userName},'%')
+			</if>
+		</where>
+		<if test="record.sort !=null">
+			order by
+			a.${record.sort} ${record.order}
+		</if>
+	</select>
+
+	<select id="findShopOrderDetail" resultType="com.matrix.system.fenxiao.vo.ShopOrderDetailVo">
+		select
+		a.order_id orderId,
+		a.create_time createTime,
+		a.amount amount,
+		a.revenue_type revenueType,
+		a.order_status orderStatus,
+		b.nick_name nickName,
+		b.avatar_url avatarUrl,
+		c.order_no orderNo,
+		c.order_money orderMoney,
+		c.order_status orderState,
+		f.shop_name storeName
+		from shop_salesman_order a
+		left join biz_user b on b.open_id=a.user_id
+		left join shop_order c on a.order_id=c.id
+		LEFT JOIN sys_shop_info f on f.id = c.store_id
+		<where>
+			a.sales_user_id = #{record.userId}
+			<if test="record.orderType != null and record.orderType != ''">
+				and a.order_status = #{record.orderType}
+			</if>
 			<if test="record.userName != null and record.userName != ''">
 				and b.nick_name like concat('%',#{record.userName},'%')
 			</if>

--
Gitblit v1.9.1