Sfoglia il codice sorgente

正常订单统计

zhangxin 1 settimana fa
parent
commit
3c3e529c0f

+ 75 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/vo/OrderCountVo.java

@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
+ *
+ * https://www.gz-yami.com/
+ *
+ */
+
+package com.yami.shop.bean.vo;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.yami.shop.bean.model.OrderRefundRecord;
+import com.yami.shop.bean.model.RefundAppointment;
+import com.yami.shop.bean.model.RefundDelivery;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.Digits;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+/***
+ * 订单统计信息
+ */
+@Data
+public class OrderCountVo implements Serializable{
+
+    @ApiModelProperty(value = "订单总数")
+    private long orderTotal =0L;
+
+    @ApiModelProperty(value = "订单总金额")
+    @Digits(integer = 10, fraction = 2, message = "运费总金额最多保留2位小数")
+    private BigDecimal orderMoneyTotal= BigDecimal.ZERO;
+
+    @ApiModelProperty(value = "商品总金额")
+    @Digits(integer = 10, fraction = 2, message = "运费总金额最多保留2位小数")
+    private BigDecimal shopMoneyTotal= BigDecimal.ZERO;
+
+    /**
+     * 运费总金额
+     */
+    @ApiModelProperty(value = "运费总金额")
+    @Digits(integer = 10, fraction = 2, message = "运费总金额最多保留2位小数")
+    private BigDecimal carriageMoneyTotal= BigDecimal.ZERO;
+    /**
+     * 支付总金额
+     */
+    @ApiModelProperty(value = "支付总金额")
+    @Digits(integer = 10, fraction = 2, message = "运费总金额最多保留2位小数")
+    private BigDecimal payMoneyTotal= BigDecimal.ZERO;
+
+    /**
+     * 积分总金额
+     */
+    @ApiModelProperty(value = "积分总金额")
+    @Digits(integer = 10, fraction = 2, message = "运费总金额最多保留2位小数")
+    private BigDecimal pointsMoneyTotal= BigDecimal.ZERO;
+
+    /**
+     * 现金总金额
+     */
+    @ApiModelProperty(value = "现金总金额")
+    @Digits(integer = 10, fraction = 2, message = "运费总金额最多保留2位小数")
+    private BigDecimal moneyTotal= BigDecimal.ZERO;
+
+    /**
+     * 客单价
+     */
+    @ApiModelProperty(value = "客单价")
+    @Digits(integer = 10, fraction = 2, message = "运费总金额最多保留2位小数")
+    private BigDecimal averageOrderValueMoney = BigDecimal.ZERO;
+
+
+}

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

@@ -18,6 +18,7 @@ import com.yami.shop.bean.enums.DvyType;
 import com.yami.shop.bean.enums.OrderStatus;
 import com.yami.shop.bean.model.*;
 import com.yami.shop.bean.param.*;
+import com.yami.shop.bean.vo.OrderCountVo;
 import com.yami.shop.common.config.Constant;
 import com.yami.shop.common.exception.GlobalException;
 import com.yami.shop.common.util.PageParam;
@@ -242,6 +243,19 @@ public class OrderController {
          orderService.export(orderParam,response);
     }
 
