Пример #1
0
        protected override QueryOptions BuildQueryOptions(SearchCondition condition)
        {
            QueryOptions queryOptions = base.BuildQueryOptions(condition);

            #region 分组(自定义属性)

            List <KeyValuePair <string, string> > keyValuePairList = new List <KeyValuePair <string, string> >();

            ProductSearchCondition pCondition = condition as ProductSearchCondition;
            if (pCondition != null && !string.IsNullOrWhiteSpace(pCondition.WithInKeyWord))
            {
                keyValuePairList.Add(new KeyValuePair <string, string>("mm", "2<75% 5<-1"));
            }

            keyValuePairList.Add(new KeyValuePair <string, string>("group", "true"));
            keyValuePairList.Add(new KeyValuePair <string, string>("group.main", "false"));
            keyValuePairList.Add(new KeyValuePair <string, string>("group.ngroups", "true"));

            if (condition.IsGroupQuery == true)
            {
                keyValuePairList.Add(new KeyValuePair <string, string>("group.sort", "p_pricesort asc"));
                keyValuePairList.Add(new KeyValuePair <string, string>("group.field", "p_productgroupvalue"));
            }
            else
            {
                keyValuePairList.Add(new KeyValuePair <string, string>("group.field", "p_sysno"));
            }

            queryOptions.ExtraParams = keyValuePairList.ToArray();

            #endregion

            return(queryOptions);
        }
Пример #2
0
        public HttpResponseMessage GetSearchProduct([FromUri] ProductSearchCondition condtion)
        {
            var productList = _productService.GetProductsByCondition(condtion).Select(a => new ProductDetail
            {
                Id              = a.Id,
                Productname     = a.Productname,
                Productimg      = a.Productimg,
                Price           = a.Price,
                SubTitle        = a.SubTitle,
                Advertisement   = a.ProductDetail.Ad1,
                ProductDetailed = a.ProductDetail.Productdetail,
                StockRule       = a.Stockrule,
                Acreage         = a.ProductParameter.FirstOrDefault(pp => pp.Parameter.Name == "面积").ParameterValue.Parametervalue.ToString(),
                Type            = a.ProductParameter.FirstOrDefault(p => p.Parameter.Name == "户型").ParameterValue.Parametervalue.ToString(),
                //ParameterValue = a.ProductParameter.Select(c => new ProductParameterModel
                //{
                //    ParameterId = c.Parameter.Id,
                //    ParameterString = c.Parameter.Name,
                //    ValueId = c.ParameterValue.Id,
                //    Value = c.ParameterValue.Parametervalue
                //}).ToArray()
            }).ToList();
            // return PageHelper.toJson(productList);
            var totalCount = _productService.GetProductCount(condtion);

            return(PageHelper.toJson(new { List = productList, TotalCount = totalCount }));
        }
Пример #3
0
        /// <summary>
        /// 获取6个商品
        /// </summary>
        /// <param name="id">分类id</param>
        /// <returns>商品列表</returns>
        public List <Product> GetSixPro(int id)
        {
            var con = new ProductSearchCondition
            {
                Page      = 1,
                PageCount = 6,
                // Name = condition.Name,
                IsDescending = true,
                // OrderBy = condition.OrderBy,
                // PriceBegin = condition.PriceBegin,
                //PriceEnd = condition.PriceEnd,
                // CategoryName = condition.CategoryName,
                CategoryId = id
            };
            List <Product> data  = new List <Product>();
            var            model = _productService.GetProductsByCondition(con).Select(c => new ProductModel
            {
                Id      = c.Id,
                Name    = c.Name,
                MainImg = c.MainImg,
            }).ToList();

            foreach (var pro in model)
            {
                Product produce = new Product
                {
                    Id      = pro.Id,
                    Name    = pro.Name,
                    MainImg = pro.MainImg
                };
                data.Add(produce);
            }
            return(data);
        }
Пример #4
0
        public PageList <ProductModel> SearchProducts(ProductSearchCondition condition)
        {
            var query = _shoppingContext.Products.AsNoTracking().AsQueryable();

            if (!string.IsNullOrEmpty(condition.Name))
            {
                query = query.Where(p => p.Name.ToLower().Contains(condition.Name.ToLower()));
            }

            if (!string.IsNullOrEmpty(condition.Code))
            {
                query = query.Where(p => p.Code.ToLower().Contains(condition.Code.ToLower()));
            }

            if (condition.CategoryId > 0)
            {
                query = query.Where(p => p.ProductCategoryId == condition.CategoryId);
            }

            if (condition.DateFrom.HasValue)
            {
                query = query.Where(p => p.CreatedDateTime >= condition.DateFrom.Value);
            }

            if (condition.DateTo.HasValue)
            {
                var dateTo = condition.DateTo.Value.AddDays(1);
                query = query.Where(p => p.CreatedDateTime < dateTo);
            }
            var products = query.OrderBy(o => o.CreatedDateTime).Skip(condition.PageSize * condition.PageNumber).Take(condition.PageSize).ToList();

            return(new PageList <ProductModel>(Mapper.Map <List <ProductModel> >(products), query.Count()));
        }
Пример #5
0
        protected override List <Product> GetingItems(System.Data.Linq.DataContext dc, SearchCondition search)
        {
            DataLoadOptions opt = new DataLoadOptions();

            opt.LoadWith <Product>(p => p.Category);
            dc.LoadOptions = opt;
            IQueryable <Product> ret = dc.GetTable <Product>();

            if (search is ProductSearchCondition)
            {
                ProductSearchCondition con = search as ProductSearchCondition;
                if (con.ProductIDS != null && con.ProductIDS.Count > 0)
                {
                    ret = ret.Where(item => con.ProductIDS.Contains(item.ID));
                }
                if (!string.IsNullOrEmpty(con.Name))
                {
                    ret = ret.Where(item => item.Name.Contains(con.Name));
                }
                if (!string.IsNullOrEmpty(con.BarCode))
                {
                    ret = ret.Where(item => item.BarCode.Contains(con.BarCode));
                }
                if (!string.IsNullOrEmpty(con.CategoryID))
                {
                    ret = ret.Where(item => item.CategoryID == con.CategoryID);
                }
                if (!string.IsNullOrEmpty(con.Specification))
                {
                    ret = ret.Where(item => item.Specification.Contains(con.Specification));
                }
            }
            return(ret.ToList());
        }
Пример #6
0
        public HttpResponseMessage GetCount(
            int?categoryId     = null,
            decimal?priceBegin = null,
            decimal?priceEnd   = null,
            bool isDescending  = false,
            string name        = "",
            string spec        = "",
            int pageCount      = 10,
            int page           = 1,
            string ids         = "",
            EnumProductSearchOrderBy orderBy = EnumProductSearchOrderBy.OrderById)
        {
            var condition = new ProductSearchCondition
            {
                CategoryId   = categoryId,
                IsDescending = isDescending,
                Name         = name,
                OrderBy      = orderBy,
                Page         = page,
                PageCount    = pageCount,
                PriceBegin   = priceBegin,
                PriceEnd     = priceEnd,
                Spec         = spec,
                Ids          = string.IsNullOrEmpty(ids) ? null : ids.Split(',').Select(int.Parse).ToArray()
            };
            var count = _productService.GetProductCount(condition);

            return(PageHelper.toJson(new { TotalCount = count, Condition = condition }));
        }
