浏览代码

fix 按用户加入时间计算标签订单数据

zoujiajian 2 年之前
父节点
当前提交
8196c2cba7

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/mapper/OrderDonMapper.java

@@ -82,7 +82,7 @@ public interface OrderDonMapper extends BaseMapper<OrderDon> {
 
 	Page<UserOrderDetailView> getPastRecord(@Param("objectPage") Page<Object> objectPage, @Param("tagIdStr") String tagIdStr, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("consumeStTime") String consumeStTime, @Param("consumeEtTime") String consumeEtTime);
 
-	UserOrderDetailView getNumOfTagFansUser(@Param("date") String date, @Param("tagIdStr") String tagIdStr, @Param("startTime") String startTime, @Param("endTime") String endTime);
+	UserOrderDetailView getNumOfTagFansUser(@Param("tagIdStr") String tagIdStr, @Param("startTime") String startTime, @Param("endTime") String endTime);
 
 	UserOrderDetailView getFansToDayOrdersView(@Param("tagIdStr") String tagIdStr, @Param("date") String date);
 }

+ 8 - 9
netflix-dao/src/main/resources/mapper/CorpUserTagMapper.xml

@@ -103,16 +103,15 @@
 
     <select id="getCorpUserIntentionView" resultType="com.cyksj.model.views.CorpUserIntentionView">
         select cu.user_id,cu.name as nickname,cu.created_time,ccc.id as intentionId,ccc.intention
