/// <summary> /// 店铺搜索 /// </summary> public ActionResult Search() { //搜索词 string word = WebHelper.GetQueryString("word"); if (word.Length == 0) { return(View("~/mobile/views/shared/prompt.cshtml", new PromptModel(WorkContext.UrlReferrer, "请输入关键词"))); } //异步保存搜索历史 Asyn.UpdateSearchHistory(WorkContext.Uid, word); //判断搜索词是否为店铺分类名称,如果是则重定向到店铺分类页面 int storeCid = Stores.GetStoreCidByStoreIdAndName(WorkContext.StoreId, word); 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"); //检查当前页数 if (page < 1) { page = 1; } //商品总数量 int totalCount = 0; //商品列表 List <PartProductInfo> productList = null; Searches.SearchStoreProducts(20, page, word, WorkContext.StoreId, storeCid, 0, 0, sortColumn, sortDirection, ref totalCount, ref productList); //分页对象 PageModel pageModel = new PageModel(20, page, totalCount); //视图对象 StoreSearchModel model = new StoreSearchModel() { Word = word, SortColumn = sortColumn, SortDirection = sortDirection, PageModel = pageModel, ProductList = productList }; return(View(model)); }
public ActionResult KeyWordSearch() { //搜索词 string keyword = WebHelper.GetQueryString("keyword"); WorkContext.SearchWord = WebHelper.HtmlEncode(keyword); if (keyword.Length == 0) { return(PromptView(WorkContext.UrlReferrer, "请输入搜索词")); } if (!SecureHelper.IsSafeSqlString(keyword)) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } //异步保存搜索历史 Asyn.UpdateSearchHistory(WorkContext.Uid, keyword); //获取当前搜索词匹配缓存结果 ProductSearchKeyInfo keyInfo = BMACache.Get(keyword) as ProductSearchKeyInfo; if (keyInfo != null && string.IsNullOrEmpty(keyInfo.Name)) //无匹配 { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } if (keyInfo == null) //未匹配过 { keyInfo = Searches.GetProductSearchKey(keyword); if (keyInfo == null || string.IsNullOrEmpty(keyInfo.Name)) { keyInfo = new ProductSearchKeyInfo() { Name = "", keyType = -1, ToId = -1 }; } BMACache.Insert(keyword, keyInfo); } //再次判断搜索词匹配结果 if (keyInfo != null && string.IsNullOrEmpty(keyInfo.Name)) //无匹配 { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } return(Redirect(Url.Action("categorysearch", new RouteValueDictionary { { "keyword", keyword }, { "searchKeyType", keyInfo.keyType }, { "searchKeyId", keyInfo.ToId } }))); }
/// <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)); }
/// <summary> /// 搜索 /// </summary> public ActionResult Search() { //搜索词 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"); //搜索词处理 WorkContext.SearchWord = word; if (word.Length == 0) { return(PromptView(WorkContext.UrlReferrer, "请输入搜索词")); } //检查当前页数 if (page < 1) { page = 1; } //筛选属性处理 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 <StoreProductInfo> productList = null; //搜索 Searches.SearchMallProducts(20, page, word, cateId, brandId, filterPrice, attrValueIdList, onlyStock, sortColumn, sortDirection, ref categoryInfo, ref catePriceRangeList, ref cateAAndVList, ref categoryList, ref brandInfo, ref brandList, ref totalCount, ref productList); if (productList == null) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } //分页对象 PageModel pageModel = new PageModel(20, page, totalCount); //视图对象 MallSearchModel model = new MallSearchModel() { Word = word, CateId = cateId, BrandId = brandId, FilterPrice = filterPrice, FilterAttr = filterAttr, OnlyStock = onlyStock, SortColumn = sortColumn, SortDirection = sortDirection, FilterAttrValueIdList = attrValueIdList, CategoryInfo = categoryInfo, CatePriceRangeList = catePriceRangeList, AAndVList = cateAAndVList, CategoryList = categoryList, BrandInfo = brandInfo, BrandList = brandList, PageModel = pageModel, ProductList = productList }; //异步保存搜索历史 Asyn.UpdateSearchHistory(WorkContext.Uid, word); return(View(model)); }
/// <summary> /// 搜索 /// </summary> public ActionResult Search() { //搜索词 string keyword = WebHelper.GetQueryString("keyword"); WorkContext.SearchWord = WebHelper.HtmlEncode(keyword); if (keyword.Length == 0) { return(PromptView(WorkContext.UrlReferrer, "请输入搜索词")); } if (!SecureHelper.IsSafeSqlString(keyword)) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } //异步保存搜索历史 Asyn.UpdateSearchHistory(WorkContext.Uid, keyword); //判断搜索词是否为分类名称,如果是则重定向到分类页面 int cateId = Categories.GetCateIdByName(keyword); if (cateId > 0) { return(Redirect(Url.Action("category", new RouteValueDictionary { { "cateId", cateId } }))); } else { cateId = WebHelper.GetQueryInt("cateId"); } //分类列表 List <CategoryInfo> categoryList = null; //分类信息 CategoryInfo categoryInfo = null; //品牌列表 List <BrandInfo> brandList = null; //品牌id int brandId = Brands.GetBrandIdByName(keyword); if (brandId > 0)//当搜索词为品牌名称时 { //获取品牌相关的分类 categoryList = Brands.GetBrandCategoryList(brandId); //由于搜索结果的展示是以分类为基础的,所以当分类不存在时直接将搜索结果设为“搜索的商品不存在” if (categoryList.Count == 0) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } if (cateId > 0) { categoryInfo = Categories.GetCategoryById(cateId); } else { //当没有进行分类的筛选时,将分类列表中的首项设为当前选中的分类 categoryInfo = categoryList[0]; cateId = categoryInfo.CateId; } brandList = new List <BrandInfo>(); brandList.Add(Brands.GetBrandById(brandId)); } else//当搜索词为商品关键词时 { //获取商品关键词相关的分类 categoryList = Searches.GetCategoryListByKeyword(keyword); //由于搜索结果的展示是以分类为基础的,所以当分类不存在时直接将搜索结果设为“搜索的商品不存在” if (categoryList.Count == 0) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } if (cateId > 0) { categoryInfo = Categories.GetCategoryById(cateId); } else { categoryInfo = categoryList[0]; cateId = categoryInfo.CateId; } //根据商品关键词获取分类相关的品牌 brandList = Searches.GetCategoryBrandListByKeyword(cateId, keyword); if (brandList.Count == 0) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } brandId = WebHelper.GetQueryInt("brandId"); } //最后再检查一遍分类是否存在 if (categoryInfo == null) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } //筛选价格 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"); //分类筛选属性及其值列表 List <KeyValuePair <AttributeInfo, List <AttributeValueInfo> > > cateAAndVList = Categories.GetCategoryFilterAAndVList(cateId); //分类价格范围列表 string[] catePriceRangeList = StringHelper.SplitString(categoryInfo.PriceRange, "\r\n"); //筛选属性处理 List <int> attrValueIdList = new List <int>(); string[] filterAttrValueIdList = StringHelper.SplitString(filterAttr, "-"); if (filterAttrValueIdList.Length != cateAAndVList.Count)//当筛选属性和分类的筛选属性数目不对应时,重置筛选属性 { if (cateAAndVList.Count == 0) { filterAttr = "0"; } else { int count = cateAAndVList.Count; StringBuilder sb = new StringBuilder(); for (int i = 0; i < count; i++) { sb.Append("0-"); } filterAttr = sb.Remove(sb.Length - 1, 1).ToString(); } } else { 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)); //视图对象 SearchModel model = new SearchModel() { Word = keyword, CateId = cateId, BrandId = brandId, FilterPrice = filterPrice, FilterAttr = filterAttr, OnlyStock = onlyStock, SortColumn = sortColumn, SortDirection = sortDirection, CategoryList = categoryList, CategoryInfo = categoryInfo, BrandList = brandList, CatePriceRangeList = catePriceRangeList, AAndVList = cateAAndVList, PageModel = pageModel, ProductList = Searches.SearchProducts(pageModel.PageSize, pageModel.PageNumber, keyword, cateId, brandId, filterPrice, catePriceRangeList, attrValueIdList, onlyStock, sortColumn, sortDirection) }; return(View(model)); }
/// <summary> /// 搜索 /// </summary> public ActionResult Search() { //搜索词 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"); WorkContext.SearchWord = word; if (word.Length == 0) { return(PromptView(WorkContext.UrlReferrer, "请输入搜索词")); } //检查当前页数 if (page < 1) { page = 1; } //筛选属性处理 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); } } //分类信息 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, attrValueIdList, onlyStock, sortColumn, sortDirection, ref categoryInfo, ref catePriceRangeList, ref cateAAndVList, ref categoryList, ref brandInfo, ref brandList, ref totalCount, ref productList); if (productList == null) { return(PromptView(WorkContext.UrlReferrer, "您搜索的商品不存在")); } //当筛选属性和分类的筛选属性数目不对应时,重置筛选属性 if (cateAAndVList == null) { filterAttr = "0"; } else { if (filterAttrValueIdList.Length != cateAAndVList.Count) { if (cateAAndVList.Count == 0) { filterAttr = "0"; } else { int count = cateAAndVList.Count; StringBuilder sb = new StringBuilder(); for (int i = 0; i < count; i++) { sb.Append("0-"); } filterAttr = sb.Remove(sb.Length - 1, 1).ToString(); } } } //用户浏览历史 List <PartProductInfo> userBrowseHistory = BrowseHistories.GetUserBrowseHistory(WorkContext.Uid, 0); //分页对象 PageModel pageModel = new PageModel(20, page, totalCount); //视图对象 SearchModel model = new SearchModel() { Word = word, CateId = cateId, BrandId = brandId, FilterPrice = filterPrice, FilterAttr = filterAttr, OnlyStock = onlyStock, SortColumn = sortColumn, SortDirection = sortDirection, FilterAttrValueIdList = attrValueIdList, CategoryInfo = categoryInfo, CatePriceRangeList = catePriceRangeList, AAndVList = cateAAndVList, CategoryList = categoryList, BrandInfo = brandInfo, BrandList = brandList, PageModel = pageModel, ProductList = productList, UserBrowseHistory = userBrowseHistory }; //异步保存搜索历史 Asyn.UpdateSearchHistory(WorkContext.Uid, word); return(View(model)); }