Пример #7
0
        public IEnumerable <ProductModel> SearchProducts(ProductSearchCondition condition)
        {
            var products      = _productService.SearchProducts(condition);
            var productModels = Mapper.Map <List <ProductModel> >(products);

            return(productModels);
        }
Пример #8
0
        /// <summary>
        /// 搜索结果
        /// </summary>
        /// <param name="isSearchResultPage">是搜索结果页还是三级类别页(1为搜索结果页)</param>
        /// <returns></returns>
        public static ProductSearchResult GetProductSearchResult(SolrProductQueryVM vm)
        {
            //获取Condition
            ProductSearchCondition condition = GetSearchCondition(vm);

            if (vm.IsSearchResultPage == 1 &&
                string.IsNullOrEmpty(condition.KeyWord) &&
                condition.NValueList == null &&
                condition.NValueList.Count <= 0)
            {
                return(new ProductSearchResult()
                {
                    Navigation = new NavigationContainer(),
                    ProductDataList = new Utility.PagedResult <Entity.SearchEngine.ProductSearchResultItem>()
                });
            }
            if (!string.IsNullOrWhiteSpace(vm.MidCategoryID) && Convert.ToInt32(vm.MidCategoryID) > 0)
            {
                condition.Filters.Add(new FieldFilter("p_categorysysno2", vm.MidCategoryID));
            }
            if (!string.IsNullOrWhiteSpace(vm.BrandID) && Convert.ToInt32(vm.BrandID) > 0)
            {
                condition.Filters.Add(new FieldFilter("p_brandid", vm.BrandID));
            }

            //获取当前页面Querystring
            queryStringCollection = HttpContext.Current.Request.QueryString;

            //获取搜索结果
            ProductSearchResult result = ProductSearchFacade.GetProductSearchResultBySolr(condition);

            return(result);
        }
Пример #9
0
        public GetProductByConditionResponse QuerySKUProductInfoFG(ProductSearchCondition SearchCondition, int pageIndex, int pageSize, out int rowCount)
        {
            string sqlWhere = "";

            if (SearchCondition != null)
            {
                sqlWhere = SKUSearchConditionFG(SearchCondition);
            }
            int tempRowCount = 0;

            DbParam[] dbParams = new DbParam[] {
                new DbParam("@Where", DbType.String, sqlWhere, ParameterDirection.Input),
                new DbParam("@PageIndex", DbType.Int32, pageIndex, ParameterDirection.Input),
                new DbParam("@PageSize", DbType.Int32, pageSize, ParameterDirection.Input),
                new DbParam("@RowCount", DbType.Int32, tempRowCount, ParameterDirection.Output)
            };

            DataTable dt = this.ExecuteDataTable("[Proc_WMS_GetSKUFG]", dbParams);

            rowCount = (int)dbParams[3].Value;
            GetProductByConditionResponse response = new GetProductByConditionResponse();

            response.Storer          = dt.ConvertToEntityCollection <Storer>();
            response.SearchCondition = dt.ConvertToEntityCollection <ProductStorer>();
            return(response);
        }
Пример #10
0
        public HttpResponseMessage GetAllProduct(int page = 1, int pageSize = 10, bool isDes = true, EnumProductSearchOrderBy orderByAll = EnumProductSearchOrderBy.OrderByAddtime)
        {
            ProductSearchCondition PSC = new ProductSearchCondition()
            {
                Page         = page,
                PageCount    = pageSize,
                IsDescending = isDes,
                OrderBy      = orderByAll
            };
            var productList = _productService.GetProductsByCondition(PSC).Select(a => new ProductDetail
            {
                Id          = a.Id,
                Productname = a.Productname,
                Productimg  = a.Productimg,
                Price       = a.Price,

                RecCommission   = a.RecCommission,
                Commission      = a.Commission,
                Dealcommission  = a.Dealcommission,
                ClassifyName    = a.Classify.Name,
                Addtime         = a.Addtime,
                Phone           = a.ContactPhone,
                SubTitle        = a.SubTitle,
                ProductDetailed = a.ProductDetail.Productdetail,
                StockRule       = a.Stockrule,
                Advertisement   = a.ProductDetail.Ad1,
                Acreage         = a.ProductParameter.FirstOrDefault(pp => pp.Parameter.Name == "面积").ParameterValue.Parametervalue.ToString(),
                Type            = a.ProductParameter.FirstOrDefault(p => p.Parameter.Name == "户型").ParameterValue.Parametervalue.ToString()
            }).ToList().Select(b => new
            {
                b.Id,
                b.Productname,
                b.Productimg,
                b.Price,

                b.RecCommission,
                b.Commission,
                b.Dealcommission,
                b.ClassifyName,
                b.Addtime,
                b.Phone,


                b.SubTitle,
                b.ProductDetailed,
                b.StockRule,
                b.Acreage,
                b.Type,
                b.Advertisement
            });
            var totalCount = _productService.GetProductCount(PSC);

            return(PageHelper.toJson(new { List = productList, Condition = PSC, TotalCount = totalCount }));
            //return PageHelper.toJson(_productService.GetProductsByCondition(PSC).ToList());
        }
Пример #11
0
        //
        // GET: /Web/Product/

        /// <summary>
        /// 搜索结果
        /// </summary>
        /// <returns></returns>
        public ActionResult SearchResult()
        {
            //获取Condition
            ProductSearchCondition condition = GetSearchCondition();

            //获取当前页面Querystring
            queryStringCollection = Request.QueryString;

            //获取搜索结果
            ProductSearchResult result = ProductSearchFacade.GetProductSearchResultBySolr(condition, queryStringCollection);

            return(RedirectToAction("SearchResult", "Product"));
        }
Пример #12
0
        public ActionResult List(DataSourceRequest command, ProductSearchCondition condition)
        {
            condition.PageSize   = command.PageSize;
            condition.PageNumber = command.Page - 1;

            var products  = _productService.SearchProducts(condition);
            var gridModel = new DataSourceResult()
            {
                Data  = products.DataSource,
                Total = products.TotalItems
            };

            return(Json(gridModel));
        }
