diff --git a/cash-service/order-service/src/main/java/com/czg/service/order/print/FeiPrinter.java b/cash-service/order-service/src/main/java/com/czg/service/order/print/FeiPrinter.java index e6090ac86..6ec647016 100644 --- a/cash-service/order-service/src/main/java/com/czg/service/order/print/FeiPrinter.java +++ b/cash-service/order-service/src/main/java/com/czg/service/order/print/FeiPrinter.java @@ -100,8 +100,15 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl { .setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0") .setOutNumber(orderInfo.getTakeCode()).setPrintTitle("结算单") .setRemark(orderInfo.getRemark()) - // 使用累计的总优惠金额,如果为 null 则用原价减去实付计算 - .setDiscountAmount(calculateDiscountAmount(orderInfo)); + // 使用累计的总优惠金额,null 表示没有优惠 + .setDiscountAmount(orderInfo.getDiscountAllAmount() != null + ? orderInfo.getDiscountAllAmount().toPlainString() + : "0.00"); + + if (orderInfo.getPayAmount() != null && orderInfo.getPayAmount().compareTo(BigDecimal.ZERO) == 0) { + // 设置支付金额为 订单原价-订单优惠金额 + printInfoDTO.setPayAmount(orderInfo.getOriginAmount().subtract(orderInfo.getDiscountAllAmount()).toPlainString()); + } String string = buildOrderPrintData(printInfoDTO, detailList); String o = sendPrintRequest(machine.getAddress(), string, null, printerNum); printMachineLogService.save(orderInfo.getId(), machine, "结算单", string, o); @@ -129,8 +136,10 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl { .setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0") .setOutNumber(orderInfo.getTakeCode()).setPrintTitle("结算单") .setRemark(orderInfo.getRemark()) - // 使用累计的总优惠金额,如果为 null 则用原价减去实付计算 - .setDiscountAmount(calculateDiscountAmount(orderInfo)); + // 使用累计的总优惠金额,null 表示没有优惠 + .setDiscountAmount(orderInfo.getDiscountAllAmount() != null + ? orderInfo.getDiscountAllAmount().toPlainString() + : "0.00"); printInfoDTO.setPrintTitle(printInfoDTO.getPrintTitle()); if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) { printInfoDTO.setSeatNum(orderInfo.getSeatNum().toString()); @@ -252,18 +261,12 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl { } /** - * 计算优惠金额:优先使用 discountAllAmount,如果为 null 则用原价 - 实付计算 + * 计算优惠金额:优先使用 discountAllAmount,如果为 null 则返回 0 */ private String calculateDiscountAmount(OrderInfo orderInfo) { - if (orderInfo.getDiscountAllAmount() != null) { - return orderInfo.getDiscountAllAmount().toPlainString(); - } - // 兜底计算:原价 + 餐位费 + 打包费 - 实付 - 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"; + return orderInfo.getDiscountAllAmount() != null + ? orderInfo.getDiscountAllAmount().toPlainString() + : "0.00"; } } diff --git a/cash-service/order-service/src/main/java/com/czg/service/order/print/YxyPrinter.java b/cash-service/order-service/src/main/java/com/czg/service/order/print/YxyPrinter.java index 9b90acb63..5b4263d3b 100644 --- a/cash-service/order-service/src/main/java/com/czg/service/order/print/YxyPrinter.java +++ b/cash-service/order-service/src/main/java/com/czg/service/order/print/YxyPrinter.java @@ -170,6 +170,10 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl { .setDiscountAmount(orderInfo.getDiscountAllAmount() != null ? orderInfo.getDiscountAllAmount().toPlainString() : "0.00"); + if (isPre) { + // 设置支付金额为 订单原价-订单优惠金额 + printInfoDTO.setPayAmount(orderInfo.getOriginAmount().subtract(orderInfo.getDiscountAllAmount()).toPlainString()); + } printInfoDTO.setPrintTitle(printInfoDTO.getPrintTitle()); if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) { printInfoDTO.setSeatNum(orderInfo.getSeatNum().toString());