|
|
@@ -10,10 +10,22 @@
|
|
|
<result column="buyerCount" property="buyerCount"/>
|
|
|
</resultMap>
|
|
|
|
|
|
+ <resultMap id="SalesAccountStatMap" type="com.fs.company.vo.SalesAccountStatCIDVO">
|
|
|
+ <result column="qwUserId" property="qwUserId"/>
|
|
|
+ <result column="qwUserName" property="qwUserName"/>
|
|
|
+ <result column="companyUserId" property="companyUserId"/>
|
|
|
+ <result column="companyUserName" property="companyUserName"/>
|
|
|
+ <result column="deptName" property="deptName"/>
|
|
|
+ <result column="fansCount" property="fansCount"/>
|
|
|
+ <result column="totalAmount" property="totalAmount"/>
|
|
|
+ <result column="orderCount" property="orderCount"/>
|
|
|
+ <result column="buyerCount" property="buyerCount"/>
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
<select id="getSalesStatisticsCID" resultMap="SalesStatMap">
|
|
|
SELECT
|
|
|
cu.user_id AS userId,
|
|
|
- cu.nick_name AS nickName,
|
|
|
+ cu.nick_name AS companyUserName,
|
|
|
d.dept_name AS deptName,
|
|
|
COALESCE(fc.fans_count, 0) AS fansCount,
|
|
|
COALESCE(oc.total_amount, 0) AS totalAmount,
|
|
|
@@ -53,16 +65,13 @@
|
|
|
) oc ON oc.company_user_id = cu.user_id
|
|
|
|
|
|
WHERE cu.del_flag = '0'
|
|
|
- <if test="(param.corpId != null and param.corpId != '') or (param.qwUserName != null and param.qwUserName.trim() != '')">
|
|
|
+ <if test="(param.corpId != null and param.corpId != '')">
|
|
|
AND EXISTS (
|
|
|
SELECT 1 FROM qw_user qu_filter
|
|
|
WHERE qu_filter.company_user_id = cu.user_id
|
|
|
<if test="param.corpId != null and param.corpId != ''">
|
|
|
AND qu_filter.corp_id = #{param.corpId}
|
|
|
</if>
|
|
|
- <if test="param.qwUserName != null and param.qwUserName.trim() != ''">
|
|
|
- AND qu_filter.qw_user_name LIKE CONCAT('%', #{param.qwUserName}, '%')
|
|
|
- </if>
|
|
|
)
|
|
|
</if>
|
|
|
<if test="param.companyId != null">
|
|
|
@@ -78,8 +87,8 @@
|
|
|
<if test="param.userId != null">
|
|
|
AND cu.user_id = #{param.userId}
|
|
|
</if>
|
|
|
- <if test="param.companyUserNickName != null and param.companyUserNickName.trim() != ''">
|
|
|
- AND cu.nick_name LIKE CONCAT('%', #{param.companyUserNickName}, '%')
|
|
|
+ <if test="param.companyUserName != null and param.companyUserName.trim() != ''">
|
|
|
+ AND cu.nick_name LIKE CONCAT('%', #{param.companyUserName}, '%')
|
|
|
</if>
|
|
|
GROUP BY cu.user_id, cu.nick_name, d.dept_name
|
|
|
-- 动态排序 ↓
|
|
|
@@ -91,6 +100,95 @@
|
|
|
</if>
|
|
|
</select>
|
|
|
|
|
|
+ <select id="getSalesAccountStatCID" resultMap="SalesAccountStatMap">
|
|
|
+ SELECT
|
|
|
+ qu.id AS qwUserId,
|
|
|
+ qu.qw_user_name AS qwUserName,
|
|
|
+ cu.user_id AS companyUserId,
|
|
|
+ cu.nick_name AS companyUserName,
|
|
|
+ d.dept_name AS deptName,
|
|
|
+ COALESCE(fc.fans_count, 0) AS fansCount,
|
|
|
+ COALESCE(oc.total_amount, 0) AS totalAmount,
|
|
|
+ COALESCE(oc.order_count, 0) AS orderCount,
|
|
|
+ COALESCE(oc.buyer_count, 0) AS buyerCount
|
|
|
+ FROM qw_user qu
|
|
|
+ INNER JOIN company_user cu ON qu.company_user_id = cu.user_id AND cu.del_flag = '0'
|
|
|
+ <if test="param.companyId != null">AND cu.company_id = #{param.companyId}</if>
|
|
|
+ <if test="param.deptId != null">
|
|
|
+ AND (cu.dept_id = #{param.deptId}
|
|
|
+ OR cu.dept_id IN (
|
|
|
+ SELECT t.dept_id FROM company_dept t
|
|
|
+ WHERE t.del_flag = '0' AND FIND_IN_SET(#{param.deptId}, t.ancestors)
|
|
|
+ ))
|
|
|
+ </if>
|
|
|
+ <if test="param.userId != null">AND cu.user_id = #{param.userId}</if>
|
|
|
+ <if test="param.companyUserName != null and param.companyUserName.trim() != ''">
|
|
|
+ AND cu.nick_name LIKE CONCAT('%', #{param.companyUserName}, '%')
|
|
|
+ </if>
|
|
|
+ LEFT JOIN company_dept d ON cu.dept_id = d.dept_id AND d.del_flag = '0'
|
|
|
+
|
|
|
+ <!--进粉统计 -->
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT qu2.id AS qw_user_id,
|
|
|
+ COUNT(DISTINCT ec.id) AS fans_count
|
|
|
+ FROM qw_user qu2
|
|
|
+ INNER JOIN qw_external_contact ec
|
|
|
+ ON ec.qw_user_id = qu2.id
|
|
|
+ AND ec.add_way = 16
|
|
|
+ <if test="param.startAddTime != null and param.endAddTime != null">
|
|
|
+ AND ec.create_time BETWEEN #{param.startAddTime} AND #{param.endAddTime}
|
|
|
+ </if>
|
|
|
+ WHERE qu2.company_user_id IN (
|
|
|
+ SELECT cu2.user_id FROM company_user cu2
|
|
|
+ WHERE cu2.del_flag = '0'
|
|
|
+ <if test="param.companyId != null">AND cu2.company_id = #{param.companyId}</if>
|
|
|
+ <if test="param.deptId != null">
|
|
|
+ AND (cu2.dept_id = #{param.deptId}
|
|
|
+ OR cu2.dept_id IN (
|
|
|
+ SELECT t.dept_id FROM company_dept t
|
|
|
+ WHERE t.del_flag = '0' AND FIND_IN_SET(#{param.deptId}, t.ancestors)
|
|
|
+ ))
|
|
|
+ </if>
|
|
|
+ <if test="param.userId != null">AND cu2.user_id = #{param.userId}</if>
|
|
|
+ )
|
|
|
+ GROUP BY qu2.id
|
|
|
+ ) fc ON fc.qw_user_id = qu.id
|
|
|
+
|
|
|
+ <!--完整的订单统计-->
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT log.company_user_id,
|
|
|
+ SUM(o.pay_price) AS total_amount,
|
|
|
+ COUNT(DISTINCT o.order_code) AS order_count,
|
|
|
+ COUNT(DISTINCT o.user_id) AS buyer_count
|
|
|
+ FROM fs_store_order o
|
|
|
+ INNER JOIN (
|
|
|
+ SELECT DISTINCT package_order_code, company_user_id
|
|
|
+ FROM fs_user_information_collection_personal_log
|
|
|
+ WHERE 1 = 1
|
|
|
+ <if test="param.startOrderTime != null and param.endOrderTime != null">
|
|
|
+ AND order_time BETWEEN #{param.startOrderTime} AND #{param.endOrderTime}
|
|
|
+ </if>
|
|
|
+ ) log ON o.order_code = log.package_order_code
|
|
|
+ WHERE o.is_pay = 1 AND o.refund_status = 0
|
|
|
+ GROUP BY log.company_user_id
|
|
|
+ ) oc ON oc.company_user_id = qu.company_user_id
|
|
|
+
|
|
|
+ WHERE 1=1
|
|
|
+ <if test="param.corpId != null and param.corpId != ''">
|
|
|
+ AND qu.corp_id = #{param.corpId}
|
|
|
+ </if>
|
|
|
+ <if test="param.qwUserName != null and param.qwUserName.trim() != ''">
|
|
|
+ AND qu.qw_user_name LIKE CONCAT('%', #{param.qwUserName}, '%')
|
|
|
+ </if>
|
|
|
+ GROUP BY qu.id, cu.user_id, d.dept_name
|
|
|
+ <if test="param.orderByColumn != null">
|
|
|
+ ORDER BY ${param.orderByColumn} ${param.isAsc}
|
|
|
+ </if>
|
|
|
+ <if test="param.orderByColumn == null">
|
|
|
+ ORDER BY qu.id
|
|
|
+ </if>
|
|
|
+ </select>
|
|
|
+
|
|
|
<select id="getSalesUserDetailCID" resultType="com.fs.company.vo.SalesUserDetailCIDVO">
|
|
|
SELECT
|
|
|
log.user_id AS userId,
|