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