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 {
BigDecimal orderTotalPrice = checkedGoodsPrice.add(freightPrice).subtract(couponPrice);
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();
order.setUserId(userId);
......@@ -301,10 +307,12 @@ public class WxOrderController {
order.setIntegralPrice(integralPrice);
order.setOrderPrice(orderTotalPrice);
order.setActualPrice(actualPrice);
// 添加订单表项
orderService.add(order);
orderId = order.getId();
// 订单商品
List<LitemallOrderGoods> orderGoodsList = new ArrayList<>(checkedGoodsList.size());
for (LitemallCart cartGoods : checkedGoodsList) {
// 订单商品
LitemallOrderGoods orderGoods = new LitemallOrderGoods();
orderGoods.setOrderId(order.getId());
orderGoods.setGoodsId(cartGoods.getGoodsId());
......@@ -316,19 +324,8 @@ public class WxOrderController {
orderGoods.setNumber(cartGoods.getNumber());
orderGoods.setGoodsSpecificationIds(cartGoods.getGoodsSpecificationIds());
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);
}
......@@ -355,7 +352,7 @@ public class WxOrderController {
txManager.commit(status);
Map<String, Object> data = new HashMap<>();
data.put("orderId", order.getId());
data.put("orderId", orderId);
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