Ver código fonte

每月订单业务数据导出

zoujiajian 3 anos atrás
pai
commit
7f27546d2e

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

@@ -10,8 +10,11 @@ import com.cyksj.model.views.ChannelPopularizeView;
 import com.cyksj.model.views.ChannelStatisticsView;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
+import java.util.Optional;
+import java.util.Set;
 
 /**
  * @author chan
@@ -41,4 +44,6 @@ public interface OrderDonMapper extends BaseMapper<OrderDon> {
 	Integer selectCouponCodeUserNum(@Param("dsPopularizeId") Long dsPopularizeId, @Param("noOrderAllStatus") List<String> noOrderAllStatus);
 
 	ChannelPopularizeView countPopularizeOrderDetail(@Param("popularizeId") Long popularizeId, @Param("startTime") String startTime, @Param("endTime") String endTime);
+
+	Optional<BigDecimal> selectThisMonthMoney(@Param("skuIds") Set<Long> skuIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
 }

+ 62 - 0
netflix-dao/src/main/java/com/cyksj/mapper/manage/statistics/StatisticsExportMapper.java

@@ -0,0 +1,62 @@
+package com.cyksj.mapper.manage.statistics;
+
+import cn.hutool.core.date.DateTime;
+import org.apache.ibatis.annotations.Param;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/*
+ *项目名: netflix
+ *文件名: StatisticsExportMapper
+ *创建者: JavaZou
+ *创建时间:2023/7/26 17:57
+ */
+public interface StatisticsExportMapper{
+	Integer getMonthNfExNumOfUser(@Param("goodsId") Long goodsId, @Param("lastYearMonth") String lastYearMonth, @Param("lastElevMonth") String lastElevMonth, @Param("lastThreeMonth") String lastThreeMonth, @Param("lastTwoMonth") String lastTwoMonth, @Param("lastMonth") String lastMonth, @Param("thisMonth") String thisMonth);
+
+	Integer getMonthNfExNumOfUserByType(@Param("goodsId") Long goodsId, @Param("type") Integer type, @Param("lastYearMonth") String lastYearMonth, @Param("lastElevMonth") String lastElevMonth, @Param("lastThreeMonth") String lastThreeMonth, @Param("lastTwoMonth") String lastTwoMonth, @Param("lastMonth") String lastMonth, @Param("thisMonth") String thisMonth, @Param("nextMonth") String nextMonth);
+
+	Integer getMonthNfRenewNumOfUser(@Param("goodsId") Long goodsId, @Param("thisMonth") DateTime thisMonth, @Param("nextMonth") DateTime nextMonth);
+
+	Integer getMonthAiExNumOfUser(@Param("skuIds") List<Long> aiMonthSkuIds, @Param("lastMonth") String lastMonth, @Param("thisMonth") DateTime thisMonth);
+
+	Integer getMonthAiExNumOfUserByType(@Param("skuIds") List<Long> aiMonthSkuIds, @Param("type") Integer type, @Param("lastMonth") String lastMonth, @Param("thisMonth") DateTime thisMonth, @Param("nextMonth") String nextMonth);
+
+
+	List<Long> getAiMonthPlus(Long goodsId);
+
+	Integer getMonthAiRenewNumOfUser(@Param("skuIds") List<Long> aiMonthSkuIds, @Param("thisMonth") DateTime thisMonth, @Param("nextMonth") DateTime nextMonth);
+
+	Integer getMonthStreamingNewNumOfUser(@Param("thisMonth") DateTime thisMonth, @Param("nextMonth") DateTime nextMonth);
+
+	Integer getMonthStreamingNewPayOtherNumOfUser(@Param("thisMonth") DateTime thisMonth, @Param("nextMonth") DateTime nextMonth);
+
+	Integer getMonthStreamingNewPayAiNumOfUser(@Param("thisMonth") DateTime thisMonth, @Param("nextMonth") DateTime nextMonth);
+
+	Integer getMonthAiNewNumOfUser(@Param("thisMonth") DateTime thisMonth, @Param("nextMonth") DateTime nextMonth);
+
+	Integer getMonthAiNewPayOtherNumOfUser(@Param("thisMonth") DateTime thisMonth, @Param("nextMonth") DateTime nextMonth);
+
+	Integer getMonthAiNewPayStreamingNumOfUser(@Param("thisMonth") DateTime thisMonth, @Param("nextMonth") DateTime nextMonth);
+
+	Integer getMonthPrivateCorpNumOfUser(@Param("type") Integer type, @Param("category") Integer category);
+
+	BigDecimal getShouldApplyMoney(String endDate);
+
+	BigDecimal getRealApplyMoney(String endDate);
+
+	Integer getMonthUserSourceNumByType(@Param("type") Integer type, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+	Integer getNfTicketNumOfUser(Long goodsId);
+
+	Integer getAiTicketNumOfUser();
+
+	Integer getNfAiTicketNumOfUser(Long goodsId);
+
+	BigDecimal getMonthAmountOfOrderByType(@Param("type") Integer type, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+	BigDecimal getMonthGoodsTypeAmountOfOrderByType(@Param("type") Integer type, @Param("goodsType") Integer goodsType, @Param("category") Integer category, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+	Integer getMonthUserSourceNumOrderByType(@Param("type") Integer type, @Param("startDate") String startDate, @Param("endDate") String endDate);
+}

+ 90 - 0
netflix-dao/src/main/java/com/cyksj/model/excel/ExcelMonthOrderData.java

@@ -0,0 +1,90 @@
+package com.cyksj.model.excel;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.experimental.Accessors;
+
+/*
+ *项目名: netflix
+ *文件名: ExcelMonthOrderData
+ *创建者: JavaZou
+ *创建时间:2023/7/26 17:16
+ */
+@Getter
+@Setter
+@Accessors(chain = true)
+public class ExcelMonthOrderData {
+	@ExcelProperty({"品类数据类", "奈飞续费数据", "A.当月到期所有用户数"})
+	private Integer monthNfExNumOfUser;
+
+	@ExcelProperty({"品类数据类", "奈飞续费数据", "B.A数据中主动续费的用户数"})
+	private Integer monthNfExRenewNumOfUser;
+
+	@ExcelProperty({"品类数据类", "奈飞续费数据", "C.A数据中,没有主动续费,但又购买奈飞的用户数"})
+	private Integer monthNfExRePayNumOfUser;
+
+	@ExcelProperty({"品类数据类", "奈飞续费数据", "D.非当月到期,但续费的用户数"})
+	private Integer monthNfNoExRenewNumOfUser;
+
+	@ExcelProperty({"品类数据类", "AI类续费(gptplus月付)", "A.月付当月到期的所有用户数"})
+	private Integer monthAiGptExNumOfUser;
+
+	@ExcelProperty({"品类数据类", "AI类续费(gptplus月付)", "B.A数据中主动续费的用户数"})
+	private Integer monthAiGptExRenewNumOfUser;
+
+	@ExcelProperty({"品类数据类", "AI类续费(gptplus月付)", "C.A数据中,没有主动续费,但又购买对应品类的用户数"})
+	private Integer monthAiGptExRePayNumOfUser;
+
+	@ExcelProperty({"品类数据类", "AI类续费(gptplus月付)", "D.非当月到期,但续费的用户数"})
+	private Integer monthAiGptNoExRenewNumOfUser;
+
+	@ExcelProperty({"品类数据类", "AI类续费(midjourney月付)", "A.月付当月到期的所有用户数"})
+	private Integer monthAiMidExNumOfUser;
+
+	@ExcelProperty({"品类数据类", "AI类续费(midjourney月付)", "B.A数据中主动续费的用户数"})
+	private Integer monthAiMidExRenewNumOfUser;
+
+	@ExcelProperty({"品类数据类", "AI类续费(midjourney月付)", "C.A数据中,没有主动续费,但又购买对应品类的用户数"})
+	private Integer monthAiMidExRePayNumOfUser;
+
+	@ExcelProperty({"品类数据类", "AI类续费(midjourney月付)", "D.非当月到期,但续费的用户数"})
+	private Integer monthAiMidNoExRenewNumOfUser;
+
+	@ExcelProperty({"品类数据类", "流媒类复购数据", "A.购买流媒体类产品为首单的当月新用户"})
+	private Integer monthStreamingNewNumOfUser;
+
+	@ExcelProperty({"品类数据类", "流媒类复购数据", "B.A用户中购买第二单任何产品的用户数"})
+	private Integer monthStreamingNewPayOtherNumOfUser;
+
+	@ExcelProperty({"品类数据类", "流媒类复购数据", "C.A用户中购买第二单AI产品的用户数"})
+	private Integer monthStreamingNewPayAiNumOfUser;
+
+	@ExcelProperty({"品类数据类", "AI类复购数据", "A.购买AI类产品为首单的当月新用户"})
+	private Integer monthAiNewNumOfUser;
+
+	@ExcelProperty({"品类数据类", "AI类复购数据", "B.A用户中购买第二单任何产品的用户数"})
+	private Integer monthAiNewPayOtherNumOfUser;
+
+	@ExcelProperty({"品类数据类", "AI类复购数据", "C.A用户中购买第二单流媒体产品的用户数"})
+	private Integer monthAiNewPayStreamingNumOfUser;
+
+//	@ExcelProperty({"历史复购","有奈飞车票的人数"})
+//	private Integer nfTicketNumOfUser;
+//
+//	@ExcelProperty({"历史复购","有AI账号车票人数"})
+//	private Integer aiTicketNumOfUser;
+//
+//	@ExcelProperty({"历史复购","二者交叉人数"})
+//	private Integer nfAiTicketNumOfUser;
+//
+//	@ExcelProperty({"私域数据类", "目前私域中,下过单的用户数(以第一次下单类型为准)", "流媒体类用户数"})
+//	private Integer monthPrivateStreamingNumOfUser;
+//
+//	@ExcelProperty({"私域数据类", "目前私域中,下过单的用户数(以第一次下单类型为准)", "AI类用户数"})
+//	private Integer monthPrivateAiNumOfUser;
+//
+//	@ExcelProperty({"私域数据类", "目前私域中,下过单的用户数(以第一次下单类型为准)", "设备类用户数"})
+//	private Integer monthPrivateEqNumOfUser;
+}
+

+ 68 - 0
netflix-dao/src/main/java/com/cyksj/model/excel/ExcelMonthlyDistributeOrderData.java

@@ -0,0 +1,68 @@
+package com.cyksj.model.excel;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+/*
+ *项目名: netflix
+ *文件名: ExcelMonthlyDistributeOrderData
+ *创建者: JavaZou
+ *创建时间:2023/7/26 17:47
+ */
+@Getter
+@Setter
+public class ExcelMonthlyDistributeOrderData {
+	@ExcelProperty({"运营数据", "自然渠道销售金额"})
+	private BigDecimal monthAmountOfOrder;
+
+	@ExcelProperty({"运营数据", "渠道商销售金额"})
+	private BigDecimal monthDsFAmountOfOrder;
+
+	@ExcelProperty({"运营数据", "个人分销售金额"})
+	private BigDecimal monthDsAmountOfOrder;
+
+	@ExcelProperty({"运营数据", "自然渠道","流媒体销售金额"})
+	private BigDecimal monthStreamingAmountOfOrder;
+
+	@ExcelProperty({"运营数据", "自然渠道","AI销售金额"})
+	private BigDecimal monthAiAmountOfOrder;
+
+	@ExcelProperty({"运营数据", "自然渠道","设备销售金额"})
+	private BigDecimal monthOfEqAmountOfOrder;
+
+	@ExcelProperty({"运营数据", "渠道商+个人分销","流媒体销售金额"})
+	private BigDecimal monthOfSpecStreamingAmountOfOrder;
+
+	@ExcelProperty({"运营数据", "渠道商+个人分销","AI销售金额"})
+	private BigDecimal monthOfSpecAiAmountOfOrder;
+
+	@ExcelProperty({"运营数据", "渠道商+个人分销","设备销售金额"})
+	private BigDecimal monthOfSpecEqAmountOfOrder;
+
+	@ExcelProperty({"分销提现数据","累计应提现"})
+	private BigDecimal shouldApplyMoney;
+
+	@ExcelProperty({"分销提现数据","累计实际提现"})
+	private BigDecimal realApplyMoney;
+
+	@ExcelProperty({"下单率","自然流量渠道","自然渠道用户数"})
+	private Integer natureUserSourceNum;
+
+	@ExcelProperty({"下单率","自然流量渠道","自然渠道下单人数"})
+	private Integer natureUserSourceOrderNum;
+
+	@ExcelProperty({"下单率","自然流量渠道","下单率"})
+	private String natureUserSourceOrderRate;
+
+	@ExcelProperty({"下单率","分销渠道","分销渠道用户数"})
+	private Integer channelUserSourceNum;
+
+	@ExcelProperty({"下单率","分销渠道","分销渠道下单人数"})
+	private Integer channelUserSourceOrderNum;
+
+	@ExcelProperty({"下单率","分销渠道","下单率"})
+	private String channelUserSourceOrderRate;
+}

+ 8 - 0
netflix-dao/src/main/resources/mapper/OrderDonMapper.xml

@@ -171,4 +171,12 @@
         and status = 'refund')
         s2
     </select>
+
+    <select id="selectThisMonthMoney" resultType="java.math.BigDecimal">
+        select sum(money) - ifnull(sum(refund_money),0) from `order_don` where sku_id in
+        <foreach collection="skuIds" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        and status not in ('close','noPayment') and created_time between #{startDate} and #{endDate}
+    </select>
 </mapper>

+ 399 - 0
netflix-dao/src/main/resources/mapper/StatisticsExportMapper.xml

@@ -0,0 +1,399 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.cyksj.mapper.manage.statistics.StatisticsExportMapper">
+
+    <select id="getMonthNfExNumOfUser" resultType="java.lang.Integer">
+        select count(distinct user_id)
+        from (select user_id
+              from `order_don`
+              where sku_id = 4
+                and status not in ('close', 'noPayment', 'refund')
+                and created_time between #{lastMonth} and #{thisMonth}
+              union all
+              select user_id
+              from `order_don`
+              where sku_id = 5
+                and status not in ('close', 'noPayment', 'refund')
+                and created_time between #{lastThreeMonth} and #{lastTwoMonth}
+              union all
+              select user_id
+              from `order_don`
+              where sku_id = 6
+                and status not in ('close', 'noPayment', 'refund')
+                and created_time between #{lastYearMonth}
+                  and #{lastElevMonth}
+             ) s
+    </select>
+
+    <select id="getMonthNfExNumOfUserByType" resultType="java.lang.Integer">
+        select count(distinct user_id)
+        from (select user_id
+              from `order_don`
+              where sku_id = 4
+                and status not in ('close', 'noPayment', 'refund')
+                and created_time between #{lastMonth} and #{thisMonth}
+              union all
+              select user_id
+              from `order_don`
+              where sku_id = 5
+                and status not in ('close', 'noPayment', 'refund')
+                and created_time between #{lastThreeMonth} and #{lastTwoMonth}
+              union all
+              select user_id
+              from `order_don`
+              where sku_id = 6
+                and status not in ('close', 'noPayment', 'refund')
+                and created_time between #{lastYearMonth}
+                  and #{lastElevMonth}) s
+        where EXISTS(select id
+                     from order_don od
+                     where status not in ('close', 'refund', 'noPayment')
+                       and created_time between #{thisMonth} and #{nextMonth}
+                       and order_type = #{type}
+                       and od.user_id = s.user_id
+                       and goods_id = #{goodsId})
+    </select>
+
+    <select id="getMonthNfRenewNumOfUser" resultType="java.lang.Integer">
+        select count(distinct user_id)
+        from `order_don`
+        where goods_id = #{goodsId}
+          and order_type = 2
+          and status not in ('close', 'refund', 'noPayment')
+          and created_time between #{thisMonth} and #{nextMonth}
+    </select>
+
+    <select id="getAiMonthPlus" resultType="java.lang.Long">
+        select id
+        from `goods_don_sku`
+        where goods_id = #{goodsId}
+          and months = 1
+    </select>
+
+    <select id="getMonthAiExNumOfUser" resultType="java.lang.Integer">
+        select count(distinct user_id)
+        from `order_don` od
+        where status not in ('close','refund','noPayment')
+        and created_time BETWEEN #{lastMonth} and #{thisMonth}
+        and sku_id in
+        <foreach collection="skuIds" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
+
+    <select id="getMonthAiExNumOfUserByType" resultType="java.lang.Integer">
+        select count(distinct user_id) from (select user_id
+        from `order_don` od
+        where status not in ('close','refund','noPayment')
+        and created_time BETWEEN #{lastMonth} and #{thisMonth}
+        and sku_id in
+        <foreach collection="skuIds" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>) s where EXISTS(select id
+        from order_don
+        where status not in ('close','refund','noPayment')
+        and created_time between #{thisMonth} and #{nextMonth}
+        and order_type = #{type}
+        and user_id = s.user_id
+        and sku_id in
+        <foreach collection="skuIds" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        )
+    </select>
+
+    <select id="getMonthAiRenewNumOfUser" resultType="java.lang.Integer">
+        select count(distinct user_id)
+        from `order_don` od
+        where status not in ('close','refund','noPayment')
+        and created_time BETWEEN #{thisMonth} and #{nextMonth}
+        and order_type = 2
+        and sku_id in
+        <foreach collection="skuIds" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
+
+    <select id="getMonthStreamingNewNumOfUser" resultType="java.lang.Integer">
+        select count(DISTINCT user_id)
+        from (select user_id, created_time
+              from `order_don`
+              where goods_id in
+                    (select id
+                     from `goods_don`
+                     where category = 2)
+                and status not in ('close', 'refund', 'noPayment')
+                and created_time BETWEEN
+                  #{thisMonth} and #{nextMonth}) s
+        where not EXISTS(select id
+                         from order_don od
+                         where status not in ('close', 'refund', 'noPayment')
+                           and od.user_id = s.user_id
+                           and od.created_time &lt;
+                               s.created_time)
+    </select>
+
+    <select id="getMonthStreamingNewPayOtherNumOfUser" resultType="java.lang.Integer">
+        select count(DISTINCT user_id)
+        from (select user_id, created_time
+              from `order_don`
+              where goods_id in
+                    (select id
+                     from `goods_don`
+                     where category = 2)
+                and status not in ('close', 'refund', 'noPayment')
+                and created_time BETWEEN
+                  #{thisMonth} and #{nextMonth}) s
+        where not EXISTS(select id
+                         from order_don od
+                         where status not in ('close', 'refund', 'noPayment')
+                           and od.user_id = s.user_id
+                           and od.created_time &lt;
+                               s.created_time)
+          and EXISTS(select id
+                     from order_don od
+                     where status not in ('close', 'refund', 'noPayment')
+                       and od.user_id = s.user_id
+                       and od.created_time between
+                         #{thisMonth} and #{nextMonth}
+                       and od.created_time > s.created_time)
+    </select>
+
+    <select id="getMonthStreamingNewPayAiNumOfUser" resultType="java.lang.Integer">
+        select count(DISTINCT user_id)
+        from (select user_id, created_time
+              from `order_don`
+              where goods_id in
+                    (select id
+                     from `goods_don`
+                     where category = 2)
+                and status not in ('close', 'refund', 'noPayment')
+                and created_time BETWEEN
+                  #{thisMonth} and #{nextMonth}) s
+        where not EXISTS(select id
+                         from order_don od
+                         where status not in ('close', 'refund', 'noPayment')
+                           and od.user_id = s.user_id
+                           and od.created_time &lt;
+                               s.created_time)
+          and EXISTS(select id
+                     from (select id, goods_id
+                           from order_don od
+                           where status not in ('close', 'refund', 'noPayment')
+                             and od.user_id = s.user_id
+                             and od.created_time between #{thisMonth} and #{nextMonth}
+                           order by od.created_time limit 1,1) s
+                     where s.goods_id in (select id from goods_don where category = 1))
+    </select>
+
+    <select id="getMonthAiNewNumOfUser" resultType="java.lang.Integer">
+        select count(DISTINCT user_id)
+        from (select user_id, created_time
+              from `order_don`
+              where goods_id in
+                    (select id from goods_don where category = 1)
+                and status not in ('close', 'refund', 'noPayment')
+                and created_time BETWEEN
+                  #{thisMonth} and #{nextMonth}) s
+        where not EXISTS(select id
+                         from order_don od
+                         where status not in ('close', 'refund', 'noPayment')
+                           and od.user_id = s.user_id
+                           and od.created_time &lt;
+                               s.created_time)
+    </select>
+
+    <select id="getMonthAiNewPayOtherNumOfUser" resultType="java.lang.Integer">
+        select count(DISTINCT user_id)
+        from (select user_id, created_time
+              from `order_don`
+              where goods_id in
+                    (select id from goods_don where category = 1)
+                and status not in ('close', 'refund', 'noPayment')
+                and created_time BETWEEN
+                  #{thisMonth} and #{nextMonth}) s
+        where not EXISTS(select id
+                         from order_don od
+                         where status not in ('close', 'refund', 'noPayment')
+                           and od.user_id = s.user_id
+                           and od.created_time &lt;
+                               s.created_time)
+          and EXISTS(select id
+                     from order_don od
+                     where status not in ('close', 'refund', 'noPayment')
+                       and od.user_id = s.user_id
+                       and od.created_time between #{thisMonth} and #{nextMonth}
+                       and od.created_time > s.created_time)
+    </select>
+
+    <select id="getMonthAiNewPayStreamingNumOfUser" resultType="java.lang.Integer">
+        select count(DISTINCT user_id)
+        from (select user_id, created_time
+              from `order_don`
+              where goods_id in
+                    (select id from goods_don where category = 1)
+                and status not in ('close', 'refund', 'noPayment')
+                and created_time BETWEEN
+                  #{thisMonth} and #{nextMonth}) s
+        where not EXISTS(select id
+                         from order_don od
+                         where status not in ('close', 'refund', 'noPayment')
+                           and od.user_id = s.user_id
+                           and od.created_time &lt;
+                               s.created_time)
+          and EXISTS(select id
+                     from (select id, goods_id
+                           from order_don od
+                           where status not in ('close', 'refund', 'noPayment')
+                             and od.user_id = s.user_id
+                             and od.created_time between #{thisMonth} and #{nextMonth}
+                           order by od.created_time limit 1,1) s
+                     where s.goods_id in (select id from goods_don where category = 2))
+    </select>
+
+    <select id="getMonthPrivateCorpNumOfUser" resultType="java.lang.Integer">
+        select count(distinct s.user_id) from (select user_id from (select user_id,created_time from `order_don` where
+        goods_id in
+        (select id from goods_don
+        <where>
+            <if test="category!=null">
+                and category = #{category}
+            </if>
+            <if test="type!=null">
+                and `type` = #{type}
+            </if>
+        </where>
+        )
+        and status not in ('close','noPayment','refund')) s where not exists (select id from `order_don` where status
+        not
+        in ('close','noPayment','refund')
+        and user_id= s.user_id and created_time &lt; s.created_time)) s inner join user u on u.id = s.user_id and
+        u.unionid != '' inner join corp_user cu on cu.user_id =
+        u.id
+        inner join corp_user_auth ca on ca.corp_user_id = cu.id and ca.wx_corp_id = 2
+    </select>
+
+    <select id="getShouldApplyMoney" resultType="java.math.BigDecimal">
+        select sum(points) / 1000
+        from `distribute_waiting_send_points`
+        where send_status = 'success'
+          and created_time &lt; #{endDate}
+    </select>
+
+    <select id="getRealApplyMoney" resultType="java.math.BigDecimal">
+        select sum(money) / 100
+        from `distribute_money_apply`
+        where `verify_status` = 'success'
+          and created_time &lt; #{endDate}
+    </select>
+
+    <select id="getMonthUserSourceNumByType" resultType="java.lang.Integer">
+        select count(u.id)
+        from (select id from `user` where created_time >= #{startDate} and created_time &lt; #{endDate}) u
+        left join user_distribute_shared us on us.user_id = u.id
+        left join user_distribute ud on ud.user_id = us.shared_id
+        <where>
+            <choose>
+                <when test="type == 1">
+                    us.id is null
+                </when>
+                <otherwise>
+                    us.id is not null
+                </otherwise>
+            </choose>
+        </where>
+    </select>
+
+    <select id="getNfTicketNumOfUser" resultType="java.lang.Integer">
+        select count(distinct user_id)
+        from `order_don`
+        where goods_id = #{goodsId}
+          and status not in ('close', 'noPayment', 'refund')
+    </select>
+
+    <select id="getAiTicketNumOfUser" resultType="java.lang.Integer">
+        select count(distinct o.user_id)
+        from `order_don` o
+                 left join goods_don g on g.id = o.goods_id
+        where g.category = 1
+          and o.status not in ('close', 'noPayment', 'refund')
+    </select>
+
+    <select id="getNfAiTicketNumOfUser" resultType="java.lang.Integer">
+        select count(distinct o.user_id)
+        from `order_don` o
+                 left join order_don o2 on o2.user_id = o.user_id
+                 left join goods_don g on g.id = o2.goods_id
+        where o.goods_id = #{goodsId}
+          and o.status not in ('close', 'noPayment', 'refund')
+          and o2.status not in ('close', 'noPayment', 'refund')
+          and g.category = 1
+    </select>
+
+    <select id="getMonthAmountOfOrderByType" resultType="java.math.BigDecimal">
+        select ifnull((sum(o.money) - ifnull(sum(o.refund_money),0))/100,0) from `order_don` o left join `user_distribute_shared`
+        us on us.user_id = o.user_Id
+        left join `user_distribute` ud on ud.user_id = us.shared_id
+        where
+        <choose>
+            <when test="type == 1">
+                us.id is null
+            </when>
+            <when test="type == 2">
+                us.id is not null and ud.id is null
+            </when>
+            <when test="type == 3">
+                ud.id is not null
+            </when>
+        </choose>
+        and o.created_time >= #{startDate} and o.created_time &lt; #{endDate}
+        and status not in ('close', 'noPayment')
+    </select>
+
+    <select id="getMonthGoodsTypeAmountOfOrderByType" resultType="java.math.BigDecimal">
+        select ifnull((sum(o.money) - ifnull(sum(o.refund_money),0))/100,0) from `order_don` o left join `user_distribute_shared`
+        us on us.user_id = o.user_Id
+        left join `user_distribute` ud on ud.user_id = us.shared_id
+        where
+        <choose>
+            <when test="type == 1">
+                us.id is null
+            </when>
+            <otherwise>
+                us.id is not null
+            </otherwise>
+        </choose>
+        and o.created_time >= #{startDate} and o.created_time &lt; #{endDate}
+        and status not in ('close', 'noPayment')
+        and goods_id in (select id from goods_don
+        <where>
+            <if test="goodsType != null">
+                `type` = #{goodsType}
+            </if>
+            <if test="category!=null">
+                category = #{category}
+            </if>
+        </where>
+        )
+    </select>
+
+    <select id="getMonthUserSourceNumOrderByType" resultType="java.lang.Integer">
+        select count(distinct s.id) from (select u.id
+        from (select id from `user` where created_time >= #{startDate} and created_time &lt; #{endDate}) u
+        left join user_distribute_shared us on us.user_id = u.id
+        left join user_distribute ud on ud.user_id = us.shared_id
+        <where>
+            <choose>
+                <when test="type == 1">
+                    us.id is null
+                </when>
+                <otherwise>
+                    us.id is not null
+                </otherwise>
+            </choose>
+        </where>
+        ) s left join order_don o on o.user_id = s.id where o.status not in ('close', 'noPayment','refund')
+        and o.created_time >= #{startDate} and o.created_time &lt; #{endDate}
+    </select>
+</mapper>

+ 9 - 5
netflix-dao/src/main/resources/mapper/StatisticsUserDataMapper.xml

@@ -4,10 +4,12 @@
 
     <select id="getExportStreamingAccountData"
             resultType="com.cyksj.model.excel.statistics.ExcelStreamingAccountData">
-        select count(distinct user_id) as numOfUser, count(*) as numOfOrder,ifnull(sum(money)/100,0) as money from
-        `order_don`
+        select count(distinct if(status = 'refund',NUll,user_id)) as numOfUser,
+               count(if(status = 'refund',NULL,id)) as numOfOrder,
+               ifnull((sum(money)-ifnull(sum(refund_money),0))/100,0) as money
+        from `order_don`
         where sku_id in (select id from `goods_don_sku` where goods_id = #{goodsId})
-        and status not in ('close','noPayment','refund')
+        and status not in ('close','noPayment')
         <if test="isDis!=null and isDis">
             and is_distribute = 1
         </if>
@@ -38,10 +40,12 @@
     </select>
 
     <select id="getExportGoodsDonDataBySkuId" resultType="com.cyksj.model.excel.statistics.ExcelRealGoodsData">
-        select count(distinct user_id) as numOfUser, count(*) as numOfOrder, ifnull(sum(money) / 100, 0) as money
+        select count(distinct if(status = 'refund',NULL,user_id)) as numOfUser,
+               count(if(status = 'refund',NULL,id)) as numOfOrder,
+               ifnull((sum(money) - ifnull(sum(refund_money),0)) / 100, 0) as money
         from `order_don`
         where sku_id = #{skuId}
-          and status not in ('close', 'noPayment', 'refund')
+          and status not in ('close', 'noPayment')
         <if test="start != null">
             and created_time >= #{start}
         </if>

+ 5 - 0
netflix-service/src/main/java/com/cyksj/service/mange/statistics/StatisticsDataService.java

@@ -36,4 +36,9 @@ public interface StatisticsDataService {
 	 * 数据导出
 	 */
 	List<ExcelSheetAndData> exportStatisticsDataByType(Integer type, Long startTime, Long endTime);
+
+	/**
+	 * 每月业务数据导出
+	 */
+	List<ExcelSheetAndData> exportMonthlyData(Long startTime, Long endTime);
 }

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/mange/statistics/impl/StatisticsDataDayServiceImpl.java

@@ -362,7 +362,7 @@ public class StatisticsDataDayServiceImpl implements StatisticsDataDayService {
 		});
 		Map<String, List<GoodsDonSku>> areaDataMap = new HashMap<>();
 		for (String name : area) {
-			List<GoodsDonSku> sku = Optional.ofNullable(goodsDonSkuService.list(Wrappers.lambdaQuery(GoodsDonSku.class).like(GoodsDonSku::getSpecVal, name).select(GoodsDonSku::getId, GoodsDonSku::getGoodsId, GoodsDonSku::getSpecVal))).orElse(new ArrayList<>());
+			List<GoodsDonSku> sku = Optional.ofNullable(goodsDonSkuService.list(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getGoodsId, 2).like(GoodsDonSku::getSpecVal, name).select(GoodsDonSku::getId, GoodsDonSku::getGoodsId, GoodsDonSku::getSpecVal))).orElse(new ArrayList<>());
 			areaDataMap.put(name, sku);
 		}
 		return areaDataMap;

+ 209 - 7
netflix-service/src/main/java/com/cyksj/service/mange/statistics/impl/StatisticsDataServiceImpl.java

@@ -13,6 +13,8 @@ import com.cyksj.mapper.*;
 import com.cyksj.mapper.manage.statistics.*;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.excel.ExcelAccountData;
+import com.cyksj.model.excel.ExcelMonthOrderData;
+import com.cyksj.model.excel.ExcelMonthlyDistributeOrderData;
 import com.cyksj.model.excel.ExcelSheetAndData;
 import com.cyksj.model.excel.statistics.ExcelAppleOneData;
 import com.cyksj.model.excel.statistics.ExcelRealGoodsData;
@@ -32,6 +34,7 @@ import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -73,6 +76,8 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 
 	private final StatisticsFashionGoodsDataMapper statisticsFashionGoodsDataMapper;
 
+	private final StatisticsExportMapper statisticsExportMapper;
+
 	@Override
 	public Result<BackgroundDataView> getStatisticsByCondition(Long startTime, Long endTime) {
 		BackgroundDataView backgroundDataView = new BackgroundDataView();
@@ -261,15 +266,212 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 				exportRegisterData(excelSheetDataList, startDate, endDate);
 				break;
 			default:
-				exportAppleOneData(excelSheetDataList, startDate, endDate);
-				exportStreamingAccountData(excelSheetDataList, startDate, endDate);
-				exportRealGoodsData(excelSheetDataList, startDate, endDate);
-				exportFashionData(excelSheetDataList, startDate, endDate);
-				exportRegisterData(excelSheetDataList, startDate, endDate);
+				exportAllTypeData(excelSheetDataList, startDate, endDate);
 		}
 		return excelSheetDataList;
 	}
 
+	@Override
+	public List<ExcelSheetAndData> exportMonthlyData(Long startTime, Long endTime) {
+		List<ExcelSheetAndData> excelSheetDataList = new ArrayList<>();
+		String startDate = null;
+		String endDate = null;
+		if (startTime != null) {
+			startDate = DateTime.of(startTime).toString();
+		}
+		if (endTime != null) {
+			endDate = DateTime.of(endTime).toString();
+		}
+		//业务订单数
+		exportBusinessMonthlyData(excelSheetDataList, startTime, endTime);
+		//分销类型订单数据
+		exportDistributeMonthlyData(excelSheetDataList, startDate, endDate);
+
+		//所有平台类型的订单数据
+		exportAllTypeData(excelSheetDataList, startDate, endDate);
+		return excelSheetDataList;
+	}
+
+	public void exportAllTypeData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
+		exportAppleOneData(excelSheetDataList, startDate, endDate);
+		exportStreamingAccountData(excelSheetDataList, startDate, endDate);
+		exportRealGoodsData(excelSheetDataList, startDate, endDate);
+		exportFashionData(excelSheetDataList, startDate, endDate);
+		exportRegisterData(excelSheetDataList, startDate, endDate);
+	}
+
+	private void exportBusinessMonthlyData(List<ExcelSheetAndData> excelSheetDataList, Long startTime, Long endTime) {
+		//月付、季付、年付
+		Long nf_goodsId = 1l;
+		DateTime thisMonth = DateTime.of(startTime);
+		DateTime nextMonth = DateUtil.offsetMonth(thisMonth, 1);
+		String lastMonth = DateUtil.offsetMonth(thisMonth, -1).toDateStr();
+		//前两个月
+		String lastTwoMonth = DateUtil.offsetMonth(thisMonth, -2).toDateStr();
+		//前三个月
+		String lastThreeMonth = DateUtil.offsetMonth(thisMonth, -3).toDateStr();
+		//前十一个月
+		String lastElevMonth = DateUtil.offsetMonth(thisMonth, -11).toDateStr();
+		//前十二个月
+		String lastYearMonth = DateUtil.offsetMonth(thisMonth, -12).toDateStr();
+		//奈飞当月过期人数
+		Integer monthNfExNumOfUser = statisticsExportMapper.getMonthNfExNumOfUser(nf_goodsId, lastYearMonth, lastElevMonth, lastThreeMonth, lastTwoMonth, lastMonth, thisMonth.toDateStr());
+		//奈飞 A主动续费
+		Integer monthNfExRenewNumOfUser = statisticsExportMapper.getMonthNfExNumOfUserByType(nf_goodsId, 2, lastYearMonth, lastElevMonth, lastThreeMonth, lastTwoMonth, lastMonth, thisMonth.toDateStr(), nextMonth.toDateStr());
+		//奈飞 A再次购买
+		Integer monthNfExRePayNumOfUser = statisticsExportMapper.getMonthNfExNumOfUserByType(nf_goodsId, 1, lastYearMonth, lastElevMonth, lastThreeMonth, lastTwoMonth, lastMonth, thisMonth.toDateStr(), nextMonth.toDateStr());
+		//奈飞 非当月到期 主动续费
+		//当月续费人数
+		Integer monthNfRenewNumOfUser = statisticsExportMapper.getMonthNfRenewNumOfUser(nf_goodsId, thisMonth, nextMonth);
+		Integer monthNfNoExRenewNumOfUser = monthNfRenewNumOfUser - monthNfExRenewNumOfUser;
+
+		//Ai Gpt月付
+		List<Long> gptMonthSkuId = statisticsExportMapper.getAiMonthPlus(18l);
+		//Ai类gptplus当月到期用户数
+		Integer monthAiGptExNumOfUser = statisticsExportMapper.getMonthAiExNumOfUser(gptMonthSkuId, lastMonth, thisMonth);
+		//AiGpt月付 A主动续费
+		Integer monthAiGptExRenewNumOfUser = statisticsExportMapper.getMonthAiExNumOfUserByType(gptMonthSkuId, 2, lastMonth, thisMonth, nextMonth.toDateStr());
+		//AiGpt月付 再次购买
+		Integer monthAiGptExRePayNumOfUser = statisticsExportMapper.getMonthAiExNumOfUserByType(gptMonthSkuId, 1, lastMonth, thisMonth, nextMonth.toDateStr());
+		//AiGpt当月续费人数
+		Integer monthAiGptRenewNumOfUser = statisticsExportMapper.getMonthAiRenewNumOfUser(gptMonthSkuId, thisMonth, nextMonth);
+		//非当月 续费人数
+		Integer monthAiGptNoExRenewNumOfUser = monthAiGptRenewNumOfUser - monthAiGptExRenewNumOfUser;
+
+		//Ai midjourney 月付
+		List<Long> midJourneyMonthSkuId = statisticsExportMapper.getAiMonthPlus(26l);
+		Integer monthAiMidExNumOfUser = statisticsExportMapper.getMonthAiExNumOfUser(midJourneyMonthSkuId, lastMonth, thisMonth);
+		//Ai midjourney月付 A主动续费
+		Integer monthAiMidExRenewNumOfUser = statisticsExportMapper.getMonthAiExNumOfUserByType(midJourneyMonthSkuId, 2, lastMonth, thisMonth, nextMonth.toDateStr());
+		//Ai midjourney月付 再次购买
+		Integer monthAiMidExRePayNumOfUser = statisticsExportMapper.getMonthAiExNumOfUserByType(midJourneyMonthSkuId, 1, lastMonth, thisMonth, nextMonth.toDateStr());
+		//Ai midjourney当月续费人数
+		Integer monthAiMidRenewNumOfUser = statisticsExportMapper.getMonthAiRenewNumOfUser(midJourneyMonthSkuId, thisMonth, nextMonth);
+		//非当月 midjourney续费人数
+		Integer monthAiMidNoExRenewNumOfUser = monthAiMidRenewNumOfUser - monthAiMidExRenewNumOfUser;
+
+		//流媒体当月首单
+		Integer monthStreamingNewNumOfUser = statisticsExportMapper.getMonthStreamingNewNumOfUser(thisMonth, nextMonth);
+
+		//流媒体 A中第二单 为任意产品
+		Integer monthStreamingNewPayOtherNumOfUser = statisticsExportMapper.getMonthStreamingNewPayOtherNumOfUser(thisMonth, nextMonth);
+		//流媒体 A中第二单 为Ai产品
+		Integer monthStreamingNewPayAiNumOfUser = statisticsExportMapper.getMonthStreamingNewPayAiNumOfUser(thisMonth, nextMonth);
+
+		//AI类复购
+		//Ai当月购买新用户数
+		Integer monthAiNewNumOfUser = statisticsExportMapper.getMonthAiNewNumOfUser(thisMonth, nextMonth);
+		//Ai A中第二单 为任意产品
+		Integer monthAiNewPayOtherNumOfUser = statisticsExportMapper.getMonthAiNewPayOtherNumOfUser(thisMonth, nextMonth);
+		//Ai A中第二单 为流媒体
+		Integer monthAiNewPayStreamingNumOfUser = statisticsExportMapper.getMonthAiNewPayStreamingNumOfUser(thisMonth, nextMonth);
+
+//		//历史复购 AI、奈飞车票人数 以及交叉
+//		Integer nfTicketNumOfUser = statisticsExportMapper.getNfTicketNumOfUser(1l);
+//
+//		Integer aiTicketNumOfUser = statisticsExportMapper.getAiTicketNumOfUser();
+//
+//		Integer nfAiTicketNumOfUser = statisticsExportMapper.getNfAiTicketNumOfUser(1l);
+//		//私域
+//		//首单流媒体用户数
+//		Integer monthPrivateStreamingNumOfUser = statisticsExportMapper.getMonthPrivateCorpNumOfUser(null, 2);
+//		//首单Ai用户数
+//		Integer monthPrivateAiNumOfUser = statisticsExportMapper.getMonthPrivateCorpNumOfUser(null, 1);
+//		//首单实物设备
+//		Integer monthPrivateEqNumOfUser = statisticsExportMapper.getMonthPrivateCorpNumOfUser(2, null);
+		ExcelMonthOrderData excelMonthOrderData = new ExcelMonthOrderData()
+				.setMonthNfExNumOfUser(monthNfExNumOfUser)
+				.setMonthNfExRenewNumOfUser(monthNfExRenewNumOfUser)
+				.setMonthNfExRePayNumOfUser(monthNfExRePayNumOfUser)
+				.setMonthNfNoExRenewNumOfUser(monthNfNoExRenewNumOfUser)
+				.setMonthAiGptExNumOfUser(monthAiGptExNumOfUser)
+				.setMonthAiGptExRenewNumOfUser(monthAiGptExRenewNumOfUser)
+				.setMonthAiGptExRePayNumOfUser(monthAiGptExRePayNumOfUser)
+				.setMonthAiGptNoExRenewNumOfUser(monthAiGptNoExRenewNumOfUser)
+				.setMonthAiMidExNumOfUser(monthAiMidExNumOfUser)
+				.setMonthAiMidExRenewNumOfUser(monthAiMidExRenewNumOfUser)
+				.setMonthAiMidExRePayNumOfUser(monthAiMidExRePayNumOfUser)
+				.setMonthAiMidNoExRenewNumOfUser(monthAiMidNoExRenewNumOfUser)
+				.setMonthStreamingNewNumOfUser(monthStreamingNewNumOfUser)
+				.setMonthStreamingNewPayOtherNumOfUser(monthStreamingNewPayOtherNumOfUser)
+				.setMonthStreamingNewPayAiNumOfUser(monthStreamingNewPayAiNumOfUser)
+				.setMonthAiNewNumOfUser(monthAiNewNumOfUser)
+				.setMonthAiNewPayOtherNumOfUser(monthAiNewPayOtherNumOfUser)
+				.setMonthAiNewPayStreamingNumOfUser(monthAiNewPayStreamingNumOfUser);
+//				.setNfTicketNumOfUser(nfTicketNumOfUser)
+//				.setAiTicketNumOfUser(aiTicketNumOfUser)
+//				.setNfAiTicketNumOfUser(nfAiTicketNumOfUser)
+//				.setMonthPrivateStreamingNumOfUser(monthPrivateStreamingNumOfUser)
+//				.setMonthPrivateAiNumOfUser(monthPrivateAiNumOfUser)
+//				.setMonthPrivateEqNumOfUser(monthPrivateEqNumOfUser);
+		excelSheetDataList.add(new ExcelSheetAndData("每月订单业务数据", List.of(excelMonthOrderData), ExcelMonthOrderData.class));
+	}
+
+	private void exportDistributeMonthlyData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
+		ExcelMonthlyDistributeOrderData excelMonthlyDistributeOrderData = new ExcelMonthlyDistributeOrderData();
+		//渠道分销数据
+		//自然渠道销售金额
+		BigDecimal monthAmountOfOrder = statisticsExportMapper.getMonthAmountOfOrderByType(1, startDate, endDate);
+		excelMonthlyDistributeOrderData.setMonthAmountOfOrder(monthAmountOfOrder);
+		//个人渠道销售金额
+		BigDecimal monthDsAmountOfOrder = statisticsExportMapper.getMonthAmountOfOrderByType(2, startDate, endDate);
+		excelMonthlyDistributeOrderData.setMonthDsAmountOfOrder(monthDsAmountOfOrder);
+		//渠道商销售金额
+		BigDecimal monthDsFAmountOfOrder = statisticsExportMapper.getMonthAmountOfOrderByType(3, startDate, endDate);
+		excelMonthlyDistributeOrderData.setMonthDsFAmountOfOrder(monthDsFAmountOfOrder);
+		//自然渠道
+		//流媒体
+		BigDecimal monthStreamingAmountOfOrder = statisticsExportMapper.getMonthGoodsTypeAmountOfOrderByType(1, null, 2, startDate, endDate);
+		excelMonthlyDistributeOrderData.setMonthStreamingAmountOfOrder(monthStreamingAmountOfOrder);
+		// AI销售金额
+		BigDecimal monthAiAmountOfOrder = statisticsExportMapper.getMonthGoodsTypeAmountOfOrderByType(1, null, 1, startDate, endDate);
+		excelMonthlyDistributeOrderData.setMonthAiAmountOfOrder(monthAiAmountOfOrder);
+		//设备销售金额
+		BigDecimal monthOfEqAmountOfOrder = statisticsExportMapper.getMonthGoodsTypeAmountOfOrderByType(1, 2, null, startDate, endDate);
+		excelMonthlyDistributeOrderData.setMonthOfEqAmountOfOrder(monthOfEqAmountOfOrder);
+		//渠道商+个人分销
+		//流媒体
+		BigDecimal monthOfSpecStreamingAmountOfOrder = statisticsExportMapper.getMonthGoodsTypeAmountOfOrderByType(2, null, 2, startDate, endDate);
+		excelMonthlyDistributeOrderData.setMonthOfSpecStreamingAmountOfOrder(monthOfSpecStreamingAmountOfOrder);
+		// AI销售金额
+		BigDecimal monthOfSpecAiAmountOfOrder = statisticsExportMapper.getMonthGoodsTypeAmountOfOrderByType(2, null, 1, startDate, endDate);
+		excelMonthlyDistributeOrderData.setMonthOfSpecAiAmountOfOrder(monthOfSpecAiAmountOfOrder);
+		//设备销售金额
+		BigDecimal monthOfSpecEqAmountOfOrder = statisticsExportMapper.getMonthGoodsTypeAmountOfOrderByType(2, 2, null, startDate, endDate);
+		excelMonthlyDistributeOrderData.setMonthOfSpecEqAmountOfOrder(monthOfSpecEqAmountOfOrder);
+
+		//分销提现数据
+		BigDecimal shouldApplyMonty = statisticsExportMapper.getShouldApplyMoney(endDate);
+		excelMonthlyDistributeOrderData.setShouldApplyMoney(shouldApplyMonty);
+		BigDecimal realApplyMoney = statisticsExportMapper.getRealApplyMoney(endDate);
+		excelMonthlyDistributeOrderData.setRealApplyMoney(realApplyMoney);
+
+		//下单率
+		//自然渠道用户数
+		Integer natureUserSourceNum = statisticsExportMapper.getMonthUserSourceNumByType(1, startDate, endDate);
+		//自然渠道下单人数
+		Integer natureUserSourceOrderNum = statisticsExportMapper.getMonthUserSourceNumOrderByType(1, startDate, endDate);
+		String natureUserSourceOrderRate;
+		if (natureUserSourceNum == 0) {
+			natureUserSourceOrderRate = StrUtil.EMPTY;
+		} else {
+			natureUserSourceOrderRate = BigDecimal.valueOf(natureUserSourceOrderNum).divide(BigDecimal.valueOf(natureUserSourceNum), 2, RoundingMode.HALF_DOWN).multiply(BigDecimal.valueOf(100)) + "%";
+		}
+		//分销渠道用户数
+		Integer channelUserSourceNum = statisticsExportMapper.getMonthUserSourceNumByType(2, startDate, endDate);
+		Integer channelUserSourceOrderNum = statisticsExportMapper.getMonthUserSourceNumOrderByType(2, startDate, endDate);
+		String channelUserSourceOrderRate = BigDecimal.valueOf(channelUserSourceOrderNum).divide(BigDecimal.valueOf(channelUserSourceNum), 2, RoundingMode.HALF_DOWN).multiply(BigDecimal.valueOf(100)) + "%";
+
+		excelMonthlyDistributeOrderData.setNatureUserSourceNum(natureUserSourceNum);
+		excelMonthlyDistributeOrderData.setNatureUserSourceOrderNum(natureUserSourceOrderNum);
+		excelMonthlyDistributeOrderData.setNatureUserSourceOrderRate(natureUserSourceOrderRate);
+
+		excelMonthlyDistributeOrderData.setChannelUserSourceNum(channelUserSourceNum);
+		excelMonthlyDistributeOrderData.setChannelUserSourceOrderNum(channelUserSourceOrderNum);
+		excelMonthlyDistributeOrderData.setChannelUserSourceOrderRate(channelUserSourceOrderRate);
+		excelSheetDataList.add(new ExcelSheetAndData("每月用户分销数据", List.of(excelMonthlyDistributeOrderData), ExcelMonthlyDistributeOrderData.class));
+	}
+
 	private void exportRegisterData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
 		List<ExcelRegisterAccountData> registerAccountData = new ArrayList<>();
 		Constant.registerAccount.forEach(platform -> {
@@ -395,7 +597,8 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 				return;
 			}
 			appleDataExcel.setNumOfExCodeOrder(exCodeOrders.size());
-			Optional<BigDecimal> money = orderDons.stream().map(OrderDon::getMoney).reduce(BigDecimal::add);
+			//金额
+			Optional<BigDecimal> money = orderDonMapper.selectThisMonthMoney(skuIds, startDate, endDate);
 			appleDataExcel.setMoney(money.isPresent() ? money.get().divide(BigDecimal.valueOf(100)) : BigDecimal.ZERO);
 			List<OrderDon> distributeOrders = orderDonMapper.selectList(Wrappers.lambdaQuery(OrderDon.class)
 					.eq(OrderDon::getIsDistribute, true)
@@ -435,7 +638,6 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 	}
 
 
-
 	private void getAppleOneDataView(BackgroundDataView backgroundDataView, Date startDate, Date endDate) {
 		if (DateUtil.beginOfDay(DateTime.now()).equals(startDate) && (DateUtil.beginOfDay(DateUtil.offsetDay(DateTime.now(), 1)).equals(endDate) || DateUtil.endOfDay(DateTime.now()).equals(endDate))) {
 			List<AppleOneData> appleOneData1 = statistics.statisticsAppleOneData(startDate, endDate, true);

+ 9 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/statistics/StatisticsDataController.java

@@ -109,6 +109,15 @@ public class StatisticsDataController {
 		EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, excelSheetDataList, "统计数据", ExcelTypeEnum.XLSX, null);
 	}
 
+	/**
+	 * 每月数据导出
+	 */
+	@GetMapping("/export/monthly/data")
+	public void exportMonthlyData(Long startTime, Long endTime, HttpServletResponse response) {
+		List<ExcelSheetAndData> excelSheetDataList = statisticsDataService.exportMonthlyData(startTime, endTime);
+		EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, excelSheetDataList, String.format("%s月订单数据", DateUtil.month(DateTime.of(startTime)) + 1), ExcelTypeEnum.XLSX, null);
+	}
+
 	/**
 	 * 有效子账号数列表
 	 */