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

调整ERP批量上架的逻辑,批量上架的库存-在售数量的库存为可上架数量

yujia 8 лет назад
Родитель
Сommit
da159d35ca

+ 15 - 0
src/main/java/com/uas/platform/b2c/core/utils/StringUtilB2C.java

@@ -258,4 +258,19 @@ public class StringUtilB2C {
 	public static String getStr(Object obj) {
 		return StringUtils.isEmpty(obj) ? "" : String.valueOf(obj);
  	}
+
+	/**
+	 * 比较两个字符串是否相等
+	 *
+	 * @param a 字符串 a
+	 * @param b 字符串 b
+	 * @return
+	 */
+ 	public static Boolean equals(String a, String b) {
+		if (a == null) {
+			return b == null;
+		} else {
+			return a.equals(b);
+		}
+	}
 }

+ 32 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/model/Goods.java

@@ -1,9 +1,12 @@
 package com.uas.platform.b2c.prod.commodity.model;
 
 import com.alibaba.fastjson.annotation.JSONField;
-import com.uas.platform.b2c.prod.product.brand.modal.BrandInfo;
 import com.uas.platform.b2c.core.utils.FastjsonUtils;
 import com.uas.platform.b2c.core.utils.NumberUtil;
+import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
+import com.uas.platform.b2c.prod.product.brand.modal.BrandInfo;
+import com.uas.platform.b2c.trade.support.CodeType;
+import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import org.apache.commons.collections.CollectionUtils;
 import org.codehaus.jackson.annotate.JsonIgnore;
@@ -1588,4 +1591,32 @@ public class Goods implements Serializable {
 		g.setUuid(product.getCmpUuId());
 		return g;
 	}
+
+	/**
+	 * 根据给定的最小购买量和最小包装量,做微调。
+	 * @param minPackQty 最小包装量
+	 * @param minBuyQty 最小起订量
+	 * @return
+	 */
+	public ResultMap adjustMinBuyAndMinPack(Double minPackQty, Double minBuyQty) {
+		int minPackQtyCom = NumberUtil.compare(minPackQty, DoubleConstant.zero);
+		int minBuyQtyCom = NumberUtil.compare(minBuyQty, DoubleConstant.zero);
+		if (minPackQtyCom == 0 && minBuyQtyCom == 0) {
+			return new ResultMap(CodeType.NOT_COMPLETE_INFO, "上架必填信息缺失");
+		} else {
+			if (minPackQtyCom == 0 || minBuyQtyCom == 0) {
+				minPackQty = minBuyQtyCom == 0 ? minPackQty : minBuyQty;
+				minBuyQty = minPackQty;
+			}
+			double remainder = minBuyQty % minPackQty;
+			minBuyQty = NumberUtil.sub(minBuyQty, remainder);
+			int k = NumberUtil.compare(minBuyQty, minPackQty);
+			if (k < 0) {
+				minBuyQty = minPackQty;
+			}
+		}
+		this.minPackQty = minPackQty;
+		this.minBuyQty = minBuyQty;
+		return new ResultMap(CodeType.OK, "成功");
+	}
 }

+ 14 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/GoodsQtyPrice.java

@@ -1,6 +1,8 @@
 package com.uas.platform.b2c.prod.commodity.model;
 
 import com.uas.api.b2c_erp.seller.model.GoodsQtyPriceUas;
+import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
+import com.uas.platform.b2c.prod.commodity.constant.StringConstant;
 
 /**
  * 商品分段数量价格
@@ -143,6 +145,18 @@ public class GoodsQtyPrice {
 		return uasdt;
 	}
 
+	public static GoodsQtyPrice createGoodsQtyPrice(String currency, Double start, Double end, Double price) {
+		GoodsQtyPrice qtyPrice = new GoodsQtyPrice();
+		qtyPrice.setStart(start);
+		qtyPrice.setEnd(end);
+		if (currency.equals(StringConstant.RMB)) {
+			qtyPrice.setRMBPrice(price);
+		} else {
+			qtyPrice.setUSDPrice(price);
+		}
+		return qtyPrice;
+	}
+
 	@Override
 	public String toString() {
 		return "GoodsQtyPrice{" +

+ 19 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/service/ProductService.java

@@ -200,4 +200,23 @@ public interface ProductService {
      * @return
      */
     ResultMap batchPutOn(Integer standard, String ids);
