From ec87cf1ee2b9382bf9d089711f0ff82ae8e7077c Mon Sep 17 00:00:00 2001
From: jyy <jyy>
Date: Wed, 09 Jun 2021 20:44:16 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/api_score_meger' into api_score_meger

---
 zq-erp/src/main/resources/mybatis/mapper/hive/AchieveNewDao.xml |  168 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 147 insertions(+), 21 deletions(-)

diff --git a/zq-erp/src/main/resources/mybatis/mapper/hive/AchieveNewDao.xml b/zq-erp/src/main/resources/mybatis/mapper/hive/AchieveNewDao.xml
index c99b814..651ca07 100644
--- a/zq-erp/src/main/resources/mybatis/mapper/hive/AchieveNewDao.xml
+++ b/zq-erp/src/main/resources/mybatis/mapper/hive/AchieveNewDao.xml
@@ -18,6 +18,7 @@
 		<result property="freeConsume" column="free_consume" />
 		<result property="hisConsume" column="his_consume" />
 		<result property="goodsCash" column="goods_cash" />
+		<result property="cardCash" column="card_cash" />
 		<result property="projNum" column="proj_num" />
 		<result property="numberOfPeople" column="number_of_people" />
 		<result property="shopName" column="shop_name" />
@@ -44,12 +45,12 @@
 		<result property="guwen" column="guwen" />
 		<result property="meiliao" column="meiliao" />
 		<result property="zkTotal" column="zk_total" />
-
+		<result property="payMethod" column="pay_method" />
 		<result property="arriveCnt" column="arrive_cnt" />
 
 		<result property="goodsNo" column="goodsNo" />
 		<result property="goodsName" column="goodsName" />
-		<result property="payMethod" column="pay_method" />
+
 		<result property="cateName" column="cateName" />
 
 	</resultMap>
@@ -66,7 +67,6 @@
 		c.vip_name,
 		e.name as pro_name,
 		b.ZK_TOTAL as zk_total,
-		a.goods_cash,
 		a.his_consume,
 		a.free_consume,
 		f.su_name meiliao,
@@ -79,6 +79,8 @@
 		h.shop_short_name shop_name,
 		a.order_type,
 		a.achieveType,
+		case when a.pay_method = '现金' then goods_cash end goods_cash,
+		case when a.pay_method = '划扣' then goods_cash end card_cash,
 		j.pay_method
 		from
 		achieve_new a
@@ -93,6 +95,7 @@
 		left join sys_proj_services l on a.service_order_id=l.id
 		left join sys_order_item j on a.order_item_id=j.ID
 		<where>
+			and	a.company_id = #{record.companyId}
 			<if test="record!=null">
 				<if
 					test="(record.shopId!=null and record.shopId!='') or  (record.shopId!='' and record.shopId==0)  ">
@@ -116,9 +119,7 @@
 				<if test="record.beaultId != null and record.beaultId !='' ">
 					and	a.beault_id = #{record.beaultId}
 				</if>
-				<if test="record.companyId != null and record.companyId !='' ">
-					and	a.company_id = #{record.companyId}
-				</if>
+
 				<if test="record.beaultId != null and record.beaultId !='' ">
 					and	a.beault_id = #{record.beaultId}
 				</if>
@@ -194,7 +195,41 @@
 		</where>
 	</select>
 
+<!--
 
+ 统计员工业绩
+
+select
+		u.name,
+		g.su_name guwen,
+		cast(SUM(b.ZK_TOTAL) AS decimal(15,2)) as zk_total,
+		cast(SUM(a.his_consume) AS decimal(15,2)),
+		cast(SUM(a.free_consume) AS decimal(15,2)),
+		cast(SUM(a.proj_percentage) AS decimal(15,2)),
+		cast(SUM(a.number_of_people) AS decimal(15,2)),
+		cast(SUM(a.proj_num) AS decimal(15,2)),
+		cast(SUM(a.proj_time) AS decimal(15,2)),
+		h.shop_short_name shop_name,
+		a.order_type,
+		a.achieveType
+		from
+		achieve_new a
+		left join sys_order b on a.order_id=b.id
+		left join sys_vip_info c on a.vip_id=c.id
+		left join sys_vip_level d on c.LEVEL_ID=d.id
+		left join shopping_goods e on a.shopping_goods_id=e.id
+		LEFT JOIN sys_users f on a.beault_id=f.su_id
+		LEFT JOIN sys_users g on a.sale_id = g.su_id
+		LEFT JOIN sys_shop_info h ON a.SHOP_ID = h.ID
+		LEFT JOIN shopping_goods_category i ON e.cate_id = i.id
+		left join sys_proj_services l on a.service_order_id=l.id
+		left join sys_order_item j on a.order_item_id=j.ID
+		left join achieve_rule u on u.id=e.achieve_rule_id
+ where h.shop_short_name='龙华店'
+	GROUP BY g.su_name , a.order_type, h.id,a.achieveType
+	ORDER BY g.su_name
+
+-->
 
 
 	<select id="findSumDailyInfoNew" resultMap="AchieveNewMap">
