Пример #1
0
        public void AddFlashSale(FlashSaleModel model)
        {
            CheckFlashSale(model);

            var product = DbFactory.Default.Get <ProductInfo>().Where(p => p.Id == model.ProductId).FirstOrDefault();

            DbFactory.Default.InTransaction(() =>
            {
                FlashSaleInfo flashSale         = new FlashSaleInfo();
                flashSale.Title                 = model.Title;
                flashSale.ShopId                = model.ShopId;
                flashSale.ProductId             = model.ProductId;
                flashSale.Status                = model.Status;
                flashSale.BeginDate             = DateTime.Parse(model.BeginDate);
                flashSale.EndDate               = DateTime.Parse(model.EndDate);
                flashSale.CategoryName          = model.CategoryName;
                flashSale.LimitCountOfThePeople = model.LimitCountOfThePeople;
                flashSale.SaleCount             = model.SaleCount;
                flashSale.ImagePath             = product.RelativePath;
                flashSale.MinPrice              = model.Details.Min(p => p.Price);
                DbFactory.Default.Add(flashSale);

                foreach (var detail in model.Details)
                {
                    FlashSaleDetailInfo fsd = new FlashSaleDetailInfo();
                    fsd.FlashSaleId         = flashSale.Id;
                    fsd.ProductId           = flashSale.ProductId;
                    fsd.SkuId      = detail.SkuId;
                    fsd.Price      = detail.Price;
                    fsd.TotalCount = detail.TotalCount;
                    DbFactory.Default.Add(fsd);
                }
            });
        }
Пример #2
0
        /// <summary>
        /// 根据商品Id获取一个限时购的详细信息
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public FlashSaleInfo GetLimitTimeMarketItemByProductId(long pid)
        {
            if (pid <= 0)
            {
                throw new MallException("商品Id不能识别");
            }
            FlashSaleInfo result = null;
            var           now    = DateTime.Now;

            //var sql = new Sql("SELECT * FROM Mall_flashsale WHERE ProductId=@0 AND Status=@1 AND BeginDate<=@2 AND EndDate > @3", pid, FlashSaleInfo.FlashSaleStatus.Ongoing.GetHashCode(), now, now);
            result = DbFactory.Default.Get <FlashSaleInfo>().Where(e => e.ProductId == pid && e.Status == FlashSaleInfo.FlashSaleStatus.Ongoing && e.BeginDate <= now && e.EndDate > now).FirstOrDefault();
            //在一个事务中,不能使用多个连接
            //result = DbFactory.Default.FirstOrDefault<FlashSaleInfo>(sql);//, new { ProductId = pid, Status = FlashSaleInfo.FlashSaleStatus.Ongoing, BeginDate = now, EndDate = now });

            return(result);
        }
Пример #3
0
        public void UpdateFlashSale(FlashSaleModel model)
        {
            CheckFlashSale(model);
            FlashSaleInfo flashSale = DbFactory.Default.Get <FlashSaleInfo>().Where(p => p.Id == model.Id).FirstOrDefault();

            if (flashSale == null)
            {
                throw new MallException("此活动已被删除");
            }
            DbFactory.Default.InTransaction(() =>
            {
                DbFactory.Default.Del <FlashSaleDetailInfo>().Where(p => p.ProductId == model.ProductId).Succeed();
                if (flashSale.Status == FlashSaleInfo.FlashSaleStatus.WaitForAuditing)
                {
                    if (flashSale.ProductId != model.ProductId)
                    {
                        var product         = DbFactory.Default.Get <ProductInfo>().Where(p => p.Id == model.ProductId).FirstOrDefault();
                        flashSale.ImagePath = product.RelativePath;
                    }

                    flashSale.Title                 = model.Title;
                    flashSale.ShopId                = model.ShopId;
                    flashSale.ProductId             = model.ProductId;
                    flashSale.BeginDate             = DateTime.Parse(model.BeginDate);
                    flashSale.CategoryName          = model.CategoryName;
                    flashSale.EndDate               = DateTime.Parse(model.EndDate);
                    flashSale.LimitCountOfThePeople = model.LimitCountOfThePeople;
                    flashSale.MinPrice              = model.Details.Min(p => p.Price);

                    if (model.Status == FlashSaleInfo.FlashSaleStatus.WaitForAuditing)
                    {
                        flashSale.Status = FlashSaleInfo.FlashSaleStatus.WaitForAuditing;
                    }
                    DbFactory.Default.Update(flashSale);

                    foreach (var detail in model.Details)
                    {
                        FlashSaleDetailInfo fsd = new FlashSaleDetailInfo();
                        fsd.ProductId           = flashSale.ProductId;
                        fsd.SkuId       = detail.SkuId;
                        fsd.Price       = detail.Price;
                        fsd.TotalCount  = detail.TotalCount;
                        fsd.FlashSaleId = flashSale.Id;
                        DbFactory.Default.Add(fsd);
                    }
                }
                else if (flashSale.Status == FlashSaleInfo.FlashSaleStatus.Ongoing)
                {
                    flashSale.Title                 = model.Title;
                    flashSale.CategoryName          = model.CategoryName;
                    flashSale.LimitCountOfThePeople = model.LimitCountOfThePeople;
                    flashSale.EndDate               = DateTime.Parse(model.EndDate);
                    flashSale.MinPrice              = model.Details.Min(p => p.Price);
                    if (model.Status == FlashSaleInfo.FlashSaleStatus.WaitForAuditing)
                    {
                        flashSale.Status = FlashSaleInfo.FlashSaleStatus.WaitForAuditing;
                    }
                    DbFactory.Default.Update(flashSale);
                    foreach (var detail in model.Details)
                    {
                        FlashSaleDetailInfo fsd = new FlashSaleDetailInfo();
                        fsd.ProductId           = flashSale.ProductId;
                        fsd.SkuId       = detail.SkuId;
                        fsd.Price       = detail.Price;
                        fsd.TotalCount  = detail.TotalCount;
                        fsd.FlashSaleId = flashSale.Id;
                        DbFactory.Default.Add(fsd);
                    }
                }
            });
        }