Example #1
0
        public bool GetProductFliterListForCate(ref List <int> productIdList, ref List <CategoryInfo> categoryList, ref List <CategoryInfo> categoryInfo, ref List <BrandInfo> brandList, ref List <KeyValuePair <AttributeInfo, List <AttributeValueInfo> > > cateAAndVList,
                                                int searchKeyType, int searchKeyId, int cateId, int brandId, string filterAttr, int onlyStock)
        {
            cateId = cateId > 0 ? cateId : searchKeyId;
            var categoryAllList = Categories.GetCategoryList();

            //获取指定的树形分类信息
            categoryInfo = Categories.GetCategoryInfoById(cateId, categoryAllList);

            //获取可选的分类信息列表
            int pid0    = categoryInfo[0].CateId;
            var pidList = categoryAllList.FindAll(p => p.ParentId == pid0 && p.Layer == 2).Select(p => p.CateId);

            categoryList = categoryAllList.FindAll(p => p.ParentId == pid0 || pidList.Contains(p.ParentId));
            if (categoryList == null || categoryList.Count == 0)
            {
                return(false);
            }

            //获取可选的筛选属性及属性值列表
            var attrProductList = Searches.GetProductIdListByAttrId(0, 0, cateId, 0);
            var attrIdList      = attrProductList.Select(p => p.AttrId).Distinct().ToList();
            var attrValueIdList = attrProductList.Select(p => p.AttrValueId).Distinct().ToList();
            var attrList        = Categories.GetFilterAttributeListByIds(attrIdList);

            foreach (var item in attrList)
            {
                var attrValueList = Categories.GetAttributeValueListByIds(item.AttrId, attrValueIdList);
                cateAAndVList.Add(new KeyValuePair <AttributeInfo, List <AttributeValueInfo> >(item, attrValueList));
            }
            if (cateAAndVList == null || cateAAndVList.Count == 0)
            {
                return(false);
            }

            //获取可选的品牌列表
            var brandIdList = attrProductList.Where(p => p.CateId == cateId).Select(p => p.BrandId).Distinct().ToList();

            brandList = Brands.GetBrandListByIds(brandIdList);

            //获取筛选条件下的商品id列表
            var _productIdList = attrProductList.Select(p => p.Pid).Distinct();

            if (!string.IsNullOrEmpty(filterAttr))
            {
                string[] filterAttrValueIdList = StringHelper.SplitString(filterAttr, "-");
                //if (filterAttrValueIdList != null && filterAttrValueIdList.Length == cateAAndVList.Count   //选定的属性应该可筛选属性数量一致
                //    && filterAttrValueIdList.Count(p => p == "0") < filterAttrValueIdList.Length)  //不能全为0
                //{
                //    List<int> pidforAttrList = attrProductList.Where(p => filterAttrValueIdList.Contains(p.AttrValueId.ToString())).Select(p => p.Pid).ToList();
                //    _productIdList = _productIdList.Where(p => pidforAttrList.Contains(p));
                //}
                if (filterAttrValueIdList != null && filterAttrValueIdList.Length == cateAAndVList.Count) //选定的属性应该可筛选属性数量一致
                {
                    foreach (var item in filterAttrValueIdList)
                    {
                        var _attrvalueid = TypeHelper.StringToInt(item);
                        if (_attrvalueid == 0)
                        {
                            continue;
                        }
                        _productIdList = _productIdList.Where(m => attrProductList.Exists(p => p.AttrValueId == _attrvalueid && p.Pid == m));
                    }
                }
            }
            if (onlyStock == 1) //有货筛选
            {
                var stockProductIdList = Products.GetStockProductIdList();
                if (stockProductIdList != null && stockProductIdList.Count > 0)
                {
                    _productIdList = _productIdList.Where(p => stockProductIdList.Contains(p));
                }
            }
            productIdList = _productIdList.ToList();

            return(true);
        }
