Exemplo n.º 1
0
        public JsonResult ClearBranchCartProducts(long shopBranchId)
        {
            BranchCartHelper helper   = new BranchCartHelper();
            long             memberId = (base.CurrentUser != null) ? base.CurrentUser.Id : 0L;
            ShoppingCartInfo cart     = helper.GetCart(memberId, shopBranchId);

            foreach (ShoppingCartItem item in cart.Items)
            {
                helper.RemoveFromCart(item.SkuId, memberId, shopBranchId);
            }
            return(base.Json(new { success = true }));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 清理门店购物车所有无效商品
        /// </summary>
        /// <param name="shopBranchId"></param>
        /// <returns></returns>
        public JsonResult ClearBranchCartInvalidProducts(long shopBranchId)
        {
            BranchCartHelper branchCartHelper = new BranchCartHelper();
            long             userId           = CurrentUser != null ? CurrentUser.Id : 0;
            var cart = branchCartHelper.GetCart(userId, shopBranchId);
            Dictionary <long, long> buyedCounts = null;

            if (userId > 0)
            {
                buyedCounts = new Dictionary <long, long>();
                buyedCounts = OrderApplication.GetProductBuyCount(userId, cart.Items.Select(x => x.ProductId));
            }
            foreach (var item in cart.Items)
            {
                var product       = _iProductService.GetProduct(item.ProductId);
                var shopbranchsku = _iShopBranchService.GetSkusByIds(shopBranchId, new List <string> {
                    item.SkuId
                }).FirstOrDefault();
                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;
                }

                if (shopbranchsku.Status != ShopBranchSkuStatus.Normal || item.Quantity > stock)
                {
                    branchCartHelper.RemoveFromCart(item.SkuId, userId, shopBranchId);
                }
            }
            return(Json(new { success = true }));
        }
Exemplo n.º 3
0
        public JsonResult GetCartProducts()
        {
            var memberId  = CurrentUser?.Id ?? 0;
            var cartItems = CartApplication.GetCartItems(memberId);
            var vshops    = VshopApplication.GetVShopsByShopIds(cartItems.Select(p => p.Shop.Id));
            var products  = cartItems.Select(item =>
            {
                var sku     = item.Sku;
                var product = item.Product;
                var shop    = item.Shop;
                var vshop   = vshops.FirstOrDefault(p => p.ShopId == shop.Id);

                var skuDetails = string.Empty;
                if (!string.IsNullOrWhiteSpace(sku.Size))
                {
                    skuDetails += sku.SizeAlias + ":" + sku.Size + "&nbsp;&nbsp;";
                }
                if (!string.IsNullOrWhiteSpace(sku.Color))
                {
                    skuDetails += sku.ColorAlias + ":" + sku.Color + "&nbsp;&nbsp;";
                }
                if (!string.IsNullOrWhiteSpace(sku.Version))
                {
                    skuDetails += sku.VersionAlias + ":" + sku.Version + "&nbsp;&nbsp;";
                }


                return(new
                {
                    cartItemId = item.ItemId,
                    skuId = sku.Id,
                    id = product.Id,
                    imgUrl = Himall.Core.HimallIO.GetProductSizeImage(product.RelativePath, 1, (int)ImageSize.Size_150),
                    name = product.ProductName,
                    price = sku.SalePrice,
                    count = item.Quantity,
                    shopId = shop.Id,
                    vshopId = vshop == null ? 0 : vshop.Id,
                    shopName = shop.ShopName,
                    shopLogo = vshop == null ? "" : vshop.Logo,
                    productstatus = item.IsLimit ? 0 : (sku.Stock <= 0 ? ProductInfo.ProductSaleStatus.InStock.GetHashCode() : product.SaleStatus.GetHashCode()),
                    status = item.IsLimit ? 1 : ProductManagerApplication.GetProductShowStatus(product, sku.Map <DTO.SKU>(), 1),   // 0:正常;1:已失效;2:库存不足;3:已下架;
                    Size = sku.Size,
                    Color = sku.Color,
                    Version = sku.Version,
                    ColorAlias = sku.ColorAlias,
                    SizeAlias = sku.SizeAlias,
                    VersionAlias = sku.VersionAlias,
                    skuDetails = skuDetails,
                    AddTime = item.AddTime,
                    minMath = ProductManagerApplication.GetProductLadderMinMath(product.Id)
                });
            }).OrderBy(p => p.status).ThenByDescending(o => o.AddTime).ToList();

            #region 门店购物车
            var  discount         = CurrentUser?.MemberDiscount ?? 1;
            var  branchCartHelper = new BranchCartHelper();
            long userId           = 0;
            if (CurrentUser != null)
            {
                userId = CurrentUser.Id;
            }
            var Branchcart     = branchCartHelper.GetCartNoCache(userId, 0);
            var shopBranchList = Branchcart.Items.Where(x => x.ShopBranchId > 0).Select(x => x.ShopBranchId).ToList();
            shopBranchList = shopBranchList.GroupBy(x => x).Select(x => x.First()).ToList();
            Dictionary <long, long> buyedCounts = null;
            if (userId > 0)
            {
                buyedCounts = new Dictionary <long, long>();
                buyedCounts = OrderApplication.GetProductBuyCount(userId, Branchcart.Items.Select(x => x.ProductId));
            }

            var branchProducts = PackageCartProducts(Branchcart, discount, true);
            var sbProducts     = branchProducts.OrderBy(p => p.status).ThenByDescending(item => item.AddTime);
            var shopBranchCart = sbProducts.GroupBy(item => item.shopBranchId);
            #endregion

            var cartModel = new { products = products, amount = products.Sum(item => item.price * item.count), totalCount = products.Sum(item => item.count), shopBranchCart = shopBranchCart };
            return(SuccessResult <dynamic>(data: cartModel));
        }
