예제 #1
0
        public FlashSaleModel GetDetailInfo(long productId)
        {
            var product = DbFactory.Default.Get <ProductInfo>().Where(p => p.Id == productId).FirstOrDefault();
            var fs      = new FlashSaleModel();

            fs.ProductId  = productId;
            fs.ProductImg = product.ImagePath;
            List <FlashSaleDetailModel> list = new List <FlashSaleDetailModel>();
            var result = DbFactory.Default.Get <SKUInfo>().Where(p => p.ProductId == productId).ToList();

            #region 阶梯商品价格--ZYF
            var price = GetMinLadderPrice(productId);
            #endregion
            foreach (var item in result)
            {
                FlashSaleDetailModel mdoel = new FlashSaleDetailModel();
                mdoel.SkuId   = item.Id;
                mdoel.Color   = item.Color;
                mdoel.Size    = item.Size;
                mdoel.Version = item.Version;
                mdoel.Stock   = (int)item.Stock;

                mdoel.SalePrice = price > 0 ? price : item.SalePrice;
                mdoel.CostPrice = item.CostPrice;
                list.Add(mdoel);
            }
            fs.Details = list;
            return(fs);
        }
예제 #2
0
        public FlashSaleModel Get(long id)
        {
            var model = DbFactory.Default.Get <FlashSaleInfo>().Where(p => p.Id == id).FirstOrDefault();

            if (model == null)
            {
                throw new MallException("活动不存在!");
            }
            var            product = ProductManagerApplication.GetProduct(model.ProductId);
            FlashSaleModel result  = new FlashSaleModel();

            result.Id                    = model.Id;
            result.Title                 = model.Title;
            result.ShopId                = model.ShopId;
            result.ProductId             = model.ProductId;
            result.Status                = model.Status;
            result.ProductName           = product.ProductName;
            result.ProductImg            = product.RelativePath;
            result.MarketPrice           = product.MarketPrice;
            result.StatusStr             = model.Status.ToDescription();
            result.BeginDate             = model.BeginDate.ToString("yyyy-MM-dd HH:mm");
            result.EndDate               = model.EndDate.ToString("yyyy-MM-dd HH:mm");
            result.LimitCountOfThePeople = model.LimitCountOfThePeople;
            result.SaleCount             = model.SaleCount;
            result.CategoryName          = model.CategoryName;
            result.MinPrice              = result.SkuMinPrice = result.SkuMaxPrice = model.MinPrice;
            result.Details               = new List <FlashSaleDetailModel>();

            var details = DbFactory.Default.Get <FlashSaleDetailInfo>().Where(p => p.FlashSaleId == result.Id).ToList();
            var skus    = DbFactory.Default.Get <SKUInfo>().Where(p => p.ProductId == model.ProductId).ToList();

            #region 阶梯商品价格--ZYF
            var price = GetMinLadderPrice(model.ProductId);
            #endregion
            if (details != null && details.Count() > 0)
            {
                result.SkuMinPrice = details.Min(t => t.Price);
                result.SkuMaxPrice = details.Max(t => t.Price);
            }

            foreach (var sku in skus)
            {
                var detail             = details.FirstOrDefault(p => p.SkuId == sku.Id);
                FlashSaleDetailModel d = new FlashSaleDetailModel();
                d.Id         = detail == null ? 0 : detail.Id;
                d.SkuId      = sku.Id;
                d.Price      = detail == null ? sku.SalePrice : (decimal)detail.Price;
                d.Color      = sku.Color;
                d.Size       = sku.Size;
                d.Version    = sku.Version;
                d.Stock      = (int)sku.Stock;
                d.TotalCount = detail == null ? 0 : Math.Min((int)sku.Stock, detail.TotalCount);
                d.CostPrice  = sku.CostPrice;
                d.SalePrice  = price > 0 ? price : sku.SalePrice;
                d.minMath    = 0;
                result.Details.Add(d);
            }
            result.Quantity = result.Details.Sum(a => a.TotalCount);

            //if( details != null )
            //{
            //    foreach( var detail in details )
            //    {
            //        var sku = context.SKUInfo.FirstOrDefault( p => p.Id == detail.SkuId );
            //        if( sku == null )
            //        {
            //            //如果sku为空,证明限时购的sku记录与商品的不一致
            //            //证明商品在限时购已存在的情况下修改了sku相关信息
            //            //暂时还没做处理
            //            break;
            //        }
            //        FlashSaleDetailModel d = new FlashSaleDetailModel();
            //        d.Id = detail.Id;
            //        d.SkuId = detail.SkuId;
            //        d.Price = ( decimal )detail.Price;
            //        d.Color = sku.Color;
            //        d.Size = sku.Size;
            //        d.Version = sku.Version;
            //        d.Stock = ( int )sku.Stock;
            //        d.CostPrice = sku.CostPrice;
            //        d.SalePrice = sku.SalePrice;
            //        result.Details.Add( d );
            //    }
            //}

            return(result);
        }