Example #2
0
        /// <summary>
        /// 获取满足搜索条件的商品id列表
        /// </summary>
        /// <param name="searchKeyList">商品id列表</param>
        /// <param name="name">搜索词</param>
        /// <param name="keytype">搜索词类型</param>
        public bool GetProductFliterList(ref List <int> productIdList, ref List <CategoryInfo> categoryList, ref List <CategoryInfo> categoryInfo, ref List <BrandInfo> brandList, ref List <KeyValuePair <AttributeInfo, List <AttributeValueInfo> > > cateAAndVList,
                                         int searchKeyType, int searchKeyId, int cateId, int brandId, string filterAttr, int onlyStock)
        {
            //获取可选的商品分类品牌列表(1商品id,2分类id,3品牌id)
            var productCateBrandList = GetProductCateBrandList(cateId, searchKeyType, searchKeyId);

            if (productCateBrandList == null || productCateBrandList.Count == 0)
            {
                return(false);
            }

            //获取可选的分类id列表
            var categoryIdList  = productCateBrandList.Select(p => p.Item2).Distinct().ToList();
            var categoryAllList = Categories.GetCategoryList();

            //获取可选的分类信息列表
            categoryIdList.AddRange(categoryAllList.Where(p => categoryIdList.Contains(p.CateId)).Select(p => p.ParentId));
            categoryList = categoryAllList.FindAll(p => categoryIdList.Contains(p.CateId));
            if (categoryList == null || categoryList.Count == 0)
            {
                return(false);
            }

            //获取指定的树形分类信息
            if (cateId == 0)
            {
                cateId = categoryList.FirstOrDefault(p => p.HasChild == 0).CateId;
            }
            categoryInfo = Categories.GetCategoryInfoById(cateId, categoryAllList);

            //获取可选的品牌列表
            var brandIdList = productCateBrandList.Where(p => p.Item2 == cateId).Select(p => p.Item3).Distinct().ToList();

            brandList = Brands.GetBrandListByIds(brandIdList);

            //获取可选的筛选属性及属性值列表
            var attrProductList = Searches.GetProductIdListByAttrId(0, 0, cateId, 0);
            var attrIdList      = attrProductList.Select(p => p.AttrId).Distinct().ToList();
            var attrValueIdList = attrProductList.Select(p => p.AttrValueId).Distinct().ToList();
            var attrList        = Categories.GetFilterAttributeListByIds(attrIdList);

            foreach (var item in attrList)
            {
                var attrValueList = Categories.GetAttributeValueListByIds(item.AttrId, attrValueIdList);
                cateAAndVList.Add(new KeyValuePair <AttributeInfo, List <AttributeValueInfo> >(item, attrValueList));
            }
            if (cateAAndVList == null || cateAAndVList.Count == 0)
            {
                return(false);
            }

            //获取筛选条件下的商品id列表
            var _productIdList = productCateBrandList.Where(p => p.Item2 == cateId && (brandId == 0 || p.Item3 == brandId)).Select(p => p.Item1).Distinct();

            if (!string.IsNullOrEmpty(filterAttr))
            {
                string[] filterAttrValueIdList = StringHelper.SplitString(filterAttr, "-");
                if (filterAttrValueIdList != null && filterAttrValueIdList.Length == cateAAndVList.Count) //选定的属性应该可筛选属性数量一致
                {
                    foreach (var item in filterAttrValueIdList)
                    {
                        var _attrvalueid = TypeHelper.StringToInt(item);
                        if (_attrvalueid == 0)
                        {
                            continue;
                        }
                        _productIdList = _productIdList.Where(m => attrProductList.Exists(p => p.AttrValueId == _attrvalueid && p.Pid == m));
                    }
                }
            }
            if (onlyStock == 1) //有货筛选
            {
                var stockProductIdList = Products.GetStockProductIdList();
                if (stockProductIdList != null && stockProductIdList.Count > 0)
                {
                    _productIdList = _productIdList.Where(p => stockProductIdList.Contains(p));
                }
            }
            productIdList = _productIdList.ToList();

            return(true);
        }
Example #3
0
        public List <Tuple <int, int, int> > GetProductCateBrandList(int cateId, int searchKeyType, int searchKeyId)
        {
            switch (searchKeyType)
            {
            case (int)ProductKeyEnum.Brand:
            {
                var attrProductList = Searches.GetProductIdListByAttrId(0, 0, 0, searchKeyId);
                if (attrProductList != null && attrProductList.Count > 0)
                {
                    return(attrProductList.Select(p => new Tuple <int, int, int>(p.Pid, p.CateId, p.BrandId)).ToList());
                }
                break;
            }

            case (int)ProductKeyEnum.Special:
            {
                var specialProductList = Searches.GetProductIdListBySpecialId(searchKeyId, 0, 0);
                if (specialProductList != null && specialProductList.Count > 0)
                {
                    return(specialProductList.Select(p => new Tuple <int, int, int>(p.Pid, p.CateId, p.BrandId)).ToList());
                }
                break;
            }

            case (int)ProductKeyEnum.Attribute:
            {
                var attrProductList = Searches.GetProductIdListByAttrId(searchKeyId, 0, 0, 0);
                if (attrProductList != null && attrProductList.Count > 0)
                {
                    return(attrProductList.Select(p => new Tuple <int, int, int>(p.Pid, p.CateId, p.BrandId)).ToList());
                }
                break;
            }

            case (int)ProductKeyEnum.AttributeValue:
            {
                var attrProductList = Searches.GetProductIdListByAttrId(0, searchKeyId, 0, 0);
                if (attrProductList != null && attrProductList.Count > 0)
                {
                    return(attrProductList.Select(p => new Tuple <int, int, int>(p.Pid, p.CateId, p.BrandId)).ToList());
                }
                break;
            }

            case (int)ProductKeyEnum.KeyWord:
            {
                var keywordProductList = Searches.GetProductIdListByKeyId(searchKeyId, 0, 0);
                if (keywordProductList != null && keywordProductList.Count > 0)
                {
                    return(keywordProductList.Select(p => new Tuple <int, int, int>(p.Pid, p.CateId, p.BrandId)).ToList());
                }
                break;
            }

            case (int)ProductKeyEnum.CategorySearch:
            {
                var attrProductList = Searches.GetProductIdListByAttrId(0, 0, searchKeyId, 0);
                if (attrProductList != null && attrProductList.Count > 0)
                {
                    return(attrProductList.Select(p => new Tuple <int, int, int>(p.Pid, p.CateId, p.BrandId)).ToList());
                }
                break;
            }
            }

            return(null);
        }