Exemplo n.º 4
0
        public JsonResult GetBranchCartProducts(long shopBranchId)
        {
            var  branchCartHelper = new BranchCartHelper();
            long userId           = 0;
            //会员折扣
            decimal discount = 1.0M;//默认折扣为1(没有折扣)

            if (CurrentUser != null)
            {
                userId   = CurrentUser.Id;
                discount = CurrentUser.MemberDiscount;
            }
            var cart = branchCartHelper.GetCart(userId, shopBranchId);
            //var shopBranch = _iShopBranchService.GetShopBranchById(shopBranchId);
            var shopBranch = ShopBranchApplication.GetShopBranchById(shopBranchId);
            Dictionary <long, long> buyedCounts = null;

            if (userId > 0)
            {
                buyedCounts = new Dictionary <long, long>();
                buyedCounts = OrderApplication.GetProductBuyCount(userId, cart.Items.Select(x => x.ProductId));
            }
            decimal prodPrice         = 0.0M;//优惠价格
            var     shopBranchSkuList = _iShopBranchService.GetSkusByIds(shopBranchId, cart.Items.Select(x => x.SkuId).ToList());

            var products = cart.Items.Select(item =>
            {
                var product       = _iProductService.GetProduct(item.ProductId);
                var shopbranchsku = shopBranchSkuList.FirstOrDefault(x => 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 shop = _iShopService.GetShop(product.ShopId);
                //Entities.SKUInfo sku = null;
                string skuDetails = "";
                if (null != shop)
                {
                    var vshop = _iVShopService.GetVShopByShopId(shop.Id);
                    //sku = _iProductService.GetSku(item.SkuId);
                    DTO.SKU sku = ProductManagerApplication.GetSKU(item.SkuId);
                    if (sku == null)
                    {
                        return(null);
                    }
                    prodPrice = sku.SalePrice;
                    if (shop.IsSelf)
                    {//官方自营店才计算会员折扣
                        prodPrice = sku.SalePrice * discount;
                    }

                    var typeInfo = TypeApplication.GetProductType(product.TypeId);
                    skuDetails   = "";
                    if (!string.IsNullOrWhiteSpace(sku.Size))
                    {
                        skuDetails += sku.Size + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Color))
                    {
                        skuDetails += sku.Color + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Version))
                    {
                        skuDetails += sku.Version + "&nbsp;&nbsp;";
                    }
                    return(new
                    {
                        bId = shopBranchId,
                        cartItemId = item.Id,
                        skuId = item.SkuId,
                        id = product.Id,
                        name = product.ProductName,
                        price = prodPrice,
                        count = item.Quantity,
                        stock = shopbranchsku == null ? 0 : stock,
                        //阶梯价商品在门店购物车自动下架
                        //status = product.IsOpenLadder ? 1 : (shopbranchsku == null ? 1 : (shopbranchsku.Status == ShopBranchSkuStatus.Normal) ? (item.Quantity > stock ? 2 : 0) : 1),//0:正常;1:冻结;2:库存不足
                        status = ProductManagerApplication.GetProductShowStatus(product, sku, 1, shopBranch, shopbranchsku),//0:正常;1:冻结;2:库存不足;3:已下架;
                        skuDetails = skuDetails,
                        AddTime = item.AddTime
                    });
                }
                else
                {
                    return(null);
                }
            }).Where(d => d != null).OrderBy(s => s.status).ThenByDescending(o => o.AddTime);

            var cartModel = new { products = products, amount = products.Where(x => x.status == 0).Sum(item => item.price * item.count), totalCount = products.Where(x => x.status == 0).Sum(item => item.count), DeliveFee = shopBranch.DeliveFee, DeliveTotalFee = shopBranch.DeliveTotalFee, FreeMailFee = shopBranch.FreeMailFee, IsFreeMail = shopBranch.IsFreeMail, shopBranchStatus = (int)shopBranch.Status };

            return(SuccessResult <dynamic>(data: cartModel));
        }
