Просмотр исходного кода

Merge remote-tracking branch 'origin/release-201831-wangcz' into release-201831-wangcz

wangcz 7 лет назад
Родитель
Сommit
02ce10afce

+ 20 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/dao/ProductPrivateDao.java

@@ -8,9 +8,28 @@ import org.springframework.data.repository.query.Param;
 
 import java.util.List;
 
+/**
+ * 私有库信息
+ *
+ * @author US50
+ */
 public interface ProductPrivateDao  extends JpaRepository<ProductPrivate, Long>, JpaSpecificationExecutor<ProductPrivate> {
 
-    public List<ProductPrivate> findByPrId(Long prId);
+    /**
+     * 通过物料id查询私有库信息
+     *
+     * @param prId 物料id
+     * @return List<ProductPrivate>
+     */
+    List<ProductPrivate> findByPrId(Long prId);
+
+    /**
+     * 通过物料id统计私有库数量
+     *
+     * @param prId 物料id
+     * @return 私有库关联物料的数量
+     */
+    Integer countByPrId(Long prId);
 
     /**
      * 根据物料的id 获取私有信息

+ 9 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/Goods.java

@@ -1197,6 +1197,15 @@ public class Goods implements Serializable {
 		this.qtyPrice = qtyPrice;
 	}
 
+    /**
+     * 获取未处理的分段价格信息
+     *
+     * @return GoodsQtyPrice
+     */
+    public List<GoodsQtyPrice> getOriginalPrices() {
+	    return this.prices;
+    }
+
 	public List<GoodsQtyPrice> getPrices() {
 		if (CollectionUtils.isEmpty(prices) && StringUtils.hasText(qtyPrice)) {
 			return FastjsonUtils.fromJsonArray(qtyPrice, GoodsQtyPrice.class);

+ 30 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/Product.java

@@ -1063,4 +1063,34 @@ public class Product {
 		// 产品导入默认可销售
 		this.isSale = ((short) 1);
 	}
+
+    /**
+     * 将 V_ProductPrivate 赋值给Product
+     * @param productPrivate V_ProductPrivate
+     */
+	public Product setByPrivate(V_ProductPrivate productPrivate) {
+		this.packaging = productPrivate.getPackaging();
+        this.minPackQty = productPrivate.getMinPackQty();
+        this.cmpImg = productPrivate.getCmpImg();
+        this.enUU = SystemSession.getUser().getEnterprise().getUu();
+        this.brand = productPrivate.getBrand();
+        this.cmpCode = productPrivate.getCmpCode();
+        this.cmpUuId = productPrivate.getCmpUuId();
+        this.kind = productPrivate.getKind();
+        this.kindid = productPrivate.getKindid();
+        this.pcmpcode = productPrivate.getPcmpcode();
+        this.pbrand = productPrivate.getPbrand();
+        this.pbranden = productPrivate.getPbranden();
+        this.pbrandid = productPrivate.getPbrandid();
+        this.pbranduuid = productPrivate.getPbranduuid();
+        this.standard = productPrivate.getStandard();
+        this.createTime = new Date(System.currentTimeMillis());
+        this.produceDate = productPrivate.getProduceDate();
+        this.spec = productPrivate.getSpec();
+        this.prodName = productPrivate.getProdName();
+        this.id = productPrivate.getId();
+        // 产品导入默认可销售
+        this.isSale = ((short) 1);
+        return this;
+	}
 }

+ 14 - 6
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/GoodsServiceImpl.java

@@ -18,7 +18,11 @@ import com.uas.platform.b2c.core.constant.ShortConstant;
 import com.uas.platform.b2c.core.constant.SplitChar;
 import com.uas.platform.b2c.core.constant.Status;
 import com.uas.platform.b2c.core.support.SystemSession;
-import com.uas.platform.b2c.core.utils.*;
+import com.uas.platform.b2c.core.utils.DoubleArith;
+import com.uas.platform.b2c.core.utils.FastjsonUtils;
+import com.uas.platform.b2c.core.utils.NumberUtil;
+import com.uas.platform.b2c.core.utils.RegexConstant;
+import com.uas.platform.b2c.core.utils.StringUtilB2C;
 import com.uas.platform.b2c.external.erp.commodity.util.ModelConverter;
 import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
 import com.uas.platform.b2c.prod.commodity.constant.IntegerConstant;
@@ -36,8 +40,6 @@ import com.uas.platform.b2c.prod.commodity.model.CommodityInOutbound;
 import com.uas.platform.b2c.prod.commodity.model.Goods;
 import com.uas.platform.b2c.prod.commodity.model.GoodsFilter;
 import com.uas.platform.b2c.prod.commodity.model.GoodsHistory;
-import com.uas.platform.b2c.prod.commodity.dao.*;
-import com.uas.platform.b2c.prod.commodity.model.*;
 import com.uas.platform.b2c.prod.commodity.model.GoodsHistory.OperateType;
 import com.uas.platform.b2c.prod.commodity.model.GoodsInfo;
 import com.uas.platform.b2c.prod.commodity.model.GoodsModifyInfo;
@@ -98,7 +100,11 @@ import com.uas.platform.b2c.trade.support.CodeType;
 import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.b2c.trade.util.BoundedExecutor;
 import com.uas.platform.core.exception.IllegalOperatorException;
-import com.uas.platform.core.model.*;
+import com.uas.platform.core.model.Constant;
+import com.uas.platform.core.model.EncodingRulesConstant;
+import com.uas.platform.core.model.PageInfo;
+import com.uas.platform.core.model.PageParams;
+import com.uas.platform.core.model.Type;
 import com.uas.platform.core.persistence.criteria.CriterionExpression;
 import com.uas.platform.core.persistence.criteria.CriterionExpression.Operator;
 import com.uas.platform.core.persistence.criteria.LogicalExpression;
@@ -712,8 +718,10 @@ public class GoodsServiceImpl implements GoodsService {
         // 设置默认税率
         goods.setTaxRate();
         // 计算未税价格
-        goods.setWithOutTaxRMBPrice();
-        goods.setWithOutTaxUSDPrice();
+        if (CollectionUtils.isNotEmpty(goods.getOriginalPrices()) && null != goods.getOriginalPrices().get(0).getPrice()) {
+            goods.setWithOutTaxRMBPrice();
+            goods.setWithOutTaxUSDPrice();
+        }
         // 计算本批最小价格
         goods.setMaxAndMinPrice();
         goods.setStatus();

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

@@ -603,34 +603,39 @@ public class ProductServiceImpl implements ProductService {
                 }
                 StringUtilB2C.removeFromList(ids, productPerson.getProductId());
             }
-            //删除匹配结果信息
-            productMatchResultDao.deleteByProductids(ids);
-
-            //更新在售产品信息
-            List<Goods> goodses = goodsService.findByProductids(ids);
-            goodsService.deleteGoods(goodses);
-
-            //调整物料为禁用状态。
-            List<ProductPrivate> productPrivates = productPrivateService.findByPrIds(ids);
-            for (ProductPrivate productPrivate : productPrivates) {
-                productPrivate.setB2cEnabled(IntegerConstant.NO_SHORT);
-                StringUtilB2C.removeFromList(ids, productPrivate.getPrId());
-            }
-            ProductPrivate pPrivate = null;
-            for (Long id : ids) {
-                pPrivate = new ProductPrivate(id);
-                if (CollectionUtils.isEmpty(productPrivates)) {
-                    productPrivates = new ArrayList<>();
+            if (CollectionUtils.isNotEmpty(ids)) {
+                //删除匹配结果信息
+                productMatchResultDao.deleteByProductids(ids);
+
+                //更新在售产品信息
+                List<Goods> goodses = goodsService.findByProductids(ids);
+                goodsService.deleteGoods(goodses);
+
+                //调整物料为禁用状态。
+                List<ProductPrivate> productPrivates = productPrivateService.findByPrIds(ids);
+                for (ProductPrivate productPrivate : productPrivates) {
+                    productPrivate.setB2cEnabled(IntegerConstant.NO_SHORT);
+                    StringUtilB2C.removeFromList(ids, productPrivate.getPrId());
+                }
+                ProductPrivate pPrivate = null;
+                for (Long id : ids) {
+                    pPrivate = new ProductPrivate(id);
+                    if (CollectionUtils.isEmpty(productPrivates)) {
+                        productPrivates = new ArrayList<>();
+                    }
+                    productPrivates.add(pPrivate);
+                }
+                if (CollectionUtils.isNotEmpty(productPrivates)) {
+                    productPrivateDao.save(productPrivates);
                 }
-                productPrivates.add(pPrivate);
-            }
-            if (CollectionUtils.isNotEmpty(productPrivates)) {
-                productPrivateDao.save(productPrivates);
             }
+            int code = 1;
             if (StringUtils.isEmpty(message)) {
                 message = "删除成功";
+            } else {
+                code = CodeType.NOT_PERMIT.code();
             }
-            return ResultMap.success(message);
+            return new ResultMap(code, message);
         }
     }
 
@@ -2434,15 +2439,15 @@ public class ProductServiceImpl implements ProductService {
                 return criterionResultMap;
             }
         }
-        Product productInfo;
+        Product productInfo = new Product();
         CommodityInOutbound inOutbound = null;
         // 物料存在,更新
-        List<Product> existProducts = productDao.findProductByPcmpcodeAndPbrandenAndEnUU(product.getCmpCode(), product.getBrand(), enUU);
+        List<V_ProductPrivate> existProducts = v_productPrivateDao.findProductByPcmpcodeAndPbrandenAndEnUU(product.getCmpCode(), product.getBrand(), enUU);
         if (CollectionUtils.isNotEmpty(existProducts)) {
-            productInfo = existProducts.get(0);
+            productInfo = productInfo.setByPrivate(existProducts.get(0));
             // 用户填写库存量是需要做对应的出入库。如果新填写的库存数大于原库存数,做入库。否则做出库。
             inOutbound = recordInventory(product, existProducts.get(0));
-            BeanUtils.copyProperties(product, productInfo, Product.class);
+            BeanUtils.copyProperties(product, productInfo, "id");
         } else {
             // 物料不存在,新增操作
             productInfo = product;
@@ -2465,9 +2470,19 @@ public class ProductServiceImpl implements ProductService {
         // 设置库存信息
         assignmentGoods(goods, productInfo);
         // 保存到商城私有库
-        ProductPrivate productPrivate = new ProductPrivate(productInfo.getId());
-        productPrivate.setAttach(product.getAttachment());
-        productPrivateDao.save(productPrivate);
+        List<ProductPrivate> productPrivates = productPrivateDao.findByPrId(productInfo.getId());
+        if (CollectionUtils.isEmpty(productPrivates)) {
+            ProductPrivate productPrivate = new ProductPrivate(productInfo.getId());
+            productPrivate.setAttach(product.getAttachment());
+            productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
+            productPrivateDao.save(productPrivate);
+        } else  {
+            ProductPrivate productPrivate = productPrivates.get(0);
+            if (null == productPrivate.getB2cEnabled() || Objects.equals(IntegerConstant.NO_SHORT, productPrivate.getB2cEnabled())) {
+                productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
+                productPrivateDao.save(productPrivate);
+            }
+        }
         // 保存出入库信息
         if (null != inOutbound) {
             for (InOutboundDetail detail : inOutbound.getInOutboundDetails()) {
@@ -2563,7 +2578,7 @@ public class ProductServiceImpl implements ProductService {
      * @param product 前台传入的物料数据
      * @param existProduct 数据库存在的物料信息
      */
-    private CommodityInOutbound recordInventory(Product product, Product existProduct) {
+    private CommodityInOutbound recordInventory(Product product, V_ProductPrivate existProduct) {
         // 入库
         String type;
         CommodityInOutbound inOutbound;
@@ -2667,7 +2682,7 @@ public class ProductServiceImpl implements ProductService {
         if (CollectionUtils.isEmpty(productPersonList)) {
             ProductPerson productPerson = new ProductPerson(userUU, enUU, productInfo.getId());
             productPerson = productPersonDao.save(productPerson);
-            logger.info("个人物料", "新增个人物料", "通过卖家中心单个物料上传绑定个人物料", "", productPerson.getId());
+            logger.info("个人物料", "新增个人物料", "通过卖家中心单个物料上传绑定个人物料", productInfo.getProdNum(), productPerson.getId());
         }
     }
 
@@ -2686,6 +2701,41 @@ public class ProductServiceImpl implements ProductService {
                 goods.setProductid(productInfo.getId());
             }
         }
+        final Double minBuyQty = goods.getMinBuyQty();
+        // 判断前端传入的分段价格是默认的值还是填写错误
+        List<GoodsQtyPrice> qtyPrices = goods.getOriginalPrices();
+        int size = qtyPrices.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 == qtyPrices.get(i).getRMBPrice() && null == qtyPrices.get(i).getUSDPrice()) {
+                    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);

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

@@ -119,9 +119,6 @@ define(['app/app', 'jquery-uploadify'], function(app) {
       $scope.objError.kind = false
     }
 
-    $scope.RegulSpecBlur = function() {
-      $scope.objError.spec = false
-    }
     /**
      * 物料编辑品牌输入框失去焦点
      *
@@ -275,6 +272,7 @@ define(['app/app', 'jquery-uploadify'], function(app) {
       } else {
         $scope.Regul.reserve = num
       }
+      $scope.objError.reserve = false
     }
 
     $scope.setOnePrice = function(num) {
@@ -521,8 +519,14 @@ define(['app/app', 'jquery-uploadify'], function(app) {
         return;
       }
       if ($scope.Regul.reserve === '' || !$scope.Regul.reserve) {
-        toaster.pop('warning','提示', '规格为必填项')
-        $scope.objError.spec = true
+        toaster.pop('warning','提示', '库存数量不能为空')
+        $scope.objError.reserve = true
+        return;
+      }
+
+      if ($scope.Regul.reserve <=0) {
+        toaster.pop('warning','提示', '库存数量必须大于等于1')
+        $scope.objError.reserve = true
         return;
       }
 

+ 1 - 1
src/main/webapp/resources/view/vendor/forstore/single_entry.html

@@ -236,7 +236,7 @@
                    placeholder="请输入规格参数"
                    ng-model="Regul.spec"
                    ng-class="objError.spec ? 'danger' : '' "
-                   ng-blur="RegulSpecBlur()"
+
                    class="form-control inputText" maxlength="50"/>
           </div>
         </div>