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); }
/// <summary> /// 根据SKU AUTOID取门店SKU /// </summary> /// <param name="shopBranchId"></param> /// <param name="skuids"></param> /// <returns></returns> public static List <ShopBranchSkusInfo> GetSkusByIds(long shopBranchId, IEnumerable <string> skuids) { var list = _shopBranchService.GetSkusByIds(shopBranchId, skuids); return(list); }
public JsonResult GetBranchCartProducts(long shopBranchId) { var branchCartHelper = new BranchCartHelper(); long userId = 0; //会员折扣 decimal discount = 1.0M;//默认折扣为1(没有折扣) if (CurrentUser != null) { userId = CurrentUser.Id; discount = CurrentUser.MemberDiscount; } var cart = branchCartHelper.GetCart(userId, shopBranchId); //var shopBranch = _iShopBranchService.GetShopBranchById(shopBranchId); var shopBranch = ShopBranchApplication.GetShopBranchById(shopBranchId); Dictionary <long, long> buyedCounts = null; if (userId > 0) { buyedCounts = new Dictionary <long, long>(); buyedCounts = OrderApplication.GetProductBuyCount(userId, cart.Items.Select(x => x.ProductId)); } decimal prodPrice = 0.0M;//优惠价格 var shopBranchSkuList = _iShopBranchService.GetSkusByIds(shopBranchId, cart.Items.Select(x => x.SkuId).ToList()); var products = cart.Items.Select(item => { var product = _iProductService.GetProduct(item.ProductId); var shopbranchsku = shopBranchSkuList.FirstOrDefault(x => x.SkuId == item.SkuId); long stock = shopbranchsku == null ? 0 : shopbranchsku.Stock; if (stock > product.MaxBuyCount && product.MaxBuyCount != 0) { stock = product.MaxBuyCount; } if (product.MaxBuyCount > 0 && buyedCounts != null && buyedCounts.ContainsKey(item.ProductId)) { long buynum = buyedCounts[item.ProductId]; stock = stock - buynum; } var shop = _iShopService.GetShop(product.ShopId); //Entities.SKUInfo sku = null; string skuDetails = ""; if (null != shop) { var vshop = _iVShopService.GetVShopByShopId(shop.Id); //sku = _iProductService.GetSku(item.SkuId); DTO.SKU sku = ProductManagerApplication.GetSKU(item.SkuId); if (sku == null) { return(null); } prodPrice = sku.SalePrice; if (shop.IsSelf) {//官方自营店才计算会员折扣 prodPrice = sku.SalePrice * discount; } var typeInfo = TypeApplication.GetProductType(product.TypeId); skuDetails = ""; if (!string.IsNullOrWhiteSpace(sku.Size)) { skuDetails += sku.Size + " "; } if (!string.IsNullOrWhiteSpace(sku.Color)) { skuDetails += sku.Color + " "; } if (!string.IsNullOrWhiteSpace(sku.Version)) { skuDetails += sku.Version + " "; } return(new { bId = shopBranchId, cartItemId = item.Id, skuId = item.SkuId, id = product.Id, name = product.ProductName, price = prodPrice, count = item.Quantity, stock = shopbranchsku == null ? 0 : stock, //阶梯价商品在门店购物车自动下架 //status = product.IsOpenLadder ? 1 : (shopbranchsku == null ? 1 : (shopbranchsku.Status == ShopBranchSkuStatus.Normal) ? (item.Quantity > stock ? 2 : 0) : 1),//0:正常;1:冻结;2:库存不足 status = ProductManagerApplication.GetProductShowStatus(product, sku, 1, shopBranch, shopbranchsku),//0:正常;1:冻结;2:库存不足;3:已下架; skuDetails = skuDetails, AddTime = item.AddTime }); } else { return(null); } }).Where(d => d != null).OrderBy(s => s.status).ThenByDescending(o => o.AddTime); var cartModel = new { products = products, amount = products.Where(x => x.status == 0).Sum(item => item.price * item.count), totalCount = products.Where(x => x.status == 0).Sum(item => item.count), DeliveFee = shopBranch.DeliveFee, DeliveTotalFee = shopBranch.DeliveTotalFee, FreeMailFee = shopBranch.FreeMailFee, IsFreeMail = shopBranch.IsFreeMail, shopBranchStatus = (int)shopBranch.Status }; return(SuccessResult <dynamic>(data: cartModel)); }
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()); }