数据报表-销量-统计

商品 规格 返回
This commit is contained in:
wangw 2024-08-15 18:23:46 +08:00
parent a183d2bfec
commit 7271e77b05
8 changed files with 71 additions and 31 deletions

View File

@ -42,10 +42,10 @@ public class SummaryByDayController {
}
@GetMapping(value = "count")
public List<TbOrderPayCountVo> summaryCount(@RequestParam String shopId,
public List<TbOrderPayCountVo> summaryCount(ShopSummaryDto summaryDto,
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startTime,
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) {
return summaryService.summaryCount(shopId, startTime, endTime);
return summaryService.summaryCount(summaryDto, startTime, endTime);
}
}

View File

@ -19,7 +19,9 @@ public class ShopSummaryDto {
}
public void setCateId(String cateId) {
this.cateId = cateId;
if(StringUtils.isNotBlank(cateId)){
this.cateId = cateId;
}
}
public String getShopId() {

View File

@ -103,7 +103,7 @@ public interface TbOrderDetailRepository extends JpaRepository<TbOrderDetail, In
List<TbOrderSalesCountByDayVo> queryTbOrderSalesCountByDay(@Param("shopId") Integer shopId,@Param("cateId")String cateId,@Param("proName")String proName, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
@Query(value = "SELECT " +
"new cn.ysk.cashier.vo.TbOrderSaleVO(oi.orderNo, od.num, od.price, od.status)\n" +
"new cn.ysk.cashier.vo.TbOrderSaleVO(oi.orderNo, od.num, od.price, od.status,od.productSkuId)\n" +
"FROM\n" +
"TbOrderInfo oi\n" +
"LEFT JOIN TbOrderDetail od ON oi.id = od.orderId \n" +
@ -115,8 +115,24 @@ public interface TbOrderDetailRepository extends JpaRepository<TbOrderDetail, In
"AND (:productId is null or od.productId = :productId)\n" +
"AND (:productSkuId is null or od.productSkuId = :productSkuId)")
List<TbOrderSaleVO> querySaleOrderInfo(@Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime, @Param("productId") Integer productId, @Param("productSkuId") Integer productSkuId, @Param("shopId") Integer shopId);
@Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" +
"SUM(CASE WHEN orders.orderType!='return' THEN info.num ELSE 0 END)," +
"SUM(CASE WHEN orders.orderType='return' THEN info.num ELSE 0 END), " +
"SUM(info.num), " +
"SUM(CASE WHEN orders.orderType!='return' THEN info.priceAmount ELSE 0 END), " +
"SUM(CASE WHEN orders.orderType='return' THEN info.priceAmount ELSE 0 END)) " +
"FROM TbOrderInfo orders " +
"LEFT JOIN TbOrderDetail info on orders.id=info.orderId " +
"LEFT JOIN TbProduct pro ON info.productId = pro.id " +
"WHERE info.shopId = :shopId " +
"AND (:cateId IS NULL OR pro.categoryId = :cateId) " +
"AND (:proName IS NULL OR info.productName LIKE %:proName%) " +
"AND info.createTime > :startTime AND info.createTime < :endTime " +
"AND (info.status = 'closed' OR info.status = 'refund') ")
TbOrderSalesCountByDayVo queryTbOrderSalesCountByDaysummaryCount(@Param("shopId") Integer shopId,@Param("cateId")String cateId,@Param("proName")String proName, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
@Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" +
@Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" +
"COALESCE(CAST(SUM(CASE WHEN orders.orderType!='return' THEN info.num ELSE 0 END) as long),0), " +
"COALESCE(CAST(SUM(CASE WHEN orders.orderType='return' THEN info.num ELSE 0 END) as long),0))" +
"FROM TbOrderInfo orders " +

View File

@ -37,7 +37,7 @@ public interface SummaryService {
*/
void download(ShopSummaryDto summaryDto, HttpServletResponse response) throws IOException;
List<TbOrderPayCountVo> summaryCount(String shopId, Date startTime, Date endTime);
List<TbOrderPayCountVo> summaryCount(ShopSummaryDto summaryDto, Date startTime, Date endTime);
List<ShopTableSaleInfoVo> selectSummaryTable(Integer shopId, Date startTime, Date endTime);

View File

@ -450,7 +450,7 @@ public class SummaryServiceImpl implements SummaryService {
}
@Override
public List<TbOrderPayCountVo> summaryCount(String shopId, Date startTime, Date endTime) {
public List<TbOrderPayCountVo> summaryCount(ShopSummaryDto summaryDto, Date startTime, Date endTime) {
List<TbOrderPayCountVo> list = new ArrayList<>();
Long start = 1704038400000L;
Long end = Instant.now().toEpochMilli();
@ -461,23 +461,35 @@ public class SummaryServiceImpl implements SummaryService {
startTime = DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L));
endTime = new Date();
}
TbOrderPayCountVo payCount = tbOrderInfoRepository.queryOrderPayCount(shopId, start, end);
TbOrderPayCountVo refCount = tbOrderInfoRepository.queryTbOrderRefund(shopId, null, start, end);
payCount.setPayAmount(new BigDecimal(payCount.getPayAmount().toString()).subtract(new BigDecimal(refCount.getPayAmount().toString())));
payCount.setIcon("el-icon-coin");
list.add(payCount);
TbOrderPayCountVo cashCount = tbOrderInfoRepository.queryOrderPayCash(shopId, start, end);
cashCount.setIcon("el-icon-circle-check");
list.add(cashCount);
refCount.setPayType("退款金额");
refCount.setIcon("el-icon-money");
list.add(refCount);
if (summaryDto.getType() != null && summaryDto.getType() == 1) {
TbOrderPayCountVo payCount = tbOrderInfoRepository.queryOrderPayCount(summaryDto.getShopId(), start, end);
TbOrderPayCountVo refCount = tbOrderInfoRepository.queryTbOrderRefund(summaryDto.getShopId(), null,start, end);
payCount.setPayAmount(new BigDecimal(payCount.getPayAmount().toString()).subtract(new BigDecimal(refCount.getPayAmount().toString())));
payCount.setIcon("el-icon-coin");
list.add(payCount);
TbOrderPayCountVo cashCount = tbOrderInfoRepository.queryOrderPayCash(summaryDto.getShopId(), start, end);
cashCount.setIcon("el-icon-circle-check");
list.add(cashCount);
refCount.setPayType("退款金额");
refCount.setIcon("el-icon-money");
list.add(refCount);
TbOrderSalesCountByDayVo numCount = detailRepository.queryTbOrderSalesCount(Integer.valueOf(shopId), startTime, endTime);
TbOrderPayCountVo salesNum = new TbOrderPayCountVo("el-icon-goods", "销售量", "0", numCount.getSalesNum() - numCount.getRefNum());
TbOrderPayCountVo refNum = new TbOrderPayCountVo("el-icon-goods", "退单量", "0", numCount.getRefNum());
list.add(salesNum);
list.add(refNum);
TbOrderSalesCountByDayVo numCount = detailRepository.queryTbOrderSalesCount(Integer.valueOf(summaryDto.getShopId()), startTime, endTime);
TbOrderPayCountVo salesNum =new TbOrderPayCountVo("el-icon-goods","销售量","0",numCount.getSalesNum()-numCount.getRefNum());
TbOrderPayCountVo refNum =new TbOrderPayCountVo("el-icon-goods","退单量","0",numCount.getRefNum());
list.add(salesNum);
list.add(refNum);
}else {
TbOrderSalesCountByDayVo tbOrderSalesCountByDayVo = detailRepository.queryTbOrderSalesCountByDaysummaryCount(Integer.valueOf(summaryDto.getShopId()), summaryDto.getCateId(), summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime());
TbOrderPayCountVo zong =new TbOrderPayCountVo("el-icon-coin","总金额","1",tbOrderSalesCountByDayVo.getSalesAmount());
TbOrderPayCountVo tuikuan =new TbOrderPayCountVo("el-icon-money","退款金额","1",tbOrderSalesCountByDayVo.getRefAmount());
TbOrderPayCountVo xiaoliang =new TbOrderPayCountVo("el-icon-goods","销售量","0",tbOrderSalesCountByDayVo.getSalesNum());
TbOrderPayCountVo tuidan =new TbOrderPayCountVo("el-icon-goods","退单量","0",tbOrderSalesCountByDayVo.getRefNum());
list.add(zong);
list.add(tuikuan);
list.add(xiaoliang);
list.add(tuidan);
}
return list;
}

View File

@ -266,10 +266,10 @@ public class StockV2Vo {
this.type = "称重商品";
break;
case "currentPrice":
this.type = "套餐商品/团购卷";
this.type = "时价商品";
break;
case "group":
this.type = "时价商品";
this.type = "套餐商品/团购卷";
break;
default:
this.type = type;

View File

@ -48,10 +48,10 @@ public class StockVo {
this.type = "称重商品";
break;
case "currentPrice":
this.type = "套餐商品/团购卷";
this.type = "时价商品";
break;
case "group":
this.type = "时价商品";
this.type = "套餐商品/团购卷";
break;
default:
this.type = type;

View File

@ -152,11 +152,21 @@ public class TbOrderSalesCountByDayVo {
count();
}
public TbOrderSalesCountByDayVo(Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount) {
this.salesNum = salesNum;
this.refNum = refNum;
this.salesAmount = salesAmount;
this.refAmount = refAmount;
this.num = num;
count();
}
public void count(){
salesNum=salesNum-refNum;
salesAmount=salesAmount.subtract(refAmount);
if (salesNum == null) salesNum = 0l;
if (refNum == null) refNum = 0l;
salesNum = salesNum - refNum;
if (salesAmount == null) salesAmount = BigDecimal.ZERO;
if (refAmount == null) refAmount = BigDecimal.ZERO;
salesAmount = salesAmount.subtract(refAmount);
}
}