Browse Source

2022年11月6 19:14

wangzhuo 3 years ago
parent
commit
a68d0f04ef

+ 1 - 0
blade-service/blade-deliver-goods/src/main/java/org/springblade/deliver/goods/service/impl/DeliveryItemsServiceImpl.java

@@ -658,6 +658,7 @@ public class DeliveryItemsServiceImpl extends ServiceImpl<DeliveryItemsMapper, D
 				gathering = gathering.add(usedProfit);
 
 				// 原来的判断 条件 : if (gathering.subtract(newDelivery.add(oldDelivery)).compareTo(BigDecimal.ZERO) <= 0){
+				//已收金额-(本次发货金额+历史发货金额)
 				if (gathering.subtract(newDelivery.add(oldDelivery)).compareTo(BigDecimal.ZERO) < 0) {
 					throw new RuntimeException("订单" + srcOrderNo + "发货金额超出 ,可发货金额为(CNY):" + (gathering.subtract(oldDelivery)).setScale(2, RoundingMode.UP));
 				}

+ 3 - 3
blade-service/blade-deliver-goods/src/main/java/org/springblade/deliver/goods/service/impl/DeliveryServiceImpl.java

@@ -791,6 +791,9 @@ public class DeliveryServiceImpl extends ServiceImpl<DeliveryMapper, Delivery> i
 			Order temp = new Order();
 			temp.setId(select.getOrgId());//销售主表id
 			temp.setOrderStatus("待收货");
+			temp.setCreateDeliver(1);
+			temp.setCreateDeliverUser(AuthUtil.getUserId().toString());
+			temp.setCreateDeliverTime(date);
 			temp.setActualDeliveryDate(select.getBusinessDate());
 			if (select.getTotalQuantity().compareTo(BigDecimal.ZERO) == 0){
 				temp.setDeliverQuantity(select.getTotalQuantity());
@@ -803,9 +806,6 @@ public class DeliveryServiceImpl extends ServiceImpl<DeliveryMapper, Delivery> i
 			Order orderTemp = new Order();
 			orderTemp.setId(select.getSrcId());//采购主表id
 			orderTemp.setOrderStatus("待收货");
-			orderTemp.setCreateDeliver(1);
-			orderTemp.setCreateDeliverUser(AuthUtil.getUserId().toString());
-			orderTemp.setCreateDeliverTime(date);
 			orderTemp.setActualDeliveryDate(select.getBusinessDate());
 			if (select.getTotalQuantity().compareTo(BigDecimal.ZERO) == 0){
 				orderTemp.setDeliverQuantity(select.getTotalQuantity());

+ 360 - 48
blade-service/blade-purchase-sales/src/main/java/org/springblade/purchase/sales/mapper/OrderMapper.xml

@@ -2030,9 +2030,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
         WHERE
-        MONTH ( create_time ) = 1
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
+        WHERE
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 1, MONTH ( create_time ) = 1 )
         GROUP BY
         b.id
         ) BOI1 ON BOI1.id = BO.id
@@ -2044,9 +2057,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 2
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 2, MONTH ( create_time ) = 2 )
         GROUP BY
         b.id
         ) BOI2 ON BOI2.id = BO.id
@@ -2058,9 +2084,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 3
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 3, MONTH ( create_time ) = 3 )
         GROUP BY
         b.id
         ) BOI3 ON BOI3.id = BO.id
@@ -2072,9 +2111,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
         WHERE
-        MONTH ( create_time ) = 4
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
+        WHERE
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 4, MONTH ( create_time ) = 4 )
         GROUP BY
         b.id
         ) BOI4 ON BOI4.id = BO.id
@@ -2086,9 +2138,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 5
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 5, MONTH ( create_time ) = 5 )
         GROUP BY
         b.id
         ) BOI5 ON BOI5.id = BO.id
@@ -2100,9 +2165,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 6
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 6, MONTH ( create_time ) = 6 )
         GROUP BY
         b.id
         ) BOI6 ON BOI6.id = BO.id
@@ -2114,9 +2192,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
         WHERE
-        MONTH ( create_time ) = 7
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
+        WHERE
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 7, MONTH ( create_time ) = 7 )
         GROUP BY
         b.id
         ) BOI7 ON BOI7.id = BO.id
