Ejemplo n.º 1
0
        /// <summary>
        /// 获取指定商品的所有促销信息
        /// </summary>
        /// <param name="productSysNo"></param>
        /// <returns></returns>
        public static ProductPromotionInfo GetProductPromotionInfo(int productSysNo)
        {
            if (productSysNo <= 0)
            {
                return(null);
            }
            string cacheKey = "GetProductPromotionInfo_" + productSysNo;

            if (HttpRuntime.Cache[cacheKey] != null)
            {
                return((ProductPromotionInfo)HttpRuntime.Cache[cacheKey]);
            }

            ProductPromotionInfo promotion = new ProductPromotionInfo();

            promotion.ProductSysNo = productSysNo;
            //套餐
            promotion.ComboList = PromotionDA.GetComboListByMasterProductSysNo(productSysNo);
            //团购
            promotion.GroupBuySysNo = PromotionDA.ProductIsGroupBuying(productSysNo);
            //限时和秒杀
            CountdownInfo countdown = PromotionDA.GetProductCountdownByProductSysNo(productSysNo);

            if (countdown != null)
            {
                promotion.Countdown      = countdown;
                promotion.CountdownSysNo = countdown.SysNo.Value;
                promotion.IsSecKill      = countdown.IsSecondKill.HasValue ? countdown.IsSecondKill.Value : false;
            }
            else
            {
                promotion.CountdownSysNo = 0;
                promotion.IsSecKill      = false;
            }
            //赠品
            promotion.SaleGiftList = PromotionDA.GetSaleGiftListByProductSysNo(productSysNo);



            HttpRuntime.Cache.Insert(cacheKey, promotion, null, DateTime.Now.AddSeconds(CacheTime.Short), Cache.NoSlidingExpiration);
            return(promotion);
        }
