解决商品不存在时的扣减出错问题

This commit is contained in:
liyj 2025-11-07 17:42:04 +08:00
parent 5ef7e407ac
commit c8e912f378

View File

@ -5321,16 +5321,15 @@ public class ShopOrderBaseServiceImpl extends BaseServiceImpl<ShopOrderBaseMappe
if (Arrays.asList(1001, 1002).contains(order_item_inventory_lock)) {
Long item_id = order_item_row.getItem_id();
ShopProductItem shopProductItem = shopProductItemService.get(item_id);
if (shopProductItem == null) {
throw new ApiException(I18nUtil._("无法获取订单中的商品,请检查!"));
}
Integer item_quantity_frozen = shopProductItem.getItem_quantity_frozen();
int quantity_frozen = item_quantity_frozen - order_item_quantity;
shopProductItem.setItem_quantity_frozen(quantity_frozen > 0 ? quantity_frozen : 0);
if (!shopProductItemService.edit(shopProductItem)) {
throw new ApiException(I18nUtil._("修改商品冻结库存失败!"));
if (shopProductItem != null) {
logger.info("无法获取订单中的商品,请检查!");//商品存在才执行库存扣减
// throw new ApiException(I18nUtil._("无法获取订单中的商品,请检查!"));
Integer item_quantity_frozen = shopProductItem.getItem_quantity_frozen();
int quantity_frozen = item_quantity_frozen - order_item_quantity;
shopProductItem.setItem_quantity_frozen(quantity_frozen > 0 ? quantity_frozen : 0);
if (!shopProductItemService.edit(shopProductItem)) {
throw new ApiException(I18nUtil._("修改商品冻结库存失败!"));
}
}
}