商品共享库存字段 移除

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

View File

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

View File

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

View File

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

View File

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

View File

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