MercMiniDeviceHomePageController.java 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package com.xy.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.date.DatePattern;
  4. import cn.hutool.core.date.DateTime;
  5. import cn.hutool.core.date.DateUtil;
  6. import com.xy.annotate.RestMappingController;
  7. import com.xy.dto.DeviceDataDto;
  8. import com.xy.dto.MercMiniDeviceDto;
  9. import com.xy.dto.OrderRefundDto;
  10. import com.xy.service.DeviceDataServiceImpl;
  11. import com.xy.service.OrderRefundService;
  12. import com.xy.utils.MercAuthUtils;
  13. import com.xy.utils.R;
  14. import io.swagger.annotations.Api;
  15. import io.swagger.annotations.ApiOperation;
  16. import lombok.AllArgsConstructor;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19. import org.springframework.web.bind.annotation.PostMapping;
  20. import java.util.Date;
  21. import java.util.List;
  22. /***
  23. * 商家端小程序-首页
  24. * @author 谭斌
  25. * @date 2023/3/13 14:38
  26. */
  27. @Service
  28. @AllArgsConstructor(onConstructor_ = @Autowired)
  29. @Api(tags = "商家端小程序-首页")
  30. @RestMappingController("merc-mini/homepage")
  31. public class MercMiniDeviceHomePageController {
  32. private DeviceDataServiceImpl deviceDataService;
  33. private OrderRefundService refundService;
  34. @PostMapping("count")
  35. @ApiOperation("首页统计")
  36. public R<MercMiniDeviceDto.HomePageVO> homepageCount() {
  37. MercMiniDeviceDto.HomePageVO vo = new MercMiniDeviceDto.HomePageVO();
  38. Long mercId = MercAuthUtils.getMercId();
  39. //当天
  40. MercMiniDeviceDto.DayCountVO day = new MercMiniDeviceDto.DayCountVO().setOrderNum(0).setSalesPrice(0).setRefundMoney(0);
  41. List<DeviceDataDto.Vo> mercDataOneDay = deviceDataService.getMercDataOneDay(mercId, DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN));
  42. if (CollUtil.isNotEmpty(mercDataOneDay)) {
  43. //今日退款成功订单金额
  44. OrderRefundDto.CountByDateVO countByDateVO = R.feignCheckData(refundService.countByDate(new OrderRefundDto.CountByDateDTO().setDate(DateTime.now()).setMercId(mercId)));
  45. Integer hisRefundMoney = countByDateVO.getHisRefundMoney();
  46. Integer todayRefundMoney = countByDateVO.getTodayRefundMoney();
  47. //今日销售额 (扣除今日的订单的退款金额)
  48. day.setDayHisRefundMoney(hisRefundMoney);
  49. day.setDayRefundMoney(todayRefundMoney);
  50. day.setSalesPrice(mercDataOneDay.stream().mapToInt(DeviceDataDto.Vo::getSalesMoney).sum() - todayRefundMoney);
  51. day.setOrderNum(mercDataOneDay.stream().mapToInt(DeviceDataDto.Vo::getSalesCount).sum());
  52. day.setRefundMoney(hisRefundMoney + todayRefundMoney);
  53. }
  54. vo.setDay(day);
  55. //当月
  56. MercMiniDeviceDto.MonthCountVO month = new MercMiniDeviceDto.MonthCountVO().setOrderNum(0).setSalesPrice(0).setRefundMoney(0);
  57. List<DeviceDataDto.Vo> mercDataOneMonth = deviceDataService.getMercDataOneMonth(mercId, DateUtil.format(new Date(), DatePattern.SIMPLE_MONTH_PATTERN));
  58. if (CollUtil.isNotEmpty(mercDataOneMonth)) {
  59. OrderRefundDto.CountByMonthVO countByMonthVO = R.feignCheckData(refundService.countByMonth(new OrderRefundDto.CountByMonthDTO().setCurMonthDate(DateTime.now()).setMercId(mercId)));
  60. Integer hisMonthRefundMoney = countByMonthVO.getHisMonthRefundMoney();
  61. Integer monthRefundMoney = countByMonthVO.getMonthRefundMoney();
  62. month.setSalesPrice(mercDataOneMonth.stream().mapToInt(DeviceDataDto.Vo::getSalesMoney).sum() - monthRefundMoney);
  63. month.setOrderNum(mercDataOneMonth.stream().mapToInt(DeviceDataDto.Vo::getSalesCount).sum());
  64. month.setRefundMoney(hisMonthRefundMoney + monthRefundMoney);
  65. month.setMonthRefundMoney(monthRefundMoney);
  66. month.setMonthHisRefundMoney(hisMonthRefundMoney);
  67. }
  68. vo.setMonth(month);
  69. return R.ok(vo);
  70. }
  71. }