From efb6f9d656f72c3016d738f079c92de021b9f14f Mon Sep 17 00:00:00 2001
From: 陶杰 <1378534974@qq.com>
Date: 星期三, 04 十二月 2024 10:04:41 +0800
Subject: [PATCH] 1.常规配置-基本配置 2.分类-修改分类名称批量修改商品名称

---
 src/main/resources/mapper/report/OrderReportMapper.xml |  249 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 221 insertions(+), 28 deletions(-)

diff --git a/src/main/resources/mapper/report/OrderReportMapper.xml b/src/main/resources/mapper/report/OrderReportMapper.xml
index e72d449..bc6b171 100644
--- a/src/main/resources/mapper/report/OrderReportMapper.xml
+++ b/src/main/resources/mapper/report/OrderReportMapper.xml
@@ -5,6 +5,7 @@
     <select id="getOrderDateReport" resultType="com.mzl.flower.dto.response.report.OrderReportResultVO">
         select
         sum(order_total)  as order_total,
+        sum(total_amount)  as total_amount,
         sum(order_supplier_price_amount)  as order_supplier_price_amount,
         sum(order_markup_one_amount)  as order_markup_one_amount,
         sum(order_markup_two_amount)  as order_markup_two_amount,
@@ -110,6 +111,7 @@
         o.create_time as orderDate,
         o.payment_time,
         o.status_backend as settleStatus,
+        vor.order_num as order_num,
         vor.order_num-vor.order_lack_num as real_sale_num,
         vor.*
         from t_order o
@@ -229,7 +231,7 @@
         IFNULL(sum(order_lack_num),0) as order_lack_num,
         IFNULL(sum(order_num)-sum(order_lack_num),0) as real_sale_num
         from (
-        select t2.payment_date,t2.id,t2.order_no,t2.create_by,ci.partner_id,p.name as partner_name,r2.* from (
+        select t2.payment_date,t2.id,t2.order_no,t2.create_by,t2.partner_id,p.name as partner_name,r2.* from (
             SELECT t.*,
             CASE
             WHEN t.payment_time > DATE(t.payment_time) + INTERVAL 17 HOUR THEN DATE(t.payment_time) + INTERVAL 1 DAY
@@ -242,10 +244,8 @@
             )t2
             left join  ( <include refid="baseSqlWithDate"></include> ) r2
             on t2.id = r2.order_id
-            left join t_customer_info ci
-            on t2.create_by=ci.user_id
             left join t_partner_info p
-            on ci.partner_id=p.id
+            on t2.partner_id=p.id
         )t3
         where t3.partner_id is not null
         <if test="dto.paymentDateStart != null">
@@ -265,7 +265,7 @@
         select t2.*,
                IFNULL(t3.fee_supplier,0) as order_fee_supplier,
                IFNULL(t3.fee_partner,0) as order_fee_partner,
-               IFNULL(t3.fee_platform,0) as order_fee_platform,
+               IFNULL(t3.fee_platform,0) +  IFNULL(t3.fee_packing_transport,0)  as order_fee_platform,
                IFNULL(t3.fee_platform_pack,0) as order_fee_platform_pack,
                IFNULL(t3.fee_platform_check,0) as order_fee_platform_check,
                IFNULL(t3.fee_platform_transport,0) as order_fee_platform_transport,
@@ -273,10 +273,13 @@
                IFNULL(t3.fee_packing_transport,0) as order_fee_packing_transport
         from (
                  select
-                     t1.order_id,sum(t1.num) as order_num , sum(t1.total) as order_total, sum(t1.supplier_price_amount) as order_supplier_price_amount, sum(t1.markup_one_amount) as order_markup_one_amount,sum(t1.markup_two_amount) as order_markup_two_amount, sum(t1.markup_partner_amount) as order_markup_partner_amount,sum(t1.price_amount) as order_price_amount,sum(t1.original_price_amount) as order_original_price_amount,sum(t1.price_discount_amount) as order_price_discount_amount,sum(t1.coupon_amount_total) as order_coupon_amount_total,sum(t1.check_fee) as order_check_fee,sum(t1.lack_fee_supplier) as order_lack_fee_supplier,sum(t1.replace_fee) as order_replace_fee,
+                     t1.order_id, t1.total_amount ,sum(t1.num) as order_num ,
+                    ( sum( t1.supplier_price_amount )+sum( t1.markup_one_amount )+sum( t1.markup_two_amount )+sum( t1.markup_partner_amount ) + t1.packing_fee + t1.transport_fee ) AS order_total,
+                     sum(t1.supplier_price_amount) as order_supplier_price_amount, sum(t1.markup_one_amount) as order_markup_one_amount,sum(t1.markup_two_amount) as order_markup_two_amount, sum(t1.markup_partner_amount) as order_markup_partner_amount,sum(t1.price_amount) as order_price_amount,sum(t1.original_price_amount) as order_original_price_amount,sum(t1.price_discount_amount) as order_price_discount_amount,sum(t1.coupon_amount_total) as order_coupon_amount_total,sum(t1.check_fee) as order_check_fee,sum(t1.lack_fee_supplier) as order_lack_fee_supplier,sum(t1.replace_fee) as order_replace_fee,
                      sum(replace_num) as order_replace_num,sum(reduce_num) as order_reduce_num,sum(lack_num) as order_lack_num
                  from (
                    SELECT
+                       o.total_amount,  o.flower_amount, o.packing_fee, o.transport_fee,
                        oi.order_id,
                        oi.id,
                        IFNULL(oi.num,0) as num,
@@ -310,9 +313,9 @@
                        IFNULL(ois.lack_fee_supplier,0) as lack_fee_supplier,
                        IFNULL(ois.replace_fee,0) as replace_fee
 
-                      ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'replace'),0) as replace_num
-                      ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'reduce'),0) as reduce_num
-                      ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'lack'),0) as lack_num
+                      ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'replace' and oic.audit_status='AGREED'),0) as replace_num
+                      ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'reduce' and oic.audit_status='AGREED'),0) as reduce_num
+                      ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'lack' and oic.audit_status='AGREED'),0) as lack_num
                    FROM  t_order o
                    left join t_order_item oi
                    on oi.order_id=o.id
