Exemplo n.º 1
0
        private int GetCartProductQuantity(Himall.Entities.ShoppingCartInfo cartInfo, long productId = 0, string skuId = "")
        {
            int cartQuantity = 0;

            if (cartInfo == null)
            {
                return(0);
            }
            else
            {
                if (productId > 0)
                {
                    cartQuantity += cartInfo.Items.Where(p => p.ProductId == productId).Sum(d => d.Quantity);
                }
                else
                {
                    cartQuantity += cartInfo.Items.Where(p => p.SkuId == skuId).Sum(d => d.Quantity);
                }
            }
            return(cartQuantity);
        }
Exemplo n.º 2
0
        private List <CartProductModel> PackageCartProducts(Himall.Entities.ShoppingCartInfo cart, decimal prodPrice, decimal discount, IProductService productService, IShopService shopService, IShopBranchService shopBranchService, IVShopService vshopService, ITypeService typeservice, bool isBranch = false)
        {
            List <CartProductModel> products = new List <CartProductModel>();
            var limitProducts = LimitTimeApplication.GetPriceByProducrIds(cart.Items.Select(e => e.ProductId).ToList());//限时购价格
            var groupCart     = cart.Items.Where(item => item.ShopBranchId == 0).Select(c =>
            {
                var cItem   = new Himall.Entities.ShoppingCartItem();
                var skuInfo = productService.GetSku(c.SkuId);
                if (skuInfo != null)
                {
                    cItem = c;
                }
                return(cItem);
            }).GroupBy(i => i.ProductId).ToList();

            foreach (var item in cart.Items)
            {
                var                        product       = ProductManagerApplication.GetProduct(item.ProductId);
                var                        shop          = shopService.GetShop(product.ShopId);
                DTO.ShopBranch             shopbranch    = null;
                Entities.ShopBranchSkuInfo shopbranchsku = null;
                if (item.ShopBranchId > 0)
                {
                    shopbranch    = ShopBranchApplication.GetShopBranchById(item.ShopBranchId);
                    shopbranchsku = shopBranchService.GetSkusByIds(item.ShopBranchId, new List <string> {
                        item.SkuId
                    }).FirstOrDefault();
                }

                if (null != shop)
                {
                    var vshop = vshopService.GetVShopByShopId(shop.Id);
                    var sku   = ProductManagerApplication.GetSKU(item.SkuId);
                    if (sku == null)
                    {
                        continue;
                    }
                    //处理限时购、会员折扣价格
                    var prod = limitProducts.FirstOrDefault(e => e.ProductId == item.ProductId);
                    prodPrice = sku.SalePrice;
                    if (prod != null && !isBranch)
                    {
                        prodPrice = prod.MinPrice;
                    }
                    else
                    {
                        if (shop.IsSelf)
                        {//官方自营店才计算会员折扣
                            prodPrice = sku.SalePrice * discount;
                        }
                    }
                    #region 阶梯价--张宇枫
                    //阶梯价
                    if (product.IsOpenLadder)
                    {
                        var quantity = groupCart.Where(i => i.Key == item.ProductId).ToList().Sum(cartitem => cartitem.Sum(i => i.Quantity));
                        prodPrice = ProductManagerApplication.GetProductLadderPrice(item.ProductId, quantity);
                        if (shop.IsSelf)
                        {
                            prodPrice = prodPrice * discount;
                        }
                    }
                    #endregion
                    Entities.TypeInfo typeInfo     = typeservice.GetType(product.TypeId);
                    string            colorAlias   = (typeInfo == null || string.IsNullOrEmpty(typeInfo.ColorAlias)) ? SpecificationType.Color.ToDescription() : typeInfo.ColorAlias;
                    string            sizeAlias    = (typeInfo == null || string.IsNullOrEmpty(typeInfo.SizeAlias)) ? SpecificationType.Size.ToDescription() : typeInfo.SizeAlias;
                    string            versionAlias = (typeInfo == null || string.IsNullOrEmpty(typeInfo.VersionAlias)) ? SpecificationType.Version.ToDescription() : typeInfo.VersionAlias;
                    if (product != null)
                    {
                        colorAlias   = !string.IsNullOrWhiteSpace(product.ColorAlias) ? product.ColorAlias : colorAlias;
                        sizeAlias    = !string.IsNullOrWhiteSpace(product.SizeAlias) ? product.SizeAlias : sizeAlias;
                        versionAlias = !string.IsNullOrWhiteSpace(product.VersionAlias) ? product.VersionAlias : versionAlias;
                    }
                    if (sku != null)
                    {
                        #region 正在参加限时抢购商品在购物车失效 TDO:ZYF
                        var isLimit = false;
                        //门店商品,在参加限时购,也可以正常购买
                        var limit = LimitTimeApplication.GetLimitTimeMarketItemByProductId(item.ProductId);
                        if (limit != null && !isBranch)
                        {
                            isLimit = limit.Status == Entities.FlashSaleInfo.FlashSaleStatus.Ongoing;
                        }
                        #endregion
                        var _tmp = new CartProductModel
                        {
                            CartItemId     = item.Id.ToString(),
                            SkuId          = item.SkuId,
                            Id             = product.Id.ToString(),
                            ImgUrl         = Core.HimallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Himall.CommonModel.ImageSize.Size_150),
                            Name           = product.ProductName,
                            Price          = prodPrice.ToString("F2"),
                            Count          = item.Quantity.ToString(),
                            ShopId         = shop.Id.ToString(),
                            Size           = sku.Size,
                            Color          = sku.Color,
                            Version        = sku.Version,
                            VShopId        = vshop == null ? "0" : vshop.Id.ToString(),
                            ShopName       = shop.ShopName,
                            ShopLogo       = vshop == null ? "" : Core.HimallIO.GetRomoteImagePath(vshop.StrLogo),
                            Url            = Core.HimallIO.GetRomoteImagePath("/m-IOS/product/detail/") + item.ProductId,
                            ProductStatus  = isLimit ? 0 : (sku.Stock <= 0 ? ProductInfo.ProductSaleStatus.InStock.GetHashCode() : product.SaleStatus.GetHashCode()),
                            Status         = isLimit ? 1 : ProductManagerApplication.GetProductShowStatus(product, sku, shopbranch == null ? 1 : item.Quantity, shopbranch, shopbranchsku),// 0:正常;1:已失效;2:库存不足;3:已下架;
                            ColorAlias     = colorAlias,
                            SizeAlias      = sizeAlias,
                            VersionAlias   = versionAlias,
                            AddTime        = item.AddTime,
                            ShopBranchId   = item.ShopBranchId,
                            ShopBranchName = null == shopbranch ? "" : shopbranch.ShopBranchName,
                            ShopBranchLogo = null == shopbranch ? "" : Core.HimallIO.GetRomoteImagePath(shopbranch.ShopImages)
                        };
                        products.Add(_tmp);
                    }
                }
            }
            return(products);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 首页商品信息
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public JsonResult <Result <List <dynamic> > > GetIndexProductData(string openId = "", int pageIndex = 1, int pageSize = 10)
        {
            var homeProducts = ServiceProvider.Instance <IWXSmallProgramService> .Create.GetWXSmallHomeProducts(pageIndex, pageSize);

            decimal discount    = 1M;
            long    SelfShopId  = 0;
            var     CartInfo    = new Himall.Entities.ShoppingCartInfo();
            var     ids         = homeProducts.Models.Select(p => p.Id).ToList();
            var     productList = new List <dynamic>();
            var     cartitems   = new List <Himall.Entities.ShoppingCartItem>();
            long    userId      = 0;

            if (CurrentUser != null)
            {
                userId   = CurrentUser.Id;
                discount = CurrentUser.MemberDiscount;
                var shopInfo = ShopApplication.GetSelfShop();
                SelfShopId = shopInfo.Id;
                CartInfo   = ServiceProvider.Instance <ICartService> .Create.GetCart(CurrentUser.Id);

                cartitems = CartApplication.GetCartQuantityByIds(CurrentUser.Id, ids);
            }

            foreach (var item in homeProducts.Models)
            {
                long activeId   = 0;
                int  activetype = 0;
                item.ImagePath = Core.HimallIO.GetRomoteProductSizeImage(Core.HimallIO.GetImagePath(item.ImagePath), 1, (int)Himall.CommonModel.ImageSize.Size_350);
                if (item.ShopId == SelfShopId)
                {
                    item.MinSalePrice = item.MinSalePrice * discount;
                }
                var limitBuy = ServiceProvider.Instance <ILimitTimeBuyService> .Create.GetLimitTimeMarketItemByProductId(item.Id);

                if (limitBuy != null)
                {
                    item.MinSalePrice = limitBuy.MinPrice;
                    activeId          = limitBuy.Id;
                    activetype        = 1;
                }
                int quantity = 0;
                quantity = cartitems.Where(d => d.ProductId == item.Id).Sum(d => d.Quantity);

                long stock = 0;

                var productInfo = ServiceProvider.Instance <IProductService> .Create.GetProduct(item.Id);

                if (productInfo != null)
                {
                    var skus = ProductManagerApplication.GetSKUs(productInfo.Id);
                    stock = skus.Sum(x => x.Stock);
                    if (productInfo.MaxBuyCount > 0)
                    {
                        stock = productInfo.MaxBuyCount;
                    }
                }
                if (productInfo.AuditStatus == Entities.ProductInfo.ProductAuditStatus.Audited)
                {
                    var ChoiceProducts = new
                    {
                        ProductId       = item.Id,
                        ProductName     = item.ProductName,
                        SalePrice       = item.MinSalePrice.ToString("0.##"),
                        ThumbnailUrl160 = item.ImagePath,
                        MarketPrice     = item.MarketPrice.ToString("0.##"),
                        CartQuantity    = quantity,
                        HasSKU          = item.HasSKU,
                        SkuId           = GetSkuIdByProductId(item.Id),
                        ActiveId        = activeId,
                        ActiveType      = activetype,//获取该商品是否参与活动
                        Stock           = stock,
                        IsVirtual       = item.ProductType == 1
                    };
                    productList.Add(ChoiceProducts);
                }
            }
            return(JsonResult(productList));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 取用户在门店的购物车数量
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="branchIds"></param>
        /// <returns></returns>
        public static Dictionary <long, int> GetShopBranchCartItemCount(long userId, List <long> branchIds)
        {
            Dictionary <long, int> result = new Dictionary <long, int>();

            if (userId == 0)
            {
                return(result);
            }
            Himall.Entities.ShoppingCartInfo memberCartInfo = new Himall.Entities.ShoppingCartInfo();
            List <DTO.Product.Product>       onSaleProducts = new List <DTO.Product.Product>();

            if (userId > 0)
            {//如果已登陆取购物车数据
                memberCartInfo = CartApplication.GetShopBranchCart(userId);
                if (memberCartInfo != null)
                {
                    onSaleProducts = ProductManagerApplication.GetAllStatusProductByIds(memberCartInfo.Items.Select(e => e.ProductId)).ToList();
                }
            }

            Dictionary <long, long> buyedCounts = null;

            if (userId > 0)
            {
                buyedCounts = new Dictionary <long, long>();
                buyedCounts = OrderApplication.GetProductBuyCount(userId, memberCartInfo.Items.Select(x => x.ProductId));
            }
            var shopBranchSkuList = Service.GetSkusByBranchIds(branchIds, skuids: memberCartInfo.Items.Select(s => s.SkuId).ToList());

            foreach (var id in branchIds)
            {
                //var cartQuantity = memberCartInfo.Items.Where(c => c.ShopBranchId.HasValue && c.ShopBranchId.Value == query.shopBranchId).Sum(c => c.Quantity);
                //过滤购物车 无效商品
                var cartQuantity = memberCartInfo.Items.Where(c => c.ShopBranchId == id).Select(item =>
                {
                    var product       = onSaleProducts.FirstOrDefault(p => p.Id == item.ProductId);
                    var shopbranchsku = shopBranchSkuList.FirstOrDefault(x => x.ShopBranchId == id && x.SkuId == item.SkuId);
                    long stock        = shopbranchsku == null ? 0 : shopbranchsku.Stock;

                    if (stock > product.MaxBuyCount && product.MaxBuyCount != 0)
                    {
                        stock = product.MaxBuyCount;
                    }
                    if (product.MaxBuyCount > 0 && buyedCounts != null && buyedCounts.ContainsKey(item.ProductId))
                    {
                        long buynum = buyedCounts[item.ProductId];
                        stock       = stock - buynum;
                    }
                    var status = product.IsOpenLadder ? 1 : (shopbranchsku == null ? 1 : (shopbranchsku.Status == ShopBranchSkuStatus.Normal) ? (item.Quantity > stock ? 2 : 0) : 1);//0:正常;1:冻结;2:库存不足
                    if (status == 0)
                    {
                        return(item.Quantity);
                    }
                    else
                    {
                        return(0);
                    }
                }).Sum(count => count);
                if (cartQuantity > 0)
                {
                    result.Add(id, cartQuantity);
                }
            }
            return(result);
        }