浏览代码

添加订单roi

zhaoxian 9 月之前
父节点
当前提交
6d9cb7cbb8

+ 59 - 34
ruixuan-live/src/main/java/com/ruixuan/isc/controller/SupplyChainController.java

@@ -97,6 +97,23 @@ public class SupplyChainController extends BaseController {
         Map<String, Object> requestMap = new HashMap<>();
         if (!Check.isNull(orderStartDate)) {
             requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
+
+            //根据本阶段日期 获取上阶段 开始 和 截至 日期
+            Map<String, String> map = DateUtils.getStartEndTime(orderStartDate, orderEndDate);
+            //下个周期的开始时间
+            String lastTimeStart = map.get("lastTimeStart");
+            //下个周期的结束时间
+            String lastTimeEnd = map.get("lastTimeEnd");
+            //当前小时
+            Integer hour = DateUtils.getNowHour() - 1;
+            //当天 yyyy-MM-dd
+            String today = DateUtils.getNowDateStr();
+            if (!(orderStartDate.equals(orderEndDate) && orderStartDate.equals(today))) {
+                hour = 23;
+            }
+            requestMap.put("lastTimeStart", DateUtils.strDateToInt(lastTimeStart));
+            requestMap.put("lastTimeEnd", DateUtils.strDateToInt(lastTimeEnd));
+            requestMap.put("hour", hour);
         }
         if (!Check.isNull(orderEndDate)) {
             requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
@@ -228,23 +245,32 @@ public class SupplyChainController extends BaseController {
             @ApiParam("用户ID") @RequestParam(value = "userId", required = false) String userId) {
         Map<String, Object> requestMap = new HashMap<>();
         if (!Check.isNull(orderStartDate) && !Check.isNull(orderEndDate)) {
-            if (!Check.isNull(orderStartDate)) {
-                requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
-            }
-            if (!Check.isNull(orderEndDate)) {
-                requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
+            requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
+            requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
+
+            //根据本阶段日期 获取上阶段 开始 和 截至 日期
+            Map<String, String> map = DateUtils.getStartEndTime(orderStartDate, orderEndDate);
+            //下个周期的开始时间
+            String lastTimeStart = map.get("lastTimeStart");
+            //下个周期的结束时间
+            String lastTimeEnd = map.get("lastTimeEnd");
+            //当前小时
+            Integer hour = DateUtils.getNowHour() - 1;
+            //当天 yyyy-MM-dd
+            String today = DateUtils.getNowDateStr();
+            if (!(orderStartDate.equals(orderEndDate) && orderStartDate.equals(today))) {
+                hour = 23;
             }
+            requestMap.put("lastTimeStart", DateUtils.strDateToInt(lastTimeStart));
+            requestMap.put("lastTimeEnd", DateUtils.strDateToInt(lastTimeEnd));
+            requestMap.put("hour", hour);
         }
 
         if (!Check.isNull(bindStartDate) && !Check.isNull(bindEndDate)) {
-            if (!Check.isNull(bindStartDate)) {
-                requestMap.put("start", DateUtils.strDateToInt(bindStartDate));
-                requestMap.put("bindStartDate", bindStartDate);
-            }
-            if (!Check.isNull(bindEndDate)) {
-                requestMap.put("end", DateUtils.strDateToInt(bindEndDate));
-                requestMap.put("bindEndDate", bindEndDate);
-            }
+            requestMap.put("start", DateUtils.strDateToInt(bindStartDate));
+            requestMap.put("bindStartDate", bindStartDate);
+            requestMap.put("end", DateUtils.strDateToInt(bindEndDate));
+            requestMap.put("bindEndDate", bindEndDate);
         }
 
         if (!Check.isNull(itemId)) {
@@ -1201,26 +1227,29 @@ public class SupplyChainController extends BaseController {
             @ApiParam("用户ID") @RequestParam(value = "userId", required = false) Long userId
     ) {
         Map<String, Object> requestMap = new HashMap<>();
-        if (!Check.isNull(orderStartDate)) {
-            Long start = DateUtils.getStartLongTime(orderStartDate);
-            requestMap.put("start", start);
-            requestMap.put("startDate", orderStartDate);
-        }
-        if (!Check.isNull(orderEndDate)) {
-            Long end = DateUtils.getEndLongTime(orderEndDate);
-            requestMap.put("end", end);
-            requestMap.put("endDate", orderEndDate + " 23:59:59");
+        if (!Check.isNull(orderStartDate) && !Check.isNull(orderEndDate)) {
+            requestMap.put("start", DateUtils.strDateToInt(orderStartDate));
+            requestMap.put("end", DateUtils.strDateToInt(orderEndDate));
 
+            //根据本阶段日期 获取上阶段 开始 和 截至 日期
+            Map<String, String> map = DateUtils.getStartEndTime(orderStartDate, orderEndDate);
+            //下个周期的开始时间
+            String lastTimeStart = map.get("lastTimeStart");
+            //下个周期的结束时间
+            String lastTimeEnd = map.get("lastTimeEnd");
+            //当前小时
+            Integer hour = DateUtils.getNowHour() - 1;
+            //当天 yyyy-MM-dd
+            String today = DateUtils.getNowDateStr();
+            if (!(orderStartDate.equals(orderEndDate) && orderStartDate.equals(today))) {
+                hour = 23;
+            }
+            requestMap.put("lastTimeStart", DateUtils.strDateToInt(lastTimeStart));
+            requestMap.put("lastTimeEnd", DateUtils.strDateToInt(lastTimeEnd));
+            requestMap.put("hour", hour);
         }
-        if (!Check.isNull(bindStartDate)) {
-            Long start = DateUtils.getStartLongTime(bindStartDate);
-            requestMap.put("start", start);
+        if (!Check.isNull(bindStartDate) && !Check.isNull(bindEndDate)) {
             requestMap.put("startDate", bindStartDate);
-        }
-
-        if (!Check.isNull(bindEndDate)) {
-            Long end = DateUtils.getEndLongTime(bindEndDate);
-            requestMap.put("end", end);
             requestMap.put("endDate", bindEndDate + " 23:59:59");
         }
 
@@ -1805,10 +1834,6 @@ public class SupplyChainController extends BaseController {
             Integer start = DateUtils.getIntegerTime(orderStartDate);
             requestMap.put("start", start);
         }
-        if (!Check.isNull(orderEndDate)) {
-            Integer end = DateUtils.getIntegerTime(orderEndDate);
-            requestMap.put("end", end);
-        }
         if (!Check.isNull(collectSampleId)) {
             requestMap.put("collectSampleId", collectSampleId);
         }

+ 71 - 11
ruixuan-live/src/main/resources/mapper/isc/SupplyChainMapper.xml

@@ -36,7 +36,8 @@
 
 
     <select id="getOrderList" resultType="com.alibaba.fastjson.JSONObject">
-        select *
+        select t.*,t2.userName,
+        ROUND(((t.orderNum-t3.orderNum)/t3.orderNum)*100,2) as 'orderNumRoi'
         from (
         select promoter_id as 'promoterId',
         promoter_nick_name as 'promoterNickName',
@@ -54,7 +55,7 @@
         then 1 else 0 end),4) as 'deliveryRadio',
         sum(case when order_status != 80 then regimental_promotion_amount else 0 end) as 'regimentalPromotionAmount'
         from kuaishou_supply_chain
-        where 1= 1
+        where stat_hour &lt;= #{hour}
         <if test="start != null and start != ''">
             and stat_date &gt;= #{start}
         </if>
@@ -67,11 +68,31 @@
         <if test="promoterNickName != null and promoterNickName != ''">
             and promoter_nick_name like concat(concat('%',#{promoterNickName}),'%')
         </if>
-        group by promoter_id) t left join (
+        group by promoter_id
+        ) t left join (
         select promoter_id as 'promoterId',group_concat(user_name) as 'userName' from kuaishou_promoter where media_id =
         2
         group by promoter_id
         ) t2 on t.promoterId = t2.promoterId
+        left join (
+        select promoter_id as 'promoterId',
+        count(oid) as 'orderNum'
+        from kuaishou_supply_chain
+        where stat_hour &lt;= #{hour}
+        <if test="lastTimeStart != null and lastTimeStart != ''">
+            and stat_date &gt;= #{lastTimeStart}
+        </if>
+        <if test="lastTimeEnd != null and lastTimeEnd != ''">
+            and stat_date &lt;= #{lastTimeEnd}
+        </if>
+        <if test="promoterId != null and promoterId != ''">
+            and promoter_id = #{promoterId}
+        </if>
+        <if test="promoterNickName != null and promoterNickName != ''">
+            and promoter_nick_name like concat(concat('%',#{promoterNickName}),'%')
+        </if>
+        group by promoter_id
+        ) t3 on t.promoterId = t3.promoterId
         order by t.orderNum desc
     </select>
     <select id="getTopOrders" resultType="com.alibaba.fastjson.JSONObject">
@@ -170,13 +191,16 @@
     </select>
     <select id="itemList" resultType="com.alibaba.fastjson.JSONObject">
         select *
-        from (select t2.user_id as 'userId',
+        from (
+        select
+        t2.user_id as 'userId',
         t2.user_name as 'userName',
         t1.item_id as 'itemId',
         t1.reserve_price as 'reservePrice',
         t1.item_title as 'itemTitle',
         t1.image_url as 'imageUrl',
         count(t1.oid) as 'orderNum',
+        ROUND(((count(t1.oid)-t6.orderNum)/t6.orderNum)*100,2) as 'orderNumRoi',
         sum(case when t1.order_status != 80 then 1 else 0 end) as 'validOrderNUm',
         round(sum(case when t1.order_status != 80 then 1 else 0 end) / count(t1.oid), 4) as 'validRadio',
         sum(case when t1.send_status = 1 then 1 else 0 end) as 'deliveryNum',
@@ -217,7 +241,26 @@
         on t1.item_id = t4.item_id
         left join kuaishou_item_list t5
         on t1.item_id = t5.item_id
-        where 1 = 1
+        left join (
+        select
+        item_id as 'itemId',
+        count(oid) as 'orderNum'
+        from kuaishou_supply_chain
+        where stat_hour &lt;= #{hour}
+        <if test="lastTimeStart != null and lastTimeStart != ''">
+            and stat_date &gt;= #{lastTimeStart}
+        </if>
+        <if test="lastTimeEnd != null and lastTimeEnd != ''">
+            and stat_date &lt;= #{lastTimeEnd}
+        </if>
+        <if test="itemId != null and itemId != ''">
+            and item_id = #{itemId}
+        </if>
+        <if test="itemTitle != null and itemTitle != ''">
+            and item_title like concat(concat('%',#{itemTitle}),'%')
+        </if>
+        group by item_id) t6 on t1.item_id = t6.itemId
+        where t1.stat_hour &lt;= #{hour}
         <if test="start != null and start != ''">
             and t1.stat_date &gt;= #{start}
         </if>
@@ -299,7 +342,6 @@
         on t1.itemId = t3.item_id
         left join kuaishou_item_list t4
         on t1.itemId = t4.item_id
-
         where 1 = 1
         <if test="itemId != null and itemId != ''">
             and t1.itemId = #{itemId}
@@ -1005,7 +1047,9 @@
         ORDER BY t.create_time DESC
     </select>
     <select id="adminReportList" resultType="com.alibaba.fastjson.JSONObject">
-        select *
+        select t.*,
+               t1.sendSampleCount,
+               ROUND(((t.orderNum-t3.orderNum)/t3.orderNum)*100,2) as 'orderNumRoi'
         from (select t1.user_id as 'userId',
         t1.user_name as 'userName',
         count(distinct t2.item_id) as 'itemCount',
@@ -1037,19 +1081,35 @@
         from kuaishou_item_bind_user t1
         left join kuaishou_supply_chain t2
         on t1.item_id = t2.item_id
-        where 1= 1
+        where t2.stat_hour &lt;= #{hour}
         <if test="start != null and start != ''">
-            and t2.stat_date &gt;= DATE_FORMAT(#{startDate},'%Y%m%d')
+            and t2.stat_date &gt;=#{start}
         </if>
         <if test="end != null and end != ''">
-            and t2.stat_date &lt;= DATE_FORMAT(#{endDate},'%Y%m%d')
+            and t2.stat_date &lt;= #{end}
         </if>
-        group by t1.user_id) t left join (
+        group by t1.user_id
+        ) t left join (
         select item_create_id,count(1) as 'sendSampleCount' from kuaishou_item_collect_samples
         where courier_number_time >= #{startDate}
         and courier_number_time &lt;= #{endDate}
         group by item_create_id
         ) t1 on t.userId = t1.item_create_id
+        left join (
+        select t1.user_id as 'userId',
+        count(t2.oid) as 'orderNum'
+        from kuaishou_item_bind_user t1
+        left join kuaishou_supply_chain t2
+        on t1.item_id = t2.item_id
+        where  t2.stat_hour &lt;= #{hour}
+        <if test="lastTimeStart != null and lastTimeStart != ''">
+            and t2.stat_date &gt;= #{lastTimeStart}
+        </if>
+        <if test="lastTimeEnd != null and lastTimeEnd != ''">
+            and t2.stat_date &lt;= #{lastTimeEnd}
+        </if>
+        group by t1.user_id
+        ) t3 on t.userId = t3.userId
         where 1 =1
         <if test="userId != null and userId != ''">
             and t.userId = #{userId}