@@ -401,9 +404,9 @@
             IFNULL(ois.lack_fee_supplier,0) as lack_fee_supplier,
             IFNULL(ois.replace_fee,0) as replace_fee
 
-            ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'replace'),0) as replace_num
-            ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'reduce'),0) as reduce_num
-            ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'lack'),0) as lack_num
+            ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'replace' and oic.audit_status='AGREED'),0) as replace_num
+            ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'reduce' and oic.audit_status='AGREED'),0) as reduce_num
+            ,IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'lack' and oic.audit_status='AGREED'),0) as lack_num
             FROM  t_order o
             left join t_order_item oi
             on oi.order_id=o.id
@@ -411,6 +414,12 @@
             left join t_supplier_info si on si.id = oi.supplier_id
             left join t_order_item_settlement ois on ois.order_item_id = oi.id
             WHERE oi.deleted = 0
+            <if test="dto.startDate != null">
+                and o.payment_time &gt; #{dto.startDate}
+            </if>
+            <if test="dto.endDate != null">
+                and o.payment_time &lt;= #{dto.endDate}
+            </if>
         )t1
         where 1=1
         <if test="dto.paymentDateStart != null">
@@ -473,7 +482,7 @@
         IFNULL( ois.check_fee, 0 ) AS check_fee,
         IFNULL( ois.replace_fee, 0 ) AS replace_fee,
         IFNULL( ois.lack_fee_supplier, 0 ) AS lack_fee_supplier,
-        IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'lack'),0) as lack_num
+        IFNULL( (select oic.num from t_order_item_check oic where oic.order_item_id = oi.id and oic.type = 'lack' and oic.audit_status='AGREED'),0) as lack_num
         FROM
         t_order o
         LEFT JOIN t_order_item oi ON oi.order_id = o.id
@@ -483,6 +492,7 @@
         WHERE
         oi.deleted = 0
         and  o.payment_time is not null
+        and  o.status_backend not in ('PENDING','CANCEL','REFUND')
         <if test="dto.startDate != null">
             and o.payment_time >= #{dto.startDate}
         </if>
@@ -490,7 +500,7 @@
             and o.payment_time &lt;= #{dto.endDate}
         </if>
         <if test="dto.supplierId != null">
-            and oi.supplierId &lt;= #{dto.supplierId}
+            and oi.supplier_id = #{dto.supplierId}
         </if>
         ) t1
         GROUP BY
@@ -508,18 +518,47 @@
         sum(order_replace_fee) + sum(order_lack_fee_supplier) order_lack_fee_supplier,
         sum(order_num)-sum(order_lack_num) as real_sale_num,
         sum(sales_fee_supplier) sales_fee_supplier,