Пример #13
0
        /// <summary>
        /// 查询品牌下商品
        /// </summary>
        /// <param name="queryInfo"></param>
        /// <returns></returns>
        private static ProductSearchResult GetProductSearchResult(BrandZoneQueryVM queryInfo)
        {
            ProductSearchCondition condition = new ProductSearchCondition()
            {
                IsGroupQuery = true,
                KeyWord      = queryInfo.Keyword
            };

            //分页
            if (queryInfo.PageNumber <= 1)
            {
                queryInfo.PageNumber = 1;
            }
            condition.PagingInfo = new Utility.DataAccess.SearchEngine.PagingInfo()
            {
                PageNumber = queryInfo.PageNumber,
                PageSize   = 15
            };
            //排序
            if (queryInfo.SortMode <= 0)
            {
                queryInfo.SortMode = 10;
            }
            SortEntity sortEntity = SortKeyValueMappingConfig.SortItemList.Find(f => f.Key == queryInfo.SortMode);

            if (sortEntity == null)
            {
                sortEntity = SortKeyValueMappingConfig.SortItemList[0];
            }
            condition.SortItems = new List <SortItem>()
            {
                sortEntity.Item
            };

            condition.NValueList = new List <string>();
            condition.Filters    = new List <FilterBase>();
            if (queryInfo.BrandSysNo > 0)
            {
                condition.Filters.Add(new FieldFilter("p_brandid_n", (ConstValue.SINGLE_BRAND_STORE_DMSID_SEED + queryInfo.BrandSysNo).ToString()));
            }
            if (!String.IsNullOrWhiteSpace(queryInfo.SubCategoryEnID))
            {
                condition.NValueList.Add(queryInfo.SubCategoryEnID);
            }

            var result = ProductSearchFacade.GetProductSearchResultBySolr(condition);

            return(result);
        }
Пример #14
0
        public ProductEntity GetProductByBrand(int BrandId)
        {
            var sech = new ProductSearchCondition
            {
                OrderBy      = EnumProductSearchOrderBy.OrderByPrice,
                ProductBrand = BrandId
            };
            var model = _productService.GetProductsByCondition(sech).FirstOrDefault();

            if (model == null)
            {
                return(null);
            }
            return(model);
        }
Пример #15
0
        public int GetProductCount(ProductSearchCondition condition)
        {
            var query = _productRepository.Table;

            try
            {
                if (condition.PriceBegin.HasValue)
                {
                    query = query.Where(q => q.Price >= condition.PriceBegin.Value);
                }
                if (condition.PriceEnd.HasValue)
                {
                    query = query.Where(q => q.Price < condition.PriceEnd.Value);
                }
                if (!string.IsNullOrEmpty(condition.Spec))
                {
                    query = query.Where(q => q.Spec == condition.Spec);
                }
                if (condition.CategoryId != null)
                {
                    query = query.Where(q => q.Category.Id == condition.CategoryId);
                }
                if (condition.Status.HasValue)
                {
                    query = query.Where(q => q.Status == condition.Status.Value);
                }
                if (!string.IsNullOrEmpty(condition.Name))
                {
                    query = query.Where(q => q.Name.Contains(condition.Name));
                }
                if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }
                return(query.Count());
            }
            catch (Exception e)
            {
                _log.Error(e, "数据库操作出错");
                return(-1);
            }
        }
Пример #16
0
        public override CommandResult Delete(ProductCategory info)
        {
            List <ProductCategory> tps = ProviderFactory.Create <IProvider <ProductCategory, string> >(RepoUri).GetItems(null).QueryObjects;

            if (tps != null && tps.Count > 0 && tps.Exists(item => item.Parent == info.ID))
            {
                return(new CommandResult(ResultCode.Fail, "类别下已经有子类别,请先将所有子类别删除,再删除此类别"));
            }
            IProvider <Product, string> sp  = ProviderFactory.Create <IProvider <Product, string> >(RepoUri);
            ProductSearchCondition      con = new ProductSearchCondition()
            {
                CategoryID = info.ID
            };

            if (sp.GetItems(con).QueryObjects.Count > 0)
            {
                return(new CommandResult(ResultCode.Fail, "此类别不能删除,已经有物料归到此类别,如果确实要删除此类别,请先更改相关物料的所属类别"));
            }
            return(base.Delete(info));
        }
Пример #17
0
        /// <summary>
        /// 获取Endeca Search Condition
        /// </summary>
        /// <returns></returns>
        private ProductSearchCondition GetSearchCondition()
        {
            this.keyWord = Request.QueryString["keyword"];
            int.TryParse(Request.QueryString["enid"], out this.endecaId);
            int.TryParse(Request.QueryString["sort"], out this.sortMode);
            this.withInKeyword = Request.QueryString["withInKeyword"];
            this.strN          = GetNavigationKey();
            this.subCategoryid = GetSubCategoryIDbyStrN(this.strN);
            int.TryParse(Request.QueryString["page"], out pageNumber);
            int.TryParse(Request.QueryString["pageSize"], out pageSize);

            ProductSearchCondition condition = new ProductSearchCondition();

            condition.Filters          = GetFilters();
            condition.FilterExpression = GetFilterExpression();

            //是否展示“仅展示”商品
            if (this.IsShowOnlyShowProducts == false)
            {
                condition.Filters.Add(new FieldFilter("p_productstatus", "1"));
            }
            condition.KeyWord       = string.IsNullOrEmpty(keyWord)?string.Empty:keyWord.Trim();
            condition.WithInKeyWord = withInKeyword;
            condition.NValueList    = GetNValueList(strN);


            condition.PagingInfo            = new Nesoft.Utility.DataAccess.SearchEngine.PagingInfo();
            condition.PagingInfo.PageNumber = this.pageNumber;
            condition.PagingInfo.PageSize   = this.pageSize;

            //condition.SortingInfo = new global::Newegg.Framework.SortingInfo();
            //condition.SortingInfo.SortField = this.sortMode.ToString();

            if (!string.IsNullOrWhiteSpace(this.keyWord) && this.sortMode <= 10)
            {
                this.sortMode = 9999;
            }

            return(condition);
        }
Пример #18
0
        /// <summary>
        /// 根据类别查询店铺商品
        /// </summary>
        /// <param name="criteria">搜索条件</param>
        /// <returns></returns>
        public SearchResultModel GetVendorProductByCategoryCode(int sellerSysNo, int categoryCode)
        {
            List <FrontProductCategoryInfo> category = ProductFacade.GetFrontProductCategory(sellerSysNo);
            int strCurrentCategorySysNo;

            if (category.Exists(x => x.SysNo == categoryCode))
            {
                strCurrentCategorySysNo = categoryCode;
            }
            else
            {
                var defaultCate = category.First(p => p.IsLeaf == CommonYesOrNo.Yes);
                if (defaultCate != null)
                {
                    strCurrentCategorySysNo = defaultCate.SysNo;
                }
                else
                {
                    strCurrentCategorySysNo = -1;
                }
            }
            ProductSearchCondition condition = new ProductSearchCondition();

            condition.NValueList = new List <string>();
            //前台分类
            condition.NValueList.Add((ConstValue.Product_SINGLE_STORECATE_DMSID_SEED + strCurrentCategorySysNo).ToString());
            condition.Filters = new List <FilterBase>();
            //商家编号
            condition.Filters.Add(new FieldFilter("p_sellersysno", sellerSysNo.ToString()));

            var searchResult = ProductSearchFacade.GetProductSearchResultBySolr(condition);

            SearchResultModel model = new SearchResultModel();

            model.ProductListItems = TransformResultItemList(searchResult.ProductDataList);
            model.PageInfo         = MapPageInfo(searchResult.ProductDataList);
            model.Filters          = MapSearchFilter(searchResult.Navigation);

            return(model);
        }
