Exemple #1
0
        public JsonResult UpdateCartItem(string skuId, int count)
        {
            long userId       = CurrentUser != null ? CurrentUser.Id : 0;
            var  orderService = _iOrderService;
            var  skuinfo      = orderService.GetSkuByID(skuId);
            var  product      = ProductManagerApplication.GetProduct(skuinfo.ProductId);

            if (product != null)
            {
                if (product.MaxBuyCount > 0 && count > product.MaxBuyCount && !product.IsOpenLadder)
                {
                    return(Json(new { success = false, msg = string.Format("每个ID限购{0}件", product.MaxBuyCount), stock = product.MaxBuyCount }));
                }
            }

            if (skuinfo.Stock < count)
            {
                return(Json(new { success = false, msg = "库存不足", stock = skuinfo.Stock }));
            }

            cartHelper.UpdateCartItem(skuId, count, userId);

            #region 购物车修改数量阶梯价变动--张宇枫
            //获取产品详情
            var price = 0m;
            if (product.IsOpenLadder)
            {
                var shop = ShopApplication.GetShop(product.ShopId);

                var groupCartByProduct = cartHelper.GetCart(userId).Items.Where(item => item.ShopBranchId == 0).Select(c =>
                {
                    var cItem   = new Himall.Entities.ShoppingCartItem();
                    var skuInfo = _iProductService.GetSku(c.SkuId);
                    if (skuInfo != null)
                    {
                        cItem = c;
                    }
                    return(cItem);
                }).GroupBy(i => i.ProductId).ToList();
                var quantity = groupCartByProduct.Where(i => i.Key == product.Id).ToList().Sum(cartitem => cartitem.Sum(i => i.Quantity));

                decimal discount = 1M;
                if (CurrentUser != null)
                {
                    discount = CurrentUser.MemberDiscount;
                }
                price = ProductManagerApplication.GetProductLadderPrice(product.Id, quantity);
                if (shop.IsSelf)
                {
                    price = price * discount;
                }
            }

            #endregion

            return(Json(new { success = true, saleprice = price.ToString("F2"), productid = product.Id, isOpenLadder = product.IsOpenLadder }));
        }
Exemple #2
0
        public object PostUpdateCartItem(CartUpdateCartItemModel value)
        {
            var productService = ServiceProvider.Instance <IProductService> .Create;

            CheckUserLogin();
            string Jsonstr      = value.jsonstr;
            var    datavalue    = Newtonsoft.Json.JsonConvert.DeserializeObject <UpdateCartSKusModel>(Jsonstr);
            var    cartService  = ServiceProvider.Instance <ICartService> .Create;
            var    ladderPrice  = 0m;
            long   productId    = 0;
            var    isOpenLadder = false;

            foreach (var sku in datavalue.skus)
            {
                Entities.SKUInfo skuinfo = OrderApplication.GetSkuByID(sku.skuId);
                if (skuinfo != null)
                {
                    var productInfo = ProductManagerApplication.GetProduct(skuinfo.ProductId);
                    if (productInfo != null)
                    {
                        if (productInfo.MaxBuyCount > 0 && sku.count > productInfo.MaxBuyCount && !productInfo.IsOpenLadder)
                        {
                            return(ErrorResult(string.Format("商品[{0}]限购{1}件", productInfo.ProductName, productInfo.MaxBuyCount), data: new { maxBuyCount = productInfo.MaxBuyCount }));
                            //throw new MallException(string.Format("每个ID限购{0}件", productInfo.MaxBuyCount));
                        }
                    }
                }
                cartService.UpdateCart(sku.skuId, sku.count, CurrentUser.Id);
                #region 阶梯价--张宇枫
                var skus    = CartApplication.GetCart(CurrentUser.Id);
                var skuItem = skus.Items.ToList().Find(i => i.SkuId == sku.skuId);
                productId = skuItem.ProductId;
                var product = ProductManagerApplication.GetProduct(productId);
                isOpenLadder = product.IsOpenLadder;
                if (isOpenLadder)
                {
                    var shop = ShopApplication.GetShop(product.ShopId);
                    var groupCartByProduct = skus.Items.Where(item => item.ShopBranchId == 0).Select(c =>
                    {
                        var cItem   = new Mall.Entities.ShoppingCartItem();
                        var skuInfo = productService.GetSku(c.SkuId);
                        if (skuInfo != null)
                        {
                            cItem = c;
                        }
                        return(cItem);
                    }).GroupBy(i => i.ProductId).ToList();
                    var quantity =
                        groupCartByProduct.Where(i => i.Key == productId)
                        .ToList()
                        .Sum(cartitem => cartitem.Sum(i => i.Quantity));
                    ladderPrice = ProductManagerApplication.GetProductLadderPrice(skuItem.ProductId, quantity);
                    if (shop.IsSelf)
                    {
                        ladderPrice = CurrentUser.MemberDiscount * ladderPrice;
                    }
                }
                #endregion
            }
            var result = new
            {
                success = true,
                //d.Url = "http://" + Url.Request.RequestUri.Host + "/m-IOS/Order/SubmiteByCart";
                Url          = Core.MallIO.GetRomoteImagePath("/m-IOS/Order/SubmiteByCart"),
                Price        = ladderPrice.ToString("F2"),
                ProductId    = productId,
                IsOpenLadder = isOpenLadder ? 1 : 0,
            };
            return(result);
        }
