Exemple #1
0
        /// <summary>
        /// 店铺搜索
        /// </summary>
        public ActionResult Search()
        {
            //搜索词
            string keyword = WebHelper.GetQueryString("keyword");

            if (keyword.Length > 0 && !SecureHelper.IsSafeSqlString(keyword))
            {
                return(View("~/mobile/views/shared/prompt.cshtml", new PromptModel(WorkContext.UrlReferrer, "您搜索的商品不存在")));
            }

            //判断搜索词是否为店铺分类名称,如果是则重定向到店铺分类页面
            int storeCid = Stores.GetStoreCidByStoreIdAndName(WorkContext.StoreId, keyword);

            if (storeCid > 0)
            {
                return(Redirect(Url.Action("class", new RouteValueDictionary {
                    { "storeId", WorkContext.StoreId }, { "storeCid", storeCid }
                })));
            }

            //排序列
            int sortColumn = WebHelper.GetQueryInt("sortColumn");
            //排序方向
            int sortDirection = WebHelper.GetQueryInt("sortDirection");
            //当前页数
            int page = WebHelper.GetQueryInt("page");

            //分页对象
            PageModel pageModel = new PageModel(20, page, Searches.GetSearchStoreProductCount(keyword, WorkContext.StoreId, 0, 0, 0));
            //视图对象
            StoreSearchModel model = new StoreSearchModel()
            {
                Word          = keyword,
                SortColumn    = sortColumn,
                SortDirection = sortDirection,
                PageModel     = pageModel,
                ProductList   = Searches.SearchStoreProducts(pageModel.PageSize, pageModel.PageNumber, keyword, WorkContext.StoreId, 0, 0, 0, sortColumn, sortDirection)
            };

            //异步保存搜索历史
            Asyn.UpdateSearchHistory(WorkContext.Uid, keyword);

            return(View(model));
        }