+
+
+    /**
+     * 计算还剩多少空闲库存
+     *
+     * @param erpReserve erp 的空闲库存
+     * @param goodses1 需要减去 库存的的goods 的
+     * @return
+     */
+    Double getGoodsReserveByErpReserve(Double erpReserve, List<Goods> goodses1);
+
+
+    /**
+     * 获取订单中还未上传到UAS的数量
+     *
+     * @param batches 批次信息
+     * @return
+     */
+    Double getQtyInOrderToBeUpload(List<String> batches);
 }

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

@@ -1330,9 +1330,6 @@ public class GoodsServiceImpl implements GoodsService {
         if (nowGoods.getSourceId() != null) {
             return new ResultMap(CodeType.NOT_PERMIT.code(), "该库存的信息属于UAS上架,平台不能修改。");
         }
-        if (nowGoods.getReserve().doubleValue() != goods.getOldReserve().doubleValue()) {
-            return new ResultMap(CodeType.INFO_UPDATE.code(), "该库存的信息已经被修改了,请刷新界面之后重新操作。");
-        }
         if (StringUtils.isEmpty(goods.getTag())) {
             return new ResultMap(CodeType.NOT_PERMIT.code(), "产品自定义标签必须填写");
         }
@@ -1409,6 +1406,20 @@ public class GoodsServiceImpl implements GoodsService {
         } else {
             throw new IllegalOperatorException("您选择的销售方式不存在");
         }
+        Product product = null;
+        if(goods.getProductid() != null) {
+            product = productDao.findOne(goods.getProductid());
+            if(product != null) {
+                if (StringConstant.ERP.equals(product.getSourceApp())) {
+                    List<Goods> goodses = goodsDao.findByProductId(product.getId());
+                    Double reserve = productService.getGoodsReserveByErpReserve(product.getErpReserve(), goodses);
+                    reserve = NumberUtil.sub(reserve, goods.getReserve());
+                    if (NumberUtil.compare(reserve, DoubleConstant.zero) < 0) {
+                        throw new IllegalOperatorException("总在售库存量超过空闲库存量");
+                    }
+                }
+            }
+        }
         setGoodsDefault(goods);
         ResultMap resultMap = checkGoods(goods);
         if (resultMap.getCode() != CodeType.OK.code()) {
@@ -1418,21 +1429,18 @@ public class GoodsServiceImpl implements GoodsService {
         //	updateGoodTransactional(goods);
         GoodsHistory goodsHistory = goodsHistoryService.converTGoodsHist(goods, OperateType.ADD_GOODS.getPhrase());
         Goods persistGoods = goodsDao.save(goods);
-        goodsHistoryDao.save(goodsHistory);
-        if(persistGoods.getProductid() != null) {
-            Product product = productDao.findOne(persistGoods.getProductid());
-            if(product != null) {
-                ProductPrivate productPrivate = releaseProductByBatchService.findByPrId(product.getId());
-                if (productPrivate == null) {
-                    productPrivate = new ProductPrivate();
-                }
-                Integer count = productPrivate.getBatchCount();
-                productPrivate.setBatchCount(count ==
-                        null ? 1 :
-                        ++count);
-                productPrivateDao.save(productPrivate);
+        if(product != null) {
+            ProductPrivate productPrivate = releaseProductByBatchService.findByPrId(product.getId());
+            if (productPrivate == null) {
+                productPrivate = new ProductPrivate();
             }
+            Integer count = productPrivate.getBatchCount();
+            productPrivate.setBatchCount(count ==
+                    null ? 1 :
+                    ++count);
+            productPrivateDao.save(productPrivate);
         }
+        goodsHistoryDao.save(goodsHistory);
         return ResultMap.success(persistGoods);
     }
 
@@ -1477,6 +1485,22 @@ public class GoodsServiceImpl implements GoodsService {
         } else {
             throw new IllegalOperatorException("您选择的销售方式不存在");
         }
+
+        if(nowGoods.getProductid() != null) {
+            Product product = productDao.findOne(nowGoods.getProductid());
+            if(product != null) {
+                if (StringConstant.ERP.equals(product.getSourceApp())) {
+                    List<Goods> goodses = goodsDao.findByProductId(product.getId());
+                    Double reserve = productService.getGoodsReserveByErpReserve(product.getErpReserve(), goodses);
+                    reserve = NumberUtil.add(reserve, nowGoods.getReserve());
+                    reserve = NumberUtil.sub(reserve, oldGoods.getReserve());
+                    if (NumberUtil.compare(reserve, DoubleConstant.zero) < 0) {
+                        throw new IllegalOperatorException("总在售库存量超过空闲库存量");
+                    }
+                }
+            }
+        }
+
         // 设置货到香港,货到大陆的延长时间
         setB2CDelayTime(nowGoods);
 

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

@@ -8,6 +8,7 @@ import com.uas.platform.b2c.core.config.SysConf;
 import com.uas.platform.b2c.core.constant.IntegerConstant;
 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.FastjsonUtils;
 import com.uas.platform.b2c.core.utils.NumberUtil;
@@ -17,6 +18,7 @@ import com.uas.platform.b2c.prod.commodity.dao.*;
 import com.uas.platform.b2c.prod.commodity.model.*;
 import com.uas.platform.b2c.prod.commodity.service.*;
 import com.uas.platform.b2c.prod.commodity.type.ProductConstant;
+import com.uas.platform.b2c.prod.commodity.util.GoodsUtil;
 import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
 import com.uas.platform.b2c.prod.product.brand.modal.Brand;
 import com.uas.platform.b2c.prod.product.component.dao.ComponentDao;
@@ -45,7 +47,6 @@ import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.model.Constant;
 import com.uas.platform.core.model.PageInfo;
-import com.uas.platform.core.model.Status;
 import com.uas.platform.core.model.Type;
 import com.uas.platform.core.persistence.criteria.LogicalExpression;
 import com.uas.platform.core.persistence.criteria.PredicateUtils;
@@ -1382,7 +1383,6 @@ public class ProductServiceImpl implements ProductService {
         Long uu = SystemSession.getUser().getEnterprise().getUu();
         ResultMap registerAddress = enterpriseService.getCurrencyByRegisterAddress();
         String currency = null;
-        List<Goods> goodsList = new ArrayList<>();
         Set<String> uuids = new HashSet<>();
         if (registerAddress.getCode() != CodeType.OK.code()) {
             currency = StringConstant.RMB;
@@ -1405,11 +1405,11 @@ public class ProductServiceImpl implements ProductService {
         String sql = null;
         Map<String, Object> map = new HashMap<>();
         if ((prIdLong != null) && (prIdLong.size() != 0)) {
-            sql = "select p.pr_id from products p left join product$private pp on pp.pr_id = p.pr_id where ifnull(pp.pr_batchcount, 0) = 0 and p.pr_sourceapp = 'ERP' and p.pr_reserve <> 0 and ifnull(pp.pr_b2cenabled, 0) = 1 and p.pr_id in (:ids) and p.pr_id not in (select DISTINCT go_productid from trade$goods where  go_productid is not null);";
+            sql = "select p.pr_id from products p left join product$private pp on pp.pr_id = p.pr_id where p.pr_sourceapp = 'ERP' and p.pr_reserve <> 0 and ifnull(pp.pr_b2cenabled, 0) = 1 and p.pr_id in (:ids);";
             map.put("ids", prIdLong);
         } else {
             // 暂时不会进入当前循环,速度比较低
-            sql = "select p.pr_id from products p left join product$private pp on pp.pr_id = p.pr_id where ifnull(pp.pr_batchcount, 0) = 0 and p.pr_sourceapp = 'ERP' and p.pr_reserve <> 0 and ifnull(pp.pr_b2cenabled,0) = 1 and ifnull(p.pr_standard, 0) = (:standard) and p.pr_enuu = (:enuu) and p.pr_id not in (select DISTINCT go_productid from trade$goods where  go_productid is not null);";
+            sql = "select p.pr_id from products p left join product$private pp on pp.pr_id = p.pr_id where p.pr_sourceapp = 'ERP' and p.pr_reserve <> 0 and ifnull(pp.pr_b2cenabled, 0) = 1 and ifnull(p.pr_standard, 0) = (:standard) and p.pr_enuu = (:enuu);";
             map.put("enuu", uu);
             map.put("standard", standard);
         }
@@ -1429,16 +1429,19 @@ public class ProductServiceImpl implements ProductService {
             }
         }
         List<Goods> goodses = productDetailPutOn(sourceAppNotPutOn, storeName, storeid, currency, property);
-        goodsList.addAll(goodses);
+        if (CollectionUtils.isEmpty(goodses)) {
+            return new ResultMap(CodeType.OK.code(), "没有可上架的信息,产品上架必填字段为空或可上架数量为0");
+        }
         List<Goods> result = new ArrayList<Goods>();
-        goodsService.publishERPProductByBatch(goodsList, uuids, result);
+        goodsService.publishERPProductByBatch(goodses, uuids, result);
         List<Long> prids = new ArrayList<>();
         for (Goods goods : result) {
             prids.add(goods.getProductid());
         }
         List<ProductPrivate> productPrivates = productPrivateDao.findByPrIds(prids);
         for (ProductPrivate productPrivate : productPrivates) {
-            productPrivate.setBatchCount(IntegerConstant.YES_SHORT);
+            Integer count = productPrivate.getBatchCount() == null ? 0 : productPrivate.getBatchCount();
+            productPrivate.setBatchCount(count + IntegerConstant.YES_SHORT);
         }
         productPrivateDao.save(productPrivates);
         for (String uuid : uuids) {
@@ -1450,9 +1453,14 @@ public class ProductServiceImpl implements ProductService {
         }
         if ((sourceAppNotPutOn.size() - result.size()) != 0) {
             if (!StringUtils.isEmpty(message)) {
-                message = message +  " ,";
+                message = message +  ",";
+            }
+            if (StringUtils.isEmpty(ids)) {
+               // message = message + "失败" + (sourceAppNotPutOn.size() - result.size()) + "个,原因:产品必填字段为空或可上架数量为0";
+            } else {
+                message = message + "失败" + (ids.split(SplitChar.COMMA).length - result.size()) + "个,原因:产品必填字段为空或可上架数量为0";
             }
-            message = "失败" + (sourceAppNotPutOn.size()-  result.size()) + "个, 失败原因:产品上架必填字段为空, 请完善";
+
         }
         return new ResultMap(CodeType.OK.code(), message);
     }
@@ -1505,19 +1513,10 @@ public class ProductServiceImpl implements ProductService {
         g.setMaxDelivery(property.getMaxDelivery());
         g.setMinDelivery(property.getMinDelivery());
         g.setProdNum(product.getProdNum());
-        List<String> tags = goodsDao.findTagByProductid(product.getId());
-        Integer i = 1;
-        String tag = StringConstant.SELF_TAG;
-        while(tags.contains(tag + i)) {
-            i++;
-        }
-        g.setTag(tag + i);
         g.setBreakUp(Boolean.FALSE);
-        g.setReserve(product.getErpReserve());
+
         String packaging = (detail == null || detail.getPackaging() == null) ? product.getPackaging(): detail.getPackaging();
-        if (packaging == null) {
-            packaging = StringConstant.DEFAULTPACKAGING;
-        }
+        packaging =  packaging == null ? StringConstant.DEFAULTPACKAGING : packaging;
         g.setPackaging(packaging);
 
         String produceDate = (detail == null || detail.getProduceDate() == null) ? product.getProduceDate() : detail.getProduceDate();
@@ -1525,38 +1524,90 @@ public class ProductServiceImpl implements ProductService {
 
         Double minPackQty = (detail == null || detail.getMinPackQty() == null) ? product.getMinPackQty() : detail.getMinPackQty();
         Double minBuyQty = detail != null ? detail.getMinBuyQty() : null;
-        int minPackQtyCom = NumberUtil.compare(minPackQty, DoubleConstant.zero);
-        int minBuyQtyCom = NumberUtil.compare(minBuyQty, DoubleConstant.zero);
-        if (minPackQtyCom == 0 && minBuyQtyCom == 0) {
-            return new ResultMap(CodeType.NOT_COMPLETE_INFO, "上架必填信息缺失");
-        } else {
-            if (minPackQtyCom == 0 || minBuyQtyCom == 0) {
-                minPackQty = minBuyQtyCom == 0 ? minPackQty : minBuyQty;
-                minBuyQty = minPackQty;
-            }
-            double remainder = minBuyQty % minPackQty;
-            minBuyQty = NumberUtil.sub(minBuyQty, remainder);
-            int k = NumberUtil.compare(minBuyQty, minPackQty);
-            if (k < 0) {
-                minBuyQty = minPackQty;
-            }
+        ResultMap resultMap = g.adjustMinBuyAndMinPack(minPackQty, minBuyQty);
+        if (resultMap.getCode() != CodeType.OK.code()) {
+            return resultMap;
         }
-        g.setMinPackQty(minPackQty);
-        g.setMinBuyQty(minBuyQty);
+
         double price = NumberUtil.mul(detail.getPrice(), property.getFluctuateRate());
         price = NumberUtil.fractionNumCeil(price, IntegerConstant.PRICE_FRACTION);
+        if (NumberUtil.compare(price, DoubleConstant.zero) < 1) {
+            return new ResultMap(CodeType.NOT_PERMIT.code(), "单价为0", null);
+        }
         List<GoodsQtyPrice> list = new ArrayList<>();
-        GoodsQtyPrice price1 = new GoodsQtyPrice();
-        price1.setStart(g.getMinBuyQty());
-        price1.setEnd(DoubleConstant.maxReserve);
-        if (currency.equals(StringConstant.RMB)) {
-            price1.setRMBPrice(price);
+        GoodsQtyPrice qtyPrice = GoodsQtyPrice.createGoodsQtyPrice(g.getCurrencyName(), g.getMinBuyQty(), DoubleConstant.maxReserve, price);
+        list.add(qtyPrice);
+        g.setPrices(list);
+
+        List<Goods> goodses1 = goodsDao.findByProductId(g.getProductid());
+        Goods sku = GoodsUtil.sameSKU(goodses1, g);
+        GoodsUtil.setTag(goodses1, sku);
+
+        Double erpReserve = getGoodsReserveByErpReserve(product.getErpReserve(), goodses1);
+        if (NumberUtil.compare(erpReserve, DoubleConstant.zero) > 0) {
+            if (sku.getStatus() == null || sku.getStatus().intValue() == Status.REMOVED.value()) {
+                sku.setReserve(erpReserve);
+            } else {
+                sku.setReserve(NumberUtil.add(sku.getReserve(), erpReserve));
+            }
+            return new ResultMap(CodeType.OK.code(), "成功", sku);
         } else {
-            price1.setUSDPrice(price);
+            return new ResultMap(CodeType.NOT_PERMIT.code(), "没有可上架的数量", null);
         }
-        list.add(price1);
-        g.setPrices(list);
-        return new ResultMap(CodeType.OK.code(), "成功", g);
+    }
+
+    /**
+     * 计算还剩多少空闲库存
+     *
+     * @param erpReserve erp 的空闲库存
+     * @param goodses1 需要减去 库存的的goods 的
+     * @return
+     */
+    @Override
+    public Double getGoodsReserveByErpReserve(Double erpReserve, List<Goods> goodses1) {
+        List<String> batches = new ArrayList<>();
+        // 目前只统计goods 在售的库存,下架和保存状态的不做调整
+        for (Goods goods : goodses1) {
+            if (goods.getStatus().intValue() == Status.UNAVAILABLE.value() || goods.getStatus().intValue() == Status.AVAILABLE.value()) {
+                erpReserve = NumberUtil.sub(erpReserve, goods.getReserve());
+            }
+            //batches.add(goods.getBatchCode());
+        }
+        //Double qty = getQtyInOrderToBeUpload(batches);
+        // erpReserve = NumberUtil.sub(erpReserve, qty);
+        return erpReserve;
+    }
+
+    /**
+     * 获取订单中还未上传到UAS的数量
+     *
+     * @param batches 批次信息
+     * @return
+     */
+    @Override
+    public Double getQtyInOrderToBeUpload(List<String> batches) {
+        if (CollectionUtils.isEmpty(batches)) {
+            return DoubleConstant.zero;
+        } else {
+            List<Integer> statuses = new ArrayList<>();
+            statuses.add(Status.TOBEPAID.value());
+            statuses.add(Status.TOBEPAIDAGAGIN.value());
+            statuses.add(Status.CANCELTOBECONFIRMED.value());
+            Double orderDetailQty = orderDetailDao.getgetSumQtyByBatchcodesAndStatus(batches, statuses);
+
+            List<Integer> puStatus = new ArrayList<>();
+            puStatus.add(Status.CONFIRMED.value());
+            puStatus.add(Status.PAID.value());
+            //获取平台还未上传的销售单
+            String sql = "select sum(detail_number) from trade$purchase p left join trade$purchase_detail pd on p.id = pd.purchase_id where p.pu_sendstatus = 202 and pd.go_batch in (:batches) and pd.detail_status in (:status);";
+            HashMap<String, Object> map = new HashMap<>();
+            map.put("batches", batches);
+            map.put("status", puStatus);
+            Double purchaseDetailQty = namedParameterJdbcTemplate.queryForObject(sql, map, Double.class);
+            double qty = NumberUtil.add(orderDetailQty, purchaseDetailQty);
+            return qty;
+        }
+
     }
 }
 

+ 75 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/util/GoodsUtil.java

@@ -1,7 +1,12 @@
 package com.uas.platform.b2c.prod.commodity.util;
 
+import com.uas.platform.b2c.core.utils.NumberUtil;
+import com.uas.platform.b2c.core.utils.StringUtilB2C;
+import com.uas.platform.b2c.prod.commodity.constant.StringConstant;
+import com.uas.platform.b2c.prod.commodity.model.Goods;
 import com.uas.platform.b2c.prod.commodity.model.GoodsQtyPrice;
 import com.uas.platform.b2c.trade.order.StringConstant.Currency;
+import com.uas.platform.core.exception.IllegalOperatorException;
 import org.apache.commons.collections.CollectionUtils;
 
 import java.util.List;
@@ -140,4 +145,74 @@ public class GoodsUtil {
 		}
 		return true;
 	}
+
+	/**
+	 * 判断是否在数据库存在同一个sku产品, 如果存在则返回存在的Goods信息,如果不存在则返回当前的goods
+	 *
+	 * @param list 数据存中的 产品信息
+	 * @param g 新的产品信息
+	 * @return goods 返回当前需要操作的信息
+	 */
+	public static Goods sameSKU(List<Goods> list, Goods g) {
+		if (g == null) {
+			throw new IllegalOperatorException("传入的信息为空");
+		}
+		if (CollectionUtils.isEmpty(list)) {
+			return g;
+		} else {
+			for (Goods goods : list) {
+				if (!StringUtilB2C.equals(g.getProduceDate(), goods.getProduceDate())) {
+					continue;
+				}
+				if (!StringUtilB2C.equals(g.getPackaging(), goods.getPackaging())) {
+					continue;
+				}
+				if (!StringUtilB2C.equals(g.getUnit(), goods.getUnit())) {
+					continue;
+				}
+				if (NumberUtil.compare(g.getMinPackQty(), goods.getMinPackQty()) != 0) {
+					continue;
+				}
+				if (NumberUtil.compare(g.getMinBuyQty(), goods.getMinBuyQty()) != 0) {
+					continue;
+				}
+				if (!g.getMaxDelivery().equals(goods.getMaxDelivery())) {
+					continue;
+				}
+				if (!g.getMinDelivery().equals(goods.getMinDelivery())) {
+					continue;
+				}
+				if (!GoodsUtil.compareWithQtyPrice(g.getPrices(), goods.getPrices(), g.getCurrencyName())) {
+					continue;
+				}
+				return goods;
+			}
+
+			return g;
+		}
+	}
+
+	/**
+	 * 设置自定义标签
+	 *
+	 * @param goodses1
+	 */
+	public static void setTag(List<Goods> goodses1, Goods g) {
+		if (g == null || g.getTag() != null) {
+			return ;
+		}
+		String tag = StringConstant.SELF_TAG;
+		Boolean isExist = false;
+		int i = 0;
+		do {
+			isExist = false;
+			i++;
+			for (Goods goods : goodses1) {
+				if ((tag + i).equals(goods.getTag())) {
+					isExist = true;
+				}
+			}
+		} while(isExist);
+		g.setTag(tag + i);
+	}
 }

+ 10 - 0
src/main/java/com/uas/platform/b2c/trade/order/dao/OrderDetailDao.java

@@ -45,4 +45,14 @@ public interface OrderDetailDao extends JpaSpecificationExecutor<OrderDetail>, J
 
 	@Query(value = "select sum(detail_number) from trade$order_detail where detail_sup_en_uu=:enuu and cmp_uuid=:uuid and detail_status=:status", nativeQuery = true)
 	Double getSumReserveBySupEnUuAndUuidAndStatus(@Param("enuu") Long enuu, @Param("uuid") String uuid, @Param("status") Integer status);
+
+	/**
+	 * 查询指定批次和状态的购买的数据,
+	 *
+	 * @param batches 批次队列
+	 * @param status 状态
+	 * @return 数据
+	 */
+	@Query(value = "select sum(detail_number) from trade$order_detail where go_batch in (:batches) and detail_status in (:status)", nativeQuery = true)
+	Double getgetSumQtyByBatchcodesAndStatus(@Param("batches") List<String> batches, @Param("status") List<Integer> status);
 }

+ 28 - 26
src/main/webapp/resources/js/vendor/controllers/forstore/vendor_materialCtrl.js

@@ -603,6 +603,9 @@ define([ 'app/app', 'jquery-uploadify' ], function(app) {
 			angular.forEach(material.goodsArr, function (g) {
 				g.edit = false;
 			});
+			if (material.sourceApp == 'ERP') {
+				material.averMonthSalePrice = (material.productDetail && material.productDetail.price) ? material.productDetail.price : 0;
+			}
             $scope.$$nonProduct.editGoods = angular.copy(goods);
 			goods.edit = true;
 
@@ -1722,32 +1725,31 @@ define([ 'app/app', 'jquery-uploadify' ], function(app) {
 		 * @param product
 		 */
 		var getProductDetail = function (product) {
-			Material.getProductDetail({id : product.id}, function (data) {
-				$scope.goods.erpReserve = typeof data.reserve == 'undefined' ? 0 : data.reserve;
-				$scope.goods.editPackaging = (data && data.packaging) || product.packaging || '无';
-				$scope.goods.editProduceDate = (data && data.produceDate) || product.produceDate;
-				$scope.goods.editMinPackQty = (data && data.minPackQty) || product.minPackQty || $scope.goods.minBuyQty || 1;
-				$scope.goods.editMinBuyQty = (data && data.minBuyQty) || $scope.goods.minPackQty;
-				$scope.goods.editMinBuyQty = $scope.goods.editMinBuyQty - ($scope.goods.editMinBuyQty % $scope.goods.editMinPackQty);
-				if ($scope.goods.editMinBuyQty < $scope.goods.editMinPackQty) {
-					$scope.goods.editMinBuyQty = $scope.goods.editMinPackQty;
-				}
-				$scope.goods.editMinDelivery = (data && data.minDelivery) || $scope.uasBatchPutOnProperty.minDelivery;
-				$scope.goods.editMaxDelivery = (data && data.maxDelivery) || $scope.uasBatchPutOnProperty.maxDelivery;
-				product.selected = true;
-				product.averMonthSalePrice = (data && data.price) ? data.price : 0;
-				var goodQtyPrice = {start: $scope.goods.editMinBuyQty, end: $scope.maxReserve};
-				var price = (((data && data.price) ? data.price : 0) *
-				($scope.uasBatchPutOnProperty.fluctuateRate ? $scope.uasBatchPutOnProperty.fluctuateRate : 1));
-				if ('MAINLAND' == $scope.store.enType) {
-					goodQtyPrice.rMBPrice = $filter('formateNumber')(price, 6);
-				}
-				if ('HK' == $scope.store.enType) {
-					goodQtyPrice.uSDPrice = $filter('formateNumber')(price, 6);
-				}
-				$scope.goods.editPrices = [];
-				$scope.goods.editPrices.push(goodQtyPrice);
-			});
+			var data = product.productDetail;
+			$scope.goods.erpReserve = (!data || typeof data.reserve == 'undefined') ? 0 : data.reserve;
+			$scope.goods.editPackaging = (data && data.packaging) || product.packaging || '无';
+			$scope.goods.editProduceDate = (data && data.produceDate) || product.produceDate;
+			$scope.goods.editMinPackQty = (data && data.minPackQty) || product.minPackQty || $scope.goods.minBuyQty || 1;
+			$scope.goods.editMinBuyQty = (data && data.minBuyQty) || $scope.goods.minPackQty;
+			$scope.goods.editMinBuyQty = $scope.goods.editMinBuyQty - ($scope.goods.editMinBuyQty % $scope.goods.editMinPackQty);
+			if ($scope.goods.editMinBuyQty < $scope.goods.editMinPackQty) {
+				$scope.goods.editMinBuyQty = $scope.goods.editMinPackQty;
+			}
+			$scope.goods.editMinDelivery = (data && data.minDelivery) || $scope.uasBatchPutOnProperty.minDelivery;
+			$scope.goods.editMaxDelivery = (data && data.maxDelivery) || $scope.uasBatchPutOnProperty.maxDelivery;
+			product.selected = true;
+			product.averMonthSalePrice = (data && data.price) ? data.price : 0;
+			var goodQtyPrice = {start: $scope.goods.editMinBuyQty, end: $scope.maxReserve};
+			var price = (((data && data.price) ? data.price : 0) *
+			($scope.uasBatchPutOnProperty.fluctuateRate ? $scope.uasBatchPutOnProperty.fluctuateRate : 1));
+			if ('MAINLAND' == $scope.store.enType) {
+				goodQtyPrice.rMBPrice = $filter('formateNumber')(price, 6);
+			}
+			if ('HK' == $scope.store.enType) {
+				goodQtyPrice.uSDPrice = $filter('formateNumber')(price, 6);
+			}
+			$scope.goods.editPrices = [];
+			$scope.goods.editPrices.push(goodQtyPrice);
 		}
 
 		/**

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

@@ -1929,7 +1929,7 @@
 													<div class="labelling">
 														<!--<em>*</em>-->
 														自定义标签 : <input maxlength="20" type="text" ng-model="goods.editTag" ng-blur="blurTag(goods)" ng-change="changeTag(goods)" placeholder="请设置产品标签"></div>
-													<span>近一个月的销售平均价:<em ng-bind="material.averMonthSalePrice |  formateNumber : 6"></em></span>
+													<span>近一个月的销售平均价:<em ng-bind="material.averMonthSalePrice |  formateNumber : 6"></em></span>{{material.b2cDownStatus}}
 												</td>
 											</tr>
 											<tr class="edit-content edits" ng-if="goods.edit">