Exemple #3
0
        private List <CartProductModel> PackageCartProducts(Mall.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 Mall.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.MallIO.GetRomoteProductSizeImage(product.RelativePath, 1, (int)Mall.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.MallIO.GetRomoteImagePath(vshop.StrLogo),
                            Url            = Core.MallIO.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.MallIO.GetRomoteImagePath(shopbranch.ShopImages)
                        };
                        products.Add(_tmp);
                    }
                }
            }
            return(products);
        }
Exemple #4
0
        public object GetUpdateToCart(string openId, string SkuID, int Quantity, int GiftID = 0)
        {
            //验证用户
            CheckUserLogin();
            var  cartHelper  = new CartHelper();
            long userId      = CurrentUser != null ? CurrentUser.Id : 0;
            var  skus        = cartHelper.GetCart(userId);
            var  oldQuantity = GetCartProductQuantity(skus, skuId: SkuID);

            oldQuantity = oldQuantity + Quantity;

            long productId = 0;
            var  skuItem   = skus.Items.FirstOrDefault(i => i.SkuId == SkuID);

            if (null == skuItem)
            {
                var sku = ProductManagerApplication.GetSKU(SkuID);
                if (null == sku)
                {
                    return(Json(ErrorResult <dynamic>("错误的参数:SkuId")));
                }
                productId = sku.ProductId;
            }
            else
            {
                productId = skuItem.ProductId;
            }
            var ladderPrice = 0m;
            var product     = ProductManagerApplication.GetProduct(productId);

            if (product != null)
            {
                if (product.MaxBuyCount > 0 && oldQuantity > product.MaxBuyCount && !product.IsOpenLadder)
                {
                    cartHelper.UpdateCartItem(SkuID, product.MaxBuyCount, userId);
                    return(Json(ErrorResult <dynamic>(string.Format("每个ID限购{0}件", product.MaxBuyCount), new { stock = product.MaxBuyCount })));
                }
            }


            SKUInfo skuinfo = OrderApplication.GetSkuByID(SkuID);

            if (skuinfo.Stock < oldQuantity)
            {
                cartHelper.UpdateCartItem(SkuID, Convert.ToInt32(skuinfo.Stock), userId);
                return(Json(ErrorResult <dynamic>("库存不足", new { stock = skuinfo.Stock })));
            }

            cartHelper.UpdateCartItem(SkuID, oldQuantity, userId);
            //调用查询购物车数据

            #region 阶梯价--张宇枫
            var isOpenLadder = product.IsOpenLadder;
            if (isOpenLadder)
            {
                var shop = ShopApplication.GetShop(product.ShopId);
                var groupCartByProduct = cartHelper.GetCart(userId).Items.Where(item => item.ShopBranchId == 0).GroupBy(i => i.ProductId).ToList();
                //var groupCartByProduct = skus.Items.Where(item => item.ShopBranchId == 0).Select(c =>
                //{
                //    var cItem = new Mall.Entities.ShoppingCartItem();
                //    var skuInfo = ServiceProvider.Instance<IProductService>.Create.GetSku(c.SkuId);
                //    if (skuInfo != null)
                //        cItem = c;
                //    return cItem;
                //}).GroupBy(i => i.ProductId).ToList();

                var quantity =
                    groupCartByProduct.Where(i => i.Key == productId)
                    .ToList()
                    .Sum(cartitem => cartitem.Sum(i => i.Quantity));
                ladderPrice = ProductManagerApplication.GetProductLadderPrice(productId, quantity);
                if (shop.IsSelf)
                {
                    ladderPrice = CurrentUser.MemberDiscount * ladderPrice;
                }
            }
            #endregion
            return(Json(new { Price = ladderPrice.ToString("F2"), ProductId = productId, IsOpenLadder = isOpenLadder ? 1 : 0 }));
        }
