public static List <ProductCollocationModel> GetDisplayCollocation(long productID) { var result = new List <ProductCollocationModel>(); var collocations = Service.GetAvailableCollocationByProduct(productID); if (collocations.Count == 0) { return(result); } var collProducts = Service.GetProducts(collocations.Select(p => p.Id).ToList()); var collSKUs = Service.GetSKUs(collProducts.Select(p => p.Id).ToList()); var allProducts = ProductManagerApplication.GetOnSaleProducts(collProducts.Select(p => p.ProductId).ToList()); var allSKUs = ProductManagerApplication.GetSKUByProducts(allProducts.Select(p => p.Id).ToList()); //移除不在销售中的活动商品 collProducts = collProducts.Where(p => allProducts.Select(o => o.Id).Contains(p.ProductId)).ToList(); var index = 0; foreach (var collocation in collocations) { var cProducts = collProducts.Where(p => p.ColloId == collocation.Id); var mainProduct = cProducts.FirstOrDefault(p => p.IsMain); if (mainProduct == null) { continue; //主商品不在销售中 } index++; var item = new ProductCollocationModel(); item.Id = item.Id; item.Name = "组合购" + GetChineseNumber(index); item.ProductId = mainProduct.ProductId; item.ShopId = collocation.ShopId; item.Products = cProducts.Select(cp => { var product = allProducts.FirstOrDefault(p => p.Id == cp.ProductId); var skus = allSKUs.Where(p => p.ProductId == cp.ProductId); var cSKUs = collSKUs.Where(p => p.ColloProductId == cp.Id); return(new CollocationProducts() { DisplaySequence = cp.DisplaySequence, IsMain = cp.IsMain, Stock = skus.Sum(t => t.Stock), MaxCollPrice = cSKUs.Max(x => x.Price), MaxSalePrice = cSKUs.Max(x => x.SkuPirce), MinCollPrice = cSKUs.Min(x => x.Price), MinSalePrice = cSKUs.Min(x => x.SkuPirce), ProductName = product.ProductName, ProductId = cp.ProductId, ColloPid = cp.Id, Image = Core.MallIO.GetImagePath(product.RelativePath) }); }).ToList(); item.Cheap = item.Products.Sum(a => a.MaxSalePrice) - item.Products.Sum(a => a.MinCollPrice); result.Add(item); } return(result); }
// GET: Mobile/PortfolioBuy public ActionResult ProductDetail(long productId) { var serivce = ServiceApplication.Create <ICollocationService>(); var collocation = serivce.GetCollocationByProductId(productId); if (collocation == null) { return(View()); } var cProducts = serivce.GetProducts(new List <long> { collocation.Id }); var allCollSKUs = serivce.GetSKUs(cProducts.Select(p => p.Id).ToList()); var products = ProductManagerApplication.GetOnSaleProducts(cProducts.Select(p => p.ProductId).ToList()); var allSKUs = ProductManagerApplication.GetSKUByProducts(products.Select(p => p.Id).ToList()); //移除下架商品 cProducts = cProducts.Where(p => products.Select(o => o.Id).Contains(p.ProductId)).ToList(); var result = cProducts.Select(item => { var product = products.FirstOrDefault(p => p.Id == item.ProductId); var cSKUs = allCollSKUs.Where(p => p.ProductId == item.ProductId); var skus = allSKUs.Where(p => p.ProductId == item.ProductId); var collocationProduct = new CollocationProducts() { DisplaySequence = item.DisplaySequence, IsMain = item.IsMain, Stock = skus.Sum(t => t.Stock), ProductName = product.ProductName, ProductId = item.ProductId, ColloPid = item.Id, Image = Core.MallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Mall.CommonModel.ImageSize.Size_100), IsShowSku = isShowSku(item.ProductId) }; if (cSKUs != null && cSKUs.Count() > 0) { collocationProduct.MaxCollPrice = cSKUs.Max(x => x.Price); collocationProduct.MaxSalePrice = cSKUs.Max(x => x.SkuPirce); collocationProduct.MinCollPrice = cSKUs.Min(x => x.Price); collocationProduct.MinSalePrice = cSKUs.Min(x => x.SkuPirce); } return(collocationProduct); }).Where(p => p.Stock > 0).OrderBy(a => a.DisplaySequence).ToList(); return(View(result)); }
/// <summary> /// 获取当前商品可参与的组合购 /// </summary> /// <param name="product"></param> /// <returns></returns> public static int GetCollocationCount(long product) { var colls = Service.GetAvailableCollocationByProduct(product); var collProducts = Service.GetProducts(colls.Select(p => p.Id).ToList()); var products = ProductManagerApplication.GetOnSaleProducts(collProducts.Select(p => p.ProductId).ToList()); int result = 0; foreach (var coll in colls) { var cProduct = collProducts.Where(p => p.ColloId == coll.Id); var mainProduct = cProduct.FirstOrDefault(p => p.IsMain); if (products.Any(p => p.Id == mainProduct.ProductId)) { result++; } } return(result); }
public object LoadProducts(long topicId, long moduleId) { var topic = TopicApplication.GetTopic(topicId); var module = TopicApplication.GetModules(moduleId); var products = TopicApplication.GetModuleProducts(moduleId); var onSales = ProductManagerApplication.GetOnSaleProducts(products.Select(p => p.ProductId).ToList()); var model = onSales.Select(item => new TopicModuleProductModel { Name = item.ProductName, Id = item.Id, Image = item.GetImage(ImageSize.Size_350), Price = item.MinSalePrice, MarketPrice = item.MarketPrice }); dynamic result = SuccessResult(); result.data = model.ToList(); return(result); }
public object GetTopicDetail(long id) { var topic = TopicApplication.GetTopic(id); var modules = TopicApplication.GetModules(id); var allModuleProducts = TopicApplication.GetModuleProducts(modules.Select(p => p.Id)); var allOnSaleProducts = ProductManagerApplication.GetOnSaleProducts(allModuleProducts.Select(p => p.ProductId).ToList()); TopicModel model = new TopicModel(); model.Id = topic.Id; model.Name = topic.Name; model.TopImage = MallIO.GetRomoteImagePath(topic.TopImage); model.TopicModule = new List <TopicModuleModel>(); foreach (var module in modules) { var topicModuleModel = new TopicModuleModel(); var moduleProducts = allModuleProducts.Where(p => p.ModuleId == module.Id); topicModuleModel.Id = module.Id; topicModuleModel.Name = module.Name; topicModuleModel.TopicModelProduct = allOnSaleProducts .Where(p => moduleProducts.Select(x => x.ProductId).Contains(p.Id)) .Select(item => new TopicModuleProductModel { Name = item.ProductName, Id = item.Id, Image = Core.MallIO.GetRomoteProductSizeImage(item.RelativePath, 1, (int)Mall.CommonModel.ImageSize.Size_350), Price = item.MinSalePrice, MarketPrice = item.MarketPrice }).ToList(); model.TopicModule.Add(topicModuleModel); } dynamic result = SuccessResult(); result.Topic = model; return(result); }
public JsonResult GetUserShippingAddressesList(long topicId, long moduleId, int page, int pageSize) { var topic = TopicApplication.GetTopic(topicId); var module = TopicApplication.GetModules(moduleId); var products = TopicApplication.GetModuleProducts(moduleId); var onSales = ProductManagerApplication.GetOnSaleProducts(products.Select(p => p.ProductId).ToList()) .Skip(pageSize * (page - 1)) .Take(pageSize); //TODO:FG 数据分页 业务需要降层。 var model = onSales.Select(item => { var flashSaleModel = _iLimitTimeBuyService.GetFlaseSaleByProductId(item.Id); return(new { name = item.ProductName, id = item.Id, image = item.GetImage(ImageSize.Size_350), price = flashSaleModel != null ? flashSaleModel.MinPrice : item.MinSalePrice, marketPrice = item.MarketPrice }); }); return(SuccessResult <dynamic>(data: model)); }
public static List <ProductBrowsedHistoryModel> GetBrowsingProducts(int num, long userId = 0) { List <ProductBrowsedHistoryModel> productIdList = new List <ProductBrowsedHistoryModel>(); string productIds = Core.Helper.WebHelper.GetCookie(CookieKeysCollection.Mall_PRODUCT_BROWSING_HISTORY); if (!string.IsNullOrEmpty(productIds)) { var arr = productIds.Split(','); foreach (var a in arr) { var item = a.Split('#'); if (item.Length > 1) { productIdList.Add(new ProductBrowsedHistoryModel() { ProductId = long.Parse(item[0]), BrowseTime = DateTime.Parse(item[1]) }); } else { productIdList.Add(new ProductBrowsedHistoryModel() { ProductId = long.Parse(item[0]), BrowseTime = DateTime.Now }); } } } var ids = productIdList.Select(p => p.ProductId).ToList(); List <FlashSalePrice> flashSaleList = LimitTimeApplication.GetPriceByProducrIds(ids); List <ProductBrowsedHistoryModel> model = new List <ProductBrowsedHistoryModel>(); if (userId == 0) { var products = ProductManagerApplication.GetProductByIds(productIdList.Select(a => a.ProductId)) .Where(d => d.SaleStatus == Entities.ProductInfo.ProductSaleStatus.OnSale && d.AuditStatus == Entities.ProductInfo.ProductAuditStatus.Audited).ToArray() .Select(a => new ProductBrowsedHistoryModel() { ImagePath = Core.MallIO.GetProductSizeImage(a.RelativePath, 1, (int)ImageSize.Size_100), ProductId = a.Id, ProductName = a.ProductName, ProductPrice = GetRealPrice(flashSaleList, a.Id, a.MinSalePrice), ShopId = a.ShopId }).ToList(); return(products.OrderByDescending(a => a.BrowseTime).ToList()); } else { foreach (var m in productIdList) { AddBrowsingProduct(m.ProductId, userId); } var browsing = ProductManagerApplication.GetBrowsingProducts(userId); var products = ProductManagerApplication.GetOnSaleProducts(browsing.Select(p => p.ProductId).ToList()); browsing = browsing.Where(p => products.Select(o => o.Id).Contains(p.ProductId)).ToList(); model = browsing.OrderByDescending(a => a.BrowseTime).Take(num) .Select(a => { var product = products.FirstOrDefault(p => p.Id == a.ProductId); return(new ProductBrowsedHistoryModel() { ImagePath = Core.MallIO.GetProductSizeImage(product.RelativePath, 1, (int)ImageSize.Size_100), ProductId = a.ProductId, ProductName = product.ProductName, ProductPrice = GetRealPrice(flashSaleList, a.ProductId, product.MinSalePrice), BrowseTime = a.BrowseTime, ShopId = product.ShopId }); }).ToList(); } return(model); }
// GET: Web/Shop // [OutputCache(VaryByParam = "id", Duration = ConstValues.PAGE_CACHE_DURATION)] public ActionResult Home(string id) { long shopId = 0; Entities.ShopInfo shopObj = null; //shopId 不是数字 if (!long.TryParse(id, out shopId)) { return(RedirectToAction("Error404", "Error", new { area = "Web" })); //404 页面 } //店铺Id不存在 shopObj = _iShopService.GetShop(shopId); if (null == shopObj) { return(RedirectToAction("Error404", "Error", new { area = "Web" })); //404 页面 } #region 初始化Model ShopHomeModel model = new ShopHomeModel { HotAttentionProducts = new List <HotProductInfo>(), HotSaleProducts = new List <HotProductInfo>(), Floors = new List <ShopHomeFloor>(), Navignations = new List <Entities.BannerInfo>(), Shop = new ShopInfoModel(), ShopCategory = new List <CategoryJsonModel>(), Slides = new List <Entities.SlideAdInfo>(), Logo = "" }; #endregion #region 店铺信息 var mark = ShopServiceMark.GetShopComprehensiveMark(shopObj.Id); model.Shop.Name = shopObj.ShopName; model.Shop.CompanyName = shopObj.CompanyName; model.Shop.Id = shopObj.Id; model.Shop.PackMark = mark.PackMark; model.Shop.ServiceMark = mark.ServiceMark; model.Shop.ComprehensiveMark = mark.ComprehensiveMark; model.Shop.Phone = shopObj.CompanyPhone; model.Shop.Address = _iRegionService.GetFullName(shopObj.CompanyRegionId); model.Logo = shopObj.Logo; #endregion if (shopObj.IsSelf) { model.Shop.PackMark = 5; model.Shop.ServiceMark = 5; model.Shop.ComprehensiveMark = 5; } #region 导航和3个推荐商品 //导航 model.Navignations = _iNavigationService.GetSellerNavigations(shopObj.Id).ToList(); //banner和3个推荐商品 var list = _iSlideAdsService.GetImageAds(shopObj.Id).OrderBy(item => item.Id).ToList(); model.ImageAds = list.Where(p => !p.IsTransverseAD).ToList(); model.TransverseAD = list.FirstOrDefault(p => p.IsTransverseAD); model.Slides = _iSlideAdsService.GetSlidAds(shopObj.Id, Entities.SlideAdInfo.SlideAdType.ShopHome).ToList(); #endregion #region 店铺分类 var categories = _iShopCategoryService.GetShopCategory(shopObj.Id).Where(a => a.IsShow).ToList();//这里不好写到底层去,有些地方产品设计上不需要过滤 foreach (var main in categories.Where(s => s.ParentCategoryId == 0)) { var topC = new CategoryJsonModel() { Name = main.Name, Id = main.Id.ToString(), SubCategory = new List <SecondLevelCategory>() }; foreach (var secondItem in categories.Where(s => s.ParentCategoryId == main.Id)) { var secondC = new SecondLevelCategory() { Name = secondItem.Name, Id = secondItem.Id.ToString(), }; topC.SubCategory.Add(secondC); } model.ShopCategory.Add(topC); } #endregion #region 楼层信息 bool isSaleCountOnOff = SiteSettingApplication.SiteSettings.ProductSaleCountOnOff == 1; var shopHomeModules = _iShopHomeModuleService.GetAllShopHomeModuleInfos(shopObj.Id).Where(a => a.IsEnable).OrderBy(p => p.DisplaySequence); ShopHomeFloorProduct info = null; var modules = shopHomeModules.Select(p => p.Id).ToList(); var imgs = _iShopHomeModuleService.GetImages(modules); var moduleProducts = _iShopHomeModuleService.GetProducts(modules); var onSaleProducts = ProductManagerApplication.GetOnSaleProducts(moduleProducts.Select(p => p.ProductId).ToList()); foreach (var item in shopHomeModules) { List <ShopHomeFloorProduct> products = new List <ShopHomeFloorProduct>(); var moduleProduct = moduleProducts.Where(p => p.HomeModuleId == item.Id); foreach (var p in moduleProduct.OrderBy(p => p.DisplaySequence)) { var product = onSaleProducts.FirstOrDefault(x => x.Id == p.ProductId); if (product == null) { continue; } info = new ShopHomeFloorProduct { Id = product.Id, Name = product.ProductName, Pic = product.ImagePath, Price = product.MinSalePrice.ToString("f2"), //TODO:FG 循环查询销量 待优化 SaleCount = (int)_iProductService.GetProductVistInfo(product.Id).SaleCounts }; if (isSaleCountOnOff) { info.SaleCount = info.SaleCount + (int)product.VirtualSaleCounts; } products.Add(info); } var topimgs = imgs .Where(p => p.HomeModuleId == item.Id) .OrderBy(p => p.DisplaySequence) .Select(i => new ShopHomeFloorTopImg { Url = i.Url, ImgPath = i.ImgPath }).ToList(); model.Floors.Add(new ShopHomeFloor { FloorName = item.Name, FloorUrl = item.Url, Products = products, TopImgs = topimgs }); } #endregion #region 热门销售 //热门销售不受平台销量开关影响 var sale = _iProductService.GetHotSaleProduct(shopObj.Id, 5); if (sale != null) { HotProductInfo hotInfo = null; foreach (var item in sale.ToArray()) { hotInfo = new HotProductInfo { ImgPath = item.ImagePath, Name = item.ProductName, Price = item.MinSalePrice, Id = item.Id, SaleCount = (int)item.SaleCounts }; hotInfo.SaleCount = hotInfo.SaleCount + Mall.Core.Helper.TypeHelper.ObjectToInt(item.VirtualSaleCounts); model.HotSaleProducts.Add(hotInfo); } } #endregion #region 热门关注 var hot = _iProductService.GetHotConcernedProduct(shopObj.Id, 5); if (hot != null) { HotProductInfo hot_Info = null; foreach (var item in hot.ToList()) { hot_Info = new HotProductInfo { ImgPath = item.ImagePath, Name = item.ProductName, Price = item.MinSalePrice, Id = item.Id, SaleCount = (int)item.ConcernedCount }; model.HotAttentionProducts.Add(hot_Info); } } #endregion #region 微店二维码 var vshop = _iVShopService.GetVShopByShopId(shopObj.Id); string vshopUrl = ""; if (vshop != null) { vshopUrl = CurrentUrlHelper.CurrentUrlNoPort() + "/m-" + PlatformType.WeiXin.ToString() + "/vshop/detail/" + vshop.Id; CreateQR(model, vshop.StrLogo, vshopUrl); } else { vshopUrl = CurrentUrlHelper.CurrentUrlNoPort() + "/m-" + PlatformType.WeiXin.ToString(); CreateQR(model, string.Empty, vshopUrl); } #endregion #region 店铺页脚 model.Footer = _iShopHomeModuleService.GetFooter(shopObj.Id); #endregion ViewBag.IsExpired = _iShopService.IsExpiredShop(shopId); ViewBag.IsFreeze = _iShopService.IsFreezeShop(shopId); //补充当前店铺红包功能 ViewBag.isShopPage = true; ViewBag.CurShopId = shopId; TempData["isShopPage"] = true; TempData["CurShopId"] = shopId; //统计店铺访问人数 StatisticApplication.StatisticShopVisitUserCount(shopId); ViewBag.Keyword = string.IsNullOrWhiteSpace(SiteSettings.SearchKeyword) ? SiteSettings.Keyword : SiteSettings.SearchKeyword; ViewBag.Keywords = SiteSettings.HotKeyWords; ViewBag.IsOpenTopImageAd = shopObj.IsOpenTopImageAd; return(View(model)); }