@@ -2128,9 +2219,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 8
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 8, MONTH ( create_time ) = 8 )
         GROUP BY
         b.id
         ) BOI8 ON BOI8.id = BO.id
@@ -2142,9 +2246,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 9
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 9, MONTH ( create_time ) = 9 )
         GROUP BY
         b.id
         ) BOI9 ON BOI9.id = BO.id
@@ -2156,9 +2273,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
         WHERE
-        MONTH ( create_time ) = 10
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
+        WHERE
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 10, MONTH ( create_time ) = 10 )
         GROUP BY
         b.id
         ) BOI10 ON BOI10.id = BO.id
@@ -2170,9 +2300,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 11
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 11, MONTH ( create_time ) = 11 )
         GROUP BY
         b.id
         ) BOI11 ON BOI11.id = BO.id
@@ -2184,9 +2327,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 12
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 12, MONTH ( create_time ) = 12 )
         GROUP BY
         b.id
         ) BOI12 ON BOI12.id = BO.id
@@ -2260,9 +2416,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
         WHERE
-        MONTH ( create_time ) = 1
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
+        WHERE
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 1, MONTH ( create_time ) = 1 )
         GROUP BY
         b.id
         ) BOI1 ON BOI1.id = BO.id
@@ -2274,9 +2443,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 2
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 2, MONTH ( create_time ) = 2 )
         GROUP BY
         b.id
         ) BOI2 ON BOI2.id = BO.id
@@ -2288,9 +2470,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 3
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 3, MONTH ( create_time ) = 3 )
         GROUP BY
         b.id
         ) BOI3 ON BOI3.id = BO.id
@@ -2302,9 +2497,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
         WHERE
-        MONTH ( create_time ) = 4
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
+        WHERE
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 4, MONTH ( create_time ) = 4 )
         GROUP BY
         b.id
         ) BOI4 ON BOI4.id = BO.id
@@ -2316,9 +2524,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 5
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 5, MONTH ( create_time ) = 5 )
         GROUP BY
         b.id
         ) BOI5 ON BOI5.id = BO.id
@@ -2330,9 +2551,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 6
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 6, MONTH ( create_time ) = 6 )
         GROUP BY
         b.id
         ) BOI6 ON BOI6.id = BO.id
@@ -2344,9 +2578,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
         WHERE
-        MONTH ( create_time ) = 7
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
+        WHERE
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 7, MONTH ( create_time ) = 7 )
         GROUP BY
         b.id
         ) BOI7 ON BOI7.id = BO.id
@@ -2358,9 +2605,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 8
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 8, MONTH ( create_time ) = 8 )
         GROUP BY
         b.id
         ) BOI8 ON BOI8.id = BO.id
@@ -2372,9 +2632,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 9
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 9, MONTH ( create_time ) = 9 )
         GROUP BY
         b.id
         ) BOI9 ON BOI9.id = BO.id
@@ -2386,9 +2659,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
         WHERE
-        MONTH ( create_time ) = 10
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
+        WHERE
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 10, MONTH ( create_time ) = 10 )
         GROUP BY
         b.id
         ) BOI10 ON BOI10.id = BO.id
@@ -2400,9 +2686,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 11
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 11, MONTH ( create_time ) = 11 )
         GROUP BY
         b.id
         ) BOI11 ON BOI11.id = BO.id
@@ -2414,9 +2713,22 @@ ORDER BY
         sum( bt.quantity ) AS quantity
         FROM
         business_order b
-        LEFT JOIN ( SELECT pid, item_id, IFNULL( sum( actual_quantity ), 0 ) AS quantity FROM business_order_items WHERE is_deleted = 0 GROUP BY pid ) bt ON bt.pid = b.id
+        LEFT JOIN (
+        SELECT
+        pid,
+        item_id,
+        IF
+        ( actual_quantity = 0, IFNULL( sum( order_quantity ), 0 ), IFNULL( sum( actual_quantity ), 0 ) ) AS quantity
+        FROM
+        business_order_items
+        WHERE
+        is_deleted = 0
+        GROUP BY
+        pid
+        ) bt ON bt.pid = b.id
         WHERE
-        MONTH ( create_time ) = 12
+        IF
+        ( receipt_time IS NOT NULL, MONTH ( receipt_time ) = 12, MONTH ( create_time ) = 12 )
         GROUP BY
         b.id
         ) BOI12 ON BOI12.id = BO.id