Пример #19
0
        /// <summary>
        /// 获取商品列表
        /// </summary>
        /// <param name="condition">查询条件</param>
        /// <returns>商品列表</returns>
        public HttpResponseMessage Get([FromUri] ProductSearchCondition condition)
        {
            var model = _productService.GetProductsByCondition(condition).Select(c => new ProductModel
            {
                Id           = c.Id,
                BussnessId   = c.BussnessId,
                BussnessName = c.BussnessName,
                Price        = c.Price,
                Name         = c.Name,
                Status       = c.Status,
                MainImg      = c.MainImg,
                IsRecommend  = c.IsRecommend,
                Sort         = c.Sort,
                Stock        = c.Stock,
                Subtitte     = c.Subtitte,
                Contactphone = c.Contactphone,
                Type         = c.Type
            }).ToList();
            var totalCount = _productService.GetProductCount(condition);

            return(PageHelper.toJson(new{ List = model, Condition = condition, TotalCount = totalCount }));
        }
        public CustomJsonResult GetProductList(ProductSearchCondition condition)
        {
            string name   = condition.Name.ToSearchString();
            string kindId = BizFactory.Product.BuildProductKindIdForSearch(condition.KindId);
            var    list   = (from p in CurrentDb.Product
                             where SqlFunctions.CharIndex(kindId, p.ProductKindIds) > 0 &&
                             (name.Length == 0 || p.Name.Contains(name))
                             select new { p.Id, p.Name, p.MainImg, p.CreateTime, p.Supplier, p.ProductCategory });

            int total = list.Count();

            int pageIndex = condition.PageIndex;
            int pageSize  = 10;

            list = list.OrderBy(r => r.Id).Skip(pageSize * (pageIndex)).Take(pageSize);

            PageEntity pageEntity = new PageEntity {
                PageSize = pageSize, TotalRecord = total, Rows = list
            };

            return(Json(ResultType.Success, pageEntity));
        }
Пример #21
0
        public JsonResult GetGoodsList(ProductSearchCondition condition)
        {
            var query = (from p in CurrentDb.Product
                         where ((int)p.Type).ToString().StartsWith("1")
                         select new { p.Id, p.Name, p.Type, p.Price, p.MainImgUrl, p.CreateTime });

            int total = query.Count();

            int pageIndex = condition.PageIndex;
            int pageSize  = 10;

            query = query.OrderByDescending(r => r.CreateTime).Skip(pageSize * (pageIndex)).Take(pageSize);



            List <object> list = new List <object>();

            foreach (var item in query)
            {
                list.Add(new
                {
                    Id         = item.Id,
                    Name       = item.Name,
                    Type       = item.Type.GetCnName(),
                    Price      = item.Price.ToPrice(),
                    ImgUrl     = item.MainImgUrl,
                    LinkUrl    = BizFactory.Product.GetLinkUrl(item.Type, item.Id),
                    CreateTime = item.CreateTime
                });
            }


            PageEntity pageEntity = new PageEntity {
                PageSize = pageSize, TotalRecord = total, Rows = list
            };

            return(Json(ResultType.Success, pageEntity, ""));
        }
Пример #22
0
        public ActionResult ProductAddPopup(int receiveId)
        {
            var model = new ProductSearchCondition();

            return(View(model));
        }
Пример #23
0
        public IQueryable <ProductEntity> GetProductsByCondition(ProductSearchCondition condition)
        {
            var query = _productRepository.Table;

            try
            {
                if (!string.IsNullOrEmpty(condition.AreaName))
                {
                    query = query.Where(q => q.ProductParameter.Count(pp => pp.ParameterValue.Parametervalue == condition.AreaName) > 0);
                }
                if (condition.TypeId.HasValue)
                {
                    query = query.Where(q => q.ProductParameter.Count(pp => pp.ParameterValue.Id == condition.TypeId) > 0);
                }
                if (condition.CommissionBegin.HasValue)
                {
                    query = query.Where(q => q.Commission >= condition.CommissionBegin.Value);
                }
                if (condition.CommissionEnd.HasValue)
                {
                    query = query.Where(q => q.Commission < condition.CommissionEnd.Value);
                }


                if (condition.PriceBegin.HasValue)
                {
                    query = query.Where(q => q.Price >= condition.PriceBegin.Value);
                }
                if (condition.PriceEnd.HasValue)
                {
                    query = query.Where(q => q.Price < condition.PriceEnd.Value);
                }


                if (condition.AddtimeBegin.HasValue)
                {
                    query = query.Where(q => q.Addtime >= condition.AddtimeBegin.Value);
                }
                if (condition.AddtimeEnd.HasValue)
                {
                    query = query.Where(q => q.Addtime < condition.AddtimeEnd.Value);
                }


                if (condition.UpdtimeBegin.HasValue)
                {
                    query = query.Where(q => q.Updtime >= condition.UpdtimeBegin.Value);
                }
                if (condition.UpdtimeEnd.HasValue)
                {
                    query = query.Where(q => q.Updtime < condition.UpdtimeEnd.Value);
                }


                if (condition.Status.HasValue)
                {
                    query = query.Where(q => q.Status == condition.Status.Value);
                }



                if (condition.Recommend.HasValue)
                {
                    query = query.Where(q => q.Recommend == condition.Recommend.Value);
                }



                if (!string.IsNullOrEmpty(condition.Productname))
                {
                    query = query.Where(q => q.Productname.Contains(condition.Productname));
                }



                if (!string.IsNullOrEmpty(condition.Productimg))
                {
                    query = query.Where(q => q.Productimg.Contains(condition.Productimg));
                }



                if (!string.IsNullOrEmpty(condition.Adduser))
                {
                    query = query.Where(q => q.Adduser.Contains(condition.Adduser));
                }



                if (!string.IsNullOrEmpty(condition.Upduser))
                {
                    query = query.Where(q => q.Upduser.Contains(condition.Upduser));
                }



                if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }


                if (condition.ProductDetails != null && condition.ProductDetails.Any())
                {
                    query = query.Where(q => condition.ProductDetails.Contains(q.ProductDetail));
                }


                if (condition.Classifys != null && condition.Classifys.Any())
                {
                    query = query.Where(q => condition.Classifys.Contains(q.Classify));
                }


                if (condition.ProductBrands != null && condition.ProductBrands.Any())
                {
                    query = query.Where(q => condition.ProductBrands.Contains(q.ProductBrand));
                }


                if (condition.Bussnessid.HasValue)
                {
                    query = query.Where(q => q.Bussnessid == condition.Bussnessid);
                }


                if (condition.Sorts != null && condition.Sorts.Any())
                {
                    query = query.Where(q => condition.Sorts.Contains(q.Sort));
                }


                if (condition.Stockrules != null && condition.Stockrules.Any())
                {
                    query = query.Where(q => condition.Stockrules.Contains(q.Stockrule));
                }

                if (condition.ProductBrand != null)
                {
                    query = query.Where(q => q.ProductBrand.Id == condition.ProductBrand);
                }


                if (condition.OrderBy.HasValue)
                {
                    switch (condition.OrderBy.Value)
                    {
                    case EnumProductSearchOrderBy.OrderById:
                        query = condition.IsDescending ? query.OrderByDescending(q => q.Id) : query.OrderBy(q => q.Id);
                        break;

                    case EnumProductSearchOrderBy.OrderByAddtime:
                        query = condition.IsDescending ? query.OrderByDescending(q => q.Addtime) : query.OrderBy(q => q.Addtime);
                        break;

                    case EnumProductSearchOrderBy.OrderByPrice:
                        query = condition.IsDescending ? query.OrderByDescending(q => q.Price) : query.OrderBy(q => q.Price);
                        break;

                    case EnumProductSearchOrderBy.OrderByDealcommission:
                        query = condition.IsDescending ? query.OrderByDescending(q => q.Dealcommission) : query.OrderBy(q => q.Dealcommission);
                        break;

                    case EnumProductSearchOrderBy.OrderByRecCommission:
                        query = condition.IsDescending ? query.OrderByDescending(q => q.RecCommission) : query.OrderBy(q => q.RecCommission);
                        break;

                    case EnumProductSearchOrderBy.OrderByCommission:
                        query = condition.IsDescending ? query.OrderByDescending(q => q.Commission) : query.OrderBy(q => q.Commission);
                        break;

                    case EnumProductSearchOrderBy.OrderByStockRule:
                        query = condition.IsDescending ? query.OrderByDescending(q => q.Stockrule) : query.OrderBy(q => q.Stockrule);
                        break;
                    }
                }

                else
                {
                    query = query.OrderBy(q => q.Id);
                }

                if (condition.Page.HasValue && condition.PageCount.HasValue)
                {
                    query = query.Skip((condition.Page.Value - 1) * condition.PageCount.Value).Take(condition.PageCount.Value);
                }
                return(query);
            }
            catch (Exception e)
            {
                _log.Error(e, "数据库操作出错");
                return(null);
            }
        }
