|
@@ -41,8 +41,14 @@ public class BuyService {
|
|
|
long productId = buyItem.getItemId();
|
|
long productId = buyItem.getItemId();
|
|
|
int amount = buyItem.getNum();
|
|
int amount = buyItem.getNum();
|
|
|
Product product = productMapper.findByItemId(productId);
|
|
Product product = productMapper.findByItemId(productId);
|
|
|
|
|
+ int stock = product.getStock();
|
|
|
|
|
+ if (amount > stock) {
|
|
|
|
|
+ // 库存不足
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
double price = product.getPrice();
|
|
double price = product.getPrice();
|
|
|
- BuyDto buyDto = new BuyDto(productId, price, amount, deliveryId);
|
|
|
|
|
|
|
+ BuyDto buyDto = new BuyDto(productId, price, amount, deliveryId, UserContext.getUser());
|
|
|
|
|
|
|
|
// TODO 创建订单和修改库存是一个分布式事务
|
|
// TODO 创建订单和修改库存是一个分布式事务
|
|
|
long orderId = newOrderService.createOrder(buyDto);
|
|
long orderId = newOrderService.createOrder(buyDto);
|