|
|
@@ -1,36 +1,41 @@
|
|
|
package com.izouma.dingdong.service.merchant;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.izouma.dingdong.domain.Appraisal;
|
|
|
import com.izouma.dingdong.domain.OrderGoodsSpec;
|
|
|
import com.izouma.dingdong.domain.OrderInfo;
|
|
|
import com.izouma.dingdong.domain.merchant.Goods;
|
|
|
import com.izouma.dingdong.domain.merchant.MerchantClassification;
|
|
|
import com.izouma.dingdong.domain.merchant.Sales;
|
|
|
+import com.izouma.dingdong.dto.SalesDTO;
|
|
|
import com.izouma.dingdong.exception.BusinessException;
|
|
|
import com.izouma.dingdong.repo.OrderGoodsSpecRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.GoodsRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.MerchantClassificationRepo;
|
|
|
+import com.izouma.dingdong.repo.merchant.MerchantRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.SalesRepo;
|
|
|
+import com.izouma.dingdong.service.MoneyRecordService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class SalesService {
|
|
|
|
|
|
- private SalesRepo salesRepo;
|
|
|
-
|
|
|
- private MerchantClassificationRepo merchantClassificationRepo;
|
|
|
-
|
|
|
- private OrderGoodsSpecRepo orderGoodsSpecRepo;
|
|
|
-
|
|
|
- private GoodsRepo goodsRepo;
|
|
|
-
|
|
|
+ private SalesRepo salesRepo;
|
|
|
+ private MerchantClassificationRepo merchantClassificationRepo;
|
|
|
+ private OrderGoodsSpecRepo orderGoodsSpecRepo;
|
|
|
+ private GoodsRepo goodsRepo;
|
|
|
private MerchantClassificationService merchantClassificationService;
|
|
|
+ private MoneyRecordService moneyRecordService;
|
|
|
+ private MerchantRepo merchantRepo;
|
|
|
|
|
|
/*
|
|
|
下订单时插入销量
|
|
|
@@ -43,10 +48,8 @@ public class SalesService {
|
|
|
spec -> {
|
|
|
//查商品销量表的销量数据
|
|
|
Sales daySales = this.newSales(spec.getGoodsId(), LocalDate.now());
|
|
|
-
|
|
|
//有订单,销量 + 购买数量
|
|
|
daySales.setDaySales(daySales.getDaySales() + spec.getNum());
|
|
|
-
|
|
|
//保存
|
|
|
salesRepo.save(daySales);
|
|
|
}
|
|
|
@@ -188,4 +191,86 @@ public class SalesService {
|
|
|
return daySales;
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ 商家报表
|
|
|
+ */
|
|
|
+ public List<SalesDTO> merchantReport(Long merchantId) {
|
|
|
+
|
|
|
+ List<SalesDTO> dtos = new ArrayList<>();
|
|
|
+
|
|
|
+ LocalDateTime nowDateTime = LocalDateTime.now();
|
|
|
+ LocalDate nowDate = nowDateTime.toLocalDate();
|
|
|
+ int year = nowDate.getYear();
|
|
|
+ int month = nowDate.getMonthValue();
|
|
|
+ LocalDateTime dateTime = LocalDateTime.of(year, month, 1, 0, 0, 0);
|
|
|
+
|
|
|
+ Long userId = merchantRepo.findById(merchantId).orElseThrow(new BusinessException("无商户")).getUserId();
|
|
|
+ //日点赞数 差评数 销量
|
|
|
+ Integer dayLikes = 0;
|
|
|
+ Integer dayBad = 0;
|
|
|
+ Integer daySales = 0;
|
|
|
+ //今日报表
|
|
|
+ Sales sales = salesRepo.findByMerchantIdAndDay(merchantId, nowDate);
|
|
|
+ if (ObjectUtil.isNotEmpty(sales)) {
|
|
|
+ dayLikes = sales.getDayLikes();
|
|
|
+ dayBad = sales.getDayBad();
|
|
|
+ daySales = sales.getDaySales();
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal dayIncome = moneyRecordService.income(userId, nowDateTime, nowDateTime);
|
|
|
+
|
|
|
+ dtos.add(SalesDTO.builder()
|
|
|
+ .bad(dayBad)
|
|
|
+ .likes(dayLikes)
|
|
|
+ .sale(daySales)
|
|
|
+ .income(dayIncome)
|
|
|
+ .name("本日报表")
|
|
|
+ .build());
|
|
|
+
|
|
|
+ //月点赞数 差评数 销量
|
|
|
+ Integer monthLikes = 0;
|
|
|
+ Integer monthBad = 0;
|
|
|
+ Integer monthSales = 0;
|
|
|
+ //所有点赞数 差评数 销量
|
|
|
+ Integer allLikes = 0;
|
|
|
+ Integer allBad = 0;
|
|
|
+ Integer allSales = 0;
|
|
|
+
|
|
|
+ List<Sales> allDaySales = salesRepo.findAllByMerchantId(merchantId);
|
|
|
+ for (Sales s : allDaySales) {
|
|
|
+ if (s.getDay().isBefore(dateTime.toLocalDate())) {
|
|
|
+ monthSales += s.getDaySales();
|
|
|
+ monthLikes += s.getDayLikes();
|
|
|
+ monthBad += s.getDayBad();
|
|
|
+ }
|
|
|
+ allLikes += s.getDaySales();
|
|
|
+ allBad += s.getDayLikes();
|
|
|
+ allSales += s.getDayBad();
|
|
|
+ }
|
|
|
+
|
|
|
+ //月收入
|
|
|
+ BigDecimal monthIncome = moneyRecordService.income(userId, dateTime, nowDateTime);
|
|
|
+ dtos.add(SalesDTO.builder()
|
|
|
+ .name("本月报表")
|
|
|
+ .bad(monthBad)
|
|
|
+ .likes(monthLikes)
|
|
|
+ .sale(monthSales)
|
|
|
+ .income(monthIncome)
|
|
|
+ .build());
|
|
|
+
|
|
|
+ //所有收入
|
|
|
+ LocalDateTime lastTime = LocalDateTime.of(2020, 7, 1, 0, 0, 0);
|
|
|
+ BigDecimal allIncome = moneyRecordService.income(userId, lastTime, nowDateTime);
|
|
|
+ dtos.add(SalesDTO.builder()
|
|
|
+ .name("所有报表")
|
|
|
+ .income(allIncome)
|
|
|
+ .sale(allSales)
|
|
|
+ .likes(allLikes)
|
|
|
+ .bad(allBad)
|
|
|
+ .build());
|
|
|
+
|
|
|
+ return dtos;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|