/// <summary> /// 添加促销商品至购物车 /// </summary> /// <param name="groupSysNo">组系统编号(组合,团购主表系统编号)</param> /// <param name="quantity">组数量</param> /// <param name="promotionSysNo">促销系统编号</param> /// <param name="source">购物车商品来源</param> /// <returns></returns> /// <remarks>2013-10-16 黄波 创建</remarks> public override void Add(int groupSysNo, int quantity, int promotionSysNo, CustomerStatus.购物车商品来源 source) { var productItems = _cookieCart.FindAll(o => o.GroupCode == groupSysNo.ToString() && o.Promotions == promotionSysNo.ToString()).ToArray(); if (productItems != null && productItems.Any()) { foreach (var jsonCartItem in productItems) { jsonCartItem.Quantity += quantity; } } else { var groupItems = GroupToCartItem(groupSysNo, quantity, promotionSysNo, source); foreach (var shoppingCartItem in groupItems) { _cookieCart.Add(new JsonCartItem { SysNo = CreateSysNo(), GroupCode = groupSysNo.ToString(), IsLock = (int)CustomerStatus.购物车是否锁定.是, IsChecked = (int)CustomerStatus.是否选中.是, ProductSalesType = shoppingCartItem.ProductSalesType, ProductSysNo = shoppingCartItem.ProductSysNo, Promotions = promotionSysNo.ToString(), Quantity = quantity }); } } SetCookieCart(); }
/// <summary> /// 添加 组 至购物车 /// </summary> /// <param name="groupCode">组系统编号(组合,团购主表系统编号)</param> /// <param name="quantity">组数量</param> /// <param name="promotionSysNo">促销系统编号</param> /// <param name="source">购物车商品来源</param> /// <returns>购物车明细集合</returns> ///<remarks>2013-11-14 杨文兵 创建</remarks> public void Add(string groupCode, int quantity, string promotionSysNo, CustomerStatus.购物车商品来源 source) { if (quantity < 1) { Remove(groupCode, promotionSysNo); return; } var item = _jsonCartItemList.FirstOrDefault(o => o.GroupCode == groupCode && o.Promotions == promotionSysNo); if (item == null) { _jsonCartItemList.Add(new JsonCartItem() { //SysNo = CreateSysNo(), 该字段对于组而言没有任何意义 GroupCode = groupCode, IsLock = (int)CustomerStatus.购物车是否锁定.是, IsChecked = (int)CustomerStatus.是否选中.是, ProductSysNo = 0, Promotions = promotionSysNo, Quantity = quantity }); } else { foreach (var jsonCartItem in _jsonCartItemList) { if (jsonCartItem.GroupCode == groupCode && jsonCartItem.Promotions == promotionSysNo) { jsonCartItem.Quantity++; } } } }
/// <summary> /// 添加商品至购物车 /// </summary> /// <param name="customerSysNo">客户系统编号</param> /// <param name="productSysNo">商品系统编号</param> /// <param name="quantity">商品数量</param> /// <param name="source">购物车商品来源</param> /// <returns></returns> /// <remarks>2013-08-13 吴文强 创建</remarks> public void Add(int customerSysNo, int productSysNo, int quantity, CustomerStatus.购物车商品来源 source) { var productPrices = PdPriceBo.Instance.GetProductPrice(productSysNo, new ProductStatus.产品价格来源[] { ProductStatus.产品价格来源.会员等级价 }); var customer = CrCustomerBo.Instance.GetModel(customerSysNo); var firstOrDefault = productPrices.FirstOrDefault(p => customer != null && p.SourceSysNo == customer.LevelSysNo); if (firstOrDefault != null) { var shoppingCartItem = new CrShoppingCartItem { IsChecked = (int)CustomerStatus.是否选中.是, CustomerSysNo = customerSysNo, ProductSysNo = productSysNo, ProductName = "", Quantity = quantity, OriginPrice = firstOrDefault.Price, IsLock = (int)CustomerStatus.购物车是否锁定.否, IsExpireReset = (int)CustomerStatus.购物车是否过期重置.是, CreateDate = DateTime.Now, Source = (int)source, ProductSalesType = (int)CustomerStatus.商品销售类型.普通, }; var list = new List <CrShoppingCartItem>(); list.Add(shoppingCartItem); ICrShoppingCartItemDao.Instance.Add(list); } }
/// <summary> /// 根据赠品转购物车明细 /// </summary> /// <param name="productSysNo">商品系统编号</param> /// <param name="quantity">数量</param> /// <param name="source">购物车商品来源</param> /// <param name="isChecked">是否选中</param> /// <returns>购物车明细</returns> /// <remarks>2013-11-14 吴文强 创建</remarks> public CBCrShoppingCartItem GetCartItemByProduct(int productSysNo, int quantity, CustomerStatus.购物车商品来源 source, CustomerStatus.是否选中 isChecked = CustomerStatus.是否选中.是) { return(new CBCrShoppingCartItem { IsChecked = (int)isChecked, ProductSysNo = productSysNo, ProductName = "", Quantity = quantity, OriginPrice = 0, IsLock = (int)CustomerStatus.购物车是否锁定.否, CreateDate = DateTime.Now, Source = (int)source, ProductSalesType = (int)CustomerStatus.商品销售类型.普通, }); }
/// <summary> /// 根据赠品转购物车明细 /// </summary> /// <param name="productSysNo">商品系统编号</param> /// <param name="quantity">数量</param> /// <param name="promotionSysNo">使用促销系统编号</param> /// <param name="source">购物车商品来源</param> /// <returns>购物车明细</returns> /// <remarks>2013-11-14 吴文强 创建</remarks> public CBCrShoppingCartItem GetCartItemByGift(int productSysNo, int quantity, int promotionSysNo, CustomerStatus.购物车商品来源 source) { return(new CBCrShoppingCartItem { IsChecked = (int)CustomerStatus.是否选中.是, ProductSysNo = productSysNo, ProductName = "", Quantity = quantity, OriginPrice = 0, IsLock = (int)CustomerStatus.购物车是否锁定.否, IsExpireReset = (int)CustomerStatus.购物车是否过期重置.是, CreateDate = DateTime.Now, Source = (int)source, ProductSalesType = (int)CustomerStatus.商品销售类型.赠品, UsedPromotions = promotionSysNo.ToString(), }); }
/// <summary> /// 购物车简单对象转购物车商品明细集合(使用当前商品价格) /// </summary> /// <param name="jsonCartItems">Json格式的购物车明细</param> /// <param name="customerLevelSysNo">客户系统编号</param> /// <param name="source">购物车商品来源</param> /// <returns>购物车商品明细集合</returns> /// <remarks>2013-11-14 吴文强 创建</remarks> public static IList <CBCrShoppingCartItem> ConvertShoppingCartItems(this IList <JsonCartItem> jsonCartItems, int customerLevelSysNo, CustomerStatus.购物车商品来源 source = CustomerStatus.购物车商品来源.PC网站) { var shoppingCartItems = new List <CBCrShoppingCartItem>(); var promotionKeys = new List <string>(); foreach (var item in jsonCartItems) { if (item.ProductSalesType == (int)CustomerStatus.商品销售类型.赠品) { shoppingCartItems.Add( CrShoppingCartConvertBo.Instance.GetCartItemByGift(item.ProductSysNo, item.Quantity, int.Parse(item.Promotions), source)); } else { if (item.IsLock == (int)CustomerStatus.购物车是否锁定.是 && !string.IsNullOrEmpty(item.GroupCode)) { var keys = string.Format("{0},{1}", item.Promotions, item.GroupCode); if (promotionKeys.Contains(keys)) { continue; } promotionKeys.Add(keys); shoppingCartItems.AddRange( CrShoppingCartConvertBo.Instance.GetCartItemByGroup(int.Parse(item.GroupCode), item.Quantity, int.Parse(item.Promotions), source, (CustomerStatus.是否选中)item.IsChecked)); } else { shoppingCartItems.Add( CrShoppingCartConvertBo.Instance.GetCartItemByProduct (item.ProductSysNo, item.Quantity, source, (CustomerStatus.是否选中)item.IsChecked)); } } } //购物车明细 shoppingCartItems = CrShoppingCartConvertBo.Instance.InitItemPriceByProduct(customerLevelSysNo, shoppingCartItems).ToList(); return(shoppingCartItems); }
/// <summary> /// 添加促销赠品至购物车 /// </summary> /// <param name="productSysNo">商品(赠品)系统编号</param> /// <param name="promotionSysNo">促销系统编号</param> /// <param name="source">购物车商品来源</param> /// <returns></returns> ///<remarks>2013-11-14 杨文兵 创建</remarks> public void AddGift(int productSysNo, string promotionSysNo, CustomerStatus.购物车商品来源 source) { var giftItem = _jsonCartItemList.FirstOrDefault(o => o.ProductSysNo == productSysNo && o.Promotions == promotionSysNo.ToString() && o.ProductSalesType == (int)CustomerStatus.商品销售类型.赠品 ); if ((giftItem == null)) { _jsonCartItemList.Add(new JsonCartItem { //SysNo = CreateSysNo(), 对修改订单功能无用的字段 GroupCode = "", IsLock = (int)CustomerStatus.购物车是否锁定.是, IsChecked = (int)CustomerStatus.是否选中.是, ProductSalesType = (int)CustomerStatus.商品销售类型.赠品, ProductSysNo = productSysNo, Promotions = promotionSysNo, Quantity = 1 }); } }
/// <summary> /// 添加促销赠品至购物车 /// </summary> /// <param name="customerSysNo">客户系统编号</param> /// <param name="productSysNo">商品(赠品)系统编号</param> /// <param name="promotionSysNo">促销系统编号</param> /// <param name="source">购物车商品来源</param> /// <returns></returns> /// <remarks>2013-08-13 吴文强 创建</remarks> public void AddGift(int customerSysNo, int productSysNo, int promotionSysNo, CustomerStatus.购物车商品来源 source) { var shoppingCartItem = new CrShoppingCartItem { IsChecked = (int)CustomerStatus.是否选中.是, CustomerSysNo = customerSysNo, ProductSysNo = productSysNo, ProductName = "", Quantity = 1, OriginPrice = 0, IsLock = (int)CustomerStatus.购物车是否锁定.否, IsExpireReset = (int)CustomerStatus.购物车是否过期重置.是, CreateDate = DateTime.Now, Source = (int)source, ProductSalesType = (int)CustomerStatus.商品销售类型.赠品, Promotions = promotionSysNo.ToString(), UsedPromotions = promotionSysNo.ToString(), }; var list = new List <CrShoppingCartItem>(); list.Add(shoppingCartItem); ICrShoppingCartItemDao.Instance.Add(list); }
/// <summary> /// 添加商品至购物车 /// </summary> /// <param name="productSysNo">商品系统编号</param> /// <param name="quantity">商品数量</param> /// <param name="source">购物车商品来源</param> /// <returns></returns> ///<remarks>2013-11-14 杨文兵 创建</remarks> public JsonCartItem Add(int productSysNo, int quantity, CustomerStatus.购物车商品来源 source) { if (quantity < 1) { _jsonCartItemList = _jsonCartItemList.Where(p => p.ProductSysNo == productSysNo && p.ProductSalesType == (int)CustomerStatus.商品销售类型.普通 ).ToList(); return(null); } var productItems = _jsonCartItemList.FirstOrDefault(o => o.ProductSysNo == productSysNo && o.ProductSalesType == (int)CustomerStatus.商品销售类型.普通 ); if (productItems != null) { productItems.Quantity += quantity; return(productItems); } else { productItems = new JsonCartItem { //SysNo = CreateSysNo(), //购物车对象之间互相转换时该属性值不能保持一致,不再依赖此属性做任何逻辑处理 GroupCode = "", IsLock = (int)CustomerStatus.购物车是否锁定.否, IsChecked = (int)CustomerStatus.是否选中.是, ProductSalesType = (int)CustomerStatus.商品销售类型.普通, ProductSysNo = productSysNo, Promotions = "", Quantity = quantity }; _jsonCartItemList.Add(productItems); return(productItems); } }
/// <summary> /// 添加促销赠品至购物车 /// </summary> /// <param name="cacheKey">缓存Key</param> /// <param name="customerSysNo">客户系统编号</param> /// <param name="productSysNo">商品(赠品)系统编号</param> /// <param name="promotionSysNo">促销系统编号</param> /// <param name="source">购物车商品来源</param> /// <remarks>2013-08-13 吴文强 创建</remarks> public void AddGift(string cacheKey, int customerSysNo, int productSysNo, int promotionSysNo, CustomerStatus.购物车商品来源 source) { _cacheKey = cacheKey; var shoppingCartItem = new CBCrShoppingCartItem { SysNo = SeqSysNo, IsChecked = (int)CustomerStatus.是否选中.是, CustomerSysNo = customerSysNo, ProductSysNo = productSysNo, ProductName = "", Quantity = 1, OriginPrice = 0, IsLock = (int)CustomerStatus.购物车是否锁定.否, IsExpireReset = (int)CustomerStatus.购物车是否过期重置.是, CreateDate = DateTime.Now, Source = (int)source, ProductSalesType = (int)CustomerStatus.商品销售类型.赠品, UsedPromotions = promotionSysNo.ToString(), }; #region 计算并写入Cache var items = CacheItems; var item = items.FirstOrDefault(sci => sci.ProductSysNo == shoppingCartItem.ProductSysNo && sci.ProductSalesType == (int)CustomerStatus.商品销售类型.赠品 && sci.UsedPromotions == promotionSysNo.ToString()); if (item == null) { items.Add(shoppingCartItem); } else { item.Quantity = 1; } CacheItems = items; #endregion }
/// <summary> /// 将组促销转换为购物车明细 /// </summary> /// <param name="cacheKey">缓存Key</param> /// <param name="customerSysNo">客户系统编号</param> /// <param name="groupSysNo">组系统编号(组合,团购主表系统编号)</param> /// <param name="quantity">组数量</param> /// <param name="promotionSysNo">促销系统编号</param> /// <param name="source">购物车商品来源</param> /// <param name="isChecked">是否选中商品</param> /// <returns>购物车明细集合</returns> /// <remarks>2013-09-01 吴文强 创建</remarks> public void Add(string cacheKey, int customerSysNo, int groupSysNo, int quantity, int promotionSysNo, CustomerStatus.购物车商品来源 source, CustomerStatus.是否选中 isChecked = CustomerStatus.是否选中.是) { _cacheKey = cacheKey; #region 计算并写入Cache var items = CacheItems; var groupItems = InitGroupToCartItem(customerSysNo, groupSysNo, quantity, promotionSysNo, source); //检查是否已存在未锁定商品,存在+1,不存在新增 foreach (var shoppingCartItem in groupItems) { var item = items.FirstOrDefault(sci => sci.ProductSysNo == shoppingCartItem.ProductSysNo && sci.CustomerSysNo == customerSysNo && sci.IsLock == shoppingCartItem.IsLock && sci.GroupCode == shoppingCartItem.GroupCode && sci.Promotions == shoppingCartItem.Promotions); if (item == null) { shoppingCartItem.SysNo = SeqSysNo; items.Add(shoppingCartItem); } else { item.Quantity = item.Quantity + quantity; } } CacheItems = items; #endregion }
/// <summary> /// 添加商品至购物车 /// </summary> /// <param name="cacheKey">缓存Key</param> /// <param name="customerSysNo">客户系统编号</param> /// <param name="productSysNo">商品系统编号</param> /// <param name="quantity">商品数量</param> /// <param name="source">购物车商品来源</param> /// <param name="isChecked">是否选中商品</param> /// <remarks>2013-08-13 吴文强 创建</remarks> public void Add(string cacheKey, int customerSysNo, int productSysNo, int quantity, CustomerStatus.购物车商品来源 source, CustomerStatus.是否选中 isChecked = CustomerStatus.是否选中.是) { _cacheKey = cacheKey; var productPrices = PdPriceBo.Instance.GetProductPrice(productSysNo, new ProductStatus.产品价格来源[] { ProductStatus.产品价格来源.会员等级价 }); var customer = CrCustomerBo.Instance.GetModel(customerSysNo); var firstOrDefault = productPrices.FirstOrDefault(p => customer != null ? p.SourceSysNo == customer.LevelSysNo : p.SourceSysNo == CustomerLevel.初级); if (firstOrDefault != null) { var shoppingCartItem = new CBCrShoppingCartItem { SysNo = SeqSysNo, IsChecked = (int)isChecked, CustomerSysNo = customerSysNo, ProductSysNo = productSysNo, ProductName = "", Quantity = quantity, OriginPrice = firstOrDefault.Price, IsLock = (int)CustomerStatus.购物车是否锁定.否, IsExpireReset = (int)CustomerStatus.购物车是否过期重置.是, CreateDate = DateTime.Now, Source = (int)source, ProductSalesType = (int)CustomerStatus.商品销售类型.普通, }; #region 计算并写入Cache var items = CacheItems; var item = items.FirstOrDefault(sci => sci.ProductSysNo == shoppingCartItem.ProductSysNo); if (item == null) { items.Add(shoppingCartItem); } else { item.Quantity = item.Quantity + quantity; } CacheItems = items; #endregion } }
/// <summary> /// 将组促销转换为购物车明细 /// </summary> /// <param name="customerSysNo">客户系统编号</param> /// <param name="groupSysNo">组系统编号(组合,团购主表系统编号)</param> /// <param name="quantity">组数量</param> /// <param name="promotionSysNo">促销系统编号</param> /// <param name="source">购物车商品来源</param> /// <param name="isChecked">是否选中商品</param> /// <returns>购物车明细集合</returns> /// <remarks>2013-09-01 吴文强 创建</remarks> private IList <CBCrShoppingCartItem> InitGroupToCartItem(int customerSysNo, int groupSysNo, int quantity, int promotionSysNo, CustomerStatus.购物车商品来源 source, CustomerStatus.是否选中 isChecked = CustomerStatus.是否选中.是) { var result = new List <CBCrShoppingCartItem>(); var promotion = SpPromotionBo.Instance.GetPromotions(new[] { promotionSysNo }).FirstOrDefault(); if (promotion == null) { return(result); } switch (promotion.PromotionType) { case (int)PromotionStatus.促销应用类型.组合套餐: //获取套餐明细 var comboItems = ISpComboItemDao.Instance.GetListByComboSysNo(groupSysNo); //将明细添加至购物车明细集合 result.AddRange(comboItems.Select(item => new CBCrShoppingCartItem { ProductName = item.ProductName, CustomerSysNo = customerSysNo, ProductSysNo = item.ProductSysNo, Quantity = quantity, OriginPrice = 0, IsChecked = (int)isChecked, IsLock = (int)CustomerStatus.购物车是否锁定.是, IsExpireReset = (int)CustomerStatus.购物车是否过期重置.是, CreateDate = DateTime.Now, Source = (int)CustomerStatus.购物车商品来源.PC网站, ProductSalesType = (int)CustomerStatus.商品销售类型.组合, Promotions = promotionSysNo.ToString(), UsedPromotions = promotionSysNo.ToString(), GroupCode = groupSysNo.ToString(), ProductSalesTypeSysNo = item.SysNo, })); break; case (int)PromotionStatus.促销应用类型.团购: //获取套餐明细 var groupShoppingItem = IGsGroupShoppingItemDao.Instance.GetItem(groupSysNo); //将明细添加至购物车明细集合 result.AddRange(groupShoppingItem.Select(item => new CBCrShoppingCartItem { ProductName = item.ProductName, CustomerSysNo = customerSysNo, ProductSysNo = item.ProductSysNo, Quantity = quantity, OriginPrice = 0, IsChecked = (int)isChecked, IsLock = (int)CustomerStatus.购物车是否锁定.是, IsExpireReset = (int)CustomerStatus.购物车是否过期重置.是, CreateDate = DateTime.Now, Source = (int)CustomerStatus.购物车商品来源.PC网站, ProductSalesType = (int)CustomerStatus.商品销售类型.团购, Promotions = promotionSysNo.ToString(), UsedPromotions = promotionSysNo.ToString(), GroupCode = groupSysNo.ToString(), ProductSalesTypeSysNo = item.SysNo, })); break; } return(result); }
/// <summary> /// 将组促销转换为购物车明细 /// </summary> /// <param name="customerSysNo">客户系统编号</param> /// <param name="groupSysNo">组系统编号(组合,团购主表系统编号)</param> /// <param name="quantity">组数量</param> /// <param name="promotionSysNo">促销系统编号</param> /// <param name="source">购物车商品来源</param> /// <returns></returns> /// <remarks>2013-09-01 吴文强 创建</remarks> public void Add(int customerSysNo, int groupSysNo, int quantity, int promotionSysNo, CustomerStatus.购物车商品来源 source) { ICrShoppingCartItemDao.Instance.Add(InitGroupToCartItem(customerSysNo, groupSysNo, quantity, promotionSysNo, source).ToList()); }
/// <summary> /// 添加商品至购物车 /// </summary> /// <param name="productSysNo">商品系统编号</param> /// <param name="quantity">商品数量</param> /// <param name="source">购物车商品来源</param> /// <param name="sysNo">系统编号</param> /// <returns>购物车商品明细</returns> /// <remarks>2013-08-13 吴文强 创建</remarks> private CBCrShoppingCartItem ProductToCartItem(int productSysNo, int quantity, CustomerStatus.购物车商品来源 source = CustomerStatus.购物车商品来源.PC网站, CustomerStatus.商品销售类型 productSalesType = CustomerStatus.商品销售类型.普通, CustomerStatus.是否选中 isChecked = CustomerStatus.是否选中.是, int sysNo = 0, string promotions = null) { var shoppingCartItem = new CBCrShoppingCartItem(); var productPrices = PdPriceBo.Instance.GetProductPrice(productSysNo, new ProductStatus.产品价格来源[] { ProductStatus.产品价格来源.会员等级价 }); var firstOrDefault = productPrices.FirstOrDefault(p => p.SourceSysNo == CustomerLevel.初级); if (firstOrDefault != null) { shoppingCartItem = new CBCrShoppingCartItem { SysNo = sysNo, IsChecked = (int)isChecked, CustomerSysNo = -1, ProductSysNo = productSysNo, ProductName = "", Quantity = quantity, OriginPrice = firstOrDefault.Price, IsLock = (int)CustomerStatus.购物车是否锁定.否, IsExpireReset = (int)CustomerStatus.购物车是否过期重置.是, CreateDate = DateTime.Now, Source = (int)source, ProductSalesType = (int)productSalesType, Promotions = promotions, UsedPromotions = promotions, }; } return(shoppingCartItem); }
/// <summary> /// 添加促销商品至购物车 /// </summary> /// <param name="groupSysNo">组系统编号(组合,团购主表系统编号)</param> /// <param name="quantity">组数量</param> /// <param name="promotionSysNo">促销系统编号</param> /// <param name="source">购物车商品来源</param> /// <returns>购物车明细集合</returns> /// <remarks>2013-10-16 黄波 创建</remarks> public abstract void Add(int groupSysNo, int quantity, int promotionSysNo, CustomerStatus.购物车商品来源 source);
/// <summary> /// 添加商品至购物车 /// </summary> /// <param name="productSysNo">商品系统编号</param> /// <param name="quantity">商品数量</param> /// <param name="source">购物车商品来源</param> /// <return></return> /// <remarks>2013-10-16 黄波 创建</remarks> public abstract void Add(int productSysNo, int quantity, CustomerStatus.购物车商品来源 source);
/// <summary> /// 添加促销赠品至购物车 /// </summary> /// <param name="productSysNo">商品(赠品)系统编号</param> /// <param name="promotionSysNo">促销系统编号</param> /// <param name="source">购物车商品来源</param> /// <return></return> /// <remarks>2013-10-16 黄波 创建</remarks> public abstract void AddGift(int productSysNo, int promotionSysNo, CustomerStatus.购物车商品来源 source);