生成订单时 不校验金额

This commit is contained in:
2025-03-01 17:33:34 +08:00
parent b8027b9c5f
commit af56a1e9ea

View File

@@ -170,10 +170,6 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
if (!shopInfo.getEatModel().contains(param.getDineMode())) { if (!shopInfo.getEatModel().contains(param.getDineMode())) {
throw new ValidateException("生成订单失败,店铺不支持该用餐模式"); throw new ValidateException("生成订单失败,店铺不支持该用餐模式");
} }
if (param.isVipPrice() && !shopInfo.getIsMemberPrice().equals(1)) {
throw new ValidateException("生成订单失败,该店铺不支持使用会员价");
}
if (param.getUserId() != null) { if (param.getUserId() != null) {
UserInfo userInfo = userInfoService.getById(param.getUserId()); UserInfo userInfo = userInfoService.getById(param.getUserId());
AssertUtil.isNull(userInfo, "生成订单失败,用户信息不存在"); AssertUtil.isNull(userInfo, "生成订单失败,用户信息不存在");
@@ -190,22 +186,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
param.setPayMode("未知"); param.setPayMode("未知");
} }
} }
//获取商品信息 计算金额 需要传入优惠券 减去优惠券
List<OrderDetail> orderDetails = cartService.getCartByTableCode(shopInfo.getId(), param.getTableCode(), param.getPlaceNum()); List<OrderDetail> orderDetails = cartService.getCartByTableCode(shopInfo.getId(), param.getTableCode(), param.getPlaceNum());
log.info("下单1 {}", JSONObject.toJSONString(orderDetails)); processOrderDetails(orderDetails);
//总打包费
BigDecimalDTO packAmount = new BigDecimalDTO(BigDecimal.ZERO);
//总商品支付金额 不包含打包费 用来计算后续
BigDecimal totalAmount = processOrderDetails(orderDetails, packAmount, param.isVipPrice());
log.info("下单2 总金额{} {}", totalAmount, JSONObject.toJSONString(orderDetails));
if (packAmount.getPrice().compareTo(param.getPackFee()) != 0) {
throw new ValidateException("生成订单失败,打包费不正确");
}
log.info("下单3 打包费{} 金额{}", param.getPackFee(), param.getOriginAmount());
//总金额
if (totalAmount.add(param.getPackFee()).compareTo(param.getOriginAmount()) != 0) {
throw new ValidateException("生成订单失败,订单金额不正确");
}
//生成订单 //生成订单
OrderInfo orderInfo = initOrderInfo(param, shopInfo, table); OrderInfo orderInfo = initOrderInfo(param, shopInfo, table);
orderDetailService.createOrderDetails(orderInfo.getId(), orderDetails); orderDetailService.createOrderDetails(orderInfo.getId(), orderDetails);
@@ -234,6 +216,11 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
throw new ValidateException("订单已过期,请重新下单"); throw new ValidateException("订单已过期,请重新下单");
} }
} }
ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId());
AssertUtil.isNull(shopInfo, "生成订单失败,店铺信息不存在");
if (param.isVipPrice() && !shopInfo.getIsMemberPrice().equals(1)) {
throw new ValidateException("生成订单失败,该店铺不支持使用会员价");
}
log.info("订单信息:{},优惠信息:{}", JSONObject.toJSONString(orderInfo), JSONObject.toJSONString(param)); log.info("订单信息:{},优惠信息:{}", JSONObject.toJSONString(orderInfo), JSONObject.toJSONString(param));
if (!orderInfo.getStatus().equals(OrderStatusEnums.UNPAID.getCode())) { if (!orderInfo.getStatus().equals(OrderStatusEnums.UNPAID.getCode())) {
throw new ValidateException("生成支付订单失败,订单不可支付"); throw new ValidateException("生成支付订单失败,订单不可支付");
@@ -276,6 +263,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
if (prodCouponAmount.getPrice().compareTo(param.getProductCouponDiscountAmount()) != 0) { if (prodCouponAmount.getPrice().compareTo(param.getProductCouponDiscountAmount()) != 0) {
throw new ValidateException("生成支付订单失败,商品优惠券优惠金额不正确"); throw new ValidateException("生成支付订单失败,商品优惠券优惠金额不正确");
} }
orderInfo.setOriginAmount(totalAmount.getPrice());
BigDecimal newTotalAmount; BigDecimal newTotalAmount;
//折扣金额 如 9折 计算 为 订单金额*0.9 向上取整 //折扣金额 如 9折 计算 为 订单金额*0.9 向上取整
if (param.getDiscountRatio().compareTo(BigDecimal.ONE) != 0) { if (param.getDiscountRatio().compareTo(BigDecimal.ONE) != 0) {
@@ -332,27 +320,21 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
* 填充 优惠券使用数量 以及 付款金额 * 填充 优惠券使用数量 以及 付款金额
* *
* @param orderDetails 订单详情 需要回填 * @param orderDetails 订单详情 需要回填
* @param packAmount 打包费
*/ */
private BigDecimal processOrderDetails(List<OrderDetail> orderDetails, BigDecimalDTO packAmount, boolean isVipPrice) { private void processOrderDetails(List<OrderDetail> orderDetails) {
BigDecimal totalAmount = BigDecimal.ZERO;
for (OrderDetail detail : orderDetails) { for (OrderDetail detail : orderDetails) {
if (detail.getDiscountSaleAmount() != null && detail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) { if (detail.getDiscountSaleAmount() != null && detail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) {
detail.setUnitPrice(detail.getDiscountSaleAmount()); detail.setUnitPrice(detail.getDiscountSaleAmount());
}else { } else {
if (isVipPrice) { if (detail.getDiscountSaleAmount() != null && detail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) {
detail.setUnitPrice(detail.getMemberPrice()); detail.setUnitPrice(detail.getDiscountSaleAmount());
}else { } else {
detail.setUnitPrice(detail.getPrice()); detail.setUnitPrice(detail.getPrice());
} }
} }
if (detail.getPackNumber().compareTo(BigDecimal.ZERO) > 0 && detail.getPackAmount().compareTo(BigDecimal.ZERO) > 0) {
packAmount.setPrice(packAmount.getPrice().add(detail.getPackAmount().multiply(detail.getPackNumber())));
}
detail.setPayAmount(detail.getNum().multiply(detail.getUnitPrice())); detail.setPayAmount(detail.getNum().multiply(detail.getUnitPrice()));
totalAmount = totalAmount.add(detail.getPayAmount());
} }
return totalAmount;
} }
/** /**
@@ -651,8 +633,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderInfo.setSeatNum(param.getSeatNum()); orderInfo.setSeatNum(param.getSeatNum());
} }
orderInfo.setPlaceNum(param.getPlaceNum()); orderInfo.setPlaceNum(param.getPlaceNum());
orderInfo.setOriginAmount(orderInfo.getOriginAmount().add(param.getOriginAmount()).add(orderInfo.getSeatAmount())); orderInfo.setOriginAmount(BigDecimal.ZERO);
orderInfo.setOrderAmount(orderInfo.getOriginAmount()); orderInfo.setOrderAmount(BigDecimal.ZERO);
orderInfo.setPackFee(orderInfo.getPackFee().add(param.getPackFee())); orderInfo.setPackFee(orderInfo.getPackFee().add(param.getPackFee()));
orderInfo.setRoundAmount(BigDecimal.ZERO); orderInfo.setRoundAmount(BigDecimal.ZERO);
orderInfo.setPointsNum(0); orderInfo.setPointsNum(0);