Пример #24
0
        public HttpResponseMessage GetByCondition(
            int?categoryId     = null,
            decimal?priceBegin = null,
            decimal?priceEnd   = null,
            bool isDescending  = false,
            string name        = "",
            string spec        = "",
            int pageCount      = 10,
            int page           = 1,
            string ids         = "",
            EnumProductSearchOrderBy orderBy = EnumProductSearchOrderBy.OrderById)
        {
            var condition = new ProductSearchCondition
            {
                CategoryId   = categoryId,
                IsDescending = isDescending,
                Name         = name,
                OrderBy      = orderBy,
                Page         = page,
                PageCount    = pageCount,
                PriceBegin   = priceBegin,
                PriceEnd     = priceEnd,
                Spec         = spec,
                Ids          = string.IsNullOrEmpty(ids) ? null : ids.Split(',').Select(int.Parse).ToArray()
            };
            var model = _productService.GetProductsByCondition(condition).Select(c => new ProductModel
            {
                Id = c.Id,

                Name = c.Name,

                Spec = c.Spec,

                Price = c.Price,

                Adduser = new UserModel {
                    Id = c.Adduser.Id, UserName = c.Adduser.UserName
                },

                Addtime = c.Addtime,

                Upduser = new UserModel {
                    Id = c.Upduser.Id, UserName = c.Upduser.UserName
                },

                Updtime = c.Updtime,

                Unit = c.Unit,


                Image = c.Image,

                //				Detail = c.Detail,

                //				Category = c.Category,

                Status = c.Status,

                //				PropertyValues = c.PropertyValues,
            }).ToList();

            return(PageHelper.toJson(new { List = model }));
            //return model;
        }
Пример #25
0
        public ActionResult List()
        {
            var model = new ProductSearchCondition();

            return(View(model));
        }
