/// <summary> /// 搜索 /// </summary> public ActionResult AjaxSearch() { //搜索词 string keyword = WebHelper.GetQueryString("keyword"); if (keyword.Length == 0) { return(Content("")); } if (!SecureHelper.IsSafeSqlString(keyword)) { return(Content("")); } //分类id int cateId = WebHelper.GetQueryInt("cateId"); //品牌id int brandId = WebHelper.GetQueryInt("brandId"); //筛选价格 int filterPrice = WebHelper.GetQueryInt("filterPrice"); //筛选属性 string filterAttr = WebHelper.GetQueryString("filterAttr"); //是否只显示有货 int onlyStock = WebHelper.GetQueryInt("onlyStock"); //排序列 int sortColumn = WebHelper.GetQueryInt("sortColumn"); //排序方向 int sortDirection = WebHelper.GetQueryInt("sortDirection"); //当前页数 int page = WebHelper.GetQueryInt("page"); //分类信息 CategoryInfo categoryInfo = Categories.GetCategoryById(cateId); //分类价格范围列表 string[] catePriceRangeList = StringHelper.SplitString(categoryInfo.PriceRange, "\r\n"); //筛选属性处理 List <int> attrValueIdList = new List <int>(); string[] filterAttrValueIdList = StringHelper.SplitString(filterAttr, "-"); foreach (string attrValueId in filterAttrValueIdList) { int temp = TypeHelper.StringToInt(attrValueId); if (temp > 0) { attrValueIdList.Add(temp); } } //分页对象 PageModel pageModel = new PageModel(20, page, Searches.GetSearchProductCount(keyword, cateId, brandId, filterPrice, catePriceRangeList, attrValueIdList, onlyStock)); //视图对象 AjaxSearchModel model = new AjaxSearchModel() { PageModel = pageModel, ProductList = Searches.SearchProducts(pageModel.PageSize, pageModel.PageNumber, keyword, cateId, brandId, filterPrice, catePriceRangeList, attrValueIdList, onlyStock, sortColumn, sortDirection) }; return(Json(model, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 搜索 /// </summary> public ActionResult AjaxSearch() { //搜索词 string word = WebHelper.GetQueryString("word"); //分类id int cateId = WebHelper.GetQueryInt("cateId"); //品牌id int brandId = WebHelper.GetQueryInt("brandId"); //筛选价格 int filterPrice = WebHelper.GetQueryInt("filterPrice"); //筛选属性 string filterAttr = WebHelper.GetQueryString("filterAttr"); //是否只显示有货 int onlyStock = WebHelper.GetQueryInt("onlyStock"); //排序列 int sortColumn = WebHelper.GetQueryInt("sortColumn"); //排序方向 int sortDirection = WebHelper.GetQueryInt("sortDirection"); //当前页数 int page = WebHelper.GetQueryInt("page"); if (word.Length == 0) { return(Content("")); } //筛选属性处理 List <int> attrValueIdList = new List <int>(); foreach (string attrValueId in StringHelper.SplitString(filterAttr, "-")) { int temp = TypeHelper.StringToInt(attrValueId); if (temp > 0) { attrValueIdList.Add(temp); } } //分类信息 CategoryInfo categoryInfo = null; //分类价格范围列表 string[] catePriceRangeList = null; //分类筛选属性及其值列表 List <KeyValuePair <AttributeInfo, List <AttributeValueInfo> > > cateAAndVList = null; //分类列表 List <CategoryInfo> categoryList = null; //品牌信息 BrandInfo brandInfo = null; //品牌列表 List <BrandInfo> brandList = null; //商品总数量 int totalCount = 0; //商品列表 List <PartProductInfo> productList = null; //搜索 Searches.SearchProducts(20, page, word, cateId, brandId, filterPrice, null, onlyStock, sortColumn, sortDirection, ref categoryInfo, ref catePriceRangeList, ref cateAAndVList, ref categoryList, ref brandInfo, ref brandList, ref totalCount, ref productList); //分页对象 PageModel pageModel = new PageModel(20, page, totalCount); //视图对象 AjaxSearchModel model = new AjaxSearchModel() { PageModel = pageModel, ProductList = productList }; return(Content(JsonConvert.SerializeObject(model))); }