diff --git a/ms-biz/src/main/java/com/ms/api/bo/MoveShopSettingBO.java b/ms-biz/src/main/java/com/ms/api/bo/MoveShopSettingBO.java index fa8ce9ff..ea44a3a1 100644 --- a/ms-biz/src/main/java/com/ms/api/bo/MoveShopSettingBO.java +++ b/ms-biz/src/main/java/com/ms/api/bo/MoveShopSettingBO.java @@ -71,7 +71,7 @@ public class MoveShopSettingBO { /** * price_tail */ - private int priceTail; + private Integer priceTail; /** * price_decimal diff --git a/ms-biz/src/main/java/com/ms/api/bo/SkuDetailBO.java b/ms-biz/src/main/java/com/ms/api/bo/SkuDetailBO.java index 15552789..3604fe0f 100644 --- a/ms-biz/src/main/java/com/ms/api/bo/SkuDetailBO.java +++ b/ms-biz/src/main/java/com/ms/api/bo/SkuDetailBO.java @@ -4,6 +4,7 @@ import lombok.Data; @Data public class SkuDetailBO { + private Long skuId; private double price; private String code; private int stockNum; diff --git a/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java b/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java index fb6224b7..900d8ca5 100644 --- a/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java +++ b/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java @@ -1483,20 +1483,115 @@ public class ProcessProductPublishTaskService extends TaskBaseService { if (price == null) { price = 0; } - + String cnaliDsDetailId = queueMsg.getCnaliDsDetailId(); + Double hasImportPrice = queueMsg.getHasImportPrice(); //skuMap = appendSkuCode(moveBaseData, queueMsg, skuMap, itemNum); // TODO 跳过 Map skuList = buildSkuListAndSkuImages(mSkus.getJSONObject("skuMap"), mSkus.getJSONObject("colorMap"), mSkus.getJSONObject("sizeMap")); -// skuList = buildSkuListAndSkuImages(mSkus.getJSONObject() ['skuMap'], mSkus['colorMap'], mSkus['sizeMap'], condition, (price > 0 ? price : queueMsg.getPrice()), queueMsg.getShopId()); -// skuList = calSkuPriceByCondition($isFastMode, $skuList, $condition['price'], $moveBaseData, $cnaliDsDetailId, $hasImportPrice); -// updateSkuMinPriceInfo = getUpdateSkuMinPriceInfo($condition['price'], $skuList); + skuList = calSkuPriceByCondition(isFastMode, skuList, condition.getPrice(), moveBaseData, cnaliDsDetailId, hasImportPrice); + List updateSkuMinPriceInfo = getUpdateSkuMinPriceInfo(condition.getPrice(), skuList); mSkus.put("skus", skuMap); StrObjMap result = new StrObjMap(); result.put("skuList", skuList); -// result.put("updateSkuMinPriceInfo", ""); + result.put("updateSkuMinPriceInfo", updateSkuMinPriceInfo); return result; } + private List getUpdateSkuMinPriceInfo(JSONObject priceCondition, Map skuList) { + if (!priceCondition.containsKey("skuMinPriceStatus") || !priceCondition.get("skuMinPriceType").equals(MoveConst.skuMinPriceTypeUpdate)) { + return new ArrayList<>(); + } + return skuList.values().stream().filter(x -> ObjectUtil.isNotNull(x.getUpdateSkuMinPriceInfo())).map(x -> (StrObjMap) x.getUpdateSkuMinPriceInfo()).collect(Collectors.toList()); + } + + private Map calSkuPriceByCondition(int isFastMode, Map skuList, JSONObject priceCondition, JSONObject moveBaseData, String cnaliDsDetailId, Double hasImportPrice) { + double maxPrice = 0; + double minPrice = 0; + int skuTotal = skuList.size(); + + Integer addSkuPriceSource = priceCondition.getInteger("addSkuPriceSource"); + double sourceMinPrice = 0; + double sourcePostFeePriceAddValue = (double) priceCondition.get("sourcePostFeePriceAddValue"); + for (Map.Entry stringSkuDetailBOEntry : skuList.entrySet()) { + SkuDetailBO skuDetail = stringSkuDetailBOEntry.getValue(); + String isSkuMinPrice = skuDetail.getIsSkuMinPrice(); + skuDetail.setIsSkuMinPrice(null); + if (isFastMode != 0 && (ObjectUtil.isNull(hasImportPrice) || hasImportPrice == 0)) { + double skuDetailPrice = skuDetail.getPrice(); + double newPrice = moveService.processConditionPrice(JSON.toJavaObject(priceCondition, MoveShopSettingBO.class), skuDetailPrice); + sourceMinPrice = ((sourceMinPrice < skuDetailPrice) && (sourceMinPrice > 0)) ? sourceMinPrice : skuDetailPrice; + if (StrUtil.isNotBlank(isSkuMinPrice)) { + if (addSkuPriceSource.equals(MoveConst.skuMinPriceSkuPriceSourceFromSource)) { + newPrice = skuDetailPrice; + } + MoveShopSettingBO moveShopSettingBO = new MoveShopSettingBO(); + moveShopSettingBO.setPricePercent(priceCondition.getBigDecimal("addSkuMinPricePricePercent")); + moveShopSettingBO.setPriceAdd(priceCondition.getBigDecimal("addSkuMinPricePriceAdd")); + moveShopSettingBO.setPriceSub(priceCondition.getBigDecimal("addSkuMinPricePriceSub")); + moveShopSettingBO.setPriceTail(priceCondition.getInteger("addSkuMinPricePriceTail")); + moveShopSettingBO.setPriceDecimal(priceCondition.getString("addSkuMinPricePriceDecimal")); + moveShopSettingBO.setPriceDecimalDiyValue(priceCondition.getString("addSkuMinPricePriceDecimalDiyValue")); + newPrice = moveService.processConditionPrice(moveShopSettingBO, newPrice); + } + skuDetail.setPrice(newPrice); + maxPrice = Math.max(maxPrice, newPrice); + minPrice = ((minPrice < newPrice) && (minPrice > 0)) ? minPrice : newPrice; + } + } + + if (isFastMode != 0 && (ObjectUtil.isNull(hasImportPrice) || hasImportPrice != 0) && (priceCondition.containsKey("skuMinPriceType") && Objects.equals(priceCondition.getInteger("skuMinPriceType"), MoveConst.skuMinPriceTypeUpdate))) { + + for (Map.Entry entry : skuList.entrySet()) { + String skuPropStr = entry.getKey(); + SkuDetailBO skuDetail = entry.getValue(); + if (skuDetail.getPrice() == minPrice) { + if (Objects.equals(priceCondition.getInteger("updateSkuPriceSource"), MoveConst.skuMinPriceSkuPriceSourceFromSource)) { + minPrice = sourceMinPrice; + } + MoveShopSettingBO moveShopSettingBO = new MoveShopSettingBO(); + moveShopSettingBO.setPricePercent(priceCondition.getBigDecimal("addSkuMinPricePricePercent")); + moveShopSettingBO.setPriceAdd(priceCondition.getBigDecimal("addSkuMinPricePriceAdd")); + moveShopSettingBO.setPriceSub(priceCondition.getBigDecimal("addSkuMinPricePriceSub")); + moveShopSettingBO.setPriceTail(priceCondition.getInteger("addSkuMinPricePriceTail")); + moveShopSettingBO.setPriceDecimal(priceCondition.getString("addSkuMinPricePriceDecimal")); + moveShopSettingBO.setPriceDecimalDiyValue(priceCondition.getString("addSkuMinPricePriceDecimalDiyValue")); + double newPrice = moveService.processConditionPrice(moveShopSettingBO, minPrice); + + if (priceCondition.containsKey("updateSkuMinPriceQuantity") && priceCondition.getInteger("updateSkuMinPriceQuantity") > 0) { + skuDetail.setStockNum(priceCondition.getInteger("updateSkuMinPriceQuantity")); + } + skuDetail.setPrice(newPrice); + StrObjMap temp = new StrObjMap(); + temp.put("skuId", skuDetail.getSkuId()); + temp.put("skuPropStr", skuPropStr); + skuDetail.setUpdateSkuMinPriceInfo(temp); + break; + } + } + } + skuList = processSourcePostFeePrice(isFastMode, sourcePostFeePriceAddValue, skuList, cnaliDsDetailId, moveBaseData); + return skuList; + } + + private Map processSourcePostFeePrice(int isFastMode, double sourcePostFeePriceAddValue, Map skuList, String cnaliDsDetailId, JSONObject moveBaseData) { + if (isFastMode != 0) { + return skuList; + } + + if (sourcePostFeePriceAddValue <= 0) { + return skuList; + } + + if (!(Boolean) moveBaseData.get("hasPostFee") && StrUtil.isBlank(cnaliDsDetailId)) { + return skuList; + } + for (Map.Entry entry : skuList.entrySet()) { + double price = entry.getValue().getPrice(); + entry.getValue().setPrice(price + sourcePostFeePriceAddValue); + } + return skuList; + } + public Map buildSkuListAndSkuImages(JSONObject skuMap, JSONObject colorMap, JSONObject sizeMap) { double defaultPrice = getSkuDefaultPrice(skuMap); Map skuList = new HashMap<>();