首页统计

pull/1/head
czc 2 years ago
parent 684bf26ee5
commit aada1a3649

@ -426,7 +426,7 @@ public class H5OrderService {
OrderOperateHistory history = new OrderOperateHistory(); OrderOperateHistory history = new OrderOperateHistory();
history.setOrderId(item.getId()); history.setOrderId(item.getId());
history.setOrderSn(item.getOrderSn()); history.setOrderSn(item.getOrderSn());
history.setOperateMan("" + item.getMemberId()); history.setOperateMan(userId == null ? "后台管理员" : "" + item.getMemberId());
history.setOrderStatus(Constants.H5OrderStatus.CLOSED); history.setOrderStatus(Constants.H5OrderStatus.CLOSED);
history.setCreateTime(optDate); history.setCreateTime(optDate);
history.setCreateBy(userId); history.setCreateBy(userId);

@ -6,6 +6,7 @@ import com.cyl.manager.oms.domain.Aftersale;
import com.cyl.manager.oms.domain.AftersaleItem; import com.cyl.manager.oms.domain.AftersaleItem;
import com.cyl.manager.oms.pojo.request.ManagerAftersaleOrderRequest; import com.cyl.manager.oms.pojo.request.ManagerAftersaleOrderRequest;
import com.cyl.manager.oms.pojo.vo.ManagerRefundOrderVO; import com.cyl.manager.oms.pojo.vo.ManagerRefundOrderVO;
import com.cyl.manager.statistics.pojo.vo.OrderAndAftersaleStatisticsVO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
/** /**
@ -26,4 +27,5 @@ public interface AftersaleMapper extends BaseMapper<Aftersale> {
int countByMemberId(Long memberId); int countByMemberId(Long memberId);
OrderAndAftersaleStatisticsVO statPendingAndProcessing();
} }

@ -1,5 +1,6 @@
package com.cyl.manager.oms.mapper; package com.cyl.manager.oms.mapper;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cyl.h5.pojo.vo.CountOrderVO; import com.cyl.h5.pojo.vo.CountOrderVO;
@ -7,6 +8,7 @@ import com.cyl.h5.pojo.vo.H5OrderVO;
import com.cyl.manager.oms.domain.Order; import com.cyl.manager.oms.domain.Order;
import com.cyl.manager.oms.pojo.request.ManagerOrderQueryRequest; import com.cyl.manager.oms.pojo.request.ManagerOrderQueryRequest;
import com.cyl.manager.oms.pojo.vo.ManagerOrderVO; import com.cyl.manager.oms.pojo.vo.ManagerOrderVO;
import com.cyl.manager.statistics.pojo.vo.OrderAndAftersaleStatisticsVO;
import com.cyl.manager.ums.pojo.vo.MemberDataStatisticsVO; import com.cyl.manager.ums.pojo.vo.MemberDataStatisticsVO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@ -37,4 +39,7 @@ public interface OrderMapper extends BaseMapper<Order> {
MemberDataStatisticsVO statOrderCountAndAmount(Long memberId); MemberDataStatisticsVO statOrderCountAndAmount(Long memberId);
Integer statWaitDelivered();
OrderAndAftersaleStatisticsVO statTodayData(@Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime);
} }

@ -0,0 +1,67 @@
package com.cyl.manager.statistics.controller;
import com.cyl.manager.statistics.pojo.GoodsStatisticsQueryParam;
import com.cyl.manager.statistics.pojo.vo.MemberAndCartStatisticsVO;
import com.cyl.manager.statistics.pojo.vo.OrderAndAftersaleStatisticsVO;
import com.cyl.manager.statistics.pojo.vo.OrderStatisticsVO;
import com.cyl.manager.statistics.pojo.vo.ProductTopVO;
import com.cyl.manager.statistics.service.IndexStatisticsService;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* ,
*
* @author zhangcheng
* @since 2023/05/15 13:53
*/
@Slf4j
@Api(tags = "管理端,首页统计数据接口")
@RestController
@RequestMapping("/dev/statistics/index")
public class IndexStatisticsManagerController {
/**
*
*/
@Autowired
private IndexStatisticsService indexStatisticsService;
@ApiOperation(value = "获取首页查询热卖商品TOP10")
@GetMapping("/goodsStatistics")
public ResponseEntity<List<ProductTopVO>> goodsStatistics(@Validated GoodsStatisticsQueryParam goodsStatisticsQueryParam) {
return ResponseEntity.ok(indexStatisticsService.goodsStatistics(goodsStatisticsQueryParam));
}
@ApiOperation(value = "订单信息")
@GetMapping("/orderStatistics")
public ResponseEntity<List<OrderStatisticsVO>> orderStatistics() {
return ResponseEntity.ok(indexStatisticsService.orderStatistics());
}
@ApiOperation(value = "会员数,加购数")
@GetMapping("/memberAndCart/statistics")
public ResponseEntity<MemberAndCartStatisticsVO> statMemberAndCart(){
return ResponseEntity.ok(indexStatisticsService.statMemberAndCart());
}
@ApiOperation(value = "订单与售后单统计")
@GetMapping("/order/aftersale/statistics")
public ResponseEntity<OrderAndAftersaleStatisticsVO> orderAndAftersaleStatistics(){
return ResponseEntity.ok(indexStatisticsService.orderAndAftersaleStatistics());
}
}

@ -0,0 +1,16 @@
package com.cyl.manager.statistics.mapper;
import com.cyl.manager.statistics.pojo.GoodsStatisticsQueryParam;
import com.cyl.manager.statistics.pojo.vo.OrderStatisticsVO;
import com.cyl.manager.statistics.pojo.vo.ProductTopVO;
import java.util.List;
public interface IndexStatisticsMapper {
List<ProductTopVO> goodsSkuStatistics(GoodsStatisticsQueryParam goodsStatisticsQueryParam);
List<ProductTopVO> goodsStatistics(GoodsStatisticsQueryParam goodsStatisticsQueryParam);
List<OrderStatisticsVO> orderStatistics();
}

@ -0,0 +1,24 @@
package com.cyl.manager.statistics.pojo;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/**
*
*
* @author zhangcheng
* @since 2023/05/15 13:53
*/
@Data
public class GoodsStatisticsQueryParam {
@NotNull(message = "统计类型 1商品规格排行 2商品排行")
private Integer statType;
@NotNull(message = "参数size不能为空")
private Integer size;
@NotBlank(message = "参数startDate不能为空")
private String startDate;
@NotBlank(message = "参数endDate不能为空")
private String endDate;
}

@ -0,0 +1,10 @@
package com.cyl.manager.statistics.pojo.vo;
import lombok.Data;
@Data
public class MemberAndCartStatisticsVO {
private Integer memberCount;
private Integer cartCount;
}

@ -0,0 +1,21 @@
package com.cyl.manager.statistics.pojo.vo;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class OrderAndAftersaleStatisticsVO {
/** 待处理售后 */
private Integer pendingAftersaleCount;
/** 处理中售后 */
private Integer processingAftersaleCount;
/** 待发货 */
private Integer waitDeliveredCount;
/** 已发货 */
private Integer todayHasDeliveredCount;
/** 订单数 */
private Integer todayOrderCount;
/** 成交额 */
private BigDecimal todayTransactionAmount;
}

@ -0,0 +1,16 @@
package com.cyl.manager.statistics.pojo.vo;
import lombok.Data;
@Data
public class OrderStatisticsVO {
private String date;
//订单笔数
private Double orderCount;
//订单金额
private Double orderAmount;
private Double numPaidOrders;
private Double numPendingOrders;
private Double numRefundOrders;
}

@ -0,0 +1,12 @@
package com.cyl.manager.statistics.pojo.vo;
import lombok.Data;
@Data
public class ProductTopVO {
private String productName;
private int totalSales;
private String pic;
private String spData;
}

@ -0,0 +1,79 @@
package com.cyl.manager.statistics.service;
import com.cyl.manager.oms.mapper.AftersaleMapper;
import com.cyl.manager.oms.mapper.OrderMapper;
import com.cyl.manager.oms.service.AftersaleService;
import com.cyl.manager.oms.service.OrderDeliveryHistoryService;
import com.cyl.manager.oms.service.OrderService;
import com.cyl.manager.statistics.mapper.IndexStatisticsMapper;
import com.cyl.manager.statistics.pojo.GoodsStatisticsQueryParam;
import com.cyl.manager.statistics.pojo.vo.MemberAndCartStatisticsVO;
import com.cyl.manager.statistics.pojo.vo.OrderAndAftersaleStatisticsVO;
import com.cyl.manager.statistics.pojo.vo.OrderStatisticsVO;
import com.cyl.manager.statistics.pojo.vo.ProductTopVO;
import com.cyl.manager.ums.mapper.MemberCartMapper;
import com.cyl.manager.ums.mapper.MemberMapper;
import com.cyl.manager.ums.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Objects;
/**
* ,Service
*
* @author zhangcheng
* @since 2023/05/15 13:53
*/
@Service
public class IndexStatisticsService {
@Autowired
private IndexStatisticsMapper indexStatisticsMapper;
@Autowired
private MemberMapper memberMapper;
@Autowired
private MemberCartMapper memberCartMapper;
@Autowired
private AftersaleMapper aftersaleMapper;
@Autowired
private OrderMapper orderMapper;
public List<ProductTopVO> goodsStatistics(GoodsStatisticsQueryParam goodsStatisticsQueryParam) {
if (goodsStatisticsQueryParam.getStatType() == 1){
return indexStatisticsMapper.goodsSkuStatistics(goodsStatisticsQueryParam);
}else {
return indexStatisticsMapper.goodsStatistics(goodsStatisticsQueryParam);
}
}
public List<OrderStatisticsVO> orderStatistics() {
return indexStatisticsMapper.orderStatistics();
}
public MemberAndCartStatisticsVO statMemberAndCart() {
MemberAndCartStatisticsVO vo = new MemberAndCartStatisticsVO();
vo.setMemberCount(memberMapper.selectCount(null));
vo.setCartCount(memberCartMapper.selectCount(null));
return vo;
}
public OrderAndAftersaleStatisticsVO orderAndAftersaleStatistics() {
//统计售后
OrderAndAftersaleStatisticsVO vo = aftersaleMapper.statPendingAndProcessing();
//统计未发货数
vo.setWaitDeliveredCount(orderMapper.statWaitDelivered());
//统计今日订单数,成交金额,发货数
LocalDateTime startTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
LocalDateTime endTime = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
OrderAndAftersaleStatisticsVO todayData = orderMapper.statTodayData(startTime, endTime);
vo.setTodayOrderCount(todayData.getTodayOrderCount());
vo.setTodayHasDeliveredCount(todayData.getTodayHasDeliveredCount());
vo.setTodayTransactionAmount(todayData.getTodayTransactionAmount());
return vo;
}
}

@ -95,5 +95,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from oms_aftersale from oms_aftersale
where member_id=#{memberId} where member_id=#{memberId}
</select> </select>
<select id="statPendingAndProcessing"
resultType="com.cyl.manager.statistics.pojo.vo.OrderAndAftersaleStatisticsVO">
select
IFNULL(sum(case when status=0 then 1 else 0 end), 0) pendingAftersaleCount,
IFNULL(sum(case when status=1 then 1 else 0 end), 0) processingAftersaleCount
from oms_aftersale
</select>
</mapper> </mapper>

@ -232,5 +232,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from oms_order from oms_order
where status in (1,2,3) and aftersale_status=1 and member_id=#{memberId} where status in (1,2,3) and aftersale_status=1 and member_id=#{memberId}
</select> </select>
<select id="statWaitDelivered" resultType="java.lang.Integer">
select IFNULL(count(id), 0) from oms_order where status=1 and aftersale_status=1
</select>
<select id="statTodayData" resultType="com.cyl.manager.statistics.pojo.vo.OrderAndAftersaleStatisticsVO">
select
IFNULL(sum(case when status in (2,3) then 1 else 0 end), 0) todayHasDeliveredCount,
IFNULL(count(id), 0) todayOrderCount,
IFNULL(sum(case when status in (1,2,3) then pay_amount else 0 end), 0) todayTransactionAmount
from oms_order
where create_time between #{startTime} and #{endTime}
</select>
</mapper> </mapper>

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cyl.manager.statistics.mapper.IndexStatisticsMapper">
<sql id="dateRange">
SELECT
curdate( ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 1 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 2 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 3 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 4 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 5 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 6 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 7 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 8 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 9 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 10 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 11 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 12 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 13 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 14 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 15 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 16 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 17 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 18 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 19 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 20 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 21 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 22 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 23 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 24 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 25 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 26 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 27 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 28 DAY ) AS date UNION ALL
SELECT date_sub( curdate( ), INTERVAL 29 DAY ) AS date
</sql>
<resultMap id="topSalesResultMap" type="com.cyl.manager.statistics.pojo.vo.ProductTopVO">
<result property="productName" column="product_name"/>
<result property="totalSales" column="total_sales"/>
<result property="pic" column="pic"/>
<result property="spData" column="sp_data"/>
</resultMap>
<select id="goodsStatistics" parameterType="com.cyl.manager.statistics.pojo.GoodsStatisticsQueryParam" resultMap="topSalesResultMap">
SELECT product_id ,
product_name,
pic,
SUM(quantity) as total_sales
FROM oms_order_item item right join oms_order o on o.id=item.order_id
WHERE DATE(item.create_time) between DATE(#{startDate}) AND DATE(#{endDate}) AND o.status in(1,2,3)
GROUP BY product_id, product_name
ORDER BY total_sales DESC
LIMIT #{size}
</select>
<select id="orderStatistics" resultType="com.cyl.manager.statistics.pojo.vo.OrderStatisticsVO">
select a.date,
IFNULL(b.order_count,0) orderCount,
IFNULL(b.order_amount,0) orderAmount
from
(
<include refid="dateRange"></include>
) a
left join (
SELECT DATE_FORMAT(create_time, '%Y-%m-%d') as date,
COUNT(*) as order_count,
SUM(total_amount) as order_amount
FROM oms_order
WHERE create_time >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND status in(1,2,3)
GROUP BY DATE_FORMAT(create_time, '%Y-%m-%d')
) b
on a.date=b.date
order by a.date asc
</select>
<select id="goodsSkuStatistics" resultMap="topSalesResultMap">
SELECT product_id ,
product_name,
pic,
sp_data,
SUM(quantity) as total_sales
FROM oms_order_item item right join oms_order o on o.id=item.order_id
WHERE DATE(item.create_time) between DATE(#{startDate}) AND DATE(#{endDate}) AND o.status in(1,2,3)
GROUP BY sku_id
ORDER BY total_sales DESC
LIMIT #{size}
</select>
</mapper>
Loading…
Cancel
Save