Ejemplo n.º 1
0
        public object GetUpdateCartItem(string skuId, int count, long shopBranchId)
        {
            CheckUserLogin();
            CheckSkuIdIsValid(skuId, shopBranchId);
            //判断库存
            var sku = ProductManagerApplication.GetSKU(skuId);

            if (sku == null)
            {
                throw new MallException("错误的SKU");
            }
            //if (count > sku.Stock)
            //{
            //    throw new MallException("库存不足");
            //}
            var shopBranch = ShopBranchApplication.GetShopBranchById(shopBranchId);

            if (shopBranch == null)
            {
                throw new MallException("错误的门店id");
            }
            var shopBranchSkuList = ShopBranchApplication.GetSkusByIds(shopBranchId, new List <string> {
                skuId
            });

            if (shopBranchSkuList == null || shopBranchSkuList.Count == 0)
            {
                throw new MallException("门店没有该商品");
            }
            if (shopBranchSkuList[0].Status == ShopBranchSkuStatus.InStock)
            {
                throw new MallException("此商品已下架");
            }
            var sbsku = shopBranchSkuList.FirstOrDefault();

            if (sbsku.Stock < count)
            {
                throw new MallException("门店库存不足");
            }
            long memberId = CurrentUser.Id;

            CartApplication.UpdateShopBranchCart(skuId, count, memberId, shopBranchId);
            return(Json(""));
        }
Ejemplo n.º 2
0
        public void UpdateCartItem(string skuId, int count, long memberId, long shopBranchId)
        {
            CheckSkuIdIsValid(skuId, shopBranchId);
            //判断库存
            var sku = ProductManagerApplication.GetSKU(skuId);

            if (sku == null)
            {
                throw new HimallException("错误的SKU");
            }
            //if (count > sku.Stock)
            //{
            //    throw new HimallException("库存不足");
            //}
            var shopBranch = ShopBranchApplication.GetShopBranchById(shopBranchId);

            if (shopBranch == null)
            {
                throw new HimallException("错误的门店id");
            }
            var shopBranchSkuList = ShopBranchApplication.GetSkusByIds(shopBranchId, new List <string> {
                skuId
            });

            if (shopBranchSkuList == null || shopBranchSkuList.Count == 0)
            {
                throw new HimallException("门店没有该商品");
            }
            if (shopBranchSkuList[0].Status == ShopBranchSkuStatus.InStock)
            {
                throw new HimallException("此商品已下架");
            }
            var sbsku = shopBranchSkuList.FirstOrDefault();

            if (sbsku.Stock < count)
            {
                throw new HimallException("门店库存不足");
            }

            if (memberId > 0)
            {
                CartApplication.UpdateShopBranchCart(skuId, count, memberId, shopBranchId);
            }
            else
            {
                string cartInfo = WebHelper.GetCookie(CookieKeysCollection.HIMALL_CART_BRANCH);
                if (!string.IsNullOrWhiteSpace(cartInfo))
                {
                    string[] cartItems   = cartInfo.Split(',');
                    string   newCartInfo = string.Empty;
                    bool     exist       = false;
                    foreach (string cartItem in cartItems)
                    {
                        var cartItemParts = cartItem.Split(':');
                        if (cartItemParts[0] == skuId && cartItemParts[2] == shopBranchId.ToString())
                        {
                            newCartInfo += "," + skuId + ":" + count + ":" + shopBranchId;
                            exist        = true;
                        }
                        else
                        {
                            newCartInfo += "," + cartItem;
                        }
                    }
                    if (!exist)
                    {
                        newCartInfo += "," + skuId + ":" + count + ":" + shopBranchId;
                    }

                    if (!string.IsNullOrWhiteSpace(newCartInfo))
                    {
                        newCartInfo = newCartInfo.Substring(1);
                    }
                    WebHelper.SetCookie(CookieKeysCollection.HIMALL_CART_BRANCH, newCartInfo);
                }
                else
                {
                    WebHelper.SetCookie(CookieKeysCollection.HIMALL_CART_BRANCH, string.Format("{0}:{1}:{2}", skuId, count, shopBranchId));
                }
            }
        }