商品列表 校验库存 以及 耗材
This commit is contained in:
@@ -75,6 +75,12 @@ public class ProductService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private TbUserInfoMapper tbUserInfoMapper;
|
private TbUserInfoMapper tbUserInfoMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TbProskuConMapper tbProskuConMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TbConsInfoMapper tbConsInfoMapper;
|
||||||
|
|
||||||
public Result queryShopIdByTableCode(String userId, String openId, String code, String lat, String lng) {
|
public Result queryShopIdByTableCode(String userId, String openId, String code, String lat, String lng) {
|
||||||
if (StringUtils.isBlank(code)) return Result.fail("桌码信息为空");
|
if (StringUtils.isBlank(code)) return Result.fail("桌码信息为空");
|
||||||
if (StringUtils.isBlank(lat) || lat.equals("undefined")) {
|
if (StringUtils.isBlank(lat) || lat.equals("undefined")) {
|
||||||
@@ -369,9 +375,9 @@ public class ProductService {
|
|||||||
it.setCartNumber("0");
|
it.setCartNumber("0");
|
||||||
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
|
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
|
||||||
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
||||||
|
//判断库存及耗材
|
||||||
|
checkPauseSale(it,tbProductSkus);
|
||||||
|
|
||||||
// 上下架对应的sku
|
|
||||||
// HashSet<String> specSet = new HashSet<>();
|
|
||||||
AtomicDouble sum = new AtomicDouble(0.0);
|
AtomicDouble sum = new AtomicDouble(0.0);
|
||||||
BigDecimal lowerPrice = null;
|
BigDecimal lowerPrice = null;
|
||||||
for (TbProductSku item : tbProductSkus) {
|
for (TbProductSku item : tbProductSkus) {
|
||||||
@@ -381,11 +387,6 @@ public class ProductService {
|
|||||||
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
|
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
|
||||||
lowerPrice = item.getSalePrice();
|
lowerPrice = item.getSalePrice();
|
||||||
}
|
}
|
||||||
|
|
||||||
String specSnap = item.getSpecSnap();
|
|
||||||
// if (specSnap != null) {
|
|
||||||
// specSet.addAll(Arrays.asList(specSnap.split(",")));
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
//销量
|
//销量
|
||||||
it.setStockNumber(sum.intValue());
|
it.setStockNumber(sum.intValue());
|
||||||
@@ -394,32 +395,6 @@ public class ProductService {
|
|||||||
}
|
}
|
||||||
//售价
|
//售价
|
||||||
it.setLowPrice(lowerPrice);
|
it.setLowPrice(lowerPrice);
|
||||||
// String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
|
|
||||||
// if (tagSnap != null) {
|
|
||||||
// JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
|
||||||
// JSONObject snapJSON;
|
|
||||||
// JSONArray finalSnap = new JSONArray();
|
|
||||||
// for (Object snap : tagSnaps) {
|
|
||||||
// snapJSON = (JSONObject) snap;
|
|
||||||
// String values = snapJSON.getString("value");
|
|
||||||
// String finalValues = "";
|
|
||||||
// if (StrUtil.isNotBlank(values)) {
|
|
||||||
// String[] valueList = values.split(",");
|
|
||||||
// for (String value : valueList) {
|
|
||||||
// if (specSet.contains(value)) {
|
|
||||||
// finalValues = finalValues + (value) + ",";
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// if (StrUtil.isNotBlank(finalValues)) {
|
|
||||||
// finalValues = StrUtil.removeSuffix(finalValues, ",");
|
|
||||||
// snapJSON.put("value", finalValues);
|
|
||||||
// finalSnap.add(snapJSON);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //sku Result
|
|
||||||
// skuResult.setTagSnap(finalSnap.toJSONString());
|
|
||||||
// }
|
|
||||||
it.setProductSkuResult(skuResult);
|
it.setProductSkuResult(skuResult);
|
||||||
});
|
});
|
||||||
return products;
|
return products;
|
||||||
@@ -428,6 +403,47 @@ public class ProductService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkPauseSale(TbProduct tbProduct, List<TbProductSku> skus) {
|
||||||
|
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暂停
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!tbProduct.getTypeEnum().equals("sku")) {
|
||||||
|
if (skus.stream().anyMatch(sku -> sku.getStockNumber() != null && sku.getStockNumber() <= 0))
|
||||||
|
tbProduct.setIsPauseSale(Byte.parseByte("1"));//售罄 1暂停
|
||||||
|
} 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();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
TbProductSku tbProductSku = iterator.next();
|
||||||
|
List<TbProskuCon> proskuConList = tbProskuConMapper.selectByShopIdAndSkuIdAndProductId(Integer.valueOf(tbProductSku.getId()), Integer.valueOf(tbProductSku.getShopId()), Integer.valueOf(tbProductSku.getProductId()));
|
||||||
|
if (Objects.nonNull(proskuConList) && proskuConList.size() > 0) {
|
||||||
|
for (TbProskuCon proskuCon : proskuConList) {
|
||||||
|
if ("1".equals(proskuCon.getStatus())) {
|
||||||
|
TbConsInfo consInfo = tbConsInfoMapper.selectByPrimaryKey(proskuCon.getConInfoId());
|
||||||
|
if ("1".equals(consInfo.getIsCheck())) {
|
||||||
|
if (N.gt(proskuCon.getSurplusStock(), consInfo.getStockNumber().abs().subtract(consInfo.getStockConsume().abs()))) {
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isEmpty(skus)) {
|
||||||
|
tbProduct.setIsPauseSale(Byte.parseByte("1"));//售罄 1暂停
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Result queryProductSku(String code, String shopId, String productId, String spec_tag) {
|
public Result queryProductSku(String code, String shopId, String productId, String spec_tag) {
|
||||||
if (ObjectUtil.isEmpty(shopId) || ObjectUtil.isEmpty(productId)) {
|
if (ObjectUtil.isEmpty(shopId) || ObjectUtil.isEmpty(productId)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user