Exemple #1
0
        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()));
        }
Exemple #2
0
        /// <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);
        }
Exemple #3
0
        /// <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);
            }
        }
Exemple #4
0
        /// <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);
        }
Exemple #5
0
        /// <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);
        }