修改计算优惠金额4

This commit is contained in:
gong
2026-03-28 13:38:06 +08:00
parent 35e35e5668
commit 37a4af8071

View File

@@ -100,10 +100,8 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl {
.setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0") .setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0")
.setOutNumber(orderInfo.getTakeCode()).setPrintTitle("结算单") .setOutNumber(orderInfo.getTakeCode()).setPrintTitle("结算单")
.setRemark(orderInfo.getRemark()) .setRemark(orderInfo.getRemark())
// 使用累计的总优惠金额null 表示没有优惠 // 使用累计的总优惠金额,如果为 null 则用原价减去实付计算
.setDiscountAmount(orderInfo.getDiscountAllAmount() != null .setDiscountAmount(calculateDiscountAmount(orderInfo));
? orderInfo.getDiscountAllAmount().toPlainString()
: "0.00");
if (orderInfo.getPayAmount() != null && orderInfo.getPayAmount().compareTo(BigDecimal.ZERO) == 0) { if (orderInfo.getPayAmount() != null && orderInfo.getPayAmount().compareTo(BigDecimal.ZERO) == 0) {
// 设置支付金额为 订单原价-订单优惠金额 // 设置支付金额为 订单原价-订单优惠金额
@@ -136,10 +134,8 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl {
.setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0") .setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0")
.setOutNumber(orderInfo.getTakeCode()).setPrintTitle("结算单") .setOutNumber(orderInfo.getTakeCode()).setPrintTitle("结算单")
.setRemark(orderInfo.getRemark()) .setRemark(orderInfo.getRemark())
// 使用累计的总优惠金额null 表示没有优惠 // 使用累计的总优惠金额,如果为 null 则用原价减去实付计算
.setDiscountAmount(orderInfo.getDiscountAllAmount() != null .setDiscountAmount(calculateDiscountAmount(orderInfo));
? orderInfo.getDiscountAllAmount().toPlainString()
: "0.00");
printInfoDTO.setPrintTitle(printInfoDTO.getPrintTitle()); printInfoDTO.setPrintTitle(printInfoDTO.getPrintTitle());
if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) { if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) {
printInfoDTO.setSeatNum(orderInfo.getSeatNum().toString()); printInfoDTO.setSeatNum(orderInfo.getSeatNum().toString());
@@ -261,12 +257,18 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl {
} }
/** /**
* 计算优惠金额:优先使用 discountAllAmount如果为 null 则返回 0 * 计算优惠金额:优先使用 discountAllAmount如果为 null 则用原价 - 实付计算
*/ */
private String calculateDiscountAmount(OrderInfo orderInfo) { private String calculateDiscountAmount(OrderInfo orderInfo) {
return orderInfo.getDiscountAllAmount() != null if (orderInfo.getDiscountAllAmount() != null) {
? orderInfo.getDiscountAllAmount().toPlainString() return orderInfo.getDiscountAllAmount().toPlainString();
: "0.00"; }
// 兜底计算:原价 + 餐位费 + 打包费 - 实付
BigDecimal originalTotal = orderInfo.getOriginAmount()
.add(orderInfo.getSeatAmount() != null ? orderInfo.getSeatAmount() : BigDecimal.ZERO)
.add(orderInfo.getPackFee() != null ? orderInfo.getPackFee() : BigDecimal.ZERO);
BigDecimal discount = originalTotal.subtract(orderInfo.getPayAmount());
return discount.compareTo(BigDecimal.ZERO) >= 0 ? discount.toPlainString() : "0.00";
} }
} }