-        sum(order_supplier_price_amount) -   sum(order_check_fee) - sum(order_replace_fee) -  sum(order_lack_fee_supplier) -  sum(sales_fee_supplier) profitFeeAmount
+        sum(order_supplier_price_amount) -   sum(order_check_fee) - sum(order_replace_fee) -  sum(order_lack_fee_supplier) -  sum(sales_fee_supplier) profitFeeAmount,
+        case when  COUNT(CASE WHEN status_backend ='COMPLETED' THEN NULL ELSE 1 END)  = 0 Then '已完成' Else '进行中' end as settleStatus
         from(
         SELECT
-        oi.id,vor.*,p.name as supplierName
-        FROM   t_order_item oi
-        left join (<include refid="baseSupplierSql"></include>) vor
-        on oi.id =vor.order_item_id
+        oi.id,vor.*,p.name as supplierName,o.status_backend
+        FROM
+        (<include refid="baseSupplierSql"></include>) vor
+        left join t_order_item oi
+        on vor.order_item_id = oi.id
         left join t_supplier_info p
         on vor.supplier_id=p.id
         left join t_order o
         on vor.order_id= o.id
-        and o.status_backend not in ('PENDING','CANCEL','REFUND')
+--         and o.status_backend not in ('PENDING','CANCEL','REFUND')
+        )  s group by dateinfo,supplier_id
+    </select>
+
+    <select id="getOrderSupplierReport" resultType="com.mzl.flower.dto.response.report.OrderSupplierReportResultVO">
+        select
+        dateinfo,
+        supplier_id,
+        supplierName,
+        sum(order_supplier_price_amount) order_supplier_price_amount,
+        sum(order_check_fee) order_check_fee,
+        sum(order_replace_fee) + sum(order_lack_fee_supplier) order_lack_fee_supplier,
+        sum(order_num)-sum(order_lack_num) as real_sale_num,
+        sum(sales_fee_supplier) sales_fee_supplier,
+        sum(order_supplier_price_amount) -   sum(order_check_fee) - sum(order_replace_fee) -  sum(order_lack_fee_supplier) -  sum(sales_fee_supplier) profitFeeAmount,
+        case when  COUNT(CASE WHEN status_backend ='COMPLETED' THEN NULL ELSE 1 END)  = 0 Then '已完成' Else '进行中' end as settleStatus
+        from(
+        SELECT
+        oi.id,vor.*,p.name as supplierName,o.status_backend
+        FROM
+        (<include refid="baseSupplierSql"></include>) vor
+        left join t_order_item oi
+        on vor.order_item_id = oi.id
+        left join t_supplier_info p
+        on vor.supplier_id=p.id
+        left join t_order o
+        on vor.order_id= o.id
+--         and o.status_backend not in ('PENDING','CANCEL','REFUND')
         )  s group by dateinfo,supplier_id
     </select>
 
@@ -541,20 +580,174 @@
         sum(order_replace_fee) + sum(order_lack_fee_supplier) order_lack_fee_supplier,
         sum(order_num)-sum(order_lack_num) as real_sale_num,
         sum(sales_fee_supplier) sales_fee_supplier,
-        sum(order_supplier_price_amount) - sum(order_check_fee) - sum(order_replace_fee) - sum(order_lack_fee_supplier)
-        - sum(sales_fee_supplier) profitFeeAmount
+        sum(order_supplier_price_amount) -   sum(order_check_fee) - sum(order_replace_fee) -  sum(order_lack_fee_supplier) -  sum(sales_fee_supplier) profitFeeAmount
         from(
         SELECT
         oi.id,vor.*,p.name as supplierName
-        FROM t_order_item oi
-        left join (<include refid="baseSupplierSql"></include>) vor
-        on oi.id =vor.order_item_id
+        FROM
+        (<include refid="baseSupplierSql"></include>) vor
+        left join t_order_item oi
+        on vor.order_item_id = oi.id
         left join t_supplier_info p
         on vor.supplier_id=p.id
         left join t_order o
         on vor.order_id= o.id
-        and o.status_backend not in ('PENDING','CANCEL','REFUND')
-        )
-        ) s
+--         and o.status_backend not in ('PENDING','CANCEL','REFUND')
+        )  s group by dateinfo,supplier_id
+        ) s2
     </select>