@@ -287,7 +322,7 @@
 		<result property="remark" column="remark" />
 		<result property="orderType" column="order_type" />
 		<result property="projPercentage" column="proj_percentage" />
-
+		<result property="payMethod" column="pay_method" />
 		<result property="t1" column="t1" />
 		<result property="t2" column="t2" />
 		<result property="achieveType" column="achieveType" />
@@ -330,7 +365,8 @@
 		t6,
 		t8,
 		t9,
-		company_id
+		company_id,
+pay_method
 	</sql>
 
 	<!-- 属性sql -->
@@ -364,7 +400,8 @@
 		#{item.t6},
 		#{item.t8},
 		#{item.t9},
-		#{item.companyId}
+		#{item.companyId},
+		#{item.payMethod}
 	</sql>
 
 	<!-- where sql -->
@@ -612,6 +649,9 @@
 			<if test="_parameter.containsKey('t9')">
 				t9 = #{t9},
 			</if>
+			<if test="_parameter.containsKey('payMethod')">
+				pay_method = #{payMethod},
+			</if>
 		</set>
 		WHERE id=#{id}
 	</update>
@@ -724,6 +764,9 @@
 			</if>
 			<if test="record.t9 != null and record.t9 != '' ">
 				t9 = #{record.t9},
+			</if>
+			<if test="record.payMethod != null and record.payMethod != '' ">
+				pay_method = #{record.payMethod},
 			</if>
 		</set>
 		WHERE id=#{record.id}
@@ -910,15 +953,13 @@
 	<select id="selectUserAchieveByTime" resultType="com.matrix.system.app.vo.UserAchieveVo">
 		select
 			sale_id id,
