public object GetIndexProductData(string openId = "", int pageIndex = 10, int pageSize = 1) { //CheckUserLogin(); var homeProducts = ServiceProvider.Instance <IWXSmallProgramService> .Create.GetWXSmallHomeProducts().OrderBy(item => item.Id).Skip((pageIndex - 1) * pageSize).Take(pageSize); decimal discount = 1M; long SelfShopId = 0; ShoppingCartInfo CartInfo = new ShoppingCartInfo(); var ids = homeProducts.Select(d => d.Id).ToArray(); List <object> productList = new List <object>(); List <ShoppingCartItem> cartitems = new List <ShoppingCartItem>(); if (CurrentUser != null) { discount = CurrentUser.MemberDiscount; var shopInfo = ShopApplication.GetSelfShop(); SelfShopId = shopInfo.Id; CartInfo = ServiceProvider.Instance <ICartService> .Create.GetCart(CurrentUser.Id); cartitems = CartApplication.GetCartQuantityByIds(CurrentUser.Id, ids); } var limit = LimitTimeApplication.GetLimitProducts(); //var fight = FightGroupApplication.GetFightGroupPrice(); foreach (var item in homeProducts) { long activeId = 0; int activetype = 0; item.ImagePath = Core.HimallIO.GetRomoteProductSizeImage(Core.HimallIO.GetImagePath(item.ImagePath), 1, (int)Himall.CommonModel.ImageSize.Size_350); if (item.ShopId == SelfShopId) { item.MinSalePrice = item.MinSalePrice * discount; } var limitBuy = ServiceProvider.Instance <ILimitTimeBuyService> .Create.GetLimitTimeMarketItemByProductId(item.Id); if (limitBuy != null) { item.MinSalePrice = limitBuy.MinPrice; activeId = limitBuy.Id; activetype = 1; } int quantity = 0; quantity = cartitems.Where(d => d.ProductId == item.Id).Sum(d => d.Quantity); //火拼 //if (activeInfo != null) //{ // item.MinSalePrice = activeInfo.MiniGroupPrice; // activeId = activeInfo.Id; // activetype = 2; //} var ChoiceProducts = new { ProductId = item.Id, ProductName = item.ProductName, SalePrice = item.MinSalePrice.ToString("0.##"), ThumbnailUrl160 = item.ImagePath, MarketPrice = item.MarketPrice.ToString("0.##"), CartQuantity = quantity, HasSKU = item.HasSKU, SkuId = GetSkuIdByProductId(item.Id), //d.Himall_Products d.Field<string>("SkuId"), ActiveId = activeId, ActiveType = activetype //获取该商品是否参与活动 }; productList.Add(ChoiceProducts); } var json = new { Status = "OK", Data = new { ChoiceProducts = productList } }; return(json); }
/// <summary> /// 首页商品信息 /// </summary> /// <param name="openId"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public JsonResult <Result <List <dynamic> > > GetIndexProductData(string openId = "", int pageIndex = 1, int pageSize = 10) { var homeProducts = ServiceProvider.Instance <IWXSmallProgramService> .Create.GetWXSmallHomeProducts(pageIndex, pageSize); decimal discount = 1M; long SelfShopId = 0; var CartInfo = new Himall.Entities.ShoppingCartInfo(); var ids = homeProducts.Models.Select(p => p.Id).ToList(); var productList = new List <dynamic>(); var cartitems = new List <Himall.Entities.ShoppingCartItem>(); long userId = 0; if (CurrentUser != null) { userId = CurrentUser.Id; discount = CurrentUser.MemberDiscount; var shopInfo = ShopApplication.GetSelfShop(); SelfShopId = shopInfo.Id; CartInfo = ServiceProvider.Instance <ICartService> .Create.GetCart(CurrentUser.Id); cartitems = CartApplication.GetCartQuantityByIds(CurrentUser.Id, ids); } foreach (var item in homeProducts.Models) { long activeId = 0; int activetype = 0; item.ImagePath = Core.HimallIO.GetRomoteProductSizeImage(Core.HimallIO.GetImagePath(item.ImagePath), 1, (int)Himall.CommonModel.ImageSize.Size_350); if (item.ShopId == SelfShopId) { item.MinSalePrice = item.MinSalePrice * discount; } var limitBuy = ServiceProvider.Instance <ILimitTimeBuyService> .Create.GetLimitTimeMarketItemByProductId(item.Id); if (limitBuy != null) { item.MinSalePrice = limitBuy.MinPrice; activeId = limitBuy.Id; activetype = 1; } int quantity = 0; quantity = cartitems.Where(d => d.ProductId == item.Id).Sum(d => d.Quantity); long stock = 0; var productInfo = ServiceProvider.Instance <IProductService> .Create.GetProduct(item.Id); if (productInfo != null) { var skus = ProductManagerApplication.GetSKUs(productInfo.Id); stock = skus.Sum(x => x.Stock); if (productInfo.MaxBuyCount > 0) { stock = productInfo.MaxBuyCount; } } if (productInfo.AuditStatus == Entities.ProductInfo.ProductAuditStatus.Audited) { var ChoiceProducts = new { ProductId = item.Id, ProductName = item.ProductName, SalePrice = item.MinSalePrice.ToString("0.##"), ThumbnailUrl160 = item.ImagePath, MarketPrice = item.MarketPrice.ToString("0.##"), CartQuantity = quantity, HasSKU = item.HasSKU, SkuId = GetSkuIdByProductId(item.Id), ActiveId = activeId, ActiveType = activetype,//获取该商品是否参与活动 Stock = stock, IsVirtual = item.ProductType == 1 }; productList.Add(ChoiceProducts); } } return(JsonResult(productList)); }