商品共享库存字段 移除

This commit is contained in:
2024-10-12 14:53:18 +08:00
parent 0f000cd0e0
commit 4ed35d3be3
6 changed files with 29 additions and 105 deletions

View File

@@ -66,11 +66,6 @@ public class TbProduct implements Serializable {
private String typeEnum;
/**
* 是否共享库存
*/
private Byte isDistribute;
private Byte isDel;
private Byte isStock;
@@ -406,13 +401,6 @@ public class TbProduct implements Serializable {
this.typeEnum = typeEnum == null ? null : typeEnum.trim();
}
public Byte getIsDistribute() {
return isDistribute;
}
public void setIsDistribute(Byte isDistribute) {
this.isDistribute = isDistribute;
}
public Byte getIsDel() {
return isDel;

View File

@@ -16,6 +16,7 @@ public class UserCouponVo {
private String detail;
private String shopId;
private String shopName;
private String orderId;
/**
* 优惠金额
*/

View File

@@ -179,17 +179,9 @@ public class CartService {
return Result.fail("商品已下架");
}
if (tbProduct.getIsStock() == 1) {
// 1:共享库存 0:独立库存
if (Integer.valueOf(tbProduct.getIsDistribute()).equals(1)) {
if (tbProduct.getIsPauseSale() == 1) {//是否售罄
rmCart(jsonObject, skuId, key);
return Result.fail("该商品已售罄");
}
} else {
if (tbProductSkuWithBLOBs.getIsPauseSale() == 1) {//是否售罄
rmCart(jsonObject, skuId, key);
return Result.fail("该商品已售罄");
}
if (tbProduct.getIsPauseSale() == 1) {//是否售罄
rmCart(jsonObject, skuId, key);
return Result.fail("该商品已售罄");
}
}
@@ -387,19 +379,10 @@ public class CartService {
if (productSku.getSuit() != null && productSku.getSuit() > 1 && isVip != 1) {
if (product.getIsStock() == 1) {
boolean isSale = false;
// 1:共享库存 0:独立库存
if (Integer.valueOf(product.getIsDistribute()).equals(1)) {
if (num > productSku.getSuit()) {
if (num > product.getStockNumber()) isSale = true;
}else {
if (productSku.getSuit() > product.getStockNumber()) isSale = true;
}
if (num > productSku.getSuit()) {
if (num > product.getStockNumber()) isSale = true;
} else {
if (num > productSku.getSuit()) {
if (num > productSku.getStockNumber()) isSale = true;
}else {
if (productSku.getSuit() > productSku.getStockNumber()) isSale = true;
}
if (productSku.getSuit() > product.getStockNumber()) isSale = true;
}
if (isSale) {
throw new MsgException("商品起售库存不足");
@@ -536,9 +519,9 @@ public class CartService {
// 修改库存
try {
if (tbProduct1.getIsStock() == 1) {
productService.updateStock(tbProduct.getProductId(), tbProduct.getId(), cashierCart.getNumber(), tbProduct1.getIsDistribute() == 1);
productService.updateStock(tbProduct.getProductId(), tbProduct.getId(), cashierCart.getNumber());
} else {
productService.updateStockAndNoCheck(tbProduct.getProductId(), tbProduct.getId(), cashierCart.getNumber(), tbProduct1.getIsDistribute() == 1);
productService.updateStockAndNoCheck(tbProduct.getProductId(), tbProduct.getId(), cashierCart.getNumber());
}
} catch (Exception e) {
JSONObject jsonObject1 = new JSONObject();

View File

@@ -338,7 +338,7 @@ public class ProductService {
spec.put("isGrounding", true);
TbProductSku sku = (TbProductSku) spec.get("info");
if (sku != null) {
tbProduct.setIsPauseSale(tbProduct.getIsDistribute() == 1 ? tbProduct.getIsPauseSale() : sku.getIsPauseSale().byteValue());
tbProduct.setIsPauseSale(sku.getIsPauseSale().byteValue());
checkPauseSale(tbProduct, new ArrayList<>(Collections.singletonList(sku)), true);
spec.put("isPauseSale", tbProduct.getIsPauseSale());
}else {
@@ -355,7 +355,7 @@ public class ProductService {
itemMap.put("isGrounding", false);
TbProductSku sku = unGroundingMap.get("specSnap");
if (sku != null) {
tbProduct.setIsPauseSale(tbProduct.getIsDistribute() == 1 ? tbProduct.getIsPauseSale() : sku.getIsPauseSale().byteValue());
tbProduct.setIsPauseSale(sku.getIsPauseSale().byteValue());
checkPauseSale(tbProduct, Collections.singletonList(sku), true);
itemMap.put("isPauseSale", tbProduct.getIsPauseSale());
}else {
@@ -443,33 +443,13 @@ public class ProductService {
public void checkPauseSale(TbProduct tbProduct, List<TbProductSku> skus, boolean isSingle) {
if (tbProduct.getIsStock() == 1) {//库存开关 1开启
if (Integer.valueOf(tbProduct.getIsDistribute()).equals(1)) {//共享库存 1开启
if (tbProduct.getStockNumber() != null && tbProduct.getStockNumber() <= 0) {
tbProduct.setIsPauseSale(Byte.parseByte("1"));//售罄 1暂停
return;
}
if (tbProduct.getStockNumber() != null && tbProduct.getStockNumber() <= 0) {
tbProduct.setIsPauseSale(Byte.parseByte("1"));//售罄 1暂停
return;
}
if (isSingle && tbProduct.getIsPauseSale() == 1) {
return;
}
} else {
if (isSingle && !skus.stream().filter(res -> res.getIsPauseSale().equals(1)).collect(Collectors.toList()).isEmpty()) {
tbProduct.setIsPauseSale(Byte.parseByte("1"));//售罄 1暂停
return;
}
if (!tbProduct.getTypeEnum().equals("sku")) {
if (skus.stream().anyMatch(sku -> sku.getStockNumber() != null && sku.getStockNumber() <= 0)){
tbProduct.setIsPauseSale(Byte.parseByte("1"));//售罄 1暂停
return;
}
} else {
skus.removeIf(sku -> sku.getStockNumber() != null && sku.getStockNumber() <= 0);
if (CollectionUtils.isEmpty(skus)) {
tbProduct.setIsPauseSale(Byte.parseByte("1"));//售罄 1暂停
return;
}
}
if (isSingle && tbProduct.getIsPauseSale() == 1) {
return;
}
Iterator<TbProductSku> iterator = skus.iterator();
while (iterator.hasNext()) {
@@ -790,39 +770,22 @@ public class ProductService {
* @param buyNum 购买数量
*/
public void updateStock(TbProduct tbProduct, TbProductSkuWithBLOBs tbProductSkuWithBLOBs, Integer buyNum) {
if (tbProduct.getIsDistribute() == 1) {
if (tbProductMapper.decrStock(String.valueOf(tbProduct.getId()), buyNum) < 1) {
throw new MsgException("库存修改失败,请稍后再试");
}
} else {
if (tbProductSkuMapper.decrStock(String.valueOf(tbProductSkuWithBLOBs.getId()), buyNum) < 1) {
throw new MsgException("库存修改失败,请稍后再试");
}
if (tbProductMapper.decrStock(String.valueOf(tbProduct.getId()), buyNum) < 1) {
throw new MsgException("库存修改失败,请稍后再试");
}
}
public void updateStock(String id, Integer skuId, Integer buyNum, boolean isDistribute) {
if (isDistribute) {
if (tbProductMapper.decrStock(String.valueOf(id), buyNum) < 1) {
throw new MsgException("库存不足,下单失败");
}
} else {
if (tbProductSkuMapper.decrStock(String.valueOf(skuId), buyNum) < 1) {
throw new MsgException("库存不足,下单失败");
}
public void updateStock(String id, Integer skuId, Integer buyNum) {
if (tbProductMapper.decrStock(String.valueOf(id), buyNum) < 1) {
throw new MsgException("库存不足,下单失败");
}
}
public void updateStockAndNoCheck(String id, Integer skuId, Integer buyNum, boolean isDistribute) {
if (isDistribute) {
if (tbProductMapper.decrStockUnCheck(String.valueOf(id), buyNum) < 1) {
throw new MsgException("库存不足,下单失败");
}
} else {
if (tbProductSkuMapper.decrStockUnCheck(String.valueOf(skuId), buyNum) < 1) {
throw new MsgException("库存不足,下单失败");
}
public void updateStockAndNoCheck(String id, Integer skuId, Integer buyNum) {
if (tbProductMapper.decrStockUnCheck(String.valueOf(id), buyNum) < 1) {
throw new MsgException("库存不足,下单失败");
}
}
}