public ApiResult <StoreProductSku> GetCart([FromQuery] long loginUserId) { var result = Resolve <ICartService>().GetCart(loginUserId); if (result.Item1.Succeeded) { return(ApiResult.Success(result.Item2)); } var storeProductSku = new StoreProductSku(); return(ApiResult.Success(storeProductSku)); //return ApiResult.Failure<StoreProductSku>(result.Item1.ToString(), MessageCodes.ParameterValidationFailure); }
/// <summary> /// 根据店铺Id列表,和商品skuId列表,输出店铺商品显示对象 /// 用户购物车、客户下单 /// 店铺数量多的情况下,改方法需要优化,店铺数量少的情况下,将店铺数据插入到了缓存了,所有性能较快 /// Gets the store product sku. /// </summary> /// <param name="storeProductSkuDtos">The store product sku dtos.</param> public Tuple <ServiceResult, StoreProductSku> GetStoreProductSku(StoreProductSkuDtos storeProductSkuDtos) { var serviceResult = ServiceResult.Success; var storeItemList = GetStoreItemListFromCache(); var productSkuItemList = _productSkuRepository.GetProductSkuItemList(storeProductSkuDtos.ProductSkuIds); if (storeProductSkuDtos.IsGroupBuy) { //如果是拼团商品,从商品中读取,处理分润价、显示价、以及拼团价 var product = Resolve <IProductService>().GetSingle(r => r.Id == storeProductSkuDtos.ProductId); if (product == null) { return(null); } var productActivity = product.ProductActivityExtension.Activitys.First(r => r.Key == typeof(GroupBuyActivity).FullName); if (productActivity == null) { return(Tuple.Create(ServiceResult.Failure("当前购买商品不是拼团商品"), new StoreProductSku())); // 不是拼团商品 } var groupBuyActivity = productActivity.Value.ToObject <GroupBuyActivity>(); productSkuItemList.Foreach(r => { var groupBuySku = groupBuyActivity.SkuProducts.FirstOrDefault(e => e.Id == r.ProductSkuId); if (groupBuySku == null) { serviceResult = ServiceResult.Failure("当前Sku未设置拼团价格"); } else { r.DisplayPrice = groupBuySku.GroupBuyDisplayPrice; r.FenRunPrice = groupBuySku.FenRunPrice; r.MaxPayPrice = groupBuySku.MaxPayPrice; r.MinPayCash = groupBuySku.MinPayCash; r.PlatformPrice = r.Price; r.Price = groupBuySku.Price; } }); } if (storeItemList == null || storeItemList?.ToList()?.Count <= 0 || productSkuItemList == null || productSkuItemList?.ToList()?.Count <= 0) { return(null); } if (storeProductSkuDtos.IsApiImage) { productSkuItemList.ToList().ForEach(c => { c.ThumbnailUrl = Resolve <IApiService>().ApiImageUrl(c.ThumbnailUrl); }); } var storeProductSku = new StoreProductSku(); storeItemList = storeItemList.Where(r => storeProductSkuDtos.StoreIds.Contains(r.StoreId)).ToList(); foreach (var item in storeItemList) { item.ProductSkuItems = productSkuItemList.Where(r => r.StoreId == item.StoreId).ToList(); storeProductSku.StoreItems.Add(item); } storeItemList = storeItemList.Where(r => r.ProductSkuItems.Count > 0); // 店铺商品数大于0的店铺,如果商品不存在,或者下架则不显示 return(Tuple.Create(serviceResult, storeProductSku)); }