From 53b823e2b1444e33f359fba79f8ff1e078253891 Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期四, 14 十一月 2024 09:26:10 +0800
Subject: [PATCH] add:-商户列表需要增加下单次数统计(已退款、已取消、待付款的不统计在内)

---
 src/main/resources/mapper/wallet/WalletReduceMapper.xml |   86 +++++++++++++++++++++++++++++++++----------
 1 files changed, 66 insertions(+), 20 deletions(-)

diff --git a/src/main/resources/mapper/wallet/WalletReduceMapper.xml b/src/main/resources/mapper/wallet/WalletReduceMapper.xml
index 3501285..fd03188 100644
--- a/src/main/resources/mapper/wallet/WalletReduceMapper.xml
+++ b/src/main/resources/mapper/wallet/WalletReduceMapper.xml
@@ -6,57 +6,78 @@
     <select id="getPage" resultType="com.mzl.flower.dto.response.wallet.WalletReduceVO">
         select *
         from (
-                 SELECT si.id as id,si.fee_supplier as fee ,si.audit_time as audit_time,'sale' as type,'售后扣款' as type_name,o.order_no as order_no,oi.supplier_id as supplier_id
+                 SELECT si.id as id
+                      ,si.fee_supplier as fee
+                      ,si.audit_time as audit_time
+                      ,o.payment_time as payment_time
+                      ,'sale' as type,'售后扣款' as type_name
+                      ,o.order_no as order_no
+                      ,oi.supplier_id as supplier_id
                  FROM t_order_item_sales si
                  join t_order_item oi on oi.id = si.order_item_id
                  left join t_order o on oi.order_id=o.id
-                 where si.deleted=0 and si.status='AGREED' and oi.deleted=0 and o.deleted=0
+                 where o.deleted=0
+                 and o.status_backend not in ('PENDING','CANCEL','REFUND')
+                 and si.deleted=0 and si.status='AGREED' and oi.deleted=0 and o.deleted=0
                 and o.payment_time &gt;= #{dto.walletOnlineTime}
                 <if test="dto.supplierId != null">
                     and oi.supplier_id = #{dto.supplierId}
                 </if>
+<!--                <if test="dto.startDate != null">-->
+<!--                    and DATE_FORMAT(si.audit_time, '%Y-%m-%d') &gt;= #{dto.startDate}-->
+<!--                </if>-->
+<!--                <if test="dto.endDate != null">-->
+<!--                    and DATE_FORMAT(si.audit_time, '%Y-%m-%d') &lt;= #{dto.endDate}-->
+<!--                </if>-->
                 <if test="dto.startDate != null">
-                    and DATE_FORMAT(si.audit_time, '%Y-%m-%d') &gt;= #{dto.startDate}
+                    and DATE_FORMAT(o.payment_time, '%Y-%m-%d') &gt;= #{dto.startDate}
                 </if>
                 <if test="dto.endDate != null">
-                    and DATE_FORMAT(si.audit_time, '%Y-%m-%d') &lt;= #{dto.endDate}
+                    and DATE_FORMAT(o.payment_time, '%Y-%m-%d') &lt;= #{dto.endDate}
                 </if>
                  union
 
-                 select  oic.id as id ,oic.deduct_amount as fee,oic.audit_time as audit_time,oic.type as type,check_type.label as type_name,o.order_no as order_no,oi.supplier_id as supplier_id
+                 select  oic.id as id ,
+                         oic.num*oi.supplier_price AS fee,
+                         oic.audit_time AS audit_time,
+                         o.payment_time as payment_time,
+                         oic.type as type,
+                         check_type.label as type_name,
+                         o.order_no as order_no,
+                         oi.supplier_id as supplier_id
                  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
                  left join t_code_value check_type
-                on check_type.value=oic.type and check_type.type_code='CHECK_TYPE'
-                 where oic.deleted=0  and oic.audit_status='AGREED' and oi.deleted=0 and o.deleted=0
+                 on check_type.value=oic.type and check_type.type_code='CHECK_TYPE'
+                 where
+                    o.deleted=0
+                    and o.status_backend not in ('PENDING','CANCEL','REFUND')
+                    and  oic.deleted=0  and oic.audit_status='AGREED' and oi.deleted=0 and o.deleted=0
                     and o.payment_time &gt;= #{dto.walletOnlineTime}
                 <if test="dto.supplierId != null">
                     and oi.supplier_id = #{dto.supplierId}
                 </if>
+<!--                <if test="dto.startDate != null">-->
+<!--                    and DATE_FORMAT(oic.audit_time, '%Y-%m-%d') &gt;= #{dto.startDate}-->
+<!--                </if>-->
+<!--                <if test="dto.endDate != null">-->
+<!--                    and DATE_FORMAT(oic.audit_time, '%Y-%m-%d') &lt;= #{dto.endDate}-->
+<!--                </if>-->
                 <if test="dto.startDate != null">
-                    and DATE_FORMAT(oic.audit_time, '%Y-%m-%d') &gt;= #{dto.startDate}
+                    and DATE_FORMAT(o.payment_time, '%Y-%m-%d') &gt;= #{dto.startDate}
                 </if>
                 <if test="dto.endDate != null">
-                    and DATE_FORMAT(oic.audit_time, '%Y-%m-%d') &lt;= #{dto.endDate}
+                    and DATE_FORMAT(o.payment_time, '%Y-%m-%d') &lt;= #{dto.endDate}
                 </if>
              ) t
 
         order by audit_time desc
     </select>
     <select id="getCheckReduceAmount" resultType="java.math.BigDecimal">
