Kaynağa Gözat

1.订单需要进行整合统计,按照日期选择,直接统计出这个时间内的单量和总金额、成交率、退货率,点击总金额可以详细的看到里面的订单内容;

yfh 14 saat önce
ebeveyn
işleme
8ee0c7680f

+ 54 - 0
fs-admin/src/main/java/com/fs/store/controller/FsStoreOrderStatisticsController.java

@@ -0,0 +1,54 @@
+package com.fs.store.controller;
+
+import com.baomidou.mybatisplus.extension.api.R;
+import com.fs.store.param.FsStoreOrderStatisticsParam;
+import com.fs.store.service.IFsStoreOrderService;
+import com.fs.store.vo.StoreOrderStatisticsVo;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.math.BigDecimal;
+
+
+@RestController
+@RequestMapping("/store/storeOrder/statistics")
+public class FsStoreOrderStatisticsController {
+
+    @Autowired
+    private IFsStoreOrderService storeOrderService;
+
+    @ApiOperation("订单统计")
+    @GetMapping("/getStoreOrderStatistics")
+    public R getStoreOrderStatistics(FsStoreOrderStatisticsParam param)
+    {
+        Integer orderCount = storeOrderService.selectFsStoreOrderCount(param);
+        param.setPaid(1);
+        //实际支付金额
+        BigDecimal totalAmount = storeOrderService.selectFsStoreOrderByPayPriceCount(param);
+        //已支付的总订单数
+        Integer orderPayCount = storeOrderService.selectFsStoreOrderCount(param);
+        //已完成订单
+        param.setStatus(5);
+        Integer orderCompleteCount = storeOrderService.selectFsStoreOrderCount(param);
+        //退货成功订单
+        param.setStatus(-2);
+        Integer orderReturnCount = storeOrderService.selectFsStoreOrderCount(param);
+        //成交率
+        int successRate = 0;
+        //退货率
+        int returnRate = 0;
+        if (orderPayCount != null && orderPayCount != 0) {
+            successRate = (int) Math.round((orderCompleteCount != null ? orderCompleteCount : 0) * 100.0 / orderPayCount);
+            returnRate = (int) Math.round((orderReturnCount != null ? orderReturnCount : 0) * 100.0 / orderPayCount);
+        }
+        StoreOrderStatisticsVo storeOrderStatisticsVo = new StoreOrderStatisticsVo();
+        storeOrderStatisticsVo.setOrderCount(orderCount);
+        storeOrderStatisticsVo.setTotalAmount(totalAmount);
+        storeOrderStatisticsVo.setSuccessRate(successRate);
+        storeOrderStatisticsVo.setReturnRate(returnRate);
+        return R.ok(storeOrderStatisticsVo);
+    }
+}

+ 28 - 0
fs-admin/src/main/java/com/fs/store/vo/StoreOrderStatisticsVo.java

@@ -0,0 +1,28 @@
+package com.fs.store.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class StoreOrderStatisticsVo {
+    /**
+     * 订单总量
+     */
+    Integer orderCount;
+
+    /**
+     * 总金额
+     */
+    BigDecimal totalAmount;
+
+    /**
+     * 成交率
+     */
+    Integer successRate;
+
+    /**
+     * 退货率
+     */
+    Integer returnRate;
+}

+ 11 - 4
fs-service-system/src/main/java/com/fs/store/mapper/FsStoreOrderMapper.java

@@ -1,5 +1,6 @@
 package com.fs.store.mapper;
 
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -13,10 +14,7 @@ import com.fs.statis.domain.Report;
 import com.fs.statis.param.ReportParam;
 import com.fs.store.domain.FsStoreOrder;
 import com.fs.store.domain.FsStoreOrderItem;
-import com.fs.store.param.FsCustomerStoreOrderListQueryParam;
-import com.fs.store.param.FsMyStoreOrderQueryParam;
-import com.fs.store.param.FsStoreOrderParam;
-import com.fs.store.param.FsStoreStatisticsParam;
+import com.fs.store.param.*;
 import com.fs.store.vo.*;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
@@ -164,6 +162,10 @@ public interface FsStoreOrderMapper
             " AND date_format(o.delivery_send_time,'%y%m%d') <= date_format(#{maps.deliverySendTimeList[1]},'%y%m%d') " +
             "</if>" +
 
+            "<if test = 'maps.paid != null and maps.paid==1   '> " +
+            "  AND o.pay_time is not null " +
+            "</if>" +
+
             "<if test = 'maps.payTimeList != null    '> " +
             " AND date_format(o.pay_time,'%y%m%d') &gt;= date_format(#{maps.payTimeList[0]},'%y%m%d') " +
             " AND date_format(o.pay_time,'%y%m%d') &lt;= date_format(#{maps.payTimeList[1]},'%y%m%d') " +
@@ -524,6 +526,7 @@ public interface FsStoreOrderMapper
             "where o.user_id=#{userId}  and o.status =#{status} " +
             "</script>"})
     int selectFsStoreOrderCount(@Param("userId")long userId,@Param("status")int status);
