fix: 折扣金额修复

This commit is contained in:
张松 2024-11-21 16:32:58 +08:00
parent 196d232e42
commit 01f43aacaf
3 changed files with 13 additions and 15 deletions

View File

@ -4,10 +4,8 @@ import cn.ysk.cashier.dto.order.UserCouponInfoDTO;
import lombok.Data;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@ -19,9 +17,9 @@ public class PayDTO {
private Integer orderId;
@NotEmpty
private String payType;
@Min(0)
@Max(1)
private Double discount;
@DecimalMin("0")
@DecimalMax("1")
private BigDecimal discount;
private Integer vipUserId;
private String code;
private String token;

View File

@ -365,12 +365,12 @@ public class TbPayServiceImpl implements TbPayService {
// return Result.fail(CodeEnum.PAYTYPENOEXIST);
// }
BigDecimal payMount = orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(payDTO.getDiscount())).setScale(2, RoundingMode.HALF_UP);
BigDecimal payMount = orderInfo.getOrderAmount().multiply(payDTO.getDiscount()).setScale(2, RoundingMode.HALF_UP);
orderInfo.setPayAmount(payMount);
orderInfo.setPayType("cash");
orderInfo.setStatus("closed");
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
orderInfo.setDiscountRatio(BigDecimal.valueOf(payDTO.getDiscount()));
orderInfo.setDiscountRatio(payDTO.getDiscount());
orderInfo.setDiscountAmount(orderInfo.getAmount().subtract(payMount));
orderInfoMapper.updateById(orderInfo);

View File

@ -2131,7 +2131,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
// 更新订单信息
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(orderInfo.getShopId(), orderInfo.getTableId());
OrderPriceDTO priceDTO = createOrderDetailWithCoupon(activateCartInfo, orderInfo, payDTO.getShopId(), false, shopEatTypeInfoDTO);
BigDecimal finalAmount = priceDTO.getTotalAmount().multiply(BigDecimal.valueOf(payDTO.getDiscount())).setScale(2, RoundingMode.HALF_UP);
BigDecimal finalAmount = priceDTO.getTotalAmount().multiply(payDTO.getDiscount()).setScale(2, RoundingMode.HALF_UP);
orderInfo.setUpdatedAt(System.currentTimeMillis());
orderInfo.setSettlementAmount(finalAmount);
@ -2177,7 +2177,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
private BigDecimal resetAmountByDiscount(PayDTO payDTO, TbOrderInfo orderInfo) {
List<TbCashierCart> cashierCarts = mpCashierCartService.selectByOrderIdAndState(orderInfo.getId());
List<TbOrderDetail> detailList = mpOrderDetailService.selectByOrderId(orderInfo.getId());
BigDecimal discount = BigDecimal.valueOf(payDTO.getDiscount());
BigDecimal discount = payDTO.getDiscount();
cashierCarts.forEach(item -> {
item.setTotalAmount(item.getTotalAmount().multiply(discount).setScale(2, RoundingMode.HALF_UP));
// item.setSalePrice(item.getSalePrice().multiply(discount).setScale(2, RoundingMode.HALF_UP));
@ -2194,10 +2194,10 @@ public class TbShopTableServiceImpl implements TbShopTableService {
mpCashierCartService.updateBatchById(cashierCarts);
mpOrderDetailService.updateBatchById(detailList);
BigDecimal oldAmount = orderInfo.getOrderAmount();
BigDecimal finalAmount = orderInfo.getOrderAmount().multiply(BigDecimal.valueOf(payDTO.getDiscount())).setScale(2, RoundingMode.HALF_UP);
BigDecimal finalAmount = orderInfo.getOrderAmount().multiply(payDTO.getDiscount()).setScale(2, RoundingMode.HALF_UP);
BigDecimal discountAmount = oldAmount.subtract(finalAmount);
orderInfo.setDiscountAmount(discountAmount);
orderInfo.setDiscountRatio(BigDecimal.valueOf(payDTO.getDiscount()));
orderInfo.setDiscountRatio(payDTO.getDiscount());
orderInfo.setOrderAmount(finalAmount);
orderInfo.setAmount(finalAmount);
orderInfo.setSettlementAmount(finalAmount);
@ -2234,12 +2234,12 @@ public class TbShopTableServiceImpl implements TbShopTableService {
}
if (payDTO.getDiscount() == null) {
payDTO.setDiscount((double) 1);
payDTO.setDiscount(new BigDecimal("1"));
}
BigDecimal finalAmount = null;
// 计算订单折扣信息
if (payDTO.getDiscount() != 1) {
if (payDTO.getDiscount().compareTo(new BigDecimal("1")) != 0) {
finalAmount = resetAmountByDiscount(payDTO, orderInfo);
}else {
finalAmount = orderInfo.getOrderAmount();