/// <summary>
        /// 获取门店
        /// </summary>
        /// <returns></returns>
        public static ShopBranch GetShopBranchById(long id)
        {
            var branchInfo = _shopBranchService.GetShopBranchById(id);

            if (branchInfo == null)
            {
                return(null);
            }
            var branchManagers = _shopBranchService.GetShopBranchManagers(id);
            var shopBranch     = AutoMapper.Mapper.Map <ShopBranchInfo, ShopBranch>(branchInfo);

            //补充地址中文名称
            //shopBranch.AddressFullName = RegionApplication.GetFullName(shopBranch.AddressId, CommonConst.ADDRESS_PATH_SPLIT);
            shopBranch.AddressFullName = RenderAddress(shopBranch.AddressPath, shopBranch.AddressDetail, 0);
            if (branchManagers != null && branchManagers.Count() > 0)
            {//补充管理员名称
                shopBranch.UserName = branchManagers.FirstOrDefault().UserName;
            }
            return(shopBranch);
        }
Exemple #2
0
        public object GetUpdateCartItem(string skuId, int count, long shopBranchId)
        {
            CheckSkuIdIsValid(skuId, shopBranchId);
            //判断库存
            var sku = _iProductService.GetSku(skuId);

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

            if (shopBranch == null)
            {
                throw new MallException("错误的门店id");
            }
            var shopBranchSkuList = _iShopBranchService.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 = 0;

            if (CurrentUser != null)
            {
                memberId = CurrentUser.Id;
            }
            if (memberId > 0)
            {
                _iBranchCartService.UpdateCart(skuId, count, memberId, shopBranchId);
            }
            else
            {
                string cartInfo = WebHelper.GetCookie(CookieKeysCollection.Mall_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.Mall_CART_BRANCH, newCartInfo);
                }
                else
                {
                    WebHelper.SetCookie(CookieKeysCollection.Mall_CART_BRANCH, string.Format("{0}:{1}:{2}", skuId, count, shopBranchId));
                }
            }
            return(SuccessResult());
        }