MercMiniDeviceHomePageController.java 3.9 KB

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