Exemplo n.º 1
0
        public ActionResult Category(int id, int?country, int?manufacturerId, int?packId, object specs, SortCriterion?sort, List <List <int> > catFilter = null, int?minPrice = null, int?maxPrice = null, string query = null)
        {
            bool exists = _shopCategoryService.CategoryExists(id);

            if (!exists)
            {
                throw new HttpException(404, "Not found");
            }


            var cat = _shopCategoryService.GetCategory(id);

            var routeValues = ParamExtractor.ExtractParamsForSEF(Request);
            var args        = new RouteValueDictionary(routeValues);

            args.Add("relativeUrl", cat.CanonicalUrl);
            args.Remove("id");
            return(RedirectPermanent(Url.RouteUrl(typeof(Category).FullName, args)));
        }
Exemplo n.º 2
0
        public ActionResult Search(string sid, long cid = 0, string keywords = "", int pageNo = 1, decimal startPrice = 0, decimal endPrice = decimal.MaxValue)
        {
            int      pageSize = 40;
            long     shopId   = 0;
            ShopInfo shopObj  = null;

            endPrice   = endPrice <= 0 || endPrice < startPrice ? decimal.MaxValue : endPrice;
            startPrice = startPrice < 0 ? 0 : startPrice;

            //shopId 不是数字
            if (!long.TryParse(sid, 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 <BannerInfo>(),
                Shop         = new ShopInfoModel(),
                ShopCategory = new List <CategoryJsonModel>(),
                Slides       = new List <SlideAdInfo>(),
                Logo         = ""
            };

            #endregion

            #region 导航和3个推荐商品

            //导航
            model.Navignations = _iNavigationService.GetSellerNavigations(shopObj.Id).ToList();

            //banner和3个推荐商品
            model.ImageAds = _iSlideAdsService.GetImageAds(shopObj.Id).OrderBy(item => item.Id).ToList();

            model.Slides = _iSlideAdsService.GetSlidAds(shopObj.Id, SlideAdInfo.SlideAdType.ShopHome).ToList();

            #endregion

            #region 店铺分类

            var categories = _iShopCategoryService.GetShopCategory(shopObj.Id).ToArray();
            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 店铺信息

            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

            #region 初始化查询Model并查询商品
            SearchProductQuery search = new SearchProductQuery()
            {
                StartPrice     = startPrice,
                EndPrice       = endPrice,
                ShopId         = shopId,
                BrandId        = 0,
                ShopCategoryId = cid,
                Keyword        = keywords,
                OrderKey       = 0,
                OrderType      = true,
                PageSize       = pageSize,
                PageNumber     = pageNo
            };

            var productsModel = _iSearchProductService.SearchProduct(search);
            int total         = productsModel.Total;
            var products      = productsModel.Data;

            foreach (var pro in products)
            {
                pro.SaleCount = (int)_iProductService.GetProductVistInfo(pro.ProductId).SaleCounts;
            }
            model.Products = products;

            #endregion

            #region 热门销售

            var sale = _iProductService.GetHotSaleProduct(shopObj.Id, 5);
            if (sale != null)
            {
                foreach (var item in sale)
                {
                    model.HotSaleProducts.Add(new HotProductInfo
                    {
                        ImgPath   = item.ImagePath,
                        Name      = item.ProductName,
                        Price     = item.MinSalePrice,
                        Id        = item.Id,
                        SaleCount = (int)item.SaleCounts
                    });
                }
            }

            #endregion


            #region 热门关注

            var hot = _iProductService.GetHotConcernedProduct(shopObj.Id, 5).ToList();
            if (hot != null)
            {
                foreach (var item in hot)
                {
                    model.HotAttentionProducts.Add(new HotProductInfo
                    {
                        ImgPath   = item.ImagePath,
                        Name      = item.ProductName,
                        Price     = item.MinSalePrice,
                        Id        = item.Id,
                        SaleCount = (int)item.ConcernedCount
                    });
                }
            }
            #endregion

            #region 获取店铺的评价统计
            var shopStatisticOrderComments = _iShopService.GetShopStatisticOrderComments(shopId);

            var productAndDescription = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescription).FirstOrDefault();
            var sellerServiceAttitude = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitude).FirstOrDefault();
            var sellerDeliverySpeed   = shopStatisticOrderComments.Where(c => c.CommentKey ==
                                                                         StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeed).FirstOrDefault();

            var productAndDescriptionPeer = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionPeer).FirstOrDefault();
            var sellerServiceAttitudePeer = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudePeer).FirstOrDefault();
            var sellerDeliverySpeedPeer   = shopStatisticOrderComments.Where(c => c.CommentKey ==
                                                                             StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedPeer).FirstOrDefault();

            var productAndDescriptionMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionMax).FirstOrDefault();
            var productAndDescriptionMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.ProductAndDescriptionMin).FirstOrDefault();

            var sellerServiceAttitudeMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudeMax).FirstOrDefault();
            var sellerServiceAttitudeMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerServiceAttitudeMin).FirstOrDefault();

            var sellerDeliverySpeedMax = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedMax).FirstOrDefault();
            var sellerDeliverySpeedMin = shopStatisticOrderComments.Where(c => c.CommentKey == StatisticOrderCommentsInfo.EnumCommentKey.SellerDeliverySpeedMin).FirstOrDefault();

            decimal defaultValue = 5;
            //宝贝与描述
            if (productAndDescription != null && productAndDescriptionPeer != null)
            {
                ViewBag.ProductAndDescription     = productAndDescription.CommentValue;
                ViewBag.ProductAndDescriptionPeer = productAndDescriptionPeer.CommentValue;
                ViewBag.ProductAndDescriptionMin  = productAndDescriptionMin.CommentValue;
                ViewBag.ProductAndDescriptionMax  = productAndDescriptionMax.CommentValue;
            }
            else
            {
                ViewBag.ProductAndDescription     = defaultValue;
                ViewBag.ProductAndDescriptionPeer = defaultValue;
                ViewBag.ProductAndDescriptionMin  = defaultValue;
                ViewBag.ProductAndDescriptionMax  = defaultValue;
            }
            //卖家服务态度
            if (sellerServiceAttitude != null && sellerServiceAttitudePeer != null)
            {
                ViewBag.SellerServiceAttitude     = sellerServiceAttitude.CommentValue;
                ViewBag.SellerServiceAttitudePeer = sellerServiceAttitudePeer.CommentValue;
                ViewBag.SellerServiceAttitudeMax  = sellerServiceAttitudeMax.CommentValue;
                ViewBag.SellerServiceAttitudeMin  = sellerServiceAttitudeMin.CommentValue;
            }
            else
            {
                ViewBag.SellerServiceAttitude     = defaultValue;
                ViewBag.SellerServiceAttitudePeer = defaultValue;
                ViewBag.SellerServiceAttitudeMax  = defaultValue;
                ViewBag.SellerServiceAttitudeMin  = defaultValue;
            }
            //卖家发货速度
            if (sellerDeliverySpeedPeer != null && sellerDeliverySpeed != null)
            {
                ViewBag.SellerDeliverySpeed     = sellerDeliverySpeed.CommentValue;
                ViewBag.SellerDeliverySpeedPeer = sellerDeliverySpeedPeer.CommentValue;
                ViewBag.SellerDeliverySpeedMax  = sellerDeliverySpeedMax.CommentValue;
                ViewBag.sellerDeliverySpeedMin  = sellerDeliverySpeedMin.CommentValue;
            }
            else
            {
                ViewBag.SellerDeliverySpeed     = defaultValue;
                ViewBag.SellerDeliverySpeedPeer = defaultValue;
                ViewBag.SellerDeliverySpeedMax  = defaultValue;
                ViewBag.sellerDeliverySpeedMin  = defaultValue;
            }
            #endregion

            #region 分页控制
            PagingInfo info = new PagingInfo
            {
                CurrentPage  = pageNo,
                ItemsPerPage = pageSize,
                TotalItems   = total
            };
            ViewBag.pageInfo = info;
            #endregion
            var categoryName = string.Empty;
            if (keywords == string.Empty)
            {
                if (cid != 0)
                {
                    var category = _iShopCategoryService.GetCategory(cid) ?? new ShopCategoryInfo()
                    {
                    };
                    categoryName = category.Name;
                }
            }
            ViewBag.CategoryName   = categoryName;
            ViewBag.Keyword        = keywords;
            ViewBag.cid            = cid;
            ViewBag.BrowsedHistory = BrowseHistrory.GetBrowsingProducts(13, CurrentUser == null ? 0 : CurrentUser.Id);

            //补充当前店铺红包功能
            ViewBag.isShopPage     = true;
            ViewBag.CurShopId      = shopId;
            TempData["isShopPage"] = true;
            TempData["CurShopId"]  = shopId;

            return(View(model));
        }