+
     @Select({"<script> " +
             "select * from fs_store_order o  " +
             "where o.delivery_id=#{deliveryId}  limit 1 " +
@@ -1044,4 +1047,8 @@ public interface FsStoreOrderMapper
     List<Long> selectFsStoreOrderNoCreateOmsAndReviewed();
 
     List<Report> selectOrderByCustomerIds(@Param("map") ReportParam param);
+
+    int selectFsStoreOrderCount(FsStoreOrderStatisticsParam param);
+
+    BigDecimal selectFsStoreOrderByPayPriceCount(FsStoreOrderStatisticsParam param);
 }

+ 5 - 0
fs-service-system/src/main/java/com/fs/store/param/FsStoreOrderParam.java

@@ -82,4 +82,9 @@ public class FsStoreOrderParam extends BaseEntity implements Serializable
 
     private String orderVisit;
 
+    /**
+     * 支付状态 待支付 1已支付
+     */
+    private int paid;
+
 }

+ 26 - 0
fs-service-system/src/main/java/com/fs/store/param/FsStoreOrderStatisticsParam.java

@@ -0,0 +1,26 @@
+package com.fs.store.param;
+
+import lombok.Data;
+
+@Data
+public class FsStoreOrderStatisticsParam {
+
+    /**
+     * 开始时间
+     */
+    String startTime;
+    /**
+     * 结束时间
+     */
+    String endTime;
+
+    /**
+     * 是否已经支付
+     */
+    Integer paid;
+
+    /**
+     * 订单状态(-1 : 申请退款 -2 : 退货成功 1:待支付 2:待发货;3:待收货;4:待评价;5:已完成)
+     */
+    private Integer status;
+}

+ 15 - 0
fs-service-system/src/main/java/com/fs/store/service/IFsStoreOrderService.java

@@ -125,6 +125,13 @@ public interface IFsStoreOrderService
 
     Integer selectFsStoreOrderCount(long userId, int status);
 
+    /**
+     * 根据时间查询订单总数
+     * @param param
+     * @return
+     */
+    Integer selectFsStoreOrderCount(FsStoreOrderStatisticsParam param);
+
     R computedPackageOrder(long userId, FsStoreComputedPackageIdOrderParam param);
 
     FsStoreOrder selectFsStoreOrderByDeliveryId(String logisticCode);
@@ -211,4 +218,12 @@ public interface IFsStoreOrderService
      * @return R
      */
     R finishStoreOrder(Long orderId);
+
+    /**
+     * 根据时间查询实际支付金额
+     *
+     * @param param
+     * @return
+     */
+    BigDecimal selectFsStoreOrderByPayPriceCount(FsStoreOrderStatisticsParam param);
 }

+ 10 - 0
fs-service-system/src/main/java/com/fs/store/service/impl/FsStoreOrderServiceImpl.java

@@ -1307,6 +1307,11 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
         }
     }
 
+    @Override
+    public BigDecimal selectFsStoreOrderByPayPriceCount(FsStoreOrderStatisticsParam param) {
+        return fsStoreOrderMapper.selectFsStoreOrderByPayPriceCount(param);
+    }
+
     @Override
     @Transactional
     //类型1支付回调 类型2货到付款
@@ -2154,6 +2159,11 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
         return fsStoreOrderMapper.selectFsStoreOrderCount(userId,status);
     }
 
+    @Override
+    public Integer selectFsStoreOrderCount(FsStoreOrderStatisticsParam param) {
+        return fsStoreOrderMapper.selectFsStoreOrderCount(param);
+    }
+
     @Override
     public R computedPackageOrder(long userId, FsStoreComputedPackageIdOrderParam param) {
         FsStoreProductPackage storeProductPackage=productPackageService.selectFsStoreProductPackageById(param.getPackageId());

+ 24 - 0
fs-service-system/src/main/resources/mapper/store/FsStoreOrderMapper.xml

@@ -507,4 +507,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             AND pay_time &lt; DATE_ADD(STR_TO_DATE(#{map.payTime}, '%Y-%m-%d'), INTERVAL 1 DAY)
         </if>
     </select>
+
+
+    <select id="selectFsStoreOrderCount" resultType="int">
+        select  count(id) from fs_store_order
+        <where>
+            <if test="startTime != null and startTime != ''">AND date_format(create_time,'%y%m%d') &gt;= date_format(#{startTime},'%y%m%d')</if>
+            <if test="endTime != null and endTime != ''">AND date_format(create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')</if>
+            <if test="status != null"> and status = #{status}</if>
+            <if test="paid != null and paid==1"> and pay_time is not null</if>
+            <if test="paid != null and paid==0"> and pay_time is null</if>
+        </where>
+
+    </select>
+
+    <select id="selectFsStoreOrderByPayPriceCount" resultType="java.math.BigDecimal">
+        select  sum(pay_price) from fs_store_order
+        <where>
+            <if test="paid != null and paid==1"> and pay_time is not null</if>
+            <if test="paid != null and paid==0"> and pay_time is null</if>
+            <if test="startTime != null and startTime != ''">AND date_format(create_time,'%y%m%d') &gt;= date_format(#{startTime},'%y%m%d')</if>
+            <if test="endTime != null and endTime != ''">AND date_format(create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')</if>
+        </where>
+
+    </select>
 </mapper>