下单扣取库存

This commit is contained in:
SongZhang 2024-07-04 17:00:33 +08:00
parent b02f92c54f
commit 47e176b45a
3 changed files with 18 additions and 4 deletions

View File

@ -48,4 +48,7 @@ public interface TbProductMapper {
@Update("update tb_product set stock_number=stock_number-#{num} WHERE id=#{id} and stock_number-#{num} > 0")
int decrStock(String id, int num);
@Update("update tb_product set stock_number=stock_number-#{num} WHERE id=#{id}")
int decrStockUnCheck(String id, int num);
}

View File

@ -46,4 +46,7 @@ public interface TbProductSkuMapper {
@Update("update tb_product_sku set stock_number=stock_number-#{num} WHERE id=#{id} and stock_number-#{num} > 0")
int decrStock(String id, int num);
@Update("update tb_product_sku set stock_number=stock_number-#{num} WHERE id=#{id} ")
int decrStockUnCheck(String id, int num);
}

View File

@ -136,13 +136,21 @@ public class ProductService {
public void decrStock(String productId, String skuId, int decrNum) {
TbProductWithBLOBs product = tbProductMapper.selectByPrimaryKey(Integer.valueOf(productId));
if (product.getIsDistribute() == 1) {
if (product.getIsStock() == 1) {
if (tbProductMapper.decrStock(productId, decrNum) < 1) {
throw new MsgException("库存不足,下单失败");
}
}else {
tbProductMapper.decrStockUnCheck(productId, decrNum);
}
}else {
if (product.getIsStock() == 1) {
if (tbProductSkuMapper.decrStock(String.valueOf(skuId), decrNum) < 1) {
throw new MsgException("库存不足,下单失败");
}
}else {
tbProductSkuMapper.decrStockUnCheck(String.valueOf(skuId), decrNum);
}
}
}
}