public static SkuAreaBll GetInstance() { if (instance == null) { instance = new SkuAreaBll(); } return(instance); }
/// <summary> /// 根据产品id 查询sku服务区域 /// </summary> /// <param name="pid">产品id</param> /// <param name="areaid">区域id</param> /// <param name="time">时间</param> /// <param name="skuValue">sku值</param> /// <param name="memberLevel">会员等级</param> /// <returns></returns> public static SkuErrorViewModel GetSkuPriceYj(int pid, int areaid, DateTime time, string skuValue, MemberLevel memberLevel = MemberLevel.普通会员) { //获取时间 DayOfWeek dayOfWeek = time.DayOfWeek; TimeSpan timeSpan = TimeSpan.Parse(time.GetDateTimeFormats('t')[0]); //获取价格 并验证是否存在 var skuPrices = SkuPriceBll.GetInstance().Table().Where(o => o.ProductId == pid).ToList(); if (skuPrices.Count() == 0) { return new SkuErrorViewModel { SkuError = SkuErrorEnum.产品的价格不服务 } } ; //获取区域 并验证是否存在 var skuAreas = SkuAreaBll.GetInstance().Table().Where(o => o.ProductId == pid).ToList(); if (skuAreas.Count() == 0) { return new SkuErrorViewModel { SkuError = SkuErrorEnum.务地区不存在 } } ; //获取时间 并验证是否存在 var skuTimes = SkuTimeBll.GetInstance().Table().Where(o => o.ProductId == pid).ToList(); if (skuTimes.Count() == 0) { return new SkuErrorViewModel { SkuError = SkuErrorEnum.务时间不存在 } } ; //获取并验证 产品价格 的 区域 var query = (from s in skuPrices join a in skuAreas on s.SkuAreaId equals a.Id where a.AreaId == areaid select s).OrderBy(o => o.Id).ToList(); if (query.Count() == 0) { return new SkuErrorViewModel { SkuError = SkuErrorEnum.务地区不存在 } } ; //获取并验证 产品价格 的 时间 query = (from s in query join t in skuTimes on s.SkuTimeId equals t.Id where t.Week == dayOfWeek && t.EndTime >= timeSpan && t.StartTime <= timeSpan select s).OrderBy(o => o.Id).ToList(); if (query.Count() == 0) { return new SkuErrorViewModel { SkuError = SkuErrorEnum.务时间不存在 } } ; query = query.Where(o => o.SkuValue == skuValue).OrderBy(o => o.Id).ToList(); if (query.Count() == 0) { return new SkuErrorViewModel { SkuError = SkuErrorEnum.Sku不存在 } } ; if (!query.FirstOrDefault().IsEnable) { return new SkuErrorViewModel { SkuError = SkuErrorEnum.产品的价格不服务 } } ; var data = query.FirstOrDefault(); string ProductCode = ProductBll.GetInstance().Get(pid).ProductCode; if (ProductCode.Trim() != "10000") { #region 查询产品价格模板是否存在价格 (isItem判断是否存在价格) //根据产品Id获取价格模板的价格 var items = PriceTempletItemBll.GetInstance().Table().Where(o => o.ProductId == pid).ToList(); // 根据已获取的产品价格Id 去获取价格模板的价格 var priceItem = new List <PriceTempletItem>(); //判断SkuPriceId if (items.Count() > 0) { priceItem = items.Where(o => o.SkuPriceId.Contains("," + data.Id.ToString() + ",")).ToList(); } //判断会员 if (priceItem.Count() > 0) { priceItem = priceItem.Where(o => o.MemberLevel.Contains("," + memberLevel + ",")).ToList(); } //判断时间 if (priceItem.Count() > 0) { foreach (var i in priceItem) { var skuTimeIdArray = i.SkuTimeId.Split(','); List <int> skuTimeIds = new List <int>(); for (int j = 0; j < skuTimeIdArray.Length; j++) { if (skuTimeIdArray[j] != "") { skuTimeIds.Add(int.Parse(skuTimeIdArray[j])); } } var priceItemTime = skuTimes.Where(o => skuTimeIds.Contains(o.Id)).ToList(); var priceTemplet = PriceTempletBll.GetInstance().Get(i.PriceTempletId); if (priceTemplet != null && priceTemplet.State == PriceTempletStateEnum.启用) { //判断价格模板时间 if (time >= priceTemplet.StartTime && time <= priceTemplet.EndTime) { foreach (var t in priceItemTime) { //判断sku时间 if (dayOfWeek == t.Week && timeSpan >= t.StartTime && timeSpan <= t.EndTime) { data.Price = i.Price; data.AdditionalPrice = i.AdditionalPrice; } } } } } } #endregion } return(new SkuErrorViewModel { SkuError = SkuErrorEnum.正常, SkuPriceView = data }); }