From c83b580b0f51a2cdf16f2b1537aa3cb113ef112f Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期五, 20 十二月 2024 17:56:10 +0800
Subject: [PATCH] add: 花材销售统计商品分类

---
 src/main/resources/mapper/report/OrderReportMapper.xml |  261 +++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 227 insertions(+), 34 deletions(-)

diff --git a/src/main/resources/mapper/report/OrderReportMapper.xml b/src/main/resources/mapper/report/OrderReportMapper.xml
index 4c5d1b7..affc3b6 100644
--- a/src/main/resources/mapper/report/OrderReportMapper.xml
+++ b/src/main/resources/mapper/report/OrderReportMapper.xml
@@ -5,12 +5,15 @@
     <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,
         sum(order_markup_partner_amount)  as order_markup_partner_amount,
+        sum(order_price_discount_amount)+sum(order_coupon_amount_total) as order_discount_total_fee,
         sum(order_price_discount_amount)  as order_price_discount_amount,
         sum(order_coupon_amount_total)  as order_coupon_amount_total,
+        sum(order_check_fee)+sum(order_lack_fee_supplier)+sum(order_replace_fee) as order_check_total_fee,
         sum(order_check_fee)  as order_check_fee,
         sum(order_lack_fee_supplier)  as order_lack_fee_supplier,
         sum(order_replace_fee)  as order_replace_fee,
@@ -38,10 +41,10 @@
         where o.deleted=0
         and o.status_backend not in ('PENDING','CANCEL','REFUND')
         <if test="dto.startDate != null">
-            and o.payment_time &gt; #{dto.startDate}
+            and o.payment_time &gt;= #{dto.startDate}
         </if>
         <if test="dto.endDate != null">
