public ActionResult Index()
        {
            string str;

            if (!IsInstalled())
            {
                return(RedirectToAction("Agreement", "Installer"));
            }
            ServiceHelper.Create <IMemberService>();
            ViewBag.OAuthValidateContents = GetOAuthValidateContents();
            ViewBag.SiteName = base.CurrentSiteSetting.SiteName;
            dynamic viewBag = base.ViewBag;

            str           = (string.IsNullOrWhiteSpace(base.CurrentSiteSetting.Site_SEOTitle) ? "Home" : base.CurrentSiteSetting.Site_SEOTitle);
            viewBag.Title = str;
            ViewEngines.Engines.FindView(base.ControllerContext, "Index", null);
            List <HomeFloorModel> homeFloorModels = new List <HomeFloorModel>();

            ViewBag.handImage = ServiceHelper.Create <ISlideAdsService>().GetHandSlidAds().ToList();
            List <SlideAdInfo> list = ServiceHelper.Create <ISlideAdsService>().GetSlidAds(0, SlideAdInfo.SlideAdType.PlatformHome).ToList();

            ViewBag.slideImage = list;
            dynamic obj = base.ViewBag;
            IEnumerable <ImageAdInfo> imageAds = ServiceHelper.Create <ISlideAdsService>().GetImageAds(0);

            obj.imageAds = imageAds.Where((ImageAdInfo p) => {
                if (p.Id <= 0)
                {
                    return(false);
                }
                return(p.Id <= 8);
            }).ToList();
            dynamic viewBag1 = base.ViewBag;
            IEnumerable <ImageAdInfo> imageAdInfos = ServiceHelper.Create <ISlideAdsService>().GetImageAds(0);

            viewBag1.imageAdsTop = imageAdInfos.Where((ImageAdInfo p) => {
                if (p.Id == 14)
                {
                    return(true);
                }
                return(p.Id == 15);
            }).ToList();
            IArticleService articleService = ServiceHelper.Create <IArticleService>();
            dynamic         obj1           = base.ViewBag;
            List <IQueryable <ArticleInfo> > queryables = new List <IQueryable <ArticleInfo> >()
            {
                articleService.GetTopNArticle <ArticleInfo>(8, 4, null, false),
                articleService.GetTopNArticle <ArticleInfo>(8, 5, null, false),
                articleService.GetTopNArticle <ArticleInfo>(8, 6, null, false),
                articleService.GetTopNArticle <ArticleInfo>(8, 7, null, false)
            };

            obj1.ArticleTabs = queryables;
            foreach (HomeFloorInfo homeFloorInfo in ServiceHelper.Create <IFloorService>().GetHomeFloors().ToList()) //超链接
            {
                if (homeFloorInfo.IsShow)                                                                            //过滤关闭的楼层
                {
                    HomeFloorModel        homeFloorModel  = new HomeFloorModel();
                    List <FloorTopicInfo> floorTopicInfos = (
                        from a in homeFloorInfo.FloorTopicInfo
                        where a.TopicType == Position.Top
                        select a).ToList();
                    List <FloorTopicInfo> list1 = (
                        from a in homeFloorInfo.FloorTopicInfo
                        where a.TopicType != Position.Top
                        select a).ToList();
                    List <FloorBrandInfo> floorBrandInfos = homeFloorInfo.FloorBrandInfo.Take(10).ToList();
                    homeFloorModel.Name           = homeFloorInfo.FloorName;
                    homeFloorModel.SubName        = homeFloorInfo.SubName;
                    homeFloorModel.StyleLevel     = homeFloorInfo.StyleLevel;
                    homeFloorModel.DefaultTabName = homeFloorInfo.DefaultTabName;
                    foreach (FloorTopicInfo floorTopicInfo in floorTopicInfos)
                    {
                        List <HomeFloorModel.WebFloorTextLink> textLinks        = homeFloorModel.TextLinks;
                        HomeFloorModel.WebFloorTextLink        webFloorTextLink = new HomeFloorModel.WebFloorTextLink()
                        {
                            Id   = floorTopicInfo.Id,
                            Name = floorTopicInfo.TopicName,
                            Url  = floorTopicInfo.Url
                        };
                        textLinks.Add(webFloorTextLink);
                    }
                    foreach (FloorTopicInfo floorTopicInfo1 in list1)
                    {
                        List <HomeFloorModel.WebFloorProductLinks> products            = homeFloorModel.Products;
                        HomeFloorModel.WebFloorProductLinks        webFloorProductLink = new HomeFloorModel.WebFloorProductLinks()
                        {
                            Id       = floorTopicInfo1.Id,
                            ImageUrl = floorTopicInfo1.TopicImage,
                            Url      = floorTopicInfo1.Url,
                            Type     = floorTopicInfo1.TopicType
                        };
                        products.Add(webFloorProductLink);
                    }
                    foreach (FloorBrandInfo floorBrandInfo in floorBrandInfos)
                    {
                        List <HomeFloorModel.WebFloorBrand> brands        = homeFloorModel.Brands;
                        HomeFloorModel.WebFloorBrand        webFloorBrand = new HomeFloorModel.WebFloorBrand()
                        {
                            Id   = floorBrandInfo.BrandInfo.Id,
                            Img  = floorBrandInfo.BrandInfo.Logo,
                            Url  = "",
                            Name = floorBrandInfo.BrandInfo.Name
                        };
                        brands.Add(webFloorBrand);
                    }
                    if (homeFloorModel.StyleLevel == 1)
                    {
                        homeFloorModel.Tabs = (
                            from p in homeFloorInfo.Himall_FloorTabls
                            orderby p.Id
                            select new HomeFloorModel.Tab()
                        {
                            Name = p.Name,
                            Detail = (
                                from d in p.Himall_FloorTablDetails
                                select new HomeFloorModel.ProductDetail()
                            {
                                ProductId = d.Himall_Products.Id,
                                ImagePath = d.Himall_Products.ImagePath,
                                Price = d.Himall_Products.MinSalePrice,
                                Name = d.Himall_Products.ProductName
                            }).ToList <HomeFloorModel.ProductDetail>()
                        }).ToList <HomeFloorModel.Tab>();
                        homeFloorModel.Scrolls = homeFloorModel.Products.Where <HomeFloorModel.WebFloorProductLinks>((HomeFloorModel.WebFloorProductLinks p) =>
                        {
                            if (p.Type == Position.ScrollOne || p.Type == Position.ScrollTwo || p.Type == Position.ScrollThree)
                            {
                                return(true);
                            }
                            return(p.Type == Position.ScrollFour);
                        }).ToList <HomeFloorModel.WebFloorProductLinks>();
                        homeFloorModel.RightTops = homeFloorModel.Products.Where <HomeFloorModel.WebFloorProductLinks>((HomeFloorModel.WebFloorProductLinks p) =>
                        {
                            if (p.Type == Position.ROne || p.Type == Position.RTwo || p.Type == Position.RThree)
                            {
                                return(true);
                            }
                            return(p.Type == Position.RFour);
                        }).ToList <HomeFloorModel.WebFloorProductLinks>();
                        homeFloorModel.RightBottons = homeFloorModel.Products.Where <HomeFloorModel.WebFloorProductLinks>((HomeFloorModel.WebFloorProductLinks p) =>
                        {
                            if (p.Type == Position.RFive || p.Type == Position.RSix || p.Type == Position.RSeven)
                            {
                                return(true);
                            }
                            return(p.Type == Position.REight);
                        }).ToList <HomeFloorModel.WebFloorProductLinks>();
                    }

                    homeFloorModels.Add(homeFloorModel);
                }
            }
            return(View(homeFloorModels));
        }
