public JsonResult UpdateCartItem(string skuId, int count) { long userId = CurrentUser != null ? CurrentUser.Id : 0; var orderService = _iOrderService; var skuinfo = orderService.GetSkuByID(skuId); var product = ProductManagerApplication.GetProduct(skuinfo.ProductId); if (product != null) { if (product.MaxBuyCount > 0 && count > product.MaxBuyCount && !product.IsOpenLadder) { return(Json(new { success = false, msg = string.Format("每个ID限购{0}件", product.MaxBuyCount), stock = product.MaxBuyCount })); } } if (skuinfo.Stock < count) { return(Json(new { success = false, msg = "库存不足", stock = skuinfo.Stock })); } cartHelper.UpdateCartItem(skuId, count, userId); #region 购物车修改数量阶梯价变动--张宇枫 //获取产品详情 var price = 0m; if (product.IsOpenLadder) { var shop = ShopApplication.GetShop(product.ShopId); var groupCartByProduct = cartHelper.GetCart(userId).Items.Where(item => item.ShopBranchId == 0).Select(c => { var cItem = new Himall.Entities.ShoppingCartItem(); var skuInfo = _iProductService.GetSku(c.SkuId); if (skuInfo != null) { cItem = c; } return(cItem); }).GroupBy(i => i.ProductId).ToList(); var quantity = groupCartByProduct.Where(i => i.Key == product.Id).ToList().Sum(cartitem => cartitem.Sum(i => i.Quantity)); decimal discount = 1M; if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; } price = ProductManagerApplication.GetProductLadderPrice(product.Id, quantity); if (shop.IsSelf) { price = price * discount; } } #endregion return(Json(new { success = true, saleprice = price.ToString("F2"), productid = product.Id, isOpenLadder = product.IsOpenLadder })); }
/// <summary> /// 判断购物车提交时,阶梯商品是否达最小批量 /// </summary> /// <param name="cartItemIds"></param> /// <returns></returns> public static bool IsExistLadderMinMath(string cartItemIds, ref string msg) { msg = "结算的商品必须满足最小批量才能购买!"; var result = true; var cartItemIdsArr = cartItemIds.Split(',').Where(d => !string.IsNullOrWhiteSpace(d)).Select(t => long.Parse(t)); var cartItems = CartApplication.GetCartItems(cartItemIdsArr); if (cartItems.Any()) { var groupCart = cartItems.Where(item => item.ShopBranchId == 0).ToList().Select(c => { var cItem = new Himall.Entities.ShoppingCartItem(); var skuInfo = Service.GetSku(c.SkuId); if (skuInfo != null) { cItem = c; } return(cItem); }).GroupBy(i => i.ProductId); foreach (var cart in cartItems.ToList()) { var product = GetProduct(cart.ProductId); if (product.IsOpenLadder) { var quantity = groupCart.Where(i => i.Key == cart.ProductId) .ToList() .Sum(cartitem => cartitem.Sum(i => i.Quantity)); var minMath = GetProductLadderMinMath(cart.ProductId); if (minMath > 0 && quantity < minMath) { result = false; } } else { var sku = Service.GetSku(cart.SkuId); if (cart.Quantity > sku.Stock) { msg = string.Format("商品“{0}”库存不足,仅剩{1}件", CutString(product.ProductName, 10, "..."), sku.Stock); return(false); } } } } return(result); }
public object PostUpdateCartItem(CartUpdateCartItemModel value) { var productService = ServiceProvider.Instance <IProductService> .Create; CheckUserLogin(); string Jsonstr = value.jsonstr; var datavalue = Newtonsoft.Json.JsonConvert.DeserializeObject <UpdateCartSKusModel>(Jsonstr); var cartService = ServiceProvider.Instance <ICartService> .Create; var ladderPrice = 0m; long productId = 0; var isOpenLadder = false; foreach (var sku in datavalue.skus) { Entities.SKUInfo skuinfo = OrderApplication.GetSkuByID(sku.skuId); if (skuinfo != null) { var productInfo = ProductManagerApplication.GetProduct(skuinfo.ProductId); if (productInfo != null) { if (productInfo.MaxBuyCount > 0 && sku.count > productInfo.MaxBuyCount && !productInfo.IsOpenLadder) { return(ErrorResult(string.Format("商品[{0}]限购{1}件", productInfo.ProductName, productInfo.MaxBuyCount), data: new { maxBuyCount = productInfo.MaxBuyCount })); //throw new HimallException(string.Format("每个ID限购{0}件", productInfo.MaxBuyCount)); } } } cartService.UpdateCart(sku.skuId, sku.count, CurrentUser.Id); #region 阶梯价--张宇枫 var skus = CartApplication.GetCart(CurrentUser.Id); var skuItem = skus.Items.ToList().Find(i => i.SkuId == sku.skuId); productId = skuItem.ProductId; var product = ProductManagerApplication.GetProduct(productId); isOpenLadder = product.IsOpenLadder; if (isOpenLadder) { var shop = ShopApplication.GetShop(product.ShopId); var groupCartByProduct = skus.Items.Where(item => item.ShopBranchId == 0).Select(c => { var cItem = new Himall.Entities.ShoppingCartItem(); var skuInfo = productService.GetSku(c.SkuId); if (skuInfo != null) { cItem = c; } return(cItem); }).GroupBy(i => i.ProductId).ToList(); var quantity = groupCartByProduct.Where(i => i.Key == productId) .ToList() .Sum(cartitem => cartitem.Sum(i => i.Quantity)); ladderPrice = ProductManagerApplication.GetProductLadderPrice(skuItem.ProductId, quantity); if (shop.IsSelf) { ladderPrice = CurrentUser.MemberDiscount * ladderPrice; } } #endregion } var result = new { success = true, //d.Url = "http://" + Url.Request.RequestUri.Host + "/m-IOS/Order/SubmiteByCart"; Url = Core.HimallIO.GetRomoteImagePath("/m-IOS/Order/SubmiteByCart"), Price = ladderPrice.ToString("F2"), ProductId = productId, IsOpenLadder = isOpenLadder ? 1 : 0, }; return(result); }
private List <CartProductModel> PackageCartProducts(Himall.Entities.ShoppingCartInfo cart, decimal prodPrice, decimal discount, IProductService productService, IShopService shopService, IShopBranchService shopBranchService, IVShopService vshopService, ITypeService typeservice, bool isBranch = false) { List <CartProductModel> products = new List <CartProductModel>(); var limitProducts = LimitTimeApplication.GetPriceByProducrIds(cart.Items.Select(e => e.ProductId).ToList());//限时购价格 var groupCart = cart.Items.Where(item => item.ShopBranchId == 0).Select(c => { var cItem = new Himall.Entities.ShoppingCartItem(); var skuInfo = productService.GetSku(c.SkuId); if (skuInfo != null) { cItem = c; } return(cItem); }).GroupBy(i => i.ProductId).ToList(); foreach (var item in cart.Items) { var product = ProductManagerApplication.GetProduct(item.ProductId); var shop = shopService.GetShop(product.ShopId); DTO.ShopBranch shopbranch = null; Entities.ShopBranchSkuInfo shopbranchsku = null; if (item.ShopBranchId > 0) { shopbranch = ShopBranchApplication.GetShopBranchById(item.ShopBranchId); shopbranchsku = shopBranchService.GetSkusByIds(item.ShopBranchId, new List <string> { item.SkuId }).FirstOrDefault(); } if (null != shop) { var vshop = vshopService.GetVShopByShopId(shop.Id); var sku = ProductManagerApplication.GetSKU(item.SkuId); if (sku == null) { continue; } //处理限时购、会员折扣价格 var prod = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId); prodPrice = sku.SalePrice; if (prod != null && !isBranch) { prodPrice = prod.MinPrice; } else { if (shop.IsSelf) {//官方自营店才计算会员折扣 prodPrice = sku.SalePrice * discount; } } #region 阶梯价--张宇枫 //阶梯价 if (product.IsOpenLadder) { var quantity = groupCart.Where(i => i.Key == item.ProductId).ToList().Sum(cartitem => cartitem.Sum(i => i.Quantity)); prodPrice = ProductManagerApplication.GetProductLadderPrice(item.ProductId, quantity); if (shop.IsSelf) { prodPrice = prodPrice * discount; } } #endregion Entities.TypeInfo typeInfo = typeservice.GetType(product.TypeId); string colorAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias; string sizeAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias; string versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias; if (product != null) { colorAlias = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias; sizeAlias = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias; versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias; } if (sku != null) { #region 正在参加限时抢购商品在购物车失效 TDO:ZYF var isLimit = false; //门店商品,在参加限时购,也可以正常购买 var limit = LimitTimeApplication.GetLimitTimeMarketItemByProductId(item.ProductId); if (limit != null && !isBranch) { isLimit = limit.Status == Entities.FlashSaleInfo.FlashSaleStatus.Ongoing; } #endregion var _tmp = new CartProductModel { CartItemId = item.Id.ToString(), SkuId = item.SkuId, Id = product.Id.ToString(), ImgUrl = Core.HimallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_150), Name = product.ProductName, Price = prodPrice.ToString("F2"), Count = item.Quantity.ToString(), ShopId = shop.Id.ToString(), Size = sku.Size, Color = sku.Color, Version = sku.Version, VShopId = vshop == null ? "0" : vshop.Id.ToString(), ShopName = shop.ShopName, ShopLogo = vshop == null ? "" : Core.HimallIO.GetRomoteImagePath(vshop.StrLogo), Url = Core.HimallIO.GetRomoteImagePath("/m-IOS/product/detail/") + item.ProductId, ProductStatus = isLimit ? 0 : (sku.Stock <= 0 ? ProductInfo.ProductSaleStatus.InStock.GetHashCode() : product.SaleStatus.GetHashCode()), Status = isLimit ? 1 : ProductManagerApplication.GetProductShowStatus(product, sku, shopbranch == null ? 1 : item.Quantity, shopbranch, shopbranchsku),// 0:正常;1:已失效;2:库存不足;3:已下架; ColorAlias = colorAlias, SizeAlias = sizeAlias, VersionAlias = versionAlias, AddTime = item.AddTime, ShopBranchId = item.ShopBranchId, ShopBranchName = null == shopbranch ? "" : shopbranch.ShopBranchName, ShopBranchLogo = null == shopbranch ? "" : Core.HimallIO.GetRomoteImagePath(shopbranch.ShopImages) }; products.Add(_tmp); } } } return(products); }