Browse Source

正常订单统计问题

zhangxin 1 week ago
parent
commit
bc8920885b

+ 1 - 1
yami-shop-platform/src/main/java/com/yami/shop/platform/controller/OrderController.java

@@ -251,7 +251,7 @@ public class OrderController {
     @GetMapping("/orderCount")
     @ApiOperation("后管端-订单列表统计")
     public R<OrderCountVo> orderCount(BackendOrderParam orderParam) {
-        getBackendOrderParam(orderParam);
+//        getBackendOrderParam(orderParam);
         return R.SUCCESS(orderService.orderCount(orderParam));
     }
 

+ 5 - 3
yami-shop-service/src/main/java/com/yami/shop/service/impl/OrderServiceImpl.java

@@ -1395,15 +1395,17 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
     public OrderCountVo orderCount(BackendOrderParam orderParam) {
         OrderCountVo orderCountVo = orderMapper.orderCount(orderParam);
         if (orderCountVo!=null){
+            if (orderCountVo.getOrderMoneyTotal()!=null&&orderCountVo.getCarriageMoneyTotal()!=null){
+                BigDecimal add = orderCountVo.getOrderMoneyTotal().add(orderCountVo.getCarriageMoneyTotal());
+                orderCountVo.setOrderMoneyTotal(add);
+                orderCountVo.setPayMoneyTotal(add);
+            }
             if (orderCountVo.getOrderTotal()!=0L
                     &&orderCountVo.getOrderMoneyTotal()!=null
                     &&orderCountVo.getOrderMoneyTotal().compareTo(BigDecimal.ZERO) != 0){
                 BigDecimal unitPrice = orderCountVo.getOrderMoneyTotal().divide(new BigDecimal(orderCountVo.getOrderTotal()), 2, RoundingMode.HALF_UP);
                 orderCountVo.setAverageOrderValueMoney(unitPrice);
             }
-            if (orderCountVo.getCarriageMoneyTotal()!=null){
-                orderCountVo.getOrderMoneyTotal().add(orderCountVo.getCarriageMoneyTotal());
-            }
         }
         return orderCountVo;
     }

+ 19 - 9
yami-shop-service/src/main/resources/mapper/OrderMapper.xml

@@ -1244,24 +1244,32 @@
     </select>
 
     <select id="orderCount" resultType="com.yami.shop.bean.vo.OrderCountVo">
+        select count(1) as orderTotal,
+        sum(orderMoney) as orderMoneyTotal,
+        sum(shopMoney) as shopMoneyTotal,
+        sum(carriageMoney) as carriageMoneyTotal,
+        sum(orderMoney) as payMoneyTotal,
+        ROUND(sum(pointsMoney) / 100,2) as pointsMoneyTotal,
+        sum(money) as moneyTotal
+        from (
         select
-        count(a.order_number) as orderTotal,
-        sum(a.total) as orderMoneyTotal,
-        sum(c.product_total_amount) as shopMoneyTotal,
-        sum(IFNUll(a.freight_amount,0)) as carriageMoneyTotal,
-        sum(a.total) as payMoneyTotal,
-        ROUND(sum(IFNUll(a.offset_points,0)) / 100,2) as pointsMoneyTotal,
-        sum(IFNUll(a.actual_total,0)) as moneyTotal
+        a.order_number,
+        a.total as orderMoney,
+        sum(c.product_total_amount) as shopMoney,
+        IFNUll(a.freight_amount,0) as carriageMoney,
+        IFNUll(a.offset_points,0) as pointsMoney,
+        IFNUll(a.actual_total,0) as money
         FROM tz_order a
         LEFT JOIN tz_user_addr_order b on a.addr_order_id=b.addr_order_id
         LEFT JOIN tz_order_item c on a.order_number =c.order_number
-        left join  tz_user e on a.user_id = e.user_id
+        left join tz_user e on a.user_id = e.user_id
         <where>
+            and a.delete_status =0
             <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
                 and a.order_number = #{orderParam.orderNumber}
             </if>
             <if test="orderParam.channelIdList != null and !orderParam.channelIdList.isEmpty()">
-                and a.channel_id  in
+                and a.channel_id in
                 <foreach collection="orderParam.channelIdList" item="channelId" open="(" close=")" separator=",">
                     #{channelId}
                 </foreach>
@@ -1314,5 +1322,7 @@
                 </if>
             </if>
         </where>
+        group by a.order_number
+        ) m
     </select>
 </mapper>