Beispiel #2
0
        public ActionResult Index()
        {
            if (!IsInstalled())
            {
                return(RedirectToAction("Agreement", "Installer"));
            }
            var ser_user = _iMemberService;

            #region 初始化首页数据
            var homePageModel = new HomePageModel();

            if (CurrentSiteSetting.AdvertisementState)
            {
                homePageModel.AdvertisementUrl       = CurrentSiteSetting.AdvertisementUrl;
                homePageModel.AdvertisementImagePath = CurrentSiteSetting.AdvertisementImagePath;
            }

            //获取信任登录插件需要在首页head中填充的验证内容
            ViewBag.OAuthValidateContents = GetOAuthValidateContents();
            homePageModel.SiteName        = CurrentSiteSetting.SiteName;
            homePageModel.Title           = string.IsNullOrWhiteSpace(CurrentSiteSetting.Site_SEOTitle) ? "商城首页" : CurrentSiteSetting.Site_SEOTitle;
            var view = ViewEngines.Engines.FindView(ControllerContext, "Index", null);
            List <HomeFloorModel> floorModels = new List <HomeFloorModel>();
            homePageModel.handImage = _iSlideAdsService.GetHandSlidAds().ToList();
            var silder = _iSlideAdsService.GetSlidAds(0, SlideAdInfo.SlideAdType.PlatformHome).ToList();
            homePageModel.slideImage = silder;
            var imageAds = _iSlideAdsService.GetImageAds(0).ToList();
            //人气单品
            homePageModel.imageAds = imageAds.Where(p => p.TypeId == Himall.CommonModel.ImageAdsType.Single).ToList();
            //banner右侧广告
            homePageModel.imageAdsTop = imageAds.Where(p => p.TypeId == Himall.CommonModel.ImageAdsType.BannerAds).ToList();

            homePageModel.CenterAds = imageAds.Where(p => p.TypeId == Himall.CommonModel.ImageAdsType.Customize).ToList();
            homePageModel.ShopAds   = imageAds.Where(p => p.TypeId == Himall.CommonModel.ImageAdsType.BrandsAds).ToList();

            if (homePageModel.imageAds.Count == 0)
            {
                homePageModel.imageAds = imageAds.Take(8).ToList();
            }
            if (homePageModel.imageAdsTop.Count == 0)
            {
                homePageModel.imageAdsTop = imageAds.Take(2).ToList();
            }
            if (homePageModel.CenterAds.Count == 0)
            {
                homePageModel.CenterAds = imageAds.Take(3).ToList();
            }
            if (homePageModel.ShopAds.Count == 0)
            {
                homePageModel.ShopAds = imageAds.Take(2).ToList();
            }

            /*没地方用,先去掉
             * var articleService = ServiceHelper.Create<IArticleService>();
             * ViewBag.ArticleTabs = new List<IQueryable<ArticleInfo>>()
             * {   articleService.GetTopNArticle<ArticleInfo>(8, 4),
             *      articleService.GetTopNArticle<ArticleInfo>(8, 5),
             *      articleService.GetTopNArticle<ArticleInfo>(8, 6),
             *      articleService.GetTopNArticle<ArticleInfo>(8, 7)
             * };
             */

            //楼层数据
            var floors = _iFloorService.GetHomeFloors().ToList();
            foreach (var f in floors)
            {
                var model          = new HomeFloorModel();
                var texts          = f.FloorTopicInfo.Where(a => a.TopicType == Position.Top).ToList();
                var products       = f.FloorTopicInfo.Where(a => a.TopicType != Position.Top).ToList();
                var productModules = f.FloorProductInfo.ToList();
                var brands         = f.FloorBrandInfo.Take(10).ToList();
                model.Name           = f.FloorName;
                model.SubName        = f.SubName;
                model.StyleLevel     = f.StyleLevel;
                model.DefaultTabName = f.DefaultTabName;

                //文本设置
                foreach (var s in texts)
                {
                    model.TextLinks.Add(new HomeFloorModel.WebFloorTextLink()
                    {
                        Id   = s.Id,
                        Name = s.TopicName,
                        Url  = s.Url
                    });
                }

                //广告设置
                foreach (var s in products)
                {
                    model.Products.Add(new HomeFloorModel.WebFloorProductLinks
                    {
                        Id       = s.Id,
                        ImageUrl = s.TopicImage,
                        Url      = s.Url,
                        Type     = s.TopicType
                    });
                }

                //推荐品牌
                foreach (var s in brands)
                {
                    model.Brands.Add(new WebFloorBrand
                    {
                        Id   = s.BrandInfo.Id,
                        Img  = s.BrandInfo.Logo,
                        Url  = "",
                        Name = s.BrandInfo.Name
                    });
                }

                //推荐商品
                foreach (var s in productModules)
                {
                    model.ProductModules.Add(new HomeFloorModel.ProductModule
                    {
                        Id          = s.Id,
                        ProductId   = s.ProductId,
                        MarketPrice = s.ProductInfo.MarketPrice,
                        price       = s.ProductInfo.MinSalePrice,
                        productImg  = Himall.Core.HimallIO.GetProductSizeImage(s.ProductInfo.ImagePath, 1, (int)ImageSize.Size_350),
                        productName = s.ProductInfo.ProductName,
                        Tab         = s.Tab
                    });
                }

                if (model.StyleLevel == 1 || model.StyleLevel == 4 || model.StyleLevel == 5 || model.StyleLevel == 6 || model.StyleLevel == 7)
                {
                    model.Tabs = f.Himall_FloorTabls.OrderBy(p => p.Id).Select(p => new Himall.Web.Areas.Web.Models.HomeFloorModel.Tab()
                    {
                        Name   = p.Name,
                        Detail = p.Himall_FloorTablDetails.ToList()
                                 .Where(d => d.Himall_Products.AuditStatus == ProductInfo.ProductAuditStatus.Audited &&
                                        d.Himall_Products.SaleStatus == ProductInfo.ProductSaleStatus.OnSale)
                                 .Select(d => new Himall.Web.Areas.Web.Models.HomeFloorModel.ProductDetail()
                        {
                            ProductId = d.Himall_Products.Id,
                            ImagePath = Himall.Core.HimallIO.GetProductSizeImage(d.Himall_Products.ImagePath, 1, (int)ImageSize.Size_350),
                            Price     = d.Himall_Products.MinSalePrice,
                            Name      = d.Himall_Products.ProductName
                        }).ToList()
                    }).ToList();

                    model.Scrolls = model.Products.Where(p => p.Type == Position.ScrollOne || p.Type == Position.ScrollTwo ||
                                                         p.Type == Position.ScrollThree || p.Type == Position.ScrollFour).ToList();

                    model.RightTops = model.Products.Where(p => p.Type == Position.ROne || p.Type == Position.RTwo ||
                                                           p.Type == Position.RThree || p.Type == Position.RFour).ToList();

                    model.RightBottons = model.Products.Where(p => p.Type == Position.RFive || p.Type == Position.RSix ||
                                                              p.Type == Position.RSeven || p.Type == Position.REight).ToList();
                }
                floorModels.Add(model);
            }
            homePageModel.floorModels = floorModels;

            //全部品牌
            HomeBrands homeBrands = new HomeBrands();
            var        listBrands = Application.BrandApplication.GetBrands(null);
            foreach (var item in listBrands)
            {
                homeBrands.listBrands.Add(new WebFloorBrand
                {
                    Id   = item.Id,
                    Img  = item.Logo,
                    Url  = "",
                    Name = item.Name
                });
            }
            homePageModel.brands = homeBrands;

            //限时购
            var setting = _iSiteSettingService.GetSiteSettings();
            if (setting.Limittime)
            {
                homePageModel.FlashSaleModel = _iLimitTimeBuyService.GetRecentFlashSale();
            }
            else
            {
                homePageModel.FlashSaleModel = new List <FlashSaleModel>();
            }

            return(View(homePageModel));

            #endregion
        }