Exemple #5
0
        public static List <CartItem> GetCartItems(long memberId)
        {
            var cart = GetShoppingCart(memberId);
            //会员折扣
            var discount = MemberApplication.GetMemberDiscount(memberId);

            var skuIds   = cart.Items.Select(p => p.SkuId).ToList();
            var skus     = GetService <IProductService>().GetSKUs(skuIds);
            var products = GetService <IProductService>().GetProducts(skus.Select(p => p.ProductId).ToList());
            var shops    = GetService <IShopService>().GetShops(products.Select(p => p.ShopId).ToList());
            var types    = TypeApplication.GetTypes();
            //限时购活动
            var limitProducts = LimitTimeApplication.GetPriceByProducrIds(products.Select(p => p.Id).ToList());
            //阶梯价商品
            var allLadders = GetService <IProductLadderPriceService>().GetLadderPricesByProductIds(products.Where(p => p.IsOpenLadder).Select(p => p.Id).ToList());

            var result = new List <CartItem>();

            foreach (var item in cart.Items)
            {
                var sku     = skus.FirstOrDefault(p => p.Id == item.SkuId);
                var product = products.FirstOrDefault(p => p.Id == item.ProductId);
                if (product == null)
                {
                    continue;                 //忽略异常数据
                }
                var shop = shops.FirstOrDefault(p => p.Id == product.ShopId);
                var type = types.FirstOrDefault(p => p.Id == product.TypeId);
                if (sku == null || shop == null)
                {
                    continue;                             //忽略异常数据
                }
                #region 价格覆盖
                var minMach = 0;
                //阶梯价格
                if (product.IsOpenLadder)
                {
                    var ladders  = allLadders.Where(p => p.ProductId == item.ProductId).ToList();
                    var quantity = cart.Items.Where(c => c.ProductId == item.ProductId && c.ShopBranchId == 0).ToList().Sum(c => c.Quantity);
                    sku.SalePrice = ProductManagerApplication.GetProductLadderPrice(ladders, quantity);
                    minMach       = ladders.Min(p => p.MinBath);
                }

                var price = -1M;//其他价格
                //限时购价格
                var limit = limitProducts.FirstOrDefault(p => p.ProductId == item.ProductId);
                if (limit != null)
                {
                    price = limit.MinPrice;
                }
                //会员折扣
                if (price < 0 && shop.IsSelf)
                {
                    price = sku.SalePrice * discount;
                }

                if (price >= 0)
                {
                    sku.SalePrice = price;
                }
                #endregion

                //填充SKU别名
                ProductManagerApplication.FillSkuAlias(sku, product, type);
                //是否限时购
                var isLimit = limit != null;



                result.Add(new CartItem
                {
                    ItemId     = item.Id,
                    Quantity   = item.Quantity,
                    AddTime    = item.AddTime,
                    Product    = product,
                    Shop       = shop,
                    Sku        = sku,
                    ShowStatus = isLimit ? 1 : ProductManagerApplication.GetProductShowStatus(product, sku.Map <DTO.SKU>(), 1),
                    LimitId    = isLimit?limit.Id:0, //参与限时购活动ID
                    IsLimit    = isLimit,            //是否参加限时购
                    MinMach    = minMach,
                });
            }
            return(result);
        }