|
@@ -240,28 +240,38 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
}
|
|
|
handleCouponAmount(orderItemList, couponAmount);
|
|
|
}
|
|
|
+ BigDecimal balanceAmount = BigDecimal.ZERO;
|
|
|
//判断是否使用积分
|
|
|
- if (orderParam.getUseIntegration() == null || orderParam.getUseIntegration().equals(0)) {
|
|
|
- //不使用积分
|
|
|
- for (OmsOrderItem orderItem : orderItemList) {
|
|
|
- orderItem.setIntegrationAmount(new BigDecimal(0));
|
|
|
+ if (orderParam.isUseBalance()) {
|
|
|
+
|
|
|
+ // 查询余额
|
|
|
+ HttpResponseResult<BigDecimal> balance = webFeignService.balance(orderParam.getUserId());
|
|
|
+ if(balance.getStatus()) {
|
|
|
+ balanceAmount = balance.getData();
|
|
|
+ } else {
|
|
|
+ LOG.error("余额查询失败:{}",balance.getMsg());
|
|
|
}
|
|
|
+
|
|
|
+ //不使用积分
|
|
|
+ // for (OmsOrderItem orderItem : orderItemList) {
|
|
|
+ // orderItem.setIntegrationAmount(new BigDecimal(0));
|
|
|
+ // }
|
|
|
} else {
|
|
|
//使用积分
|
|
|
- BigDecimal totalAmount = calcTotalAmount(orderItemList);
|
|
|
- BigDecimal integrationAmount = getUseIntegrationAmount(orderParam.getUseIntegration(), totalAmount,
|
|
|
- currentMember, orderParam.getCouponId() != null);
|
|
|
- if (integrationAmount.compareTo(new BigDecimal(0)) == 0) {
|
|
|
- Asserts.fail("积分不可用");
|
|
|
- } else {
|
|
|
- //可用情况下分摊到可用商品中
|
|
|
- for (OmsOrderItem orderItem : orderItemList) {
|
|
|
- BigDecimal perAmount = orderItem.getProductPrice()
|
|
|
- .divide(totalAmount, 3, RoundingMode.HALF_EVEN)
|
|
|
- .multiply(integrationAmount);
|
|
|
- orderItem.setIntegrationAmount(perAmount);
|
|
|
- }
|
|
|
- }
|
|
|
+ // BigDecimal totalAmount = calcTotalAmount(orderItemList);
|
|
|
+ // BigDecimal integrationAmount = getUseIntegrationAmount(orderParam.getUseIntegration(), totalAmount,
|
|
|
+ // currentMember, orderParam.getCouponId() != null);
|
|
|
+ // if (integrationAmount.compareTo(new BigDecimal(0)) == 0) {
|
|
|
+ // Asserts.fail("积分不可用");
|
|
|
+ // } else {
|
|
|
+ // //可用情况下分摊到可用商品中
|
|
|
+ // for (OmsOrderItem orderItem : orderItemList) {
|
|
|
+ // BigDecimal perAmount = orderItem.getProductPrice()
|
|
|
+ // .divide(totalAmount, 3, RoundingMode.HALF_EVEN)
|
|
|
+ // .multiply(integrationAmount);
|
|
|
+ // orderItem.setIntegrationAmount(perAmount);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
}
|
|
|
//计算order_item的实付金额
|
|
|
handleRealAmount(orderItemList);
|
|
@@ -286,18 +296,18 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
order.setCouponId(orderParam.getCouponId());
|
|
|
order.setCouponAmount(couponAmount);
|
|
|
}
|
|
|
- if (orderParam.getUseIntegration() == null) {
|
|
|
+ if (!orderParam.isUseBalance()) {
|
|
|
order.setIntegration(0);
|
|
|
order.setIntegrationAmount(new BigDecimal(0));
|
|
|
} else {
|
|
|
- order.setIntegration(orderParam.getUseIntegration());
|
|
|
- order.setIntegrationAmount(calcIntegrationAmount(orderItemList));
|
|
|
+ order.setIntegration(0);
|
|
|
+ order.setIntegrationAmount(balanceAmount);
|
|
|
}
|
|
|
LOG.info("payAmount:{},totalAmount:{},couponAmount:{}",order.getTotalAmount().subtract(couponAmount),order.getTotalAmount(),couponAmount);
|
|
|
if (orderParam.getOrderAmount().compareTo(order.getTotalAmount().subtract(couponAmount)) != 0) {
|
|
|
throw new BizException("订单金额校验不通过");
|
|
|
}
|
|
|
- order.setPayAmount(orderParam.getOrderAmount());
|
|
|
+ order.setPayAmount(orderParam.getOrderAmount().subtract(balanceAmount));
|
|
|
//转化为订单信息并插入数据库
|
|
|
order.setMemberId(currentMember.getId());
|
|
|
order.setCreateTime(new Date());
|
|
@@ -395,6 +405,9 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
|
|
userOrderPayment.setStatus(TradeStatusEnum.succeeded.getCode());
|
|
|
userOrderPaymentService.saveOrUpdate(userOrderPayment);
|
|
|
}
|
|
|
+ if (balanceAmount.compareTo(MapUtil.get(data, "balanceAmount",BigDecimal.class)) != 0 ) {
|
|
|
+ throw new BizException("余额有变动,订单生成失败");
|
|
|
+ }
|
|
|
result.put("pay",data);
|
|
|
|
|
|
return result;
|