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 Mall.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 }); }
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); }
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); }
public JsonResult UpdateCartItem(string skuId, int count) { //TODO:FG 购物车改造 购物车数量变更 long userId = CurrentUser != null ? CurrentUser.Id : 0; var cartHelper = new CartHelper(); var skucart = cartHelper.GetCart(userId).Items.FirstOrDefault(d => d.SkuId == skuId); bool isadd = true; if (skucart != null) { if (skucart.Quantity > count) { isadd = false; } } Entities.SKUInfo skuinfo = OrderApplication.GetSkuByID(skuId); if (skuinfo.Stock < count && isadd) { return(Json(new { success = false, msg = "库存不足", stock = skuinfo.Stock })); } 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 })); } } 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 Mall.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(SuccessResult <dynamic>(data: new { saleprice = price.ToString("F2"), productid = product.Id, isOpenLadder = product.IsOpenLadder })); }