Exemplo n.º 5
0
        public JsonResult GetCartProducts()
        {
            ShoppingCartInfo cart           = new CartHelper().GetCart(base.CurrentUser.Id);
            IProductService  productService = this._iProductService;
            IShopService     shopService    = this._iShopService;
            IVShopService    vshopService   = this._iVShopService;
            decimal          discount       = 1.0M;

            if (base.CurrentUser != null)
            {
                discount = base.CurrentUser.MemberDiscount;
            }
            List <long>           list          = new List <long>();
            decimal               prodPrice     = 0.0M;
            List <FlashSalePrice> limitProducts = LimitTimeApplication.GetPriceByProducrIds((from e in cart.Items select e.ProductId).ToList <long>());
            var source = from s in cart.Items.Where <ShoppingCartItem>(delegate(ShoppingCartItem d)
            {
                long?nullable;
                return(!d.ShopBranchId.HasValue || (((nullable = d.ShopBranchId).GetValueOrDefault() == 0L) && nullable.HasValue));
            }).Select(delegate(ShoppingCartItem item)
            {
                Func <FlashSalePrice, bool> predicate = null;
                ProductInfo product = productService.GetProduct(item.ProductId);
                ShopInfo shop       = shopService.GetShop(product.ShopId, false);
                SKUInfo sku         = null;
                string str          = "";
                string str2         = "";
                string str3         = "";
                string str4         = "";
                if (null != shop)
                {
                    string str5;
                    VShopInfo vShopByShopId = vshopService.GetVShopByShopId(shop.Id);
                    sku = productService.GetSku(item.SkuId);
                    if (sku == null)
                    {
                        return(null);
                    }
                    if (predicate == null)
                    {
                        predicate = e => e.ProductId == item.ProductId;
                    }
                    FlashSalePrice price = limitProducts.FirstOrDefault <FlashSalePrice>(predicate);
                    prodPrice            = sku.SalePrice;
                    if (price != null)
                    {
                        prodPrice = price.MinPrice;
                    }
                    else if (shop.IsSelf)
                    {
                        prodPrice = sku.SalePrice * discount;
                    }
                    ProductType type = TypeApplication.GetType(product.TypeId);
                    str  = ((type == null) || string.IsNullOrEmpty(type.ColorAlias)) ? SpecificationType.Color.ToDescription() : type.ColorAlias;
                    str2 = ((type == null) || string.IsNullOrEmpty(type.SizeAlias)) ? SpecificationType.Size.ToDescription() : type.SizeAlias;
                    str3 = ((type == null) || string.IsNullOrEmpty(type.VersionAlias)) ? SpecificationType.Version.ToDescription() : type.VersionAlias;
                    str4 = "";
                    if (!string.IsNullOrWhiteSpace(sku.Size))
                    {
                        str5 = str4;
                        str4 = str5 + str2 + ":" + sku.Size + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Color))
                    {
                        str5 = str4;
                        str4 = str5 + str + ":" + sku.Color + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Version))
                    {
                        str5 = str4;
                        str4 = str5 + str3 + ":" + sku.Version + "&nbsp;&nbsp;";
                    }
                    return(new
                    {
                        cartItemId = item.Id,
                        skuId = item.SkuId,
                        id = product.Id,
                        imgUrl = HimallIO.GetProductSizeImage(product.RelativePath, 1, 150),
                        name = product.ProductName,
                        price = prodPrice,
                        count = item.Quantity,
                        shopId = shop.Id,
                        vshopId = (vShopByShopId == null) ? 0L : vShopByShopId.Id,
                        shopName = shop.ShopName,
                        shopLogo = (vShopByShopId == null) ? "" : vShopByShopId.Logo,
                        status = ((product.AuditStatus == ProductInfo.ProductAuditStatus.Audited) && (product.SaleStatus == ProductInfo.ProductSaleStatus.OnSale)) ? 1 : 0,
                        Size = sku.Size,
                        Color = sku.Color,
                        Version = sku.Version,
                        ColorAlias = str,
                        SizeAlias = str2,
                        VersionAlias = str3,
                        skuDetails = str4,
                        AddTime = item.AddTime
                    });
                }
                return(null);
            })
                         where s != null
                         orderby s.vshopId, s.AddTime descending
            select s;
            BranchCartHelper helper2  = new BranchCartHelper();
            long             memberId = 0L;

            if (base.CurrentUser != null)
            {
                memberId = base.CurrentUser.Id;
            }
            ShoppingCartInfo cartNoCache = helper2.GetCartNoCache(memberId, 0L);
            List <long>      list2       = (from x in
                                            (from x in cartNoCache.Items
                                             where x.ShopBranchId.HasValue
                                             select x.ShopBranchId.Value).ToList <long>()
                                            group x by x into x
                                            select x.First <long>()).ToList <long>();
            Dictionary <long, int> buyedCounts = null;

            if (memberId > 0L)
            {
                cart        = helper2.GetCart(memberId, 0L);
                buyedCounts = new Dictionary <long, int>();
                buyedCounts = OrderApplication.GetProductBuyCount(memberId, from x in cart.Items select x.ProductId);
            }
            List <object> list3 = new List <object>();

            using (List <long> .Enumerator enumerator = list2.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Func <ShoppingCartItem, bool> func = null;
                    long shopBranchId = enumerator.Current;
                    prodPrice = 0.0M;
                    List <ShopBranchSkusInfo> shopBranchSkuList = this._iShopBranchService.GetSkusByIds(shopBranchId, from x in cartNoCache.Items select x.SkuId);
                    if (func == null)
                    {
                        func = delegate(ShoppingCartItem x)
                        {
                            long?nullable1 = x.ShopBranchId;
                            long num       = shopBranchId;
                            return((nullable1.GetValueOrDefault() == num) && nullable1.HasValue);
                        };
                    }
                    var enumerable2 = from s in cartNoCache.Items.Where <ShoppingCartItem>(func).Select(delegate(ShoppingCartItem item)
                    {
                        Func <ShopBranchSkusInfo, bool> predicate = null;
                        if (shopBranchId == 0x63L)
                        {
                        }
                        ShopBranchInfo shopBranchById = this._iShopBranchService.GetShopBranchById(shopBranchId);
                        ProductInfo product           = this._iProductService.GetProduct(item.ProductId);
                        ShopInfo shop = this._iShopService.GetShop(product.ShopId, false);
                        SKUInfo sku   = null;
                        if ((shop != null) && (shopBranchById != null))
                        {
                            VShopInfo vShopByShopId = this._iVShopService.GetVShopByShopId(shop.Id);
                            sku = this._iProductService.GetSku(item.SkuId);
                            if (sku == null)
                            {
                                return(null);
                            }
                            prodPrice = sku.SalePrice;
                            if (shop.IsSelf)
                            {
                                prodPrice = sku.SalePrice * discount;
                            }
                            if (predicate == null)
                            {
                                predicate = x => x.SkuId == item.SkuId;
                            }
                            ShopBranchSkusInfo info6 = shopBranchSkuList.FirstOrDefault <ShopBranchSkusInfo>(predicate);
                            long maxBuyCount         = (info6 == null) ? ((long)0) : ((long)info6.Stock);
                            if ((maxBuyCount > product.MaxBuyCount) && (product.MaxBuyCount > 0))
                            {
                                maxBuyCount = product.MaxBuyCount;
                            }
                            if (((product.MaxBuyCount > 0) && (buyedCounts != null)) && buyedCounts.ContainsKey(item.ProductId))
                            {
                                int num3     = buyedCounts[item.ProductId];
                                maxBuyCount -= num3;
                            }
                            return(new { cartItemId = item.Id, skuId = item.SkuId, id = product.Id, imgUrl = HimallIO.GetProductSizeImage(product.RelativePath, 1, 150), name = product.ProductName, price = prodPrice, count = item.Quantity, status = (info6 == null) ? 1 : ((info6.Status == ShopBranchSkuStatus.Normal) ? ((item.Quantity > maxBuyCount) ? 2 : 0) : 1), AddTime = item.AddTime, shopBranchId = shopBranchById.Id, shopBranchName = shopBranchById.ShopBranchName });
                        }
                        return(null);
                    })
                                      where s != null
                                      orderby s.AddTime descending
                                      select s;
                    list3.Add(enumerable2);
                }
            }
            var data = new
            {
                products       = source,
                amount         = Enumerable.Sum(source, item => item.price * (Decimal)item.count),
                totalCount     = Enumerable.Sum(source, item => item.count),
                shopBranchCart = list3
            };

            return(base.Json(data));
        }
