库存警戒线
This commit is contained in:
@@ -140,6 +140,9 @@ public class TbProduct implements Serializable {
|
||||
//是否可售 1 可售 0非可售
|
||||
private Integer isSale = 1;
|
||||
|
||||
private Integer warnLine = 0;
|
||||
|
||||
|
||||
|
||||
public String getImages() {
|
||||
return images;
|
||||
@@ -683,4 +686,12 @@ public class TbProduct implements Serializable {
|
||||
public void setIsSale(Integer isSale) {
|
||||
this.isSale = isSale;
|
||||
}
|
||||
|
||||
public Integer getWarnLine() {
|
||||
return warnLine;
|
||||
}
|
||||
|
||||
public void setWarnLine(Integer warnLine) {
|
||||
this.warnLine = warnLine;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ public class TbProductSku implements Serializable {
|
||||
|
||||
private String coverImg;
|
||||
|
||||
private Integer warnLine;
|
||||
|
||||
private Double weight;
|
||||
|
||||
@@ -175,14 +174,6 @@ public class TbProductSku implements Serializable {
|
||||
this.coverImg = coverImg == null ? null : coverImg.trim();
|
||||
}
|
||||
|
||||
public Integer getWarnLine() {
|
||||
return warnLine;
|
||||
}
|
||||
|
||||
public void setWarnLine(Integer warnLine) {
|
||||
this.warnLine = warnLine;
|
||||
}
|
||||
|
||||
public Double getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
@@ -329,22 +329,9 @@ public class CartService {
|
||||
* @param num 库存数
|
||||
*/
|
||||
private void updateProductStock(TbProduct product, TbProductSkuWithBLOBs productSku, Integer num) {
|
||||
String key = RedisCst.PRODUCT + product.getShopId() + ":product" + product.getId();
|
||||
double stock = num;
|
||||
if (product.getIsDistribute() == 1) {
|
||||
productMapper.updateStockById(product.getId().toString(), num);
|
||||
stock = (double) (product.getStockNumber() - num);
|
||||
} else {
|
||||
key = RedisCst.PRODUCT + product.getShopId() + ":" + productSku.getId();
|
||||
productSkuMapper.updateStockById(productSku.getId().toString(), num);
|
||||
stock = productSku.getStockNumber() - num;
|
||||
}
|
||||
|
||||
if (num > 0) {
|
||||
redisUtil.getIncrNum(key, "1");
|
||||
} else {
|
||||
redisUtil.getIncrNum(key, "2");
|
||||
}
|
||||
productMapper.updateStockById(product.getId().toString(), num);
|
||||
|
||||
|
||||
CompletableFuture.runAsync(() -> checkWarnLineAndSendMsg(productSku, product, num));
|
||||
|
||||
@@ -356,7 +343,7 @@ public class CartService {
|
||||
* @param productSku sku
|
||||
*/
|
||||
private void checkWarnLineAndSendMsg(TbProductSku productSku, TbProduct product, Integer num) {
|
||||
if (productSku.getWarnLine() == null) {
|
||||
if (product.getWarnLine() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -370,23 +357,17 @@ public class CartService {
|
||||
return;
|
||||
}
|
||||
|
||||
if (productSku.getStockNumber() == null) {
|
||||
productSku.setStockNumber((double) 0);
|
||||
}
|
||||
|
||||
if (product.getStockNumber() == null) {
|
||||
product.setStockNumber(0);
|
||||
}
|
||||
if (
|
||||
(product.getIsDistribute() == 1 && product.getStockNumber() - num <= productSku.getWarnLine())
|
||||
|| (product.getIsDistribute() != 1) && productSku.getStockNumber() - num <= productSku.getWarnLine()
|
||||
) {
|
||||
if (product.getStockNumber() - num <= product.getWarnLine()) {
|
||||
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectStateByShopIdAndType(product.getShopId(), ShopWxMsgTypeEnum.STOCK_MSG.getType());
|
||||
shopOpenIds.forEach(item -> {
|
||||
String message = redisUtil.getMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId());
|
||||
if (message == null) {
|
||||
wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(),
|
||||
product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num)
|
||||
product.getStockNumber() - num
|
||||
, item.getOpenId(), ShopWxMsgTypeEnum.STOCK_MSG, shopInfo.getId());
|
||||
redisUtil.saveMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId(), product.getId().toString(), 60 * 30L);
|
||||
}else {
|
||||
|
||||
Reference in New Issue
Block a user