-        from (select relation_id
-        from `corp_user_tag` ct
-        where tag_id = #{tagIdStr}
-        group by relation_id
+        from (select distinct cu.*
+        from (select DISTINCT relation_id from corp_user_tag where tag_id = #{tagIdStr}) ct
+        inner join corp_user_follow_relation cufr on cufr.id = ct.relation_id
+        inner join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
+        inner join corp_user cu on cu.id = ca.corp_user_id
         <if test="thisDate != null">
-            having date_format(min(ct.created_time),'%Y-%m-%d') = #{thisDate}
-        </if>) s
-        left join corp_user_follow_relation cufr on cufr.id = s.relation_id
-        left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
-        left join corp_user cu on cu.id = ca.corp_user_id
+            where date_format(cu.created_time,'%Y-%m-%d') = #{thisDate}
+        </if>
+        ) cu
         left join corp_customer_acquistion_callback ccc on ccc.union_id = cu.unionid
         <where>
             <if test="userId != null">

+ 73 - 97
netflix-dao/src/main/resources/mapper/OrderDonMapper.xml

@@ -321,50 +321,43 @@
 
     <select id="getTagUserOrdersData" resultType="com.cyksj.model.views.UserOrderDetailView">
         select count(if(status != 'refund', 1, NULL)) as numOfOrder,
-               cast((sum(money) - sum(ifnull(refund_money, 0))) / 100 as decimal(10,2)) as orderMoney,
-               count(if(status != 'refund' and o.goods_id = 15,1,NULL)) as numOfEpOrder,
-              cast((sum(if(o.goods_id = 15,money,0)) - sum(ifnull(if(o.goods_id = 15,refund_money,0), 0))) / 100 as decimal(10,2)) as epOrderMoney,
-               count(distinct corpUserId) as numOfUser
-        from (select cu.id as corpUserId,
-        cu.user_id,
-        date_format(s.created_time, '%Y-%m-%d') as joinTime
-        from (select relation_id,
-        min(ct.created_time) as created_time
-        from `corp_user_tag` ct
-        where tag_id = #{tagIdStr}
-        group by ct.relation_id
+        cast((sum(money) - sum(ifnull(refund_money, 0))) / 100 as decimal(10,2)) as orderMoney,
+        count(if(status != 'refund' and o.goods_id = 15,1,NULL)) as numOfEpOrder,
+        cast((sum(if(o.goods_id = 15,money,0)) - sum(ifnull(if(o.goods_id = 15,refund_money,0), 0))) / 100 as
+        decimal(10,2)) as epOrderMoney
+        from (select distinct cu.user_id,cu.created_time from (select DISTINCT relation_id from corp_user_tag where tag_id = #{tagIdStr})
+        ct inner join corp_user_follow_relation cufr on cufr.id = ct.relation_id
+        inner join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
+        inner join corp_user cu on cu.id = ca.corp_user_id
+        where cu.user_id != 0
         <if test="startTime != null">
-            having date_format(min(ct.created_time), '%Y-%m-%d') >= #{startTime}
+            and cu.created_time >= #{startTime}
         </if>
         <if test="endTime != null">
-            and date_format(min(ct.created_time), '%Y-%m-%d') &lt; #{endTime}
-        </if>) s
-        left join corp_user_follow_relation cufr on cufr.id = s.relation_id
-        left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
-        left join corp_user cu on cu.id = ca.corp_user_id) s
-        inner join order_don o on o.user_id = s.user_id and o.user_id != 0
-        and o.status not in ('close', 'noPayment')
-        and o.money > 0
-        and date_format(o.created_time, '%Y-%m-%d') >= joinTime
+            and cu.created_time &lt; #{endTime}
+        </if>)
+        cu inner join order_don o on o.user_id = cu.user_id
+        and o.`status` not in ('close','noPayment')
+        AND o.money > 0
+        and o.created_time > cu.created_time
         <if test="consumeStTime != null">
-            and date_format(o.created_time, '%Y-%m-%d') >= #{consumeStTime}
+            and o.created_time >= #{consumeStTime}
         </if>
         <if test="consumeEtTime != null">
-            and date_format(o.created_time, '%Y-%m-%d') &lt; #{consumeEtTime}
+            and o.created_time &lt; #{consumeEtTime}
         </if>
     </select>
 
     <select id="getTagUserDataPage" resultType="com.cyksj.model.views.UserOrderDetailView">
-        select joinTime as `date`,
-               count(distinct corp_user_id) as numOfUser
-        from (select cufr.corp_user_id, date_format(s.created_time, '%Y-%m-%d') joinTime
-              from (select relation_id, min(created_time) as created_time
-                    from `corp_user_tag` ct
-                    where tag_id = #{tagIdStr}
-                    group by relation_id) s
-                       inner join corp_user_follow_relation cufr on cufr.id = s.relation_id) s
-        group by joinTime
-        order by joinTime desc
+        select date_format(cu.created_time, '%Y-%m-%d') as `date`,
+               count(distinct cu.id)                    as numOfUser
+        from (select distinct cu.id, cu.user_id, cu.created_time
+              from (select DISTINCT relation_id from corp_user_tag where tag_id = #{tagIdStr}) ct
+                       inner join corp_user_follow_relation cufr on cufr.id = ct.relation_id
+                       inner join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
+                       inner join corp_user cu on cu.id = ca.corp_user_id) cu
+        group by date_format(cu.created_time, '%Y-%m-%d')
+        order by date_format(cu.created_time, '%Y-%m-%d') desc
     </select>
 
     <select id="getTagUserTimeOrderData" resultType="com.cyksj.model.views.CorpTagUserOrderDataView">
@@ -372,18 +365,12 @@
         (select nickname from user u where u.id = o.user_id limit 1),
         o.order_no,o.goods_id,g.title,o.sku_id,sku.spec_val,
         o.money/100 as money,o.created_time
-        from (select cu.id as corpUserId,
-        cu.user_id,
-        date_format(s.created_time, '%Y-%m-%d') joinTime
-        from (select relation_id,
-        min(ct.created_time) as created_time
-        from `corp_user_tag` ct
-        where tag_id = #{tagIdStr}
-        group by ct.relation_id) s
-        left join corp_user_follow_relation cufr on cufr.id = s.relation_id
-        left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
-        left join corp_user cu on cu.id = ca.corp_user_id) s
-        inner join order_don o on o.user_id = s.user_id and o.user_id != 0
+        from (select distinct cu.user_id, date_format(cu.created_time, '%Y-%m-%d') joinTime
+        from (select DISTINCT relation_id from corp_user_tag where tag_id = #{tagIdStr}) ct
+        inner join corp_user_follow_relation cufr on cufr.id = ct.relation_id
+        inner join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
+        inner join corp_user cu on cu.id = ca.corp_user_id
+        where cu.user_id != 0) cu inner join order_don o on o.user_id = cu.user_id
         and o.status not in ('close', 'noPayment','refund')
         and date_format(o.created_time, '%Y-%m-%d') = joinTime
         and o.money > 0
@@ -450,65 +437,54 @@
     </select>
 
     <select id="getPastRecord" resultType="com.cyksj.model.views.UserOrderDetailView">
-        select date_format(o.created_time,'%Y-%m-%d') as `date`,
-        count(if(status != 'refund', 1, NULL)) as numOfOrder,
-        cast((ifnull(sum(money),0) - sum(ifnull(refund_money, 0))) / 100 as decimal(10,2)) as orderMoney
-        from (select cu.id as corpUserId,
-        cu.user_id,
-        date_format(s.created_time, '%Y-%m-%d') joinTime
-        from (select relation_id,
-        min(ct.created_time) as created_time
-        from `corp_user_tag` ct
-        where tag_id = #{tagIdStr}
-        group by ct.relation_id) s
-        left join corp_user_follow_relation cufr on cufr.id = s.relation_id
-        left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
-        left join corp_user cu on cu.id = ca.corp_user_id where cu.user_id != 0)s
-        inner join order_don o on o.user_id = s.user_id
-        and o.status not in ('close','noPayment')
-        and date_format(o.created_time, '%Y-%m-%d') >= joinTime
-        and o.money > 0
-        group by date_format(o.created_time,'%Y-%m-%d')
-        order by date_format(o.created_time,'%Y-%m-%d') desc
+        select date_format(o.created_time, '%Y-%m-%d')                                              as `date`,
+               count(if(status != 'refund', 1, NULL))                                               as numOfOrder,
+               cast((ifnull(sum(money), 0) - sum(ifnull(refund_money, 0))) / 100 as decimal(10, 2)) as orderMoney
+        from (select distinct cu.user_id, cu.created_time
+              from (select DISTINCT relation_id from corp_user_tag where tag_id = #{tagIdStr}) ct
+                       inner join corp_user_follow_relation cufr on cufr.id = ct.relation_id
+                       inner join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
+                       inner join corp_user cu on cu.id = ca.corp_user_id
+              where cu.user_id != 0) cu
+                 inner join order_don o
+                            on o.user_id = cu.user_id
+                                and o.`status` not in ('close', 'noPayment')
+                                AND money > 0
+                                and o.created_time > cu.created_time
+        group by date_format(o.created_time, '%Y-%m-%d')
+        order by date_format(o.created_time, '%Y-%m-%d') desc
     </select>
 
     <select id="getNumOfTagFansUser" resultType="com.cyksj.model.views.UserOrderDetailView">
-        select count(distinct cufr.corp_user_id) as numOfUser,
-        count(distinct if(cufr.status = 0,cufr.corp_user_id,NULL)) as delNumOfUser
-        from (select relation_id
-        from `corp_user_tag` ct
-        where tag_id = #{tagIdStr}
-        group by relation_id
-        <if test="startTime != null">
-            having min(ct.created_time) >= #{startTime}
-        </if>
-        <if test="endTime != null">
-            and min(ct.created_time) &lt; #{endTime}
-        </if>
-        <if test="date != null">
-            HAVING date_format(min(ct.created_time), '%Y-%m-%d') = #{date}
-        </if>
-        ) s
+        select count(distinct cu.id) as numOfUser,
+        count(distinct if(cufr.status = 0,cu.id,NULL)) as delNumOfUser
+        from (select distinct relation_id from `corp_user_tag` where tag_id = #{tagIdStr}) s
         inner join corp_user_follow_relation cufr on cufr.id = s.relation_id
+        inner join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
+        inner join corp_user cu on cu.id = ca.corp_user_id
+        <where>
+            <if test="startTime != null">
+                cu.created_time >= #{startTime}
+            </if>
+            <if test="endTime != null">
+                and cu.created_time &lt; #{endTime}
+            </if>
+        </where>
     </select>
 
     <select id="getFansToDayOrdersView" resultType="com.cyksj.model.views.UserOrderDetailView">
         select count(if(status != 'refund', 1, NULL))                                               as numOfOrder,
                cast((ifnull(sum(money), 0) - sum(ifnull(refund_money, 0))) / 100 as decimal(10, 2)) as orderMoney
-        from (select cu.user_id
-              from (select relation_id
-                    from `corp_user_tag` ct
-                    where tag_id = #{tagIdStr}
-                    group by ct.relation_id
-                    having date_format(min(created_time), '%Y-%m-%d') = #{date}) s
-                       left join corp_user_follow_relation cufr on cufr.id = s.relation_id
-                       left join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
-                       left join corp_user cu on cu.id = ca.corp_user_id
-              where cu.user_id != 0) s
-                 left join order_don o
-                           on o.user_id = s.user_id
-                               and o.status not in ('close', 'noPayment')
-                               and date_format(o.created_time, '%Y-%m-%d') = #{date}
-                               and o.money > 0
+        from (select distinct cu.user_id, cu.created_time
+              from (select DISTINCT relation_id from corp_user_tag where tag_id = #{tagIdStr}) ct
+                       inner join corp_user_follow_relation cufr on cufr.id = ct.relation_id
+                       inner join corp_user_auth ca on ca.external_userid = cufr.corp_user_id
+                       inner join corp_user cu on cu.id = ca.corp_user_id
+              where cu.user_id != 0) cu
+                 inner join order_don o on o.user_id = cu.user_id
+            and o.`status` not in ('close', 'noPayment')
+            AND money > 0
+            and date_format(o.created_time, '%Y-%m-%d') = date_format(cu.created_time, '%Y-%m-%d')
+            and date_format(o.created_time, '%Y-%m-%d') = #{date}
     </select>
 </mapper>

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpTagServiceImpl.java

@@ -448,7 +448,7 @@ public class CorpTagServiceImpl implements CorpTagService {
 	@Override
 	public UserOrderDetailView tagUserHeadData(String tagIdStr, String startTime, String endTime, String consumeStTime, String consumeEtTime) {
 		//被删除用户数,用户数
-		UserOrderDetailView userOrderDetailView = orderDonMapper.getNumOfTagFansUser(null, tagIdStr, startTime, endTime);
+		UserOrderDetailView userOrderDetailView = orderDonMapper.getNumOfTagFansUser(tagIdStr, startTime, endTime);
 
 		//订单情况
 		UserOrderDetailView headView = orderDonMapper.getTagUserOrdersData(tagIdStr, startTime, endTime, consumeStTime, consumeEtTime);