Ejemplo n.º 2
0
        private PromoInfoModel TransformPromoInfo(ProductPromotionInfo promotionInfo)
        {
            PromoInfoModel result = new PromoInfoModel();

            result.CountDownSysNo = promotionInfo.CountdownSysNo;
            if (promotionInfo.Countdown != null && promotionInfo.Countdown.EndTime.HasValue)
            {
                //计算限时抢购剩余时间
                if (promotionInfo.Countdown.EndTime <= DateTime.Now)
                {
                    result.CountDownLeftSecond = 0;
                }
                else
                {
                    var ts = promotionInfo.Countdown.EndTime.Value - DateTime.Now;
                    result.CountDownLeftSecond = (int)ts.TotalSeconds;
                }
            }
            result.GroupBuyingSysNo = promotionInfo.GroupBuySysNo;
            //读取单品买赠和厂商赠品列表
            result.GiftInfo = new List <GiftItemModel>();
            if (promotionInfo.SaleGiftList == null)
            {
                promotionInfo.SaleGiftList = new List <SaleGiftInfo>();
            }
            var       giftPromoList = promotionInfo.SaleGiftList.Where(item => item.SaleGiftType == SaleGiftType.Single || item.SaleGiftType == SaleGiftType.Vendor);
            ImageSize imageSizeGift = ImageUrlHelper.GetImageSize(ImageType.Tiny);

            foreach (var promo in giftPromoList)
            {
                if (promo.GiftItemList == null)
                {
                    promo.GiftItemList = new List <GiftItem>();
                }
                foreach (var giftItem in promo.GiftItemList)
                {
                    GiftItemModel model = new GiftItemModel();
                    model.ID           = giftItem.ProductSysNo;
                    model.ProductName  = giftItem.ProductName;
                    model.ImageUrl     = ProductFacade.BuildProductImage(imageSizeGift, giftItem.DefaultImage);
                    model.UnitQuantity = giftItem.UnitQuantity;

                    result.GiftInfo.Add(model);
                }
            }
            //套餐活动信息
            result.ComboInfo = new List <ComboInfoModel>();
            var       comboList      = promotionInfo.ComboList ?? new List <ComboInfo>();
            ImageSize imageSizeCombo = ImageUrlHelper.GetImageSize(ImageType.Middle);

            foreach (var combo in comboList)
            {
                decimal originalTotal = 0;
                decimal discount      = 0;
                List <ComboItemModel> comboItemList = new List <ComboItemModel>();
                foreach (var item in combo.Items)
                {
                    ComboItemModel itemModel = new ComboItemModel();
                    itemModel.ID           = item.ProductSysNo;
                    itemModel.Code         = item.ProductID;
                    itemModel.ProductTitle = item.ProductName;
                    itemModel.Quantity     = item.Quantity;
                    itemModel.ImageUrl     = ProductFacade.BuildProductImage(imageSizeCombo, item.DefaultImage);
                    itemModel.CurrentPrice = item.CurrentPrice;
                    var tariffPrice = item.TariffRate * item.CurrentPrice;
                    itemModel.TariffPrice = tariffPrice;
                    itemModel.Discount    = item.Discount;
                    if (tariffPrice <= ConstValue.TariffFreeLimit)
                    {
                        originalTotal += item.CurrentPrice * item.Quantity;
                    }
                    else
                    {
                        originalTotal += (item.CurrentPrice + tariffPrice) * item.Quantity;
                    }

                    discount += item.Discount * item.Quantity;

                    comboItemList.Add(itemModel);
                }

                ComboInfoModel model = new ComboInfoModel();
                if (combo.SysNo.HasValue)
                {
                    model.SysNo = combo.SysNo.Value;
                }
                model.SaleRuleName  = combo.SaleRuleName;
                model.OriginalPrice = originalTotal;
                model.DiscountPrice = discount;
                model.TotalPrice    = originalTotal + (discount > 0 ? -discount : discount);
                model.Items         = comboItemList;

                result.ComboInfo.Add(model);
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取商品详情
        /// </summary>
        /// <param name="id">系统编号</param>
        /// <param name="isGroupBuy">0--标识id为商品系统编号,1--标识id为团购活动系统编号</param>
        /// <returns></returns>
        public ProductDetailModel GetProductDetails(int id, int isGroupBuy)
        {
            int             productSysNo = 0;
            GroupBuyingInfo groupBuyInfo = null;

            if (isGroupBuy == 1)
            {
                groupBuyInfo = GroupBuyingFacade.GetGroupBuyingInfoBySysNo(id);
                if (groupBuyInfo == null)
                {
                    //提示团购活动找不到
                    throw new BusinessException("团购活动找不到啦,请选购其它商品,谢谢。");
                }
                productSysNo = groupBuyInfo.ProductSysNo;
            }
            else
            {
                productSysNo = id;
            }


            //商品基本信息
            ProductBasicInfo basicInfo = ProductFacade.GetProductBasicInfoBySysNo(productSysNo);

            //商品销售信息
            ProductSalesInfo salesInfo = ProductFacade.GetProductSalesInfoBySysNo(productSysNo);

            if (basicInfo == null || salesInfo == null)
            {
                //提示商品找不到
                throw new BusinessException("商品找不到啦,请选购其它商品,谢谢。");
            }
            //如果是不展示或下架
            if (basicInfo.ProductStatus == ProductStatus.NotShow || basicInfo.ProductStatus == ProductStatus.Abandon)
            {
                //提示商品状态已下架或已作废
                throw new BusinessException("商品已下架或已作废,请选购其它商品,谢谢。");
            }
            //商品组信息
            List <ProductPropertyView> propertyView = ProductFacade.GetProductPropetyView(productSysNo, basicInfo.ProductCommonInfoSysNo);

            //商品附件
            List <ProductItemInfo> attachmentList = ProductFacade.GetProductAttachmentList(productSysNo);

            //商品配件
            List <ProductAccessories> accessoriesList = ProductFacade.GetProductAccessoriesList(productSysNo);

            //商家信息
            StoreBasicInfo storeinfo = StoreFacade.QueryStoreBasicInfo(basicInfo.VendorSysno);

            //商品促销信息
            ProductPromotionInfo promotionInfo = Nesoft.ECWeb.Facade.Product.ProductFacade.GetProductPromotionInfo(productSysNo);

            //商品组图片信息
            List <ProductImage> productImages = ProductFacade.GetProductImages(basicInfo.ProductCommonInfoSysNo);

            //商品内容(商品详情,规格参数,售后服务,购买须知等)
            List <ProductContent> contentList = ProductFacade.GetProductContentList(basicInfo);

            ProductDetailModel result = new ProductDetailModel();

            //基本信息
            result.BasicInfo = TransformBasicInfo(basicInfo);
            //商品销售(价格,库存等)信息
            result.SalesInfo = TransformSalesInfo(basicInfo, salesInfo);

            //商品图片列表
            result.ImageList = TransformImageList(productImages);
            //商品描述信息
            result.DescInfo = TransformDescInfo(contentList);
            //if (result.DescInfo != null && basicInfo != null)
            //    result.DescInfo.Performance = basicInfo.Performance;


            //分组属性
            result.GroupPropertyInfo = TransformGroupProperty(propertyView);
            //附件信息
            result.AttachmentInfo = TransformAttachmentInfo(attachmentList);
            //配件信息
            result.AccessoryList = TransformAccessoryInfo(accessoriesList);

            //商家信息
            result.StoreBasicInfo = Transformstoreinfo(storeinfo);


            //限时抢购,赠品,套餐等促销信息
            result.PromoInfo = TransformPromoInfo(promotionInfo);

            //如果是团购商品进一步加载团购详情
            if (promotionInfo != null && promotionInfo.GroupBuySysNo > 0)
            {
                if (groupBuyInfo == null)
                {
                    groupBuyInfo = GroupBuyingFacade.GetGroupBuyingInfoBySysNo(promotionInfo.GroupBuySysNo);
                }
                if (groupBuyInfo == null)
                {
                    result.PromoInfo.GroupBuyingSysNo = 0;
                }
                else
                {
                    //团购图片特殊处理,用活动设置的图片
                    result.BasicInfo.DefaultImageUrl = groupBuyInfo.GroupBuyingPicUrl;
                    result.ImageList.Clear();
                    ProductImageModel groupBuyImage = new ProductImageModel();
                    groupBuyImage.ImageUrlBig  = groupBuyInfo.GroupBuyingPicUrl;
                    groupBuyImage.ImageUrlHuge = groupBuyInfo.GroupBuyingPicUrl;
                    result.ImageList.Add(groupBuyImage);
                    //海外团购商品,算税
                    if (groupBuyInfo.GroupBuyingTypeSysNo == 0)
                    {
                        result.SalesInfo.TariffPrice = salesInfo.CurrentPrice * salesInfo.TariffRate;

                        if (result.SalesInfo.TariffPrice <= ConstValue.TariffFreeLimit)
                        {
                            result.SalesInfo.FreeEntryTax = true;
                            result.SalesInfo.TotalPrice   = salesInfo.CurrentPrice;
                        }
                        else
                        {
                            result.SalesInfo.FreeEntryTax = false;
                            result.SalesInfo.TotalPrice   = salesInfo.CurrentPrice + result.SalesInfo.TariffPrice;
                        }
                        decimal snapShotTariffPrice = groupBuyInfo.SnapShotCurrentPrice * salesInfo.TariffRate;
                        if (snapShotTariffPrice <= ConstValue.TariffFreeLimit)
                        {
                            snapShotTariffPrice = 0;
                        }
                        result.SalesInfo.BasicPrice = groupBuyInfo.SnapShotCurrentPrice + groupBuyInfo.SnapShotCashRebate + snapShotTariffPrice;
                    }
                    else
                    {
                        result.SalesInfo.BasicPrice   = groupBuyInfo.SnapShotCurrentPrice + groupBuyInfo.SnapShotCashRebate;
                        result.SalesInfo.TotalPrice   = salesInfo.CurrentPrice;
                        result.SalesInfo.TariffPrice  = 0;
                        result.SalesInfo.FreeEntryTax = false;
                    }
                    groupBuyInfo.MarketPrice = result.SalesInfo.BasicPrice;

                    result.GroupBuyInfo = MapGroupBuyInfo(groupBuyInfo);
                }
            }
            if (promotionInfo != null && promotionInfo.Countdown != null)
            {
                //限时抢购重算市场价
                decimal snapShotTariffPrice = promotionInfo.Countdown.SnapShotCurrentPrice * salesInfo.TariffRate;
                if (snapShotTariffPrice <= ConstValue.TariffFreeLimit)
                {
                    snapShotTariffPrice = 0;
                }
                result.SalesInfo.BasicPrice = promotionInfo.Countdown.SnapShotCurrentPrice + promotionInfo.Countdown.SnapShotCashRebate + snapShotTariffPrice;
            }

            result.ActionInfo = MapActionInfo(result);

            return(result);
        }