/// <summary> /// 根据请购买申请单重新初始化购物车 /// </summary> /// <param name="ApplyID"></param> /// <returns></returns> public static ORD_OrderCartBLL InitByOrderApply(int OrderID) { ORD_OrderBLL Order = new ORD_OrderBLL(OrderID); if (Order.Model == null) { return(null); } ORD_PublishBLL publish = new ORD_PublishBLL(Order.Model.PublishID); if (publish.Model == null) { return(null); } ORD_OrderCartBLL cart = new ORD_OrderCartBLL(Order.Model.AccountMonth, Order.Model.PublishID, Order.Model.Client, Order.Model.Supplier, Order.Model.Classify, Order.Model.PayMode, Order.Model.ReqWarehouse, Order.Model.ReqArrivalDate); int quotaid = ORD_QuotaBLL.GetQuotaByClientAndMonth(cart.Client, cart.AccountMonth); ORD_QuotaBLL quota = new ORD_QuotaBLL(quotaid); foreach (ORD_OrderDetail item in Order.Items) { ORD_PublishDetail _m = publish.Items.FirstOrDefault(m => m.Product == item.Product); if (_m == null) { continue; } ORD_OrderCartItem cartitem = new ORD_OrderCartItem(); cartitem.ID = _m.ID; cartitem.Product = _m.Product; cartitem.MinQuantity = _m.MinQuantity; cartitem.MaxQuantity = _m.MaxQuantity; cartitem.Price = item.Price; cartitem.AvailableQuantity = _m.AvailableQuantity; cartitem.SubmitQuantity = ORD_OrderBLL.GetSubmitQuantity(Order.Model.AccountMonth, Order.Model.Client, _m.Product, Order.Model.Classify == 1 ? 1 : 0); cartitem.BookQuantity = item.BookQuantity; cartitem.Points = item.Points; #region 获取配额数量 if (quota.Model != null) { ORD_QuotaDetail d = quota.Items.FirstOrDefault(p => p.Product == _m.Product); if (d != null) { cartitem.QuotaQuantity = d.StdQuota + d.AdjQuota; } } #endregion cart.Items.Add(cartitem); } return(cart); }
/// <summary> /// 向购物车中新增产品 /// </summary> /// <param name="product"></param> /// <returns>0:成功 -1:发布目录中不包括此产品 -2:已超可请购数量 -3:该产品已在购物车中 -4:超订货配额</returns> public int AddProduct(int product, int bookquantity) { if (Items.FirstOrDefault(p => p.Product == product) != null) { return(-3); } ORD_PublishDetail _m = new ORD_PublishBLL(_publish).Items.FirstOrDefault(m => m.Product == product); if (_m != null) { ORD_OrderCartItem cartitem = new ORD_OrderCartItem(); cartitem.Product = _m.Product; cartitem.MinQuantity = _m.MinQuantity; cartitem.MaxQuantity = _m.MaxQuantity; cartitem.Price = _m.Price; cartitem.Points = _m.Points; cartitem.AvailableQuantity = _m.AvailableQuantity; cartitem.SubmitQuantity = ORD_OrderBLL.GetSubmitQuantity(_accountmonth, _client, product, _classify == 1 ? 1 : 0); if (bookquantity == 0) { cartitem.BookQuantity = cartitem.MinQuantity > 0 ? cartitem.MinQuantity : new PDT_ProductBLL(product).Model.ConvertFactor; } else { cartitem.BookQuantity = bookquantity; } cartitem.ConfirmQuantity = cartitem.BookQuantity; #region 判断是否超过发布目录设定的可订货数量 if (cartitem.AvailableQuantity > 0) { int totalquantity = ORD_PublishBLL.GetSubmitQuantity(_publish, product); if (cartitem.BookQuantity > cartitem.AvailableQuantity - totalquantity) { return(-2); } } #endregion #region 获取配额,判断是否超过配额 if (_classify == 1) { //常规订单,按配额订货 cartitem.QuotaQuantity = 0; int quotaid = ORD_QuotaBLL.GetQuotaByClientAndMonth(_client, _accountmonth); ORD_QuotaBLL quota = new ORD_QuotaBLL(quotaid); if (quota != null) { ORD_QuotaDetail d = quota.Items.FirstOrDefault(p => p.Product == product); if (d != null) { cartitem.QuotaQuantity = d.StdQuota + d.AdjQuota; } } if (cartitem.BookQuantity > cartitem.QuotaQuantity - cartitem.SubmitQuantity) { return(-4); } } #endregion _items.Add(cartitem); return(0); } return(-1); }