+
+    /**
+     * 订单订单统计数
+     * @param orderParam
+     */
+    @GetMapping("/orderCount")
+    @ApiOperation("后管端-订单列表统计")
+    public R<OrderCountVo> orderCount(BackendOrderParam orderParam) {
+        getBackendOrderParam(orderParam);
+        return R.SUCCESS(orderService.orderCount(orderParam));
+    }
+
+
     private void getBackendOrderParam(BackendOrderParam orderParam){
         if (orderParam.getChannelIdList()==null||orderParam.getChannelIdList().isEmpty()){
             throw new GlobalException("请求参数-所属企业不允许为空");

+ 3 - 0
yami-shop-service/src/main/java/com/yami/shop/dao/OrderMapper.java

@@ -19,6 +19,7 @@ import com.yami.shop.bean.app.dto.OrderCountData;
 import com.yami.shop.bean.distribution.UserShoppingDataDto;
 import com.yami.shop.bean.model.Order;
 import com.yami.shop.bean.param.*;
+import com.yami.shop.bean.vo.OrderCountVo;
 import com.yami.shop.common.util.PageAdapter;
 import com.yami.shop.common.util.PageParam;
 import org.apache.ibatis.annotations.Param;
@@ -141,4 +142,6 @@ public interface OrderMapper extends BaseMapper<Order> {
     IPage<Order> deliveryOrder(@Param("page") PageParam<Order> page, @Param("orderParam") OrderStatisticsParam orderParam);
 
     List<Order> findList( @Param("orderParam")BackendOrderParam orderParam);
+
+    OrderCountVo orderCount(@Param("orderParam") BackendOrderParam orderParam);
 }

+ 5 - 0
yami-shop-service/src/main/java/com/yami/shop/service/OrderService.java

@@ -20,7 +20,9 @@ import com.yami.shop.bean.model.Order;
 import com.yami.shop.bean.model.OrderItem;
 import com.yami.shop.bean.model.OrderRefund;
 import com.yami.shop.bean.param.*;
+import com.yami.shop.bean.vo.OrderCountVo;
 import com.yami.shop.common.util.PageParam;
+import com.yami.shop.common.util.R;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.Date;
@@ -178,4 +180,7 @@ public interface OrderService extends IService<Order> {
     IPage<Order> deliveryOrder(PageParam<Order> page, OrderStatisticsParam orderParam);
 
     void export(BackendOrderParam orderParam, HttpServletResponse response);
+
+
+    OrderCountVo orderCount(BackendOrderParam orderParam);
 }

+ 20 - 1
yami-shop-service/src/main/java/com/yami/shop/service/impl/OrderServiceImpl.java

@@ -42,6 +42,7 @@ import com.yami.shop.bean.event.SubmitOrderEvent;
 import com.yami.shop.bean.event.SubmitScoreOrderEvent;
 import com.yami.shop.bean.model.*;
 import com.yami.shop.bean.param.*;
+import com.yami.shop.bean.vo.OrderCountVo;
 import com.yami.shop.common.config.Constant;
 import com.yami.shop.common.exception.GlobalException;
 import com.yami.shop.common.util.Arith;
@@ -78,6 +79,7 @@ import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.time.Instant;
 import java.time.LocalDateTime;
@@ -1389,7 +1391,24 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
 
         }
 
-        /**
+    @Override
+    public OrderCountVo orderCount(BackendOrderParam orderParam) {
+        OrderCountVo orderCountVo = orderMapper.orderCount(orderParam);
+        if (orderCountVo!=null){
+            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;
+    }
+
+    /**
          * 导出正常订单数据到Excel(直接输出到HttpServletResponse)
          */
         public void exportNormalOrders (List < Order > orderList,

+ 73 - 0
yami-shop-service/src/main/resources/mapper/OrderMapper.xml

@@ -1242,4 +1242,77 @@
         </where>
         order by a.create_time desc,a.order_id desc
     </select>
+
+    <select id="orderCount" resultType="com.yami.shop.bean.vo.OrderCountVo">
+        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
+        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
+        <where>
+            <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
+                <foreach collection="orderParam.channelIdList" item="channelId" open="(" close=")" separator=",">
+                    #{channelId}
+                </foreach>
+            </if>
+            <if test="orderParam.userAttrType != null and orderParam.userAttrType != '' and orderParam.userAttrType != 0">
+                AND e.user_attr_type = #{orderParam.userAttrType}
+            </if>
+            <if test="orderParam.dvyType != null and orderParam.dvyType != ''">
+                and a.dvy_type = #{orderParam.dvyType}
+            </if>
+            <if test="orderParam.shopId != null">
+                and a.shop_id = #{orderParam.shopId}
+            </if>
+            <if test="orderParam.startTime != null">
+                and a.create_time &gt; #{orderParam.startTime}
+            </if>
+            <if test="orderParam.endTime != null">
+                and a.create_time &lt; #{orderParam.endTime}
+            </if>
+            <if test="orderParam.refundStatus != null and orderParam.refundStatus != 0">
+                and a.refund_status = #{orderParam.refundStatus}
+            </if>
+            <if test="orderParam.receiver != null">
+                and b.receiver LIKE concat("%",#{orderParam.receiver},"%")
+            </if>
+            <if test="orderParam.userMobile != null">
+                and b.mobile LIKE concat("%",#{orderParam.userMobile},"%")
+            </if>
+
+            <if test="orderParam.orderStatus != null and orderParam.orderStatus != ''">
+                <if test="orderParam.orderStatus == 'all'">
+                    AND a.hb_order_status in (0, 1,20,30,40,50,60,70,80)
+                </if>
+                <if test="orderParam.orderStatus == 'paddingPay'">
+                    AND a.hb_order_status in (0)
+                </if>
+
+                <if test="orderParam.orderStatus == 'paddingShipped'">
+                    AND a.hb_order_status in (1)
+                </if>
+
+                <if test="orderParam.orderStatus == 'paddingReceived'">
+                    AND a.hb_order_status in (20,30,40,70)
+                </if>
+                <if test="orderParam.orderStatus == 'completed'">
+                    AND a.hb_order_status in (80)
+                </if>
+                <if test="orderParam.orderStatus == 'cancel'">
+                    AND a.hb_order_status in (50,60)
+                </if>
+            </if>
+        </where>
+    </select>
 </mapper>