-			(select ifnull(sum(case b.pay_method when '现金' then goods_cash else 0 end),0)
+			(select ifnull(sum(case pay_method when '现金' then goods_cash else 0 end),0)
 				from achieve_new a
-				inner join sys_order_item b on a.order_item_id=b.ID
 			where a.beault_id=#{userId}
 			and (date_format(datatime, '%Y-%m-%d') >= date_format(#{startTime}, '%Y-%m-%d') and date_format(#{endTime}, '%Y-%m-%d') >= date_format(datatime, '%Y-%m-%d'))
 			) orderCash,
-			(select ifnull(sum(case b.pay_method when '划扣' then goods_cash else 0 end),0)
+			(select ifnull(sum(case pay_method when '划扣' then goods_cash else 0 end),0)
 				from achieve_new a
-				inner join sys_order_item b on a.order_item_id=b.ID
 			where  a.beault_id=#{userId}
 			and (date_format(datatime, '%Y-%m-%d') >= date_format(#{startTime}, '%Y-%m-%d') and date_format(#{endTime}, '%Y-%m-%d') >= date_format(datatime, '%Y-%m-%d'))
 			) cash,
@@ -969,6 +1010,7 @@
 		select
 			b.su_name name,
 			b.su_id id,
+			b.su_photo photo,
 			sum(IFNULL(a.free_consume,0) + IFNULL(a.his_consume, 0) ) amount,
 			c.shop_short_name shopName
 		from achieve_new a
@@ -1002,8 +1044,7 @@
 			b.code goodsNo,
 			b.name goodsName,
 			c.su_name meiliao,
-			d.count*d.zk_price zk_total,
-		    d.pay_method
+			d.count*d.zk_price zk_total
 		from achieve_new a
 		left join shopping_goods b on a.shopping_goods_id=b.id
 		left join sys_users c on a.beault_id=c.su_id
@@ -1046,24 +1087,109 @@
 		select
 			b.shop_short_name name,
 			b.SHOP_IMAG photo,
-			sum(IFNULL(a.goods_cash,0)) amount
-		from achieve_new a
-		left join sys_shop_info b on a.shop_id=b.ID and shop_type!=1
+			sum(IFNULL(a.amount,0)) amount
+		from sys_order_flow a
+		inner join sys_order c on a.order_id=c.id and c.STATU != '已取消'
+		inner join sys_shop_info b on a.shop_id=b.id and shop_type!=1
 		<where>
+			a.pay_method not in ('储值卡', '欠款')
 			<if test="record.companyId != null">
 				and a.company_id=#{record.companyId}
 			</if>
 			<if test='record.t1 == "1" and record.datatime != null'>
-				and date_format(datatime, '%Y-%m-%d') = date_format(#{record.datatime}, '%Y-%m-%d')
+				and date_format(a.create_time, '%Y-%m-%d') = date_format(#{record.datatime}, '%Y-%m-%d')
 			</if>
 			<if test='record.t1 == "2" and record.datatime != null'>
-				and date_format(datatime, '%Y-%m') = date_format(#{record.datatime}, '%Y-%m')
+				and date_format(a.create_time, '%Y-%m') = date_format(#{record.datatime}, '%Y-%m')
 			</if>
 			<if test='record.t1 == "3" and record.datatime != null'>
-				and date_format(datatime, '%Y') = date_format(#{record.datatime}, '%Y')
+				and date_format(a.create_time, '%Y') = date_format(#{record.datatime}, '%Y')
 			</if>
 		</where>
 		group by a.shop_id
 		order by amount desc, a.shop_id
 	</select>
+
+	<!-- 顾问当天下单列表 -->
+	<select id="selectSaleManAchieveList" resultMap="AchieveNewMap">
+		select * from achieve_new
+		where sale_id=#{saleId} and vip_id=#{vipId} and sale_id=beault_id
+		  and date_format(datatime, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d')
+	</select>
+
+	<select id="selectBeautyManAchieveList" resultMap="AchieveNewMap">
+		select * from achieve_new
+		where beault_id=#{beautyId} and vip_id=#{vipId}
+		  and date_format(datatime, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d')
+	</select>
+
+	<select id="achieveNewStatistics" resultType="com.matrix.system.hive.vo.AchieveNewStatisticsVo">
+
+		select
+			u.name ruleName,
+			f.su_name guwen,
+			f.su_id gwid,
+			g.su_name createBy,
+			g.su_id createId,
+			cast(SUM(b.ZK_TOTAL) AS decimal(15,2)) as zk_total,
+			cast(SUM(a.his_consume) AS decimal(15,2)) his_consume,
+			cast(SUM(a.free_consume) AS decimal(15,2)) free_consume,
+			cast(SUM(a.proj_percentage) AS decimal(15,2)) proj_percentage,
+			cast(SUM(a.number_of_people) AS decimal(15,2)) number_of_people,
+			cast(SUM(a.proj_num) AS decimal(15,2)) proj_num,
+			cast(SUM(case when a.pay_method = '划扣' then goods_cash end )AS decimal(15,2)) card_cash,
+			cast(SUM(a.proj_time) AS decimal(15,2)) proj_time,
+			cast(SUM(case when a.pay_method = '现金' then goods_cash end )AS decimal(15,2)) goods_cash,
+			h.shop_short_name shop_name,
+			a.order_type
+		from
+			achieve_new a
+				left join sys_order b on a.order_id=b.id
+				left join sys_vip_info c on a.vip_id=c.id
+				left join sys_vip_level d on c.LEVEL_ID=d.id
+				left join shopping_goods e on a.shopping_goods_id=e.id
+				LEFT JOIN sys_users f on a.beault_id=f.su_id
+				LEFT JOIN sys_users g on a.sale_id = g.su_id
+				LEFT JOIN sys_shop_info h ON a.SHOP_ID = h.ID
+				LEFT JOIN shopping_goods_category i ON e.cate_id = i.id
+				left join sys_proj_services l on a.service_order_id=l.id
+				left join sys_order_item j on a.order_item_id=j.ID
+				left join achieve_rule u on u.id=e.achieve_rule_id
+		<where>
+			and a.company_id = #{record.companyId}
+			<if test="record.shopId != null">
+				and a.shop_id = #{record.shopId}
+			</if>
+			<if test="record.achieveRuleId != null">
+				and u.id = #{record.achieveRuleId}
+			</if>
+
+			<if test="record.staffName != null and record.staffName!=''">
+			<!-- 创建人和归属人都有业绩 -->
+				and (f.su_name like concat('%',#{record.staffName},'%')  or g.su_name like concat('%',#{record.staffName},'%')  )
+			</if>
+
+			<if test="record.orderType != null and record.orderType != '' ">
+				and a.order_type= #{record.orderType}
+			</if>
+			<if test="record.beginTime != null ">
+				and a.datatime >= #{record.beginTime}
+			</if>
+			<if test="record.endTime != null   ">
+				<![CDATA[and a.datatime <= #{record.endTime}]]>
+			</if>
+
+		</where>
+		GROUP BY g.su_id , f.su_id, a.order_type, h.id,a.achieveType,u.name
+		<if test="record.sort !=null and record.sort!=''"> order by ${record.sort} ${record.order}</if>
+
+	</select>
+
+
+	<update id="updateAchieveNumOfPeople">
+		<foreach collection="list" item="item" index="index"
+				 separator=";">
+			update achieve_new set number_of_people=#{num} where id=#{item.id}
+		</foreach>
+	</update>
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.1