+    <select id="getAppSupplierAmountStatistics"
+            resultType="com.mzl.flower.dto.response.report.AppSupplierStatisticsVO">
+        select
+          ( <include refid="all_supplier_amount"></include> ) as all_supplier_amount
+        , (	<include refid="cur_mon_supplier_amount"></include> ) as cur_mon_supplier_amount
+        , (	<include refid="last_mon_supplier_amount"></include> ) as last_mon_supplier_amount
+        , (	<include refid="today_supplier_amount"></include> ) as today_supplier_amount
+        , (	<include refid="cur_mon_lack_num"></include> ) as cur_mon_lack_num
+        , (	<include refid="last_mon_lack_num"></include> ) as last_mon_lack_num
+        , (	<include refid="cur_mon_reduce_num"></include> ) as cur_mon_reduce_num
+        , ( <include refid="last_mon_reduce_num"></include> ) as last_mon_reduce_num
+        , ( <include refid="cur_mon_replace_num"></include> ) as cur_mon_replace_num
+        , (	<include refid="last_mon_replace_num"></include> ) as last_mon_replace_num
+
+    </select>
+
+    <!--供应商总价款-->
+    <sql id="all_supplier_amount">
+        select IFNULL(sum(oi.supplier_price*oi.num),0) as supplier_amount
+        from t_order_item oi
+        left join t_order o
+        on oi.order_id = o.id
+        where o.deleted=0
+          and o.status_backend not in ('PENDING','CANCEL','REFUND')
+          and  oi.supplier_id = #{dto.supplierId}
+    </sql>
+    <!--本月成交:本月售卖的底价合计-->
+    <sql id="cur_mon_supplier_amount">
+        select IFNULL(sum(oi.supplier_price*oi.num),0) as cur_mon_supplier_amount
+        from t_order_item oi
+        left join t_order o
+        on oi.order_id = o.id
+        where o.deleted=0
+        and o.status_backend not in ('PENDING','CANCEL','REFUND')
+        and oi.supplier_id = #{dto.supplierId}
+        and o.payment_time &gt; DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH)), '%Y-%m-%d 17:00:00')
+        and o.payment_time &lt;= DATE_FORMAT(LAST_DAY(CURRENT_DATE()), '%Y-%m-%d 17:00:00')
+    </sql>
+    <!--上月成交:上月售卖的底价合计-->
+    <sql id="last_mon_supplier_amount">
+        select IFNULL(sum(oi.supplier_price*oi.num),0) as last_mon_supplier_amount
+        from t_order_item oi
+        left join t_order o
+        on oi.order_id = o.id
+        where o.deleted=0
+        and o.status_backend not in ('PENDING','CANCEL','REFUND')
+        and oi.supplier_id =  #{dto.supplierId}
+        and o.payment_time &gt; DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 2 MONTH)), '%Y-%m-%d 17:00:00')
+        and o.payment_time &lt;= DATE_FORMAT(DATE_SUB(DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01'), INTERVAL 1 DAY), '%Y-%m-%d 17:00:00')
+    </sql>
+    <!--今日成交:今日售卖的底价合计 // todo 需要根据当前时间判断今日的开始时间和结束时间-->
+    <sql id="today_supplier_amount">
+        select IFNULL(sum(oi.supplier_price*oi.num),0) as today_supplier_amount
+        from t_order_item oi
+        left join t_order o
+        on oi.order_id = o.id
+        where o.deleted=0
+        and o.status_backend not in ('PENDING','CANCEL','REFUND')
+        and oi.supplier_id =  #{dto.supplierId}
+        and o.payment_time &gt; #{dto.startDateTime}
+        and o.payment_time &lt;= #{dto.endDateTime}
+    </sql>
+    <!--缺货(本月):本月质检缺货,并且web端审核通过的数量合计-->
+    <sql id="cur_mon_lack_num">
+        select IFNULL(sum(oic.num),0) as cur_mon_lack_num
+        from t_order_item_check oic
+        left join t_order_item oi
+        on oic.order_item_id=oi.ID
+        left join t_order o
+        on oi.order_id = o.id
+        where o.deleted=0
+        and o.status_backend not in ('PENDING','CANCEL','REFUND')
+        and oi.supplier_id =  #{dto.supplierId}
+        and oic.type = 'lack' and oic.audit_status='AGREED'
+        and o.payment_time &gt; DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH)), '%Y-%m-%d 17:00:00')
+        and o.payment_time &lt;= DATE_FORMAT(LAST_DAY(CURRENT_DATE()), '%Y-%m-%d 17:00:00')
+    </sql>
+    <!--缺货(上月):上月质检缺货,并且web端审核通过的数量合计-->
+    <sql id="last_mon_lack_num">
+        select IFNULL(sum(oic.num),0) as last_mon_lack_num
+        from t_order_item_check oic
+        left join t_order_item oi
+        on oic.order_item_id=oi.ID
+        left join t_order o
+        on oi.order_id = o.id
+        where o.deleted=0
+        and o.status_backend not in ('PENDING','CANCEL','REFUND')
+        and oi.supplier_id =  #{dto.supplierId}
+        and oic.type = 'lack' and oic.audit_status='AGREED'
+        and o.payment_time &gt; DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 2 MONTH)), '%Y-%m-%d 17:00:00')
+        and o.payment_time &lt;= DATE_FORMAT(DATE_SUB(DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01'), INTERVAL 1 DAY), '%Y-%m-%d 17:00:00')
+    </sql>
+    <!--降级(本月):本月质检降级,并且web端审核通过的数量合计-->
+    <sql id="cur_mon_reduce_num">
+        select IFNULL(sum(oic.num),0) as cur_mon_reduce_num
+        from t_order_item_check oic
+        left join t_order_item oi
+        on oic.order_item_id=oi.ID
+        left join t_order o
+        on oi.order_id = o.id
+        where o.deleted=0
+          and o.status_backend not in ('PENDING','CANCEL','REFUND')
+          and oi.supplier_id =  #{dto.supplierId}
+        and oic.type = 'reduce' and oic.audit_status='AGREED'
+        and o.payment_time &gt; DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH)), '%Y-%m-%d 17:00:00')
+        and o.payment_time &lt;= DATE_FORMAT(LAST_DAY(CURRENT_DATE()), '%Y-%m-%d 17:00:00')
+    </sql>
+
+<!--    降级(上月):上月质检降级,并且web端审核通过的数量合计-->
+    <sql id="last_mon_reduce_num">
+        select IFNULL(sum(oic.num),0) as last_mon_reduce_num
+        from t_order_item_check oic
+        left join t_order_item oi
+        on oic.order_item_id=oi.ID
+        left join t_order o
+        on oi.order_id = o.id
+        where o.deleted=0
+          and o.status_backend not in ('PENDING','CANCEL','REFUND')
+          and oi.supplier_id =  #{dto.supplierId}
+        and oic.type = 'reduce' and oic.audit_status='AGREED'
+        and o.payment_time &gt; DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 2 MONTH)), '%Y-%m-%d 17:00:00')
+        and o.payment_time &lt;= DATE_FORMAT(DATE_SUB(DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01'), INTERVAL 1 DAY), '%Y-%m-%d 17:00:00')
+    </sql>
+<!--    补货(本月):本月质检补货,并且web端审核通过的数量合计-->
+    <sql id="cur_mon_replace_num">
+        select IFNULL(sum(oic.num),0) as cur_mon_replace_num
+        from t_order_item_check oic
+        left join t_order_item oi
+        on oic.order_item_id=oi.ID
+        left join t_order o
+        on oi.order_id = o.id
+        where o.deleted=0
+          and o.status_backend not in ('PENDING','CANCEL','REFUND')
+          and oi.supplier_id =  #{dto.supplierId}
+        and oic.type = 'replace' and oic.audit_status='AGREED'
+        and o.payment_time &gt; DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH)), '%Y-%m-%d 17:00:00')
+        and o.payment_time &lt;= DATE_FORMAT(LAST_DAY(CURRENT_DATE()), '%Y-%m-%d 17:00:00')
+    </sql>
+   <!-- 补货(上月):上月质检补货,并且web端审核通过的数量合计-->
+    <sql id="last_mon_replace_num">
+        select IFNULL(sum(oic.num),0) as last_mon_replace_num
+        from t_order_item_check oic
+        left join t_order_item oi
+        on oic.order_item_id=oi.ID
+        left join t_order o
+        on oi.order_id = o.id
+        where o.deleted=0
+          and o.status_backend not in ('PENDING','CANCEL','REFUND')
+          and oi.supplier_id =  #{dto.supplierId}
+        and oic.type = 'replace' and oic.audit_status='AGREED'
+        and o.payment_time &gt; DATE_FORMAT(LAST_DAY(DATE_SUB(CURRENT_DATE(), INTERVAL 2 MONTH)), '%Y-%m-%d 17:00:00')
+        and o.payment_time &lt;= DATE_FORMAT(DATE_SUB(DATE_FORMAT(CURRENT_DATE(), '%Y-%m-01'), INTERVAL 1 DAY), '%Y-%m-%d 17:00:00')
+    </sql>
+
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.3