public JsonResult GetCartProducts() { var memberId = CurrentUser?.Id ?? 0; var cartItems = CartApplication.GetCartItems(memberId); var vshops = VshopApplication.GetVShopsByShopIds(cartItems.Select(p => p.Shop.Id)); var products = cartItems.Select(item => { var sku = item.Sku; var product = item.Product; var shop = item.Shop; var vshop = vshops.FirstOrDefault(p => p.ShopId == shop.Id); var skuDetails = string.Empty; if (!string.IsNullOrWhiteSpace(sku.Size)) { skuDetails += sku.SizeAlias + ":" + sku.Size + " "; } if (!string.IsNullOrWhiteSpace(sku.Color)) { skuDetails += sku.ColorAlias + ":" + sku.Color + " "; } if (!string.IsNullOrWhiteSpace(sku.Version)) { skuDetails += sku.VersionAlias + ":" + sku.Version + " "; } return(new { cartItemId = item.ItemId, skuId = sku.Id, id = product.Id, imgUrl = Himall.Core.HimallIO.GetProductSizeImage(product.RelativePath, 1, (int)ImageSize.Size_150), name = product.ProductName, price = sku.SalePrice, count = item.Quantity, shopId = shop.Id, vshopId = vshop == null ? 0 : vshop.Id, shopName = shop.ShopName, shopLogo = vshop == null ? "" : vshop.Logo, productstatus = item.IsLimit ? 0 : (sku.Stock <= 0 ? ProductInfo.ProductSaleStatus.InStock.GetHashCode() : product.SaleStatus.GetHashCode()), status = item.IsLimit ? 1 : ProductManagerApplication.GetProductShowStatus(product, sku.Map <DTO.SKU>(), 1), // 0:正常;1:已失效;2:库存不足;3:已下架; Size = sku.Size, Color = sku.Color, Version = sku.Version, ColorAlias = sku.ColorAlias, SizeAlias = sku.SizeAlias, VersionAlias = sku.VersionAlias, skuDetails = skuDetails, AddTime = item.AddTime, minMath = ProductManagerApplication.GetProductLadderMinMath(product.Id) }); }).OrderBy(p => p.status).ThenByDescending(o => o.AddTime).ToList(); #region 门店购物车 var discount = CurrentUser?.MemberDiscount ?? 1; var branchCartHelper = new BranchCartHelper(); long userId = 0; if (CurrentUser != null) { userId = CurrentUser.Id; } var Branchcart = branchCartHelper.GetCartNoCache(userId, 0); var shopBranchList = Branchcart.Items.Where(x => x.ShopBranchId > 0).Select(x => x.ShopBranchId).ToList(); shopBranchList = shopBranchList.GroupBy(x => x).Select(x => x.First()).ToList(); Dictionary <long, long> buyedCounts = null; if (userId > 0) { buyedCounts = new Dictionary <long, long>(); buyedCounts = OrderApplication.GetProductBuyCount(userId, Branchcart.Items.Select(x => x.ProductId)); } var branchProducts = PackageCartProducts(Branchcart, discount, true); var sbProducts = branchProducts.OrderBy(p => p.status).ThenByDescending(item => item.AddTime); var shopBranchCart = sbProducts.GroupBy(item => item.shopBranchId); #endregion var cartModel = new { products = products, amount = products.Sum(item => item.price * item.count), totalCount = products.Sum(item => item.count), shopBranchCart = shopBranchCart }; return(SuccessResult <dynamic>(data: cartModel)); }
public JsonResult GetCartProducts() { ShoppingCartInfo cart = new CartHelper().GetCart(base.CurrentUser.Id); IProductService productService = this._iProductService; IShopService shopService = this._iShopService; IVShopService vshopService = this._iVShopService; decimal discount = 1.0M; if (base.CurrentUser != null) { discount = base.CurrentUser.MemberDiscount; } List <long> list = new List <long>(); decimal prodPrice = 0.0M; List <FlashSalePrice> limitProducts = LimitTimeApplication.GetPriceByProducrIds((from e in cart.Items select e.ProductId).ToList <long>()); var source = from s in cart.Items.Where <ShoppingCartItem>(delegate(ShoppingCartItem d) { long?nullable; return(!d.ShopBranchId.HasValue || (((nullable = d.ShopBranchId).GetValueOrDefault() == 0L) && nullable.HasValue)); }).Select(delegate(ShoppingCartItem item) { Func <FlashSalePrice, bool> predicate = null; ProductInfo product = productService.GetProduct(item.ProductId); ShopInfo shop = shopService.GetShop(product.ShopId, false); SKUInfo sku = null; string str = ""; string str2 = ""; string str3 = ""; string str4 = ""; if (null != shop) { string str5; VShopInfo vShopByShopId = vshopService.GetVShopByShopId(shop.Id); sku = productService.GetSku(item.SkuId); if (sku == null) { return(null); } if (predicate == null) { predicate = e => e.ProductId == item.ProductId; } FlashSalePrice price = limitProducts.FirstOrDefault <FlashSalePrice>(predicate); prodPrice = sku.SalePrice; if (price != null) { prodPrice = price.MinPrice; } else if (shop.IsSelf) { prodPrice = sku.SalePrice * discount; } ProductType type = TypeApplication.GetType(product.TypeId); str = ((type == null) || string.IsNullOrEmpty(type.ColorAlias)) ? SpecificationType.Color.ToDescription() : type.ColorAlias; str2 = ((type == null) || string.IsNullOrEmpty(type.SizeAlias)) ? SpecificationType.Size.ToDescription() : type.SizeAlias; str3 = ((type == null) || string.IsNullOrEmpty(type.VersionAlias)) ? SpecificationType.Version.ToDescription() : type.VersionAlias; str4 = ""; if (!string.IsNullOrWhiteSpace(sku.Size)) { str5 = str4; str4 = str5 + str2 + ":" + sku.Size + " "; } if (!string.IsNullOrWhiteSpace(sku.Color)) { str5 = str4; str4 = str5 + str + ":" + sku.Color + " "; } if (!string.IsNullOrWhiteSpace(sku.Version)) { str5 = str4; str4 = str5 + str3 + ":" + sku.Version + " "; } return(new { cartItemId = item.Id, skuId = item.SkuId, id = product.Id, imgUrl = HimallIO.GetProductSizeImage(product.RelativePath, 1, 150), name = product.ProductName, price = prodPrice, count = item.Quantity, shopId = shop.Id, vshopId = (vShopByShopId == null) ? 0L : vShopByShopId.Id, shopName = shop.ShopName, shopLogo = (vShopByShopId == null) ? "" : vShopByShopId.Logo, status = ((product.AuditStatus == ProductInfo.ProductAuditStatus.Audited) && (product.SaleStatus == ProductInfo.ProductSaleStatus.OnSale)) ? 1 : 0, Size = sku.Size, Color = sku.Color, Version = sku.Version, ColorAlias = str, SizeAlias = str2, VersionAlias = str3, skuDetails = str4, AddTime = item.AddTime }); } return(null); }) where s != null orderby s.vshopId, s.AddTime descending select s; BranchCartHelper helper2 = new BranchCartHelper(); long memberId = 0L; if (base.CurrentUser != null) { memberId = base.CurrentUser.Id; } ShoppingCartInfo cartNoCache = helper2.GetCartNoCache(memberId, 0L); List <long> list2 = (from x in (from x in cartNoCache.Items where x.ShopBranchId.HasValue select x.ShopBranchId.Value).ToList <long>() group x by x into x select x.First <long>()).ToList <long>(); Dictionary <long, int> buyedCounts = null; if (memberId > 0L) { cart = helper2.GetCart(memberId, 0L); buyedCounts = new Dictionary <long, int>(); buyedCounts = OrderApplication.GetProductBuyCount(memberId, from x in cart.Items select x.ProductId); } List <object> list3 = new List <object>(); using (List <long> .Enumerator enumerator = list2.GetEnumerator()) { while (enumerator.MoveNext()) { Func <ShoppingCartItem, bool> func = null; long shopBranchId = enumerator.Current; prodPrice = 0.0M; List <ShopBranchSkusInfo> shopBranchSkuList = this._iShopBranchService.GetSkusByIds(shopBranchId, from x in cartNoCache.Items select x.SkuId); if (func == null) { func = delegate(ShoppingCartItem x) { long?nullable1 = x.ShopBranchId; long num = shopBranchId; return((nullable1.GetValueOrDefault() == num) && nullable1.HasValue); }; } var enumerable2 = from s in cartNoCache.Items.Where <ShoppingCartItem>(func).Select(delegate(ShoppingCartItem item) { Func <ShopBranchSkusInfo, bool> predicate = null; if (shopBranchId == 0x63L) { } ShopBranchInfo shopBranchById = this._iShopBranchService.GetShopBranchById(shopBranchId); ProductInfo product = this._iProductService.GetProduct(item.ProductId); ShopInfo shop = this._iShopService.GetShop(product.ShopId, false); SKUInfo sku = null; if ((shop != null) && (shopBranchById != null)) { VShopInfo vShopByShopId = this._iVShopService.GetVShopByShopId(shop.Id); sku = this._iProductService.GetSku(item.SkuId); if (sku == null) { return(null); } prodPrice = sku.SalePrice; if (shop.IsSelf) { prodPrice = sku.SalePrice * discount; } if (predicate == null) { predicate = x => x.SkuId == item.SkuId; } ShopBranchSkusInfo info6 = shopBranchSkuList.FirstOrDefault <ShopBranchSkusInfo>(predicate); long maxBuyCount = (info6 == null) ? ((long)0) : ((long)info6.Stock); if ((maxBuyCount > product.MaxBuyCount) && (product.MaxBuyCount > 0)) { maxBuyCount = product.MaxBuyCount; } if (((product.MaxBuyCount > 0) && (buyedCounts != null)) && buyedCounts.ContainsKey(item.ProductId)) { int num3 = buyedCounts[item.ProductId]; maxBuyCount -= num3; } return(new { cartItemId = item.Id, skuId = item.SkuId, id = product.Id, imgUrl = HimallIO.GetProductSizeImage(product.RelativePath, 1, 150), name = product.ProductName, price = prodPrice, count = item.Quantity, status = (info6 == null) ? 1 : ((info6.Status == ShopBranchSkuStatus.Normal) ? ((item.Quantity > maxBuyCount) ? 2 : 0) : 1), AddTime = item.AddTime, shopBranchId = shopBranchById.Id, shopBranchName = shopBranchById.ShopBranchName }); } return(null); }) where s != null orderby s.AddTime descending select s; list3.Add(enumerable2); } } var data = new { products = source, amount = Enumerable.Sum(source, item => item.price * (Decimal)item.count), totalCount = Enumerable.Sum(source, item => item.count), shopBranchCart = list3 }; return(base.Json(data)); }