-            and o.payment_time &lt;= #{dto.endDate}
+            and o.payment_time &lt; #{dto.endDate}
         </if>
         <if test="dto.partnerId != null">
             and o.create_by in (
@@ -87,10 +90,10 @@
                  where o.deleted=0
                  and o.status_backend not in ('PENDING','CANCEL','REFUND')
                 <if test="dto.startDate != null">
-                    and o.payment_time &gt; #{dto.startDate}
+                    and o.payment_time &gt;= #{dto.startDate}
                 </if>
                 <if test="dto.endDate != null">
-                    and o.payment_time &lt;= #{dto.endDate}
+                    and o.payment_time &lt; #{dto.endDate}
                 </if>
                 <if test="dto.partnerId != null">
                     and o.create_by in (
@@ -110,6 +113,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
@@ -120,10 +124,10 @@
         where o.deleted=0
         and o.status_backend not in ('PENDING','CANCEL','REFUND')
         <if test="dto.startDate != null">
-            and o.payment_time &gt; #{dto.startDate}
+            and o.payment_time &gt;= #{dto.startDate}
         </if>
         <if test="dto.endDate != null">
-            and o.payment_time &lt;= #{dto.endDate}
+            and o.payment_time &lt; #{dto.endDate}
         </if>
         <if test="dto.partnerId != null">
             and o.create_by in (
@@ -149,10 +153,10 @@
         where o.deleted=0
         and o.status_backend not in ('PENDING','CANCEL','REFUND')
         <if test="dto.startDate != null">
-            and o.payment_time &gt; #{dto.startDate}
+            and o.payment_time &gt;= #{dto.startDate}
         </if>
         <if test="dto.endDate != null">
-            and o.payment_time &lt;= #{dto.endDate}
+            and o.payment_time &lt; #{dto.endDate}
         </if>
         <if test="dto.partnerId != null">
             and o.create_by in (
@@ -212,6 +216,7 @@
         IFNULL(sum(order_markup_partner_amount),0)  as order_markup_partner_amount,
         IFNULL(sum(order_price_discount_amount),0)  as order_price_discount_amount,
         IFNULL(sum(order_coupon_amount_total),0)  as order_coupon_amount_total,
+        IFNULL(sum(order_check_fee)+sum(order_lack_fee_supplier)+sum(order_replace_fee),0) as order_check_total_fee,
         IFNULL(sum(order_check_fee),0)  as order_check_fee,
         IFNULL(sum(order_lack_fee_supplier),0)  as order_lack_fee_supplier,
         IFNULL(sum(order_replace_fee),0)  as order_replace_fee,
@@ -229,10 +234,10 @@
         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
+            WHEN t.payment_time >= DATE(t.payment_time) + INTERVAL 17 HOUR THEN DATE(t.payment_time) + INTERVAL 1 DAY
             ELSE DATE(t.payment_time)
             END AS payment_date,
             t.payment_time as payment_time2
@@ -242,10 +247,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">
@@ -263,6 +266,8 @@
 
     <sql id="baseSql">
         select t2.*,
+               IFNULL(t2.order_check_fee+t2.order_lack_fee_supplier+t2.order_replace_fee,0) as order_check_total_fee,
+               IFNULL(t2.order_price_discount_amount+t2.order_coupon_amount_total,0) as order_discount_total_fee,
                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,
@@ -273,10 +278,24 @@
                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,
-                     sum(replace_num) as order_replace_num,sum(reduce_num) as order_reduce_num,sum(lack_num) as order_lack_num
+                     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 +329,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
@@ -321,10 +340,10 @@
                    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}
+                        and o.payment_time &gt;= #{dto.startDate}
                     </if>
                     <if test="dto.endDate != null">
-                        and o.payment_time &lt;= #{dto.endDate}
+                        and o.payment_time &lt; #{dto.endDate}
                     </if>
 
                )t1
@@ -365,7 +384,7 @@
         from (
         SELECT
             CASE
-            WHEN o.payment_time > DATE(o.payment_time) + INTERVAL 17 HOUR THEN DATE(o.payment_time) + INTERVAL 1 DAY
+            WHEN o.payment_time >= DATE(o.payment_time) + INTERVAL 17 HOUR THEN DATE(o.payment_time) + INTERVAL 1 DAY
             ELSE DATE(o.payment_time)
             END AS payment_date,
             oi.order_id,
@@ -401,9 +420,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 +430,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">
@@ -456,7 +481,9 @@
         sum( t1.replace_fee ) AS order_replace_fee,
         sum( t1.lack_fee_supplier ) AS order_lack_fee_supplier,
         sum( t1.num ) AS order_num,
-        sum( t1.lack_num ) AS order_lack_num
+        sum( t1.lack_num ) AS order_lack_num,
+        sum( t1.reduce_num ) AS order_reduce_num,
+        sum( t1.replace_num ) AS order_replace_num
         FROM
         (
         SELECT
@@ -472,8 +499,11 @@
         IFNULL( oi.supplier_price, 0 ) * IFNULL( oi.num, 0 ) AS supplier_price_amount,
         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( 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 = '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
@@ -483,14 +513,15 @@
         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>
         <if test="dto.endDate != null">
-            and o.payment_time &lt;= #{dto.endDate}
+            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
@@ -506,10 +537,14 @@
         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) as order_num,
         sum(order_num)-sum(order_lack_num) as real_sale_num,
+        sum(order_lack_num) as order_lack_num,
+        sum(order_reduce_num ) AS order_reduce_num,
+        sum(order_replace_num ) AS order_replace_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 IS NULL THEN 1 ELSE NULL END)  = 0 Then '已完成' Else '进行中' end as settleStatus
+        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
@@ -521,7 +556,7 @@
         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>
 
@@ -533,10 +568,14 @@
         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) as order_num,
         sum(order_num)-sum(order_lack_num) as real_sale_num,
+        sum(order_lack_num) as order_lack_num,
+        sum(order_reduce_num ) AS order_reduce_num,
+        sum(order_replace_num ) AS order_replace_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 IS NULL THEN 1 ELSE NULL END)  = 0 Then '已完成' Else '进行中' end as settleStatus
+        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
@@ -548,7 +587,7 @@
         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>
 
@@ -582,8 +621,162 @@
         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
         ) 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