public List <CommodityDTO> GetCommodityList(Guid promotionID) { var comIds = from b in PromotionItems.ObjectSet() where promotionID.Equals(promotionID) select b.CommodityId; var comList = from a in Commodity.ObjectSet() where (comIds.Contains(a.Id) && a.CommodityType == 0) select a; return(new Commodity().ToEntityDataList(comList.ToList())); }
/// <summary> /// 删除操作 /// </summary> public void Del(PromotionItems promotionItems) { ContextSession contextSession = ContextFactory.CurrentThreadContext; promotionItems.EntityState = System.Data.EntityState.Deleted; contextSession.Delete(promotionItems); contextSession.SaveChange(); }
/// <summary> /// 添加操作 /// </summary> public void Add(PromotionItemsDTO promotionItemsDTO) { PromotionItems promotionItems = new PromotionItems().FromEntityData(promotionItemsDTO); ContextSession contextSession = ContextFactory.CurrentThreadContext; promotionItems.EntityState = System.Data.EntityState.Added; contextSession.SaveObject(promotionItems); contextSession.SaveChanges(); }
/// <summary> /// 查询商品的折扣 /// </summary> /// <param name="commodityIds"></param> /// <returns></returns> public Dictionary <Guid, decimal> GetIntensity(List <Guid> commodityIds) { DateTime now = DateTime.Now; var promotionDic = (from p in PromotionItems.ObjectSet() join pro in Promotion.ObjectSet() on p.PromotionId equals pro.Id where commodityIds.Contains(p.CommodityId) && pro.EndTime > now && pro.StartTime < now select new { ComId = p.CommodityId, Intensity = pro.Intensity }).ToDictionary(p => p.ComId, p => p.Intensity); return(promotionDic); }
/// <summary> /// 查询某个商品的折扣 /// </summary> /// <param name="commodityId"></param> /// <returns></returns> public Decimal SelectIntensity(Guid commodityId, Guid appid) { DateTime now = DateTime.Now; var promotion = (from data in Promotion.ObjectSet() join data1 in PromotionItems.ObjectSet() on data.Id equals data1.PromotionId where data1.CommodityId == commodityId && data.AppId == appid && data.EndTime >= now && data.StartTime <= now select data).FirstOrDefault(); if (promotion == null) { return((decimal)10); } else { return(promotion.Intensity); } }
/// <summary> /// 根据促销ID查询促销商品 /// </summary> /// <param name="promotionID">促销ID</param> /// <param name="pageSize">每页显示数量</param> /// <param name="pageIndex">当前页</param> /// <returns></returns> public System.Collections.Generic.IEnumerable <Jinher.AMP.BTP.Deploy.CustomDTO.PromotionItemsVM> GetPromotionItemsByPromotionID(System.Guid promotionID, int pageSize, int pageIndex) { var quary = from n in PromotionItems.ObjectSet() join m in Promotion.ObjectSet() on n.PromotionId equals m.Id join b in Commodity.ObjectSet() on n.CommodityId equals b.Id where (n.PromotionId == promotionID && b.CommodityType == 0) select new PromotionItemsVM { AppId = n.AppId, PromotionId = m.Id, CommodityId = b.Id, CommodityName = b.Name, Price = b.Price, Stock = b.Stock, PicturesPath = b.PicturesPath, TotalCollection = b.TotalCollection, TotalReview = b.TotalReview, Salesvolume = b.Salesvolume, State = b.State, Intensity = m.Intensity, No_Codes = b.No_Code, PromotionSubTime = b.SubTime }; var query1 = quary.OrderByDescending(n => n.PromotionSubTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); foreach (var c in query1) { c.CommodityCategorys = from cc in CommodityCategory.ObjectSet() join cate in Category.ObjectSet() on cc.CategoryId equals cate.Id where cc.CommodityId == c.CommodityId && cc.AppId == c.AppId select cate.Name; } return(query1); }
/// <summary> /// Redis重置活动资源数据 /// </summary> /// <param name="promotionId">活动ID</param> public static int PromotionRedis(Guid promotionId) { try { var userLimits = (from ul in UserLimited.ObjectSet() where ul.PromotionId == promotionId select ul).ToList(); var promotionItems = (from p in PromotionItems.ObjectSet() where p.PromotionId == promotionId select new { Id = p.Id, CommodityId = p.CommodityId, SurplusLimitBuyTotal = p.SurplusLimitBuyTotal }).ToList(); if (promotionItems.Any()) { string hashProSaleCountId = RedisKeyConst.ProSaleCountPrefix + promotionId.ToString(); foreach (var promotion in promotionItems) { var surplusLimitBuyTotal = promotion.SurplusLimitBuyTotal.HasValue ? promotion.SurplusLimitBuyTotal.Value : 0; RedisHelper.AddHash(hashProSaleCountId, promotion.CommodityId.ToString(), surplusLimitBuyTotal); string hashGulId = RedisKeyConst.UserLimitPrefix + promotionId.ToString() + ":" + promotion.CommodityId; var userLimitedList = from p in userLimits where p.PromotionId == promotionId && p.CommodityId == promotion.CommodityId group p by p.UserId into g select new { UserId = g.Key, userCount = g.Sum(c => c.Count) }; if (userLimitedList.Any()) { foreach (var userLimited in userLimitedList) { RedisHelper.AddHash(hashGulId, userLimited.UserId.ToString(), userLimited.userCount); } } } } if (userLimits.Any()) { var uids = (from ul in userLimits select ul.UserId).Distinct(); foreach (Guid uid in uids) { //活动全场限购,用户在当前活动已购买数量 var ubc = (from ul in userLimits where ul.UserId == uid select ul.Count).Sum(); RedisHelper.AddHash(RedisKeyConst.UserPromotionLimitPrefix + promotionId.ToString(), uid.ToString(), ubc); } } } catch (Exception ex) { LogHelper.Error(string.Format("Promotion.PromotionRedis异常:Exception={0}", ex)); return(0); } return(1); }
/// <summary> /// 订单商品LIST方法 /// </summary> /// <param name="userId"></param> /// <param name="appId"></param> /// <returns></returns> public Dictionary <Guid, List <CommodityForOrderDTO> > GetAllOrderItemsExt(System.Guid userId, System.Guid appId, List <Guid> commodityOrderIds) { //获取商品信息 var query = (from o in OrderItem.ObjectSet() where commodityOrderIds.Contains(o.CommodityOrderId) select new CommodityOrderItemDTO { Id = o.Id, PicturesPath = o.PicturesPath, Name = o.Name, Price = o.CurrentPrice, //o.CommodityOrder.Price,单价 Intensity = o.Intensity, Number = o.Number, //数量 CommodityOrderId = o.CommodityOrderId, ComAttributeIds = o.ComAttributeIds, CommodityAttributes = o.CommodityAttributes, CommodityId = o.CommodityId //OrderState = o.CommodityOrder.State }).ToList(); //查询待付款的商品ID List <Guid> commodityIds = query.Where(o => o.OrderState == 0).Select(o => o.CommodityId).ToList(); Dictionary <Guid, decimal> promotionDic = new Dictionary <Guid, decimal>(); //判断促销信息 if (commodityIds.Count > 0) { PromotionItems promotionItems = new PromotionItems(); //获取折扣信息 promotionDic = promotionItems.GetIntensity(commodityIds); } Jinher.JAP.Common.Loging.LogHelper.Error("GetAllOrderItemsExt方法:"); List <CommodityForOrderDTO> commoditySDTOList = new List <CommodityForOrderDTO>(); //遍历订单待付款的 foreach (CommodityOrderItemDTO commodityOrderItemDTO in query) { decimal?realIntensity = null; //待付款 if (commodityOrderItemDTO.OrderState == 0) { Guid commodityId = commodityOrderItemDTO.CommodityId; if (promotionDic != null && promotionDic.ContainsKey(commodityId)) { realIntensity = promotionDic[commodityId]; } else { realIntensity = 10; } } else { realIntensity = commodityOrderItemDTO.Intensity; } CommodityForOrderDTO commoditySDTO = new CommodityForOrderDTO(); commoditySDTO.Id = commodityOrderItemDTO.Id; commoditySDTO.Pic = commodityOrderItemDTO.PicturesPath; commoditySDTO.Name = commodityOrderItemDTO.Name; commoditySDTO.Price = commodityOrderItemDTO.Price; Jinher.JAP.Common.Loging.LogHelper.Error("商品价格为:" + commodityOrderItemDTO.Price); Jinher.JAP.Common.Loging.LogHelper.Error("realIntensity商品折扣为:" + realIntensity); Jinher.JAP.Common.Loging.LogHelper.Error("commodityOrderItemDTO.Intensity商品折扣为:" + commodityOrderItemDTO.Intensity); commoditySDTO.Intensity = commodityOrderItemDTO.Intensity;// realIntensity; commoditySDTO.CommodityNumber = commodityOrderItemDTO.Number; commoditySDTO.OrderId = commodityOrderItemDTO.CommodityOrderId; commoditySDTO.AttributesString = commodityOrderItemDTO.ComAttributeIds; commoditySDTO.SelectedAttributes = Util.ConvertToAttributeList(commodityOrderItemDTO.CommodityAttributes); commoditySDTOList.Add(commoditySDTO); } return(commoditySDTOList.GroupBy(c => c.OrderId, (key, group) => new { OrderId = key, CommodityList = group }).ToDictionary(c => c.OrderId, c => c.CommodityList.ToList())); }
/// <summary> /// 订单商品LIST方法 /// </summary> /// <param name="userId"></param> /// <param name="appId"></param> /// <returns></returns> public System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.CustomDTO.CommodityForOrderDTO> GetOrderItemsExt(System.Guid userId, System.Guid appId, Guid commodityOrderId, int state) { var commodityOrderList = (from o in OrderItem.ObjectSet() where o.CommodityOrderId == commodityOrderId select new CommodityOrderItemDTO { Id = o.Id, PicturesPath = o.PicturesPath, Name = o.Name, Price = o.CurrentPrice, // o.CommodityOrder.Price, 商品单价 Intensity = o.Intensity, //折扣 Number = o.Number, //数量 CommodityOrderId = o.CommodityOrderId, ComAttributeIds = o.ComAttributeIds, CommodityAttributes = o.CommodityAttributes, CommodityId = o.CommodityId, HasReview = o.AlreadyReview, RealPrice = o.CurrentPrice, // 原价 DiscountPrice = o.DiscountPrice }).ToList(); Dictionary <Guid, decimal> promotionDic = new Dictionary <Guid, decimal>(); if (state == 0) { List <Guid> commodityIds = commodityOrderList.Select(o => o.CommodityId).ToList(); if (commodityIds.Count > 0) { PromotionItems promotionItems = new PromotionItems(); promotionDic = promotionItems.GetIntensity(commodityIds); } } List <CommodityForOrderDTO> commoditySDTOList = new List <CommodityForOrderDTO>(); foreach (CommodityOrderItemDTO commodityOrderItemDTO in commodityOrderList) { decimal?realIntensity = null; CommodityForOrderDTO commoditySDTO = new CommodityForOrderDTO(); commoditySDTO.Id = commodityOrderItemDTO.Id; commoditySDTO.Pic = commodityOrderItemDTO.PicturesPath; commoditySDTO.Name = commodityOrderItemDTO.Name; //待付款 if (state == 0) { Guid commodityId = commodityOrderItemDTO.CommodityId; if (promotionDic != null && promotionDic.ContainsKey(commodityId)) { realIntensity = promotionDic[commodityId]; } else { realIntensity = commodityOrderItemDTO.Intensity; } commoditySDTO.Price = commodityOrderItemDTO.Price; commoditySDTO.Intensity = realIntensity; } else { commoditySDTO.Price = commodityOrderItemDTO.RealPrice; commoditySDTO.Intensity = commodityOrderItemDTO.Intensity;//折扣 } commoditySDTO.CommodityNumber = commodityOrderItemDTO.Number; commoditySDTO.OrderId = commodityOrderItemDTO.CommodityOrderId; commoditySDTO.AttributesString = commodityOrderItemDTO.ComAttributeIds; commoditySDTO.HasReview = commodityOrderItemDTO.HasReview; commoditySDTO.SelectedAttributes = Util.ConvertToAttributeList(commodityOrderItemDTO.CommodityAttributes); commoditySDTOList.Add(commoditySDTO); } return(commoditySDTOList); }