fix: 折扣金额修复
This commit is contained in:
parent
196d232e42
commit
01f43aacaf
|
|
@ -4,10 +4,8 @@ import cn.ysk.cashier.dto.order.UserCouponInfoDTO;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import javax.validation.constraints.Max;
|
import javax.validation.constraints.*;
|
||||||
import javax.validation.constraints.Min;
|
import java.math.BigDecimal;
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -19,9 +17,9 @@ public class PayDTO {
|
||||||
private Integer orderId;
|
private Integer orderId;
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String payType;
|
private String payType;
|
||||||
@Min(0)
|
@DecimalMin("0")
|
||||||
@Max(1)
|
@DecimalMax("1")
|
||||||
private Double discount;
|
private BigDecimal discount;
|
||||||
private Integer vipUserId;
|
private Integer vipUserId;
|
||||||
private String code;
|
private String code;
|
||||||
private String token;
|
private String token;
|
||||||
|
|
|
||||||
|
|
@ -365,12 +365,12 @@ public class TbPayServiceImpl implements TbPayService {
|
||||||
// return Result.fail(CodeEnum.PAYTYPENOEXIST);
|
// 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.setPayAmount(payMount);
|
||||||
orderInfo.setPayType("cash");
|
orderInfo.setPayType("cash");
|
||||||
orderInfo.setStatus("closed");
|
orderInfo.setStatus("closed");
|
||||||
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
orderInfo.setPayOrderNo("cash".concat(SnowFlakeUtil.generateOrderNo()));
|
||||||
orderInfo.setDiscountRatio(BigDecimal.valueOf(payDTO.getDiscount()));
|
orderInfo.setDiscountRatio(payDTO.getDiscount());
|
||||||
orderInfo.setDiscountAmount(orderInfo.getAmount().subtract(payMount));
|
orderInfo.setDiscountAmount(orderInfo.getAmount().subtract(payMount));
|
||||||
orderInfoMapper.updateById(orderInfo);
|
orderInfoMapper.updateById(orderInfo);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2131,7 +2131,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
// 更新订单信息
|
// 更新订单信息
|
||||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(orderInfo.getShopId(), orderInfo.getTableId());
|
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(orderInfo.getShopId(), orderInfo.getTableId());
|
||||||
OrderPriceDTO priceDTO = createOrderDetailWithCoupon(activateCartInfo, orderInfo, payDTO.getShopId(), false, shopEatTypeInfoDTO);
|
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.setUpdatedAt(System.currentTimeMillis());
|
||||||
orderInfo.setSettlementAmount(finalAmount);
|
orderInfo.setSettlementAmount(finalAmount);
|
||||||
|
|
@ -2177,7 +2177,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
private BigDecimal resetAmountByDiscount(PayDTO payDTO, TbOrderInfo orderInfo) {
|
private BigDecimal resetAmountByDiscount(PayDTO payDTO, TbOrderInfo orderInfo) {
|
||||||
List<TbCashierCart> cashierCarts = mpCashierCartService.selectByOrderIdAndState(orderInfo.getId());
|
List<TbCashierCart> cashierCarts = mpCashierCartService.selectByOrderIdAndState(orderInfo.getId());
|
||||||
List<TbOrderDetail> detailList = mpOrderDetailService.selectByOrderId(orderInfo.getId());
|
List<TbOrderDetail> detailList = mpOrderDetailService.selectByOrderId(orderInfo.getId());
|
||||||
BigDecimal discount = BigDecimal.valueOf(payDTO.getDiscount());
|
BigDecimal discount = payDTO.getDiscount();
|
||||||
cashierCarts.forEach(item -> {
|
cashierCarts.forEach(item -> {
|
||||||
item.setTotalAmount(item.getTotalAmount().multiply(discount).setScale(2, RoundingMode.HALF_UP));
|
item.setTotalAmount(item.getTotalAmount().multiply(discount).setScale(2, RoundingMode.HALF_UP));
|
||||||
// item.setSalePrice(item.getSalePrice().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);
|
mpCashierCartService.updateBatchById(cashierCarts);
|
||||||
mpOrderDetailService.updateBatchById(detailList);
|
mpOrderDetailService.updateBatchById(detailList);
|
||||||
BigDecimal oldAmount = orderInfo.getOrderAmount();
|
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);
|
BigDecimal discountAmount = oldAmount.subtract(finalAmount);
|
||||||
orderInfo.setDiscountAmount(discountAmount);
|
orderInfo.setDiscountAmount(discountAmount);
|
||||||
orderInfo.setDiscountRatio(BigDecimal.valueOf(payDTO.getDiscount()));
|
orderInfo.setDiscountRatio(payDTO.getDiscount());
|
||||||
orderInfo.setOrderAmount(finalAmount);
|
orderInfo.setOrderAmount(finalAmount);
|
||||||
orderInfo.setAmount(finalAmount);
|
orderInfo.setAmount(finalAmount);
|
||||||
orderInfo.setSettlementAmount(finalAmount);
|
orderInfo.setSettlementAmount(finalAmount);
|
||||||
|
|
@ -2234,12 +2234,12 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payDTO.getDiscount() == null) {
|
if (payDTO.getDiscount() == null) {
|
||||||
payDTO.setDiscount((double) 1);
|
payDTO.setDiscount(new BigDecimal("1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal finalAmount = null;
|
BigDecimal finalAmount = null;
|
||||||
// 计算订单折扣信息
|
// 计算订单折扣信息
|
||||||
if (payDTO.getDiscount() != 1) {
|
if (payDTO.getDiscount().compareTo(new BigDecimal("1")) != 0) {
|
||||||
finalAmount = resetAmountByDiscount(payDTO, orderInfo);
|
finalAmount = resetAmountByDiscount(payDTO, orderInfo);
|
||||||
}else {
|
}else {
|
||||||
finalAmount = orderInfo.getOrderAmount();
|
finalAmount = orderInfo.getOrderAmount();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue