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); }
public object GetCartProduct() { CheckUserLogin(); var cartHelper = ServiceProvider.Instance <ICartService> .Create; var cart = cartHelper.GetCart(CurrentUser.Id); var productService = ServiceProvider.Instance <IProductService> .Create; var shopService = ServiceProvider.Instance <IShopService> .Create; var vshopService = ServiceProvider.Instance <IVShopService> .Create; var siteSetting = ServiceProvider.Instance <ISiteSettingService> .Create.GetSiteSettings(); var typeservice = ServiceProvider.Instance <ITypeService> .Create; List <CartProductModel> products = new List <CartProductModel>(); //会员折扣 decimal discount = 1.0M;//默认折扣为1(没有折扣) if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; } decimal prodPrice = 0.0M; //优惠价格 var limitProducts = LimitTimeApplication.GetPriceByProducrIds(cart.Items.Select(e => e.ProductId).ToList()); //限时购价格 foreach (var item in cart.Items) { var product = productService.GetProduct(item.ProductId); var shop = shopService.GetShop(product.ShopId); if (null != shop) { var vshop = vshopService.GetVShopByShopId(shop.Id); SKUInfo sku = productService.GetSku(item.SkuId); if (sku == null) { continue; } //处理限时购、会员折扣价格 var prod = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId); prodPrice = sku.SalePrice; if (prod != null) { prodPrice = prod.MinPrice; } else { if (shop.IsSelf) {//官方自营店才计算会员折扣 prodPrice = sku.SalePrice * discount; } } ProductTypeInfo 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 (sku != null) { 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.Logo), Url = Core.HimallIO.GetRomoteImagePath("/m-IOS/product/detail/") + item.ProductId, Status = (product.AuditStatus == ProductInfo.ProductAuditStatus.Audited && product.SaleStatus == ProductInfo.ProductSaleStatus.OnSale) ? 1 : 0, ColorAlias = colorAlias, SizeAlias = sizeAlias, VersionAlias = versionAlias, AddTime = item.AddTime }; products.Add(_tmp); } } } products = products.OrderBy(item => item.ShopId).ThenByDescending(o => o.AddTime).ToList(); //var invalidProducts = products.Where(item => item.Status == 0).ToArray(); //products = products.Where(item => item.Status == 1).ToArray(); var cartShop = products.GroupBy(item => item.ShopId); var cartModel = new { Success = "true", Shop = cartShop }; return(Json(cartModel)); }