Пример #26
0
        private NavigationContainer GetNavigation(SolrQueryResults <ProductSearchRecord> solrQueryResult, ProductSearchCondition condition)
        {
            var brandFacets         = solrQueryResult.FacetFields["p_brandname_facet"];
            var originFacets        = solrQueryResult.FacetFields["p_originName_facet"];
            var propertyValueFacets = solrQueryResult.FacetFields["p_propertyvalue_facet"];
            var categoryName3Facets = solrQueryResult.FacetFields["p_categoryname3_facet"];
            var priceFacet          = solrQueryResult.FacetFields["p_price_n"];
            var storeCategoryFacets = solrQueryResult.FacetFields["p_storecategory_facet"];

            NavigationContainer NaviRet = new NavigationContainer();

            NaviRet.NavigationItems = new List <NavigationItem>();

            //当前页面N值
            string NValue = string.Empty;

            if (condition.NValueList != null && condition.NValueList.Count > 0)
            {
                foreach (string str in condition.NValueList)
                {
                    NValue += str + ' ';
                }
            }

            #region 分类
            KeyValuePair <NavigationItemType, string> NavSubcategory = new KeyValuePair <NavigationItemType, string>(NavigationItemType.SubCategory, "平台类别");
            NavigationItem NavSubcategoryItem = new NavigationItem();
            NavSubcategoryItem.SubNavigationItems = new List <NavigationItem>();
            foreach (var facet in categoryName3Facets)
            {
                int num = facet.Value;

                string[] facetItemArray = facet.Key.Split(new string[] { "@!@" }, StringSplitOptions.RemoveEmptyEntries);

                bool isExists = NavSubcategoryItem.SubNavigationItems.Exists(delegate(NavigationItem eachItem)
                {
                    return(eachItem.Value == facetItemArray[1].ToString());
                });
                if (isExists)
                {
                    continue;
                }

                NavSubcategoryItem.ItemType = NavSubcategory.Key;
                NavSubcategoryItem.Name     = NavSubcategory.Value;


                NavigationItem subNavItem = new NavigationItem();
                subNavItem.Name         = facetItemArray[0].ToString();
                subNavItem.NumberOfItem = num;
                subNavItem.Value        = facetItemArray[1].ToString();//(NValue + facetItemArray[1].ToString()).Trim();

                subNavItem.ItemType = NavigationItemType.SubCategory;
                NavSubcategoryItem.SubNavigationItems.Add(subNavItem);
            }
            NaviRet.NavigationItems.Add(NavSubcategoryItem);
            #endregion

            #region 店铺分类
            NavigationItem NavStoreCateItem = new NavigationItem();
            NavStoreCateItem.SubNavigationItems = new List <NavigationItem>();
            KeyValuePair <NavigationItemType, string> NavStoreCate = new KeyValuePair <NavigationItemType, string>(NavigationItemType.StoreCategory, "店铺类别");
            foreach (var facet in storeCategoryFacets)
            {
                int num = facet.Value;

                string[] facetItemArray = facet.Key.Split(new string[] { "@!@" }, StringSplitOptions.RemoveEmptyEntries);

                bool isExists = NavStoreCateItem.SubNavigationItems.Exists(delegate(NavigationItem eachItem)
                {
                    return(eachItem.Value == facetItemArray[1].ToString());
                });
                if (isExists)
                {
                    continue;
                }

                NavStoreCateItem.ItemType = NavStoreCate.Key;
                NavStoreCateItem.Name     = NavStoreCate.Value;


                NavigationItem subNavItem = new NavigationItem();
                subNavItem.Name         = facetItemArray[0].ToString();
                subNavItem.NumberOfItem = num;
                subNavItem.Value        = facetItemArray[1].ToString();//(NValue + facetItemArray[1].ToString()).Trim();
                subNavItem.ItemType     = NavigationItemType.StoreCategory;
                NavStoreCateItem.SubNavigationItems.Add(subNavItem);
            }
            NaviRet.NavigationItems.Add(NavStoreCateItem);
            #endregion

            #region 品牌
            NavigationItem NavBrandItem = new NavigationItem();
            NavBrandItem.SubNavigationItems = new List <NavigationItem>();
            KeyValuePair <NavigationItemType, string> NavBrand = new KeyValuePair <NavigationItemType, string>(NavigationItemType.Brand, "品牌");
            foreach (var facet in brandFacets)
            {
                int num = facet.Value;

                string[] facetItemArray = facet.Key.Split(new string[] { "@!@" }, StringSplitOptions.RemoveEmptyEntries);

                bool isExists = NavBrandItem.SubNavigationItems.Exists(delegate(NavigationItem eachItem)
                {
                    return(eachItem.Value == facetItemArray[1].ToString());
                });
                if (isExists)
                {
                    continue;
                }

                NavBrandItem.ItemType = NavBrand.Key;
                NavBrandItem.Name     = NavBrand.Value;


                NavigationItem subNavItem = new NavigationItem();
                subNavItem.Name         = facetItemArray[0].ToString();
                subNavItem.NumberOfItem = num;
                subNavItem.Value        = facetItemArray[1].ToString();//(NValue + facetItemArray[1].ToString()).Trim();
                subNavItem.ItemType     = NavigationItemType.Brand;
                NavBrandItem.SubNavigationItems.Add(subNavItem);
            }
            NaviRet.NavigationItems.Add(NavBrandItem);
            #endregion

            #region 价格
            NavigationItem NavPriceItem = new NavigationItem();
            NavPriceItem.SubNavigationItems = new List <NavigationItem>();
            KeyValuePair <NavigationItemType, string> NavPrice = new KeyValuePair <NavigationItemType, string>(NavigationItemType.Price, "价格");
            foreach (var facet in priceFacet)
            {
                int num = facet.Value;

                string facetItem = facet.Key;

                bool isExists = NavPriceItem.SubNavigationItems.Exists(delegate(NavigationItem eachItem)
                {
                    return(eachItem.Value == facetItem);
                });
                if (isExists)
                {
                    continue;
                }

                NavPriceItem.ItemType = NavPrice.Key;
                NavPriceItem.Name     = NavPrice.Value;

                NavigationItem subNavItem = new NavigationItem();

                PriceRange priceRangeInfo = ProductPriceRangeConfig.PriceRangeList.Find(delegate(PriceRange eachPriceRange) { return(eachPriceRange.Key == facetItem); });

                if (priceRangeInfo != null)
                {
                    subNavItem.Name = priceRangeInfo.Text;
                }

                subNavItem.NumberOfItem = num;
                subNavItem.Value        = facetItem.TrimEnd();//(NValue + facetItem.TrimEnd()).Trim();
                subNavItem.ItemType     = NavigationItemType.Price;
                NavPriceItem.SubNavigationItems.Add(subNavItem);
            }
            //价格筛选条件按照价格升序
            NavPriceItem.SubNavigationItems.Sort(delegate(NavigationItem a, NavigationItem b)
            {
                return(a.Value.CompareTo(b.Value));
            });
            NaviRet.NavigationItems.Add(NavPriceItem);
            #endregion

            #region 产地
            NavigationItem NavOriginItem = new NavigationItem();
            NavOriginItem.SubNavigationItems = new List <NavigationItem>();
            KeyValuePair <NavigationItemType, string> NavOrigin = new KeyValuePair <NavigationItemType, string>(NavigationItemType.Origin, "产地");
            foreach (var facet in originFacets)
            {
                int num = facet.Value;

                string[] facetItemArray = facet.Key.Split(new string[] { "@!@" }, StringSplitOptions.RemoveEmptyEntries);

                bool isExists = NavOriginItem.SubNavigationItems.Exists(delegate(NavigationItem eachItem)
                {
                    return(eachItem.Value == facetItemArray[1].ToString());
                });
                if (isExists)
                {
                    continue;
                }

                NavOriginItem.ItemType = NavOrigin.Key;
                NavOriginItem.Name     = NavOrigin.Value;


                NavigationItem subNavItem = new NavigationItem();
                subNavItem.Name         = facetItemArray[0].ToString();
                subNavItem.NumberOfItem = num;
                subNavItem.Value        = facetItemArray[1].ToString();//(NValue + facetItemArray[1].ToString()).Trim();
                subNavItem.ItemType     = NavigationItemType.Origin;
                NavOriginItem.SubNavigationItems.Add(subNavItem);
            }
            NaviRet.NavigationItems.Add(NavOriginItem);
            #endregion

            #region 产品属性
            List <NavigationItem> tempNavList = new List <NavigationItem>();
            foreach (var facet in propertyValueFacets)
            {
                int num = facet.Value;

                string[] facetItemArray = facet.Key.Split(new string[] { "@!@" }, StringSplitOptions.RemoveEmptyEntries);

                NavigationItem NavItem = new NavigationItem();
                NavItem.Name               = Utils.removePrefix(facetItemArray[0]);
                NavItem.Priority           = Convert.ToInt32(facetItemArray[4]);
                NavItem.ItemType           = NavigationItemType.Attribute;
                NavItem.SubNavigationItems = new List <NavigationItem>();

                NavigationItem subNavItem = new NavigationItem();
                subNavItem.Name         = facetItemArray[1];
                subNavItem.NumberOfItem = num;
                subNavItem.Value        = facetItemArray[2];//(NValue + facetItemArray[2]).Trim();
                subNavItem.Priority     = Convert.ToInt32(facetItemArray[5]);

                NavigationItem tempNavItem = tempNavList.Find(delegate(NavigationItem eachItem) { return(eachItem.Name == NavItem.Name); });
                if (tempNavItem == null)
                {
                    NavItem.SubNavigationItems.Add(subNavItem);
                    tempNavList.Add(NavItem);
                }
                else
                {
                    var tempSubNavItem = tempNavItem.SubNavigationItems.Find(delegate(NavigationItem eachItem)
                    {
                        return(eachItem.Value == subNavItem.Value);
                    });
                    if (tempSubNavItem != null)
                    {
                        tempSubNavItem.NumberOfItem += num;
                        continue;
                    }
                    tempNavItem.SubNavigationItems.Add(subNavItem);
                }
            }
            tempNavList.Sort(delegate(NavigationItem a, NavigationItem b)
            {
                return(a.Priority.CompareTo(b.Priority));
            });
            foreach (NavigationItem eachNavItem in tempNavList)
            {
                eachNavItem.Name = Utils.GetEndSplitName(eachNavItem.Name);
                eachNavItem.SubNavigationItems.Sort(delegate(NavigationItem a, NavigationItem b)
                {
                    int tmp = a.Priority.CompareTo(b.Priority);
                    return(tmp == 0 ? b.NumberOfItem.CompareTo(a.NumberOfItem) : tmp);
                });

                NaviRet.NavigationItems.Add(eachNavItem);
            }
            #endregion

            return(NaviRet);
        }
