商品共享库存字段 移除

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("库存不足,下单失败");
}
}
}

View File

@@ -30,6 +30,7 @@
<select id="queryVipPro" resultType="com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo">
SELECT tb_product.NAME AS detail,
tb_activate_out_record.order_id as orderId,
1 AS status,
tb_activate_out_record.use_num AS num,
<choose>

View File

@@ -31,7 +31,6 @@
<result column="is_on_sale" jdbcType="TINYINT" property="isOnSale" />
<result column="is_show" jdbcType="TINYINT" property="isShow" />
<result column="type_enum" jdbcType="VARCHAR" property="typeEnum" />
<result column="is_distribute" jdbcType="TINYINT" property="isDistribute" />
<result column="is_del" jdbcType="TINYINT" property="isDel" />
<result column="is_stock" jdbcType="TINYINT" property="isStock" />
<result column="is_pause_sale" jdbcType="TINYINT" property="isPauseSale" />
@@ -110,7 +109,7 @@
sort, limit_number, product_score,
status, fail_msg, is_recommend,
is_hot, is_new, is_on_sale,
is_show, type_enum, is_distribute,
is_show, type_enum,
is_del, is_stock, is_pause_sale,
is_free_freight, freight_id, strategy_type,
strategy_id, is_vip, is_delete,
@@ -133,7 +132,7 @@
#{sort,jdbcType=INTEGER}, #{limitNumber,jdbcType=INTEGER}, #{productScore,jdbcType=INTEGER},
#{status,jdbcType=TINYINT}, #{failMsg,jdbcType=VARCHAR}, #{isRecommend,jdbcType=TINYINT},
#{isHot,jdbcType=TINYINT}, #{isNew,jdbcType=TINYINT}, #{isOnSale,jdbcType=TINYINT},
#{isShow,jdbcType=TINYINT}, #{typeEnum,jdbcType=VARCHAR}, #{isDistribute,jdbcType=TINYINT},
#{isShow,jdbcType=TINYINT}, #{typeEnum,jdbcType=VARCHAR},
#{isDel,jdbcType=TINYINT}, #{isStock,jdbcType=TINYINT}, #{isPauseSale,jdbcType=TINYINT},
#{isFreeFreight,jdbcType=TINYINT}, #{freightId,jdbcType=BIGINT}, #{strategyType,jdbcType=VARCHAR},
#{strategyId,jdbcType=INTEGER}, #{isVip,jdbcType=TINYINT}, #{isDelete,jdbcType=TINYINT},
@@ -239,9 +238,6 @@
<if test="typeEnum != null">
type_enum,
</if>
<if test="isDistribute != null">
is_distribute,
</if>
<if test="isDel != null">
is_del,
</if>
@@ -448,9 +444,6 @@
<if test="typeEnum != null">
#{typeEnum,jdbcType=VARCHAR},
</if>
<if test="isDistribute != null">
#{isDistribute,jdbcType=TINYINT},
</if>
<if test="isDel != null">
#{isDel,jdbcType=TINYINT},
</if>
@@ -657,9 +650,6 @@
<if test="typeEnum != null">
type_enum = #{typeEnum,jdbcType=VARCHAR},
</if>
<if test="isDistribute != null">
is_distribute = #{isDistribute,jdbcType=TINYINT},
</if>
<if test="isDel != null">
is_del = #{isDel,jdbcType=TINYINT},
</if>
@@ -810,7 +800,6 @@
is_on_sale = #{isOnSale,jdbcType=TINYINT},
is_show = #{isShow,jdbcType=TINYINT},
type_enum = #{typeEnum,jdbcType=VARCHAR},
is_distribute = #{isDistribute,jdbcType=TINYINT},
is_del = #{isDel,jdbcType=TINYINT},
is_stock = #{isStock,jdbcType=TINYINT},
is_pause_sale = #{isPauseSale,jdbcType=TINYINT},
@@ -882,7 +871,6 @@
is_on_sale = #{isOnSale,jdbcType=TINYINT},
is_show = #{isShow,jdbcType=TINYINT},
type_enum = #{typeEnum,jdbcType=VARCHAR},
is_distribute = #{isDistribute,jdbcType=TINYINT},
is_del = #{isDel,jdbcType=TINYINT},
is_stock = #{isStock,jdbcType=TINYINT},
is_pause_sale = #{isPauseSale,jdbcType=TINYINT},