Exemplo n.º 6
0
        public JsonResult GetBranchCartProducts(long shopBranchId)
        {
            BranchCartHelper helper   = new BranchCartHelper();
            long             memberId = 0L;
            decimal          discount = 1.0M;

            if (base.CurrentUser != null)
            {
                memberId = base.CurrentUser.Id;
                discount = base.CurrentUser.MemberDiscount;
            }
            ShoppingCartInfo       cart           = helper.GetCart(memberId, shopBranchId);
            ShopBranchInfo         shopBranchById = this._iShopBranchService.GetShopBranchById(shopBranchId);
            Dictionary <long, int> buyedCounts    = null;

            if (memberId > 0L)
            {
                buyedCounts = new Dictionary <long, int>();
                buyedCounts = OrderApplication.GetProductBuyCount(memberId, from x in cart.Items select x.ProductId);
            }
            decimal prodPrice = 0.0M;
            List <ShopBranchSkusInfo> shopBranchSkuList = this._iShopBranchService.GetSkusByIds(shopBranchId, from x in cart.Items select x.SkuId);
            var enumerable = from s in cart.Items.Select(delegate(ShoppingCartItem item)
            {
                ProductInfo product      = this._iProductService.GetProduct(item.ProductId);
                ShopBranchSkusInfo info2 = shopBranchSkuList.FirstOrDefault <ShopBranchSkusInfo>(x => x.SkuId == item.SkuId);
                long maxBuyCount         = (info2 == null) ? ((long)0) : ((long)info2.Stock);
                if ((maxBuyCount > product.MaxBuyCount) && (product.MaxBuyCount != 0))
                {
                    maxBuyCount = product.MaxBuyCount;
                }
                if (((product.MaxBuyCount > 0) && (buyedCounts != null)) && buyedCounts.ContainsKey(item.ProductId))
                {
                    int num2     = buyedCounts[item.ProductId];
                    maxBuyCount -= num2;
                }
                ShopInfo shop = this._iShopService.GetShop(product.ShopId, false);
                SKUInfo sku   = null;
                string str    = "";
                if (null != shop)
                {
                    VShopInfo vShopByShopId = this._iVShopService.GetVShopByShopId(shop.Id);
                    sku = this._iProductService.GetSku(item.SkuId);
                    if (sku == null)
                    {
                        return(null);
                    }
                    prodPrice = sku.SalePrice;
                    if (shop.IsSelf)
                    {
                        prodPrice = sku.SalePrice * discount;
                    }
                    ProductType type = TypeApplication.GetType(product.TypeId);
                    str = "";
                    if (!string.IsNullOrWhiteSpace(sku.Size))
                    {
                        str = str + sku.Size + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Color))
                    {
                        str = str + sku.Color + "&nbsp;&nbsp;";
                    }
                    if (!string.IsNullOrWhiteSpace(sku.Version))
                    {
                        str = str + sku.Version + "&nbsp;&nbsp;";
                    }
                    return(new { bId = shopBranchId, cartItemId = item.Id, skuId = item.SkuId, id = product.Id, name = product.ProductName, price = prodPrice, count = item.Quantity, stock = (info2 == null) ? 0L : maxBuyCount, status = (info2 == null) ? 1 : ((info2.Status == ShopBranchSkuStatus.Normal) ? ((item.Quantity > maxBuyCount) ? 2 : 0) : 1), skuDetails = str, AddTime = item.AddTime });
                }
                return(null);
            })
                             where s != null
                             orderby s.status, s.AddTime descending
            select s;
            var data = new
            {
                products         = enumerable,
                amount           = Enumerable.Sum(Enumerable.Where(enumerable, x => x.status == 0), item => item.price * (Decimal)item.count),
                totalCount       = Enumerable.Sum(Enumerable.Where(enumerable, x => x.status == 0), item => item.count),
                DeliveFee        = shopBranchById.DeliveFee,
                DeliveTotalFee   = shopBranchById.DeliveTotalFee,
                FreeMailFee      = shopBranchById.FreeMailFee,
                shopBranchStatus = shopBranchById.Status
            };

            return(base.Json(data));
        }