Пример #27
0
        public int GetProductCount(ProductSearchCondition condition)
        {
            var query = _productRepository.Table;

            try
            {
                if (!string.IsNullOrEmpty(condition.AreaName))
                {
                    query = query.Where(q => q.ProductParameter.Count(pp => pp.ParameterValue.Parametervalue == condition.AreaName) > 0);
                }
                if (condition.TypeId.HasValue)
                {
                    query = query.Where(q => q.ProductParameter.Count(pp => pp.ParameterValue.Id == condition.TypeId) > 0);
                }
                if (condition.CommissionBegin.HasValue)
                {
                    query = query.Where(q => q.Commission >= condition.CommissionBegin.Value);
                }
                if (condition.CommissionEnd.HasValue)
                {
                    query = query.Where(q => q.Commission < condition.CommissionEnd.Value);
                }

                if (condition.ProductBrand != null)
                {
                    query = query.Where(q => q.ProductBrand.Id == condition.ProductBrand);
                }

                if (condition.PriceBegin.HasValue)
                {
                    query = query.Where(q => q.Price >= condition.PriceBegin.Value);
                }
                if (condition.PriceEnd.HasValue)
                {
                    query = query.Where(q => q.Price < condition.PriceEnd.Value);
                }


                if (condition.AddtimeBegin.HasValue)
                {
                    query = query.Where(q => q.Addtime >= condition.AddtimeBegin.Value);
                }
                if (condition.AddtimeEnd.HasValue)
                {
                    query = query.Where(q => q.Addtime < condition.AddtimeEnd.Value);
                }


                if (condition.UpdtimeBegin.HasValue)
                {
                    query = query.Where(q => q.Updtime >= condition.UpdtimeBegin.Value);
                }
                if (condition.UpdtimeEnd.HasValue)
                {
                    query = query.Where(q => q.Updtime < condition.UpdtimeEnd.Value);
                }


                if (condition.Status.HasValue)
                {
                    query = query.Where(q => q.Status == condition.Status.Value);
                }



                if (condition.Recommend.HasValue)
                {
                    query = query.Where(q => q.Recommend == condition.Recommend.Value);
                }



                if (!string.IsNullOrEmpty(condition.Productname))
                {
                    query = query.Where(q => q.Productname.Contains(condition.Productname));
                }



                if (!string.IsNullOrEmpty(condition.Productimg))
                {
                    query = query.Where(q => q.Productimg.Contains(condition.Productimg));
                }



                if (!string.IsNullOrEmpty(condition.Adduser))
                {
                    query = query.Where(q => q.Adduser.Contains(condition.Adduser));
                }



                if (!string.IsNullOrEmpty(condition.Upduser))
                {
                    query = query.Where(q => q.Upduser.Contains(condition.Upduser));
                }



                if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }


                if (condition.ProductDetails != null && condition.ProductDetails.Any())
                {
                    query = query.Where(q => condition.ProductDetails.Contains(q.ProductDetail));
                }


                if (condition.Classifys != null && condition.Classifys.Any())
                {
                    query = query.Where(q => condition.Classifys.Contains(q.Classify));
                }


                if (condition.ProductBrands != null && condition.ProductBrands.Any())
                {
                    query = query.Where(q => condition.ProductBrands.Contains(q.ProductBrand));
                }


                if (condition.Bussnessid.HasValue)
                {
                    query = query.Where(q => q.Bussnessid == condition.Bussnessid);
                }



                if (condition.Sorts != null && condition.Sorts.Any())
                {
                    query = query.Where(q => condition.Sorts.Contains(q.Sort));
                }


                if (condition.Stockrules != null && condition.Stockrules.Any())
                {
                    query = query.Where(q => condition.Stockrules.Contains(q.Stockrule));
                }



                return(query.Count());
            }
            catch (Exception e)
            {
                _log.Error(e, "数据库操作出错");
                return(-1);
            }
        }
Пример #28
0
        //构造搜索引擎相关参数
        private static ProductSearchCondition GetSearchCondition(SearchCriteriaModel criteria, NameValueCollection pageQueryString)
        {
            ProductSearchCondition condition = new ProductSearchCondition();

            condition.Filters    = new List <FilterBase>();
            condition.NValueList = new List <string>();

            //使用Category3ID搜索
            if (criteria.Category3ID > 0)
            {
                //将商品分类ID转换成NValue格式
                var subCatNValue = ProductSearchFacade.GetSubcategoryDimensionValues(criteria.Category3ID.Value);
                condition.NValueList.Add(subCatNValue.ToString());
            }

            //使用品牌ID搜索
            if (criteria.BrandID > 0)
            {
                //将品牌ID转换成NValue格式
                var brandNValue = ProductSearchFacade.GetBrandNValue(criteria.BrandID.Value);
                condition.NValueList.Add(brandNValue.ToString());
            }

            //使用Category1ID搜索
            if (criteria.Category1ID > 0)
            {
                condition.Filters.Add(new FieldFilter("p_tabstoreids", criteria.Category1ID.ToString()));
            }

            string keyWord   = string.Empty;
            int    sortKey   = 0,
                   pageIndex = criteria.PageIndex.GetValueOrDefault(),
                   pageSize  = criteria.PageSize.GetValueOrDefault();

            if (pageQueryString != null)
            {
                keyWord = pageQueryString["keyword"];
                int.TryParse(pageQueryString["sort"], out sortKey);

                int temp;
                if (int.TryParse(pageQueryString["pageIndex"], out temp))
                {
                    pageIndex = temp;
                }
                if (int.TryParse(pageQueryString["pageSize"], out temp))
                {
                    pageSize = temp;
                }
            }

            //使用关键字搜索
            if (!string.IsNullOrWhiteSpace(keyWord))
            {
                //解决“- +”号报错的bug
                if (!string.IsNullOrEmpty(keyWord) && keyWord.StartsWith("-"))
                {
                    keyWord = keyWord.Replace("-", "-");
                }
                if (!string.IsNullOrEmpty(keyWord) && keyWord.StartsWith("+"))
                {
                    keyWord = keyWord.Replace("+", "+");
                }
                condition.KeyWord = keyWord.Trim();
            }

            //分页
            if (pageIndex <= 0)
            {
                pageIndex = 0;
            }
            if (pageSize <= 0)
            {
                pageSize = 10;
            }
            condition.PagingInfo            = new Nesoft.Utility.DataAccess.SearchEngine.PagingInfo();
            condition.PagingInfo.PageNumber = (++pageIndex);
            condition.PagingInfo.PageSize   = pageSize;

            //排序
            if (sortKey <= 0)
            {
                sortKey = 10;
            }
            List <SortItem> sortItems = new List <SortItem>();

            sortItems.Add(SortKeyValueMappingConfig.SortItemList.Find(f => f.Key == sortKey).Item);
            condition.SortItems = sortItems;

            return(condition);
        }
