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); }
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 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(SuccessResult <dynamic>(data: new { saleprice = price.ToString("F2"), productid = product.Id, isOpenLadder = product.IsOpenLadder })); }