public ProductPriceWeight SelectGuideParaByType(string firstType, string secondType, string thirdType) { var priceWeight = DalBaoYangPriceGuide.SelectAllWeight(); var baseValue = priceWeight.FirstOrDefault(p => p.WeightType.Equals("Base")); ProductPriceWeight result = new ProductPriceWeight { CategoryWeights = new Dictionary <string, List <CategoryWeight> >(), BaseWeight = Tuple.Create(baseValue?.PKID, (int)(baseValue?.WeightValue ?? 0)) }; try { var data = DalBaoYangPriceGuide.SelectGuideParaByType(firstType, secondType, thirdType); if (data != null && data.Rows.Count > 0) { var dic = data.AsEnumerable() .GroupBy(p => (int)p["ParentOid"]) .ToDictionary(t => t.Key, o => o.Select(p => p)); foreach (var keyValue in dic) { List <CategoryWeight> categorys = new List <CategoryWeight>(); var parentNode = DalBaoYangPriceGuide.SelectProductCategoryByOid(keyValue.Key); foreach (var node in keyValue.Value) { var currentCategory = categorys.FirstOrDefault(p => p.WeightName.Equals(node["Link"].ToString())); var categoryWeight = priceWeight.FirstOrDefault( p => p.WeightType.Equals("Category") && p.WeightName.Equals(node["Link"].ToString())); if (currentCategory == null) { CategoryWeight category = new CategoryWeight { Pkid = categoryWeight?.PKID, WeightName = node["Link"].ToString(), DisplayName = node["Item"].ToString(), WeightValue = (int)(categoryWeight?.WeightValue ?? 0), }; if (!string.IsNullOrWhiteSpace(node["CP_Brand"].ToString())) { var brand = priceWeight.FirstOrDefault( p => p.WeightType.Equals("Brand") && p.WeightName.Equals(node["CP_Brand"].ToString()) && p.CategoryName.Equals(node["Link"].ToString())); category.Brands = new List <BrandWeight> { new BrandWeight { Pkid = brand?.PKID, WeightName = node["CP_Brand"].ToString(), WeightValue = (int)(brand?.WeightValue ?? 0) } }; } categorys.Add(category); } else { if (!string.IsNullOrWhiteSpace(node["CP_Brand"].ToString())) { var brand = priceWeight.FirstOrDefault( p => p.WeightType.Equals("Brand") && p.WeightName.Equals(node["CP_Brand"].ToString()) && p.CategoryName.Equals(node["Link"].ToString())); if (currentCategory.Brands == null) { currentCategory.Brands = new List <BrandWeight>(); } currentCategory.Brands.Add(new BrandWeight { Pkid = brand?.PKID, WeightName = node["CP_Brand"].ToString(), WeightValue = (int)(brand?.WeightValue ?? 0) }); } } } result.CategoryWeights[parentNode.Item2] = categorys; } } } catch (Exception ex) { Logger.Log(Level.Error, ex, "SelectGuideParaByType"); } return(result); }
public List <BaoYangPriceGuideList> IntegrateProductInfo(List <BaoYangPriceGuideList> baseData, BaoYangPriceSelectModel param) { try { var warnLine = DalBaoYangPriceGuide.SelectWarningLine(); var priceWeight = DalBaoYangPriceGuide.SelectAllWeight(); var pageNum = baseData.Count / 100 + (baseData.Count % 100 > 0 ? 1 : 0); if (param.QplMaoLiE != null || param.QplMaoLiLv != null || param.ShopMaoLiE != null || param.ShopMaoLiLv != null || (!string.IsNullOrWhiteSpace(param.SitePrices) && param.SitePrices.Contains("QPLPrice")) || (!string.IsNullOrWhiteSpace(param.SitePrice) && param.SitePrice.Equals("QPLPrice"))) { for (var i = 0; i < pageNum; i++) { var currentData = baseData.Skip(100 * (i - 1)).Take(100).Select(t => t).ToList(); AppendQplPrice(currentData); } } foreach (var list in baseData) { //获取加权值 list.JiaQuan = (int)((priceWeight.FirstOrDefault(p => p.WeightType.Equals("Base"))? .WeightValue ?? 0) + (priceWeight.FirstOrDefault( p => p.WeightType.Equals("Brand") && p.WeightName.Equals(list.Brand) && p.CategoryName.Equals(list.Category))? .WeightValue ?? 0) + (priceWeight.FirstOrDefault( p => p.WeightType.Equals("Category") && p.WeightName.Equals(list.Category)) ? .WeightValue ?? 0)); var theoryGuidePrice = list.cost == null ? (decimal?)null : list.cost.Value * (100 + list.JiaQuan) / 100; decimal?actualGuidePrice = null; if (list.cost == null || list.cost == 0) { if (list.JDSelfPrice > 0) { actualGuidePrice = list.JDSelfPrice; } } else { if (list.JDSelfPrice == null) { actualGuidePrice = theoryGuidePrice; } else { actualGuidePrice = Math.Min(theoryGuidePrice.Value, list.JDSelfPrice.Value); } } list.TheoryGuidePrice = theoryGuidePrice; list.ActualGuidePrice = actualGuidePrice; //获取预警线 var currentWarnLine = warnLine.FirstOrDefault( p => p.MinGuidePrice <= (actualGuidePrice ?? 0) && p.MaxGuidePrice > (actualGuidePrice ?? 0)); if (currentWarnLine != null) { list.UpperLimit = currentWarnLine.UpperLimit; list.LowerLimit = currentWarnLine.LowerLimit; } } } catch (Exception ex) { Logger.Log(Level.Error, ex, "IntegrateProductInfo"); } return(baseData); }