Пример #29
0
        public Collection <Product> Search(ProductSearchCondition condition)
        {
            try
            {
                using (OpenPOSDbEntities ctx = new OpenPOSDbEntities())
                {
                    ctx.ContextOptions.LazyLoadingEnabled = false;
                    ctx.Customers.MergeOption             = MergeOption.NoTracking;

                    var items = ctx.Products.Include("Supplier").Include("Category").Include("TaxCategory").Where(x => x.Status == true);

                    if (!string.IsNullOrEmpty(condition.Name) && !string.IsNullOrEmpty(condition.Barcode))
                    {
                        items = items.Where(x => x.Name.Contains(condition.Name) ||
                                            x.Barcode.Contains(condition.Barcode));
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(condition.Barcode))
                        {
                            items = items.Where(x => x.Barcode.Contains(condition.Barcode));
                        }

                        if (!string.IsNullOrEmpty(condition.Name))
                        {
                            items = items.Where(x => x.Name.Contains(condition.Name));
                        }

                        if (condition.SupplierId != Guid.Empty)
                        {
                            items = items.Where(x => x.SupplierId == condition.SupplierId);
                        }
                        else if (!string.IsNullOrEmpty(condition.SupplierName))
                        {
                            items = items.Where(x => x.Supplier.Name.Contains(condition.SupplierName));
                        }

                        if (condition.MinMRP > 0 && condition.MaxMRP > 0)
                        {
                            items = items.Where(x => x.MRP >= condition.MinMRP && x.MRP <= condition.MaxMRP);
                        }
                        else if (condition.MinMRP > 0 && condition.MaxMRP <= 0)
                        {
                            items = items.Where(x => x.MRP >= condition.MinMRP);
                        }
                        else if (condition.MinMRP <= 0 && condition.MaxMRP > 0)
                        {
                            items = items.Where(x => x.MRP <= condition.MaxMRP);
                        }

                        if (condition.MinSellPrice > 0 && condition.MaxSellPrice > 0)
                        {
                            items = items.Where(x => x.SellPrice >= condition.MinSellPrice && x.SellPrice <= condition.MaxSellPrice);
                        }
                        else if (condition.MinSellPrice > 0 && condition.MaxSellPrice <= 0)
                        {
                            items = items.Where(x => x.SellPrice >= condition.MinSellPrice);
                        }
                        else if (condition.MinSellPrice <= 0 && condition.MaxSellPrice > 0)
                        {
                            items = items.Where(x => x.SellPrice <= condition.MaxSellPrice);
                        }
                    }

                    items = items.OrderBy(x => x.Name);

                    if (condition.PageNo > 0 && condition.PageSize > 0)
                    {
                        items = items.Skip((condition.PageNo - 1) * condition.PageSize).Take(condition.PageSize);
                    }

                    return(new Collection <Product>(items.ToList()));
                }
            }
            catch (Exception ex)
            {
                LogService.Error("Error while searching products", ex);
                throw ex;
            }
        }
Пример #30
0
        //构造搜索引擎相关参数
        private ProductSearchCondition MapSearchCondition(SearchCriteriaModel criteria)
        {
            ProductSearchCondition condition = new ProductSearchCondition();

            condition.Filters = new List <FilterBase>();
            condition.Filters.Add(new FieldFilter("p_productstatus", "1"));
            condition.NValueList = ProductSearchFacade.GetNValueList(criteria.FilterValue);

            //使用关键字搜索
            string keyWord = criteria.Keywords;

            if (string.IsNullOrEmpty(keyWord))
            {
                keyWord = criteria.Barcode;
            }
            if (!string.IsNullOrEmpty(keyWord))
            {
                //解决“- +”号报错的bug
                if (!string.IsNullOrEmpty(keyWord) && keyWord.StartsWith("-"))
                {
                    keyWord = keyWord.Replace("-", "-");
                }
                if (!string.IsNullOrEmpty(keyWord) && keyWord.StartsWith("+"))
                {
                    keyWord = keyWord.Replace("+", "+");
                }
                condition.KeyWord = keyWord.Trim();
            }

            //使用CategoryID搜索
            if (criteria.CategoryID > 0)
            {
                //将商品分类ID转换成NValue格式
                var subCatNValue = ProductSearchFacade.GetSubcategoryDimensionValues(criteria.CategoryID.Value);
                condition.NValueList.Add(subCatNValue.ToString());
                condition.Filters.Add(new FieldFilter("Nvalue", subCatNValue.ToString()));
            }

            //使用品牌ID搜索
            if (criteria.BrandID > 0)
            {
                //将品牌ID转换成NValue格式
                var brandNValue = ProductSearchFacade.GetBrandNValue(criteria.BrandID.Value);
                condition.NValueList.Add(brandNValue.ToString());
                condition.Filters.Add(new FieldFilter("Nvalue", brandNValue.ToString()));
            }

            //分页
            if (criteria.PageIndex <= 0)
            {
                criteria.PageIndex = 1;
            }
            if (criteria.PageSize <= 0)
            {
                criteria.PageSize = 10;
            }
            condition.PagingInfo            = new Nesoft.Utility.DataAccess.SearchEngine.PagingInfo();
            condition.PagingInfo.PageNumber = criteria.PageIndex;
            condition.PagingInfo.PageSize   = criteria.PageSize;

            //排序
            if (criteria.SortValue <= 0)
            {
                criteria.SortValue = 10;
            }
            List <SortItem> sortItems = new List <SortItem>();

            sortItems.Add(SortKeyValueMappingConfig.SortItemList.Find(f => f.Key == criteria.SortValue).Item);
            condition.SortItems = sortItems;

            return(condition);
        }