public static QueryProductsListModel QueryProductsForProductLibrary(SeachProducts model) { if (!string.IsNullOrWhiteSpace(model.category)) { model.category = !model.category.EndsWith(".") ? model.category + "." : model.category; QueryProductsListModel _QueryProductsListModel = new QueryProductsListModel(); var data = _ProductLibraryConfigManage.QueryProductsForProductLibrary(model); if (data != null) { _QueryProductsListModel.QueryProducts = data.OrderByDescending(x => x.Maoli).ToList();//list as IEnumerable<QueryProductsModel>; string sessionKey = $"ProductLibraryConfigBrandList{model.category}"; using (var client = CacheHelper.CreateCacheClient(nameof(ProductLibraryConfigController))) { var QueryProductsListModel = client.GetOrSet <QueryProductsListModel>(sessionKey, () => { var queryProductsListModel = new QueryProductsListModel(); System.Data.DataSet _FilterConditionItems = _ProductLibraryConfigManage.GetFilterCondition(model.category); if (_FilterConditionItems != null && _FilterConditionItems.Tables.Count <= 3) { if (_FilterConditionItems.Tables[0] != null && _FilterConditionItems.Tables[0].Rows.Count > 0) { queryProductsListModel.CP_BrandList = _FilterConditionItems.Tables[0].ConvertTo <FilterConditionModel>().ToList() ?? new List <FilterConditionModel>(); } if (_FilterConditionItems.Tables[2] != null && _FilterConditionItems.Tables[2].Rows.Count > 0) { queryProductsListModel.CP_Tire_RimList = _FilterConditionItems.Tables[2].ConvertTo <FilterConditionModel>().ToList() ?? new List <FilterConditionModel>(); } if (_FilterConditionItems.Tables[1] != null && _FilterConditionItems.Tables[1].Rows.Count > 0) { IEnumerable <FilterConditionModel> CP_tabList = _FilterConditionItems.Tables[1].ConvertTo <FilterConditionModel>() ?? new List <FilterConditionModel>(); List <string> tabList = new List <string>(); foreach (var item in CP_tabList) { if (!string.IsNullOrWhiteSpace(item.Name)) { string[] tabArr = item.Name.Split(';'); foreach (var itemarr in tabArr) { tabList.Add(itemarr); } } } queryProductsListModel.CP_tabList = new HashSet <string>(tabList); } } return(queryProductsListModel); }, TimeSpan.FromHours(1)).Value; QueryProductsListModel.QueryProducts = _QueryProductsListModel.QueryProducts; return(QueryProductsListModel); } } return(_QueryProductsListModel); } return(null); }
/// <summary> /// 查询产品库优惠券配置 /// </summary> /// <param name="model"></param> /// <returns></returns> public static QueryProductsListModel QueryProductsForProductLibrary(SeachProducts model) { if (string.IsNullOrWhiteSpace(model.Category)) { return(null); } model.Category = !model.Category.EndsWith(".") ? model.Category + "." : model.Category; var queryProductModel = new QueryProductsListModel(); var data = _ProductLibraryConfigManage.QueryProductsForProductLibrary(model, out int queryProductTotalCount); if (data == null) { return(queryProductModel); } queryProductModel.ProductsTotalCount = queryProductTotalCount; queryProductModel.QueryProducts = data.OrderByDescending(x => x.Maoli).ToList(); return(queryProductModel); }
public ActionResult Edit() { if (Session["ProductLibraryConfigPattern"] != null) { ViewBag.Pattern = Session["ProductLibraryConfigPattern"] as List <string>; } else { List <string> Pattern = _ProductLibraryConfigManage.GetPattern(); Session["ProductLibraryConfigPattern"] = Pattern; ViewBag.Pattern = Pattern; } int pageCount = 0; SeachProducts search = new SeachProducts() { category = Request.QueryString["Category"] ?? "Tires", brand = Request.QueryString["CP_Brand"] ?? "", tab = Request.QueryString["CP_Tab"] ?? "", rim = Request.QueryString["CP_Tire_Rim"] ?? "", couponIds = Request.QueryString["S_Coupon"] ?? "", price = Request.QueryString["S_Price"] ?? "", SalePriceAfter = Request.QueryString["SalePriceAfter"] ?? "", CostPrice = Request.QueryString["S_CostPrice"] ?? "", pid = Request.QueryString["S_PID"] ?? "", pattern = Request.QueryString["S_Figure"] ?? "", soft = Request.QueryString["S_PiceSoft"] ?? "", pageIndex = Request.QueryString["pageIndex"] != null?int.Parse(Request.QueryString["pageIndex"]) : 1, pageSize = Request.QueryString["pageSize"] != null?int.Parse(Request.QueryString["pageSize"]) : 100, onSale = Request.QueryString["onSale"] ?? "", maoli = Request.QueryString["maoli"] ?? "", MaoliAfter = Request.QueryString["maoliAfter"] ?? "", maoliSort = Request.QueryString["maoliSort"] ?? "", isShow = Request.QueryString["S_IsShow"] ?? "", FiltrateType = Request.QueryString["filtrateType"] ?? "" }; var products = QueryProductsForProductLibrary(search); if (products != null && products.QueryProducts != null && products.QueryProducts.Any()) { //products.QueryProducts = _ProductLibraryConfigManage.CalculateUseCouponEffects(products.QueryProducts).ToList(); //这一行的逻辑已经合并到query里去了,因为多个循环太慢了 IEnumerable <QueryProductsModel> queryResult = products.QueryProducts; if (!string.IsNullOrEmpty(search.SalePriceAfter))//筛选券后最低价 { var salePriceAfter = search.SalePriceAfter.Split('|'); if (salePriceAfter.Length == 2) { queryResult = queryResult.Where(x => x.PriceAfterCoupon >= decimal.Parse(salePriceAfter[0].Trim()) && x.PriceAfterCoupon <= decimal.Parse(salePriceAfter[1].Trim())); } } else if (!string.IsNullOrEmpty(search.MaoliAfter)) //筛选券后毛利 { var maoliAfter = search.MaoliAfter.Split('|'); if (maoliAfter.Length == 2) { queryResult = queryResult.Where(x => x.GrossProfit >= decimal.Parse(maoliAfter[0].Trim()) && x.GrossProfit <= decimal.Parse(maoliAfter[1].Trim())); } } else if (!string.IsNullOrEmpty(search.price)) //筛选销售价 { var salePrice = search.price.Split('|'); if (salePrice.Length == 2) { queryResult = queryResult.Where(x => x.cy_list_price >= decimal.Parse(salePrice[0].Trim()) && x.cy_list_price <= decimal.Parse(salePrice[1].Trim())); } } else if (!string.IsNullOrEmpty(search.CostPrice)) //筛选成本价 { var costPrice = search.CostPrice.Split('|'); if (costPrice.Length == 2) { queryResult = queryResult.Where(x => x.cy_cost >= decimal.Parse(costPrice[0].Trim()) && x.cy_cost <= decimal.Parse(costPrice[1].Trim())); } } if (!string.IsNullOrEmpty(search.maoliSort) && search.FiltrateType == "SalePriceAfter") { if (search.maoliSort.Contains("asc")) { queryResult = queryResult.OrderBy(x => x.PriceAfterCoupon.GetValueOrDefault()); } else { queryResult = queryResult.OrderByDescending(x => x.PriceAfterCoupon.GetValueOrDefault()); } } else if (!string.IsNullOrEmpty(search.maoliSort) && search.FiltrateType == "GrossMarginAfter") { if (search.maoliSort.Contains("asc")) { queryResult = queryResult.OrderBy(x => x.GrossProfit.GetValueOrDefault()); } else { queryResult = queryResult.OrderByDescending(x => x.GrossProfit.GetValueOrDefault()); } } else if (!string.IsNullOrEmpty(search.maoliSort) && search.FiltrateType == "SalePrice") { if (search.maoliSort.Contains("asc")) { queryResult = queryResult.OrderBy(x => x.cy_list_price); } else { queryResult = queryResult.OrderByDescending(x => x.cy_list_price); } } else if (!string.IsNullOrEmpty(search.maoliSort) && search.FiltrateType == "CostPrice") { if (search.maoliSort.Contains("asc")) { queryResult = queryResult.OrderBy(x => x.cy_cost); } else { queryResult = queryResult.OrderByDescending(x => x.cy_cost); } } products.QueryProducts = queryResult.ToList(); if (products.QueryProducts.Count % search.pageSize == 0) { pageCount = products.QueryProducts.Count / search.pageSize; } else { pageCount = (products.QueryProducts.Count / search.pageSize) + 1; } products.QueryProducts = products.QueryProducts.Skip(search.pageSize * (search.pageIndex - 1)) .Take(search.pageSize).Select( i => { i.PageCount = pageCount; return(i); }).ToList(); } QueryProductsListModel model = products; ViewBag.pageIndex = Request.QueryString["pageIndex"] != null?int.Parse(Request.QueryString["pageIndex"]) : 1; ViewBag.pageSize = Request.QueryString["pageSize"] != null?int.Parse(Request.QueryString["pageSize"]) : 100; return(View(model)); }