浏览代码

更新分段价格填写判断方法

hejq 7 年之前
父节点
当前提交
f7fc168b0e

+ 34 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductServiceImpl.java

@@ -2689,6 +2689,40 @@ public class ProductServiceImpl implements ProductService {
                 goods.setProductid(productInfo.getId());
             }
         }
+        final Double minBuyQty = goods.getMinBuyQty();
+        // 判断前端传入的分段价格是默认的值还是填写错误
+        int size = goods.getOriginalPrices().size();
+        if (size == 1) {
+            GoodsQtyPrice qtyPrice = goods.getOriginalPrices().get(0);
+            // 前端设置的默认值,不用保存
+            if (null == qtyPrice.getPrice()) {
+                goods.setQtyPrice("");
+            }
+        } else if (size > 1) {
+            StringBuffer errMsg = new StringBuffer();
+            for (int i = 0; i < size; i++) {
+                if (null == goods.getOriginalPrices().get(i).getPrice()) {
+                    jointErrMsg(errMsg, String.valueOf(i + 1));
+                }
+            }
+            if (!StringUtils.isEmpty(errMsg.toString())) {
+                throw new IllegalOperatorException("第" + errMsg.toString() + "价格未填写");
+            }
+        }
+        if (!StringUtils.isEmpty(goods.getQtyPrice())) {
+            if (CollectionUtils.isNotEmpty(goods.getOriginalPrices())) {
+                goods.getOriginalPrices().forEach(subPrice -> {
+                    // 分段数量不能超过最大数量
+                    Double endQty = NumberUtil.compare(subPrice.getEnd(), DoubleConstant.maxReserve) == 1 ? DoubleConstant.maxReserve : subPrice.getEnd();
+                    subPrice.setEnd(endQty);
+
+                    // 起始数量不能大于最小订购数
+                    Double startQty = NumberUtil.compare(minBuyQty, subPrice.getStart()) == 1 ? subPrice.getStart() : minBuyQty;
+                    subPrice.setStart(startQty);
+                });
+            }
+            goods.setQtyPrice(JSON.toJSONString(goods.getOriginalPrices()));
+        }
         goodsService.setGoodsDefault(goods);
         boolean autoPublish = goods.getAutoPublish() == null ? true : goods.getAutoPublish();
         goods.setAutoPublish(autoPublish);

+ 3 - 3
src/main/webapp/resources/js/vendor/controllers/forstore/single_entry.js

@@ -520,9 +520,9 @@ define(['app/app', 'jquery-uploadify'], function(app) {
         $scope.objError.pcmpcode = true
         return;
       }
-      if ($scope.Regul.reserve === '' || !$scope.Regul.reserve) {
-        toaster.pop('warning','提示', '为必填项')
-        $scope.objError.reserve = true
+      if ($scope.Regul.spec === '' || !$scope.Regul.spec) {
+        toaster.pop('warning','提示', '规格为必填项')
+        $scope.objError.spec = true
         return;
       }