public FilterParameters2 CopyByAttr(long attrId, string attrVal) { FilterParameters2 fp = new FilterParameters2(this); string newAttr = ""; if (!string.IsNullOrEmpty(fp.Attribute)) { if (fp.Attribute.IndexOf('@') != -1) { string[] Attributes = fp.Attribute.Split('@'); foreach (string Attr_Item in Attributes) { if (!string.IsNullOrEmpty(Attr_Item)) { if (Attr_Item.IndexOf('_') != -1) { string[] Attr_Value = Attr_Item.Split('_'); if (!string.IsNullOrEmpty(Attr_Value[0]) && !string.IsNullOrEmpty(Attr_Value[1])) { if (long.Parse(Attr_Value[0]) != attrId) { newAttr += $"@{ Attr_Value[0]}_{ Attr_Value[1]}"; } } } } } } } newAttr += $"@{attrId}_{attrVal}"; fp.Attribute = newAttr; return(fp); }
public static IList <dynamic> GetCategoryByApiProductList(DataSource ds, int categoryId, int categorylevel, FilterParameters2 parameters, int productType = 1) { DbWhereQueue where = null; ///关键词 if (!string.IsNullOrEmpty(parameters.KeyWord)) { foreach (string s in parameters.KeyWord.Split(' ')) { if (!string.IsNullOrEmpty(s)) { if (where == null) { where = W("Title", s, DbWhereType.Like); } else { where |= W("Title", s, DbWhereType.Like); } } } } else { where = W <Product>("Title", parameters.KeyWord, DbWhereType.Like); } where &= (W("State", ProductState.Sale) | W("State", ProductState.BeforeSaved)) & W("ParentId", 0); //分类 if (categoryId > 0) { if (categorylevel == 3) { where &= W("CategoryId", categoryId); } else if (categorylevel == 2) { where &= (W("CategoryId", categoryId) | W("CategoryId").InSelect <ProductCategory>(S("Id")).Where(W("ParentId", categoryId)).Result()); } else if (categorylevel == 1) { where &= (W("CategoryId", categoryId) | W("CategoryId").InSelect <ProductCategory>(S("Id")).Where(W("ParentId", categoryId)).Result() | W("CategoryId").InSelect <ProductCategory>(S("Id")).Where(W("ParentId").InSelect <ProductCategory>(S("Id")).Where(W("ParentId", categoryId)).Result()).Result()); } } ///产品属性 if (!string.IsNullOrEmpty(parameters.Attribute)) { if (parameters.Attribute.IndexOf('@') != -1) { string[] Attributes = parameters.Attribute.Split('@'); foreach (string Attr_Item in Attributes) { if (!string.IsNullOrEmpty(Attr_Item)) { if (Attr_Item.IndexOf('_') != -1) { string[] Attr_Value = Attr_Item.Split('_'); if (!string.IsNullOrEmpty(Attr_Value[0]) && !string.IsNullOrEmpty(Attr_Value[1])) { where &= (W("Id").InSelect <ProductAttributeMapping>(S("ProductId")).Where(W("AttributeId", long.Parse(Attr_Value[0].ToString())) & W("Value", Attr_Value[1].ToString())).Result()); } } } } } } //供应类型 if (parameters.SupplierType != -1) { where &= W("SupplierType", parameters.SupplierType); } if (parameters.Brand > 0) { where &= W("BrandId", parameters.Brand); } //} if (parameters.StoreId > 0) { where &= W("SupplierId", parameters.StoreId); if (parameters.StoreId > 0) { where &= W("SupplierId", parameters.StoreId); if (parameters.StoreCategoryId > 0) { if (Db <StoreCategory> .Query(ds).Select(S("ParentId")).Where(W("Id", parameters.StoreCategoryId)).First <StoreCategory>().ParentId > 0) { where &= W("StoreCategoryId", parameters.StoreCategoryId); } else { where &= (W("StoreCategoryId", parameters.StoreCategoryId) | W("StoreCategoryId").InSelect <StoreCategory>(S("Id")).Where(W("ParentId", parameters.StoreCategoryId)).Result()); } } } } where &= W("ProductType", productType); IList <dynamic> list = Db <ProductCategory> .Query(ds).Select(S <ProductCategory>("*")) .Where(W("Id").InSelect <Product>(S("CategoryId")).Where(where).Result()) .ToList(); return(list); }