Commit 10fdeded authored by Junling Bu's avatar Junling Bu
Browse files

fix[litemall-wx-api]: 订单商品表项中订单ID是null。

parent 78018fe2
...@@ -285,6 +285,12 @@ public class WxOrderController { ...@@ -285,6 +285,12 @@ public class WxOrderController {
BigDecimal orderTotalPrice = checkedGoodsPrice.add(freightPrice).subtract(couponPrice); BigDecimal orderTotalPrice = checkedGoodsPrice.add(freightPrice).subtract(couponPrice);
BigDecimal actualPrice = orderTotalPrice.subtract(integralPrice); BigDecimal actualPrice = orderTotalPrice.subtract(integralPrice);
// 开启事务管理
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = txManager.getTransaction(def);
Integer orderId = null;
try {
// 订单 // 订单
LitemallOrder order = new LitemallOrder(); LitemallOrder order = new LitemallOrder();
order.setUserId(userId); order.setUserId(userId);
...@@ -301,10 +307,12 @@ public class WxOrderController { ...@@ -301,10 +307,12 @@ public class WxOrderController {
order.setIntegralPrice(integralPrice); order.setIntegralPrice(integralPrice);
order.setOrderPrice(orderTotalPrice); order.setOrderPrice(orderTotalPrice);
order.setActualPrice(actualPrice); order.setActualPrice(actualPrice);
// 添加订单表项
orderService.add(order);
orderId = order.getId();
// 订单商品
List<LitemallOrderGoods> orderGoodsList = new ArrayList<>(checkedGoodsList.size());
for (LitemallCart cartGoods : checkedGoodsList) { for (LitemallCart cartGoods : checkedGoodsList) {
// 订单商品
LitemallOrderGoods orderGoods = new LitemallOrderGoods(); LitemallOrderGoods orderGoods = new LitemallOrderGoods();
orderGoods.setOrderId(order.getId()); orderGoods.setOrderId(order.getId());
orderGoods.setGoodsId(cartGoods.getGoodsId()); orderGoods.setGoodsId(cartGoods.getGoodsId());
...@@ -316,19 +324,8 @@ public class WxOrderController { ...@@ -316,19 +324,8 @@ public class WxOrderController {
orderGoods.setNumber(cartGoods.getNumber()); orderGoods.setNumber(cartGoods.getNumber());
orderGoods.setGoodsSpecificationIds(cartGoods.getGoodsSpecificationIds()); orderGoods.setGoodsSpecificationIds(cartGoods.getGoodsSpecificationIds());
orderGoods.setGoodsSpecificationValues(cartGoods.getGoodsSpecificationValues()); orderGoods.setGoodsSpecificationValues(cartGoods.getGoodsSpecificationValues());
orderGoodsList.add(orderGoods);
}
// 开启事务管理
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = txManager.getTransaction(def);
try {
// 添加订单表项
orderService.add(order);
// 添加订单商品表项 // 添加订单商品表项
for (LitemallOrderGoods orderGoods : orderGoodsList) {
orderGoodsService.add(orderGoods); orderGoodsService.add(orderGoods);
} }
...@@ -355,7 +352,7 @@ public class WxOrderController { ...@@ -355,7 +352,7 @@ public class WxOrderController {
txManager.commit(status); txManager.commit(status);
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
data.put("orderId", order.getId()); data.put("orderId", orderId);
return ResponseUtil.ok(data); return ResponseUtil.ok(data);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment