|
@@ -172,12 +172,13 @@ public class OrderInfoService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void completed1(Long orderInfoId, String transactionId) {
|
|
|
|
|
|
|
+ public void completed1(Long orderInfoId, String transactionId, PayMethod payMethod) {
|
|
|
// 修改订单状态
|
|
// 修改订单状态
|
|
|
OrderInfo order = orderInfoRepo.findById(orderInfoId).orElseThrow(new BusinessException("无订单"));
|
|
OrderInfo order = orderInfoRepo.findById(orderInfoId).orElseThrow(new BusinessException("无订单"));
|
|
|
order.setStatus(OrderInfoStatus.PAID);
|
|
order.setStatus(OrderInfoStatus.PAID);
|
|
|
order.setTransactionId(transactionId);
|
|
order.setTransactionId(transactionId);
|
|
|
order.setPaidAt(LocalDateTime.now());
|
|
order.setPaidAt(LocalDateTime.now());
|
|
|
|
|
+ order.setPayMethod(payMethod);
|
|
|
orderInfoRepo.save(order);
|
|
orderInfoRepo.save(order);
|
|
|
|
|
|
|
|
Integer num = order.getNum();
|
|
Integer num = order.getNum();
|
|
@@ -661,21 +662,35 @@ public class OrderInfoService {
|
|
|
/*
|
|
/*
|
|
|
购物车一起付款
|
|
购物车一起付款
|
|
|
*/
|
|
*/
|
|
|
- public void batchByCart(List<Long> shoppingCartIds,PayMethod payMethod) {
|
|
|
|
|
|
|
+ public void batchByCart(List<Long> shoppingCartIds) {
|
|
|
List<ShoppingCart> carts = shoppingCartRepo.findAllById(shoppingCartIds);
|
|
List<ShoppingCart> carts = shoppingCartRepo.findAllById(shoppingCartIds);
|
|
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
String localTime = df.format(LocalDateTime.now());
|
|
String localTime = df.format(LocalDateTime.now());
|
|
|
|
|
+ Set<Long> packageIds = carts.stream().map(ShoppingCart::getPackageId).collect(Collectors.toSet());
|
|
|
|
|
+ Map<Long, Package> packageMap = packageRepo.findAllById(packageIds)
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .collect(Collectors.toMap(Package::getId, aPackage -> aPackage));
|
|
|
carts.forEach(cart -> {
|
|
carts.forEach(cart -> {
|
|
|
|
|
+ // 判断套餐库存
|
|
|
|
|
+ Package aPackage = packageMap.get(cart.getPackageId());
|
|
|
|
|
+ if (cart.getNum() > aPackage.getInventory()) {
|
|
|
|
|
+ throw new BusinessException("库存不足");
|
|
|
|
|
+ }
|
|
|
OrderInfo orderInfo = new OrderInfo();
|
|
OrderInfo orderInfo = new OrderInfo();
|
|
|
BeanUtil.copyProperties(cart, orderInfo);
|
|
BeanUtil.copyProperties(cart, orderInfo);
|
|
|
orderInfo.setStatus(OrderInfoStatus.UNPAID);
|
|
orderInfo.setStatus(OrderInfoStatus.UNPAID);
|
|
|
- orderInfo.setPayMethod(payMethod);
|
|
|
|
|
|
|
+// orderInfo.setPayMethod(payMethod);
|
|
|
// 订单号
|
|
// 订单号
|
|
|
String orderNum = String.format("%05d", orderInfoRepo.orderNum() + 1);
|
|
String orderNum = String.format("%05d", orderInfoRepo.orderNum() + 1);
|
|
|
orderInfo.setOrderNumber(localTime + orderNum);
|
|
orderInfo.setOrderNumber(localTime + orderNum);
|
|
|
// 规格
|
|
// 规格
|
|
|
if (ObjectUtil.isNotNull(cart.getStockId())) {
|
|
if (ObjectUtil.isNotNull(cart.getStockId())) {
|
|
|
Stock stock = stockRepo.findById(cart.getStockId()).orElseThrow(new BusinessException("无规格"));
|
|
Stock stock = stockRepo.findById(cart.getStockId()).orElseThrow(new BusinessException("无规格"));
|
|
|
|
|
+ // 判断规格库存
|
|
|
|
|
+ if (cart.getNum() > stock.getInventory()) {
|
|
|
|
|
+ throw new BusinessException("库存不足");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
orderInfo.setSpecification(stock.getSpecification());
|
|
orderInfo.setSpecification(stock.getSpecification());
|
|
|
orderInfo.setDay(stock.getDay());
|
|
orderInfo.setDay(stock.getDay());
|
|
|
orderInfo.setPrice(stock.getPrice());
|
|
orderInfo.setPrice(stock.getPrice());
|