财务报表

This commit is contained in:
gong
2026-02-02 14:51:21 +08:00
parent c9a432b786
commit ad24a91a28
10 changed files with 739 additions and 177 deletions

View File

@@ -131,7 +131,6 @@ public class AShopUserServiceImpl implements AShopUserService {
public void exportUserList(String key, Integer isVip, HttpServletResponse response) {
Long mainIdByShopId = shopInfoService.getMainIdByShopId(StpKit.USER.getShopId());
ShopInfo shopInfo = shopInfoService.getById(StpKit.USER.getShopId());
PageHelper.startPage(PageUtil.buildPageHelp());
List<ShopUserDTO> dtoList = shopUserMapper.selectPageByKeyAndIsVip(mainIdByShopId, isVip, key, null);
// 将 dtoList 转换为 ShopUserExportDTO 列表

View File

@@ -0,0 +1,103 @@
package com.czg.service.order.service.impl;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.czg.excel.ExcelExportUtil;
import com.czg.exception.CzgException;
import com.czg.order.dto.FinanceStsDTO;
import com.czg.order.entity.ShopOrderStatistic;
import com.czg.order.param.FinanceStsQueryParam;
import com.czg.order.service.FinanceStsService;
import com.czg.order.service.ShopOrderStatisticService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
/**
* @author yjjie
* @date 2026/2/2 10:11
*/
@Service
public class FinanceStsServiceImpl implements FinanceStsService {
@Resource
private ShopOrderStatisticService orderStatisticService;
@Override
public FinanceStsDTO getFinanceSts(FinanceStsQueryParam param) {
if (param.notValidDateRange()) {
throw new CzgException("日期范围无效");
}
ShopOrderStatistic statistic = getStatisticData(param);
return new FinanceStsDTO()
.setDate(LocalDateTimeUtil.format(param.getQueryDate(), "yyyy-MM-dd"))
.setTurnover(new FinanceStsDTO.TurnoverSts()
.setTurnover(statistic.getPayAmount())
.setWechat(statistic.getWechatPayAmount())
.setAlipay(statistic.getAlipayPayAmount())
.setSelfScan(statistic.getMainScanPayAmount())
.setCash(statistic.getCashPayAmount())
.setRecharge(statistic.getRechargeAmount())
.setOwed(statistic.getCreditPayAmount())
.setBalance(statistic.getMemberPayAmount()))
.setOrder(new FinanceStsDTO.OrderSts()
.setOrderAmount(statistic.getPayAmount())
.setOrderCount(statistic.getOrderCount()))
.setDiscount(new FinanceStsDTO.DiscountSts()
.setDiscountAmount(statistic.getDiscountAmount())
.setDiscountCount(statistic.getDiscountCount())
.setNewConsumerDiscount(statistic.getNewCustomerDiscountAmount())
.setFreeCashAmount(statistic.getBackDiscountAmount())
.setFullMinusAmount(statistic.getFullDiscountAmount())
.setCouponAmount(statistic.getCouponDiscountAmount())
.setMemberDiscount(statistic.getMemberDiscountAmount())
.setPointsDiscountAmount(statistic.getPointDiscountAmount())
.setOrderDiscount(statistic.getOrderPriceDiscountAmount()))
.setRefund(new FinanceStsDTO.RefundSts()
.setRefundAmount(statistic.getRefundAmount())
.setOnlineRefundAmount(statistic.getOnlineRefundAmount())
.setCashRefundAmount(statistic.getCashRefundAmount())
.setRechargeRefundAmount(statistic.getRechargeRefundAmount())
.setOnlineRechargeRefundAmount(statistic.getOnlineRechargeRefundAmount())
.setCashRechargeRefundAmount(statistic.getCashRechargeRefundAmount())
.setMemberRefundAmount(statistic.getMemberRefundAmount()))
.setSts(new FinanceStsDTO.Sts()
.setCustomerCount(statistic.getCustomerCount())
.setOrderCount(statistic.getOrderCount())
.setTableCount(statistic.getTableCount())
.setAvgPayAmount(statistic.getAvgPayAmount())
.setTurnoverRate(statistic.getTurnoverRate())
.setProfitAmount(statistic.getProfitAmount())
.setProductCostAmount(statistic.getProductCostAmount())
.setProfitRate(statistic.getProfitRate())
.setNetProfitRate(statistic.getNetProfitRate())
.setNetProfitRate(statistic.getNetProfitRate()));
}
@Override
public void exportFinanceSts(FinanceStsQueryParam param, HttpServletResponse response) {
if (param.notValidDateRange()) {
throw new CzgException("日期范围无效");
}
ShopOrderStatistic statistic = getStatisticData(param);
if ("czg".equals(param.getPlatform())) {
ExcelExportUtil.exportToResponse(List.of(statistic), ShopOrderStatistic.class, "财务报表", response);
return;
}
throw new CzgException("平台不支持");
}
private ShopOrderStatistic getStatisticData(FinanceStsQueryParam param) {
LocalDate today = LocalDate.now();
if (param.getQueryDate().equals(today)) {
return orderStatisticService.getRealTimeDataByDay(param.getShopId(), param.getQueryDate());
}
return orderStatisticService.getStatSingleDate(param.getShopId(), param.getQueryDate());
}
}

View File

@@ -186,7 +186,7 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
BigDecimal rechargeAmount = cashRechargeAmount.add(onlineRechargeAmount);
result.setRechargeAmount(rechargeAmount);
//会员充值退款 充值退款金额(线上退款+现金退款)
BigDecimal onlineRefundAmount = Objects.requireNonNullElse(
BigDecimal onlineRechargeRefundAmount = Objects.requireNonNullElse(
(onlineStat != null) ? onlineStat.getOnlineRechargeRefundAmount() : null,
BigDecimal.ZERO
);
@@ -194,7 +194,9 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
(userFlowStat != null) ? userFlowStat.getCashRechargeRefundAmount() : null,
BigDecimal.ZERO
);
BigDecimal rechargeRefundAmountTotal = onlineRefundAmount.add(userFlowRefundAmount);
BigDecimal rechargeRefundAmountTotal = onlineRechargeRefundAmount.add(userFlowRefundAmount);
result.setOnlineRefundAmount(onlineStat == null ? BigDecimal.ZERO : onlineStat.getOnlineRefundAmount());
result.setOnlineRechargeRefundAmount(onlineStat == null ? BigDecimal.ZERO : onlineStat.getOnlineRechargeRefundAmount());
result.setRechargeRefundAmount(rechargeRefundAmountTotal);
//实付金额 (线上付款 现金支付 会员支付 挂账)
BigDecimal onlinePayAmount = (onlineStat != null)
@@ -218,6 +220,9 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
.add(creditPayAmount);
result.setPayAmount(totalPayAmount);
calculateShopOrderStatistic(result);
calculateProfitInfo(result);
calculateTurnoverRate(result);
calculateAvgPayAmount(result);
return result;
}