-        SELECT sum(si.fee_supplier)
-        FROM t_order_item_sales si
-        join t_order_item oi on oi.id = si.order_item_id
-        left join t_order o on oi.order_id=o.id
-        where si.deleted=0 and si.status='AGREED' and oi.deleted=0 and o.deleted=0
-          and oi.supplier_id = #{dto.supplierId}
-          and o.payment_time &gt;= #{dto.startTime}
-    </select>
-    <select id="getSaleReduceAmount" resultType="java.math.BigDecimal">
-        select  sum(oic.deduct_amount)
+        select  sum(oic.num*oi.supplier_price)
         from t_order_item_check oic
         left join t_order_item oi
         on oic.order_item_id=oi.id
@@ -64,7 +85,32 @@
         on oi.order_id=o.id
         left join t_code_value check_type
         on check_type.value=oic.type and check_type.type_code='CHECK_TYPE'
-        where oic.deleted=0  and oic.audit_status='AGREED' and oi.deleted=0 and o.deleted=0
+        where o.deleted=0
+          and o.status_backend not in ('PENDING','CANCEL','REFUND')
+          and oic.deleted=0  and oic.audit_status='AGREED' and oi.deleted=0 and o.deleted=0
+          and oi.supplier_id = #{dto.supplierId}
+          and o.payment_time &gt;= #{dto.startTime}
+    </select>
+    <select id="getSaleReduceAmount" resultType="java.math.BigDecimal">
+
+        SELECT sum(si.fee_supplier)
+        FROM t_order_item_sales si
+        join t_order_item oi on oi.id = si.order_item_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  si.deleted=0 and si.status='AGREED' and oi.deleted=0 and o.deleted=0
+          and oi.supplier_id = #{dto.supplierId}
+          and o.payment_time &gt;= #{dto.startTime}
+    </select>
+    <select id="getStationFeeAmount" resultType="java.math.BigDecimal">
+        SELECT sum(ois.station_fee)
+        FROM t_order_item_settlement ois
+        join t_order_item oi on oi.id = ois.order_item_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  ois.deleted=0 and oi.deleted=0
           and oi.supplier_id = #{dto.supplierId}
           and o.payment_time &gt;= #{dto.startTime}
     </select>

--
Gitblit v1.9.3