private async Task <List <OrderItemImport> > GetOrderItem(string productSku, string orderNumber) { var orderItemList = new List <OrderItemImport>(); try { var itemArray = productSku.Split(','); if (!itemArray.Any()) { //_logger.Error($"订单号:{orderNumber}sku不存在,导入失败"); return(orderItemList); } for (int i = 0; i < itemArray.Length; i++) { var item = itemArray[i].Split('/'); var orderItem = new OrderItemImport(); var product = await _productManager.FindBySkuAsync(item[0]); if (product != null) { orderItem.IsCombin = false; orderItem.Product = product; orderItem.Quantity = Convert.ToInt32(item[1]); } else { var combin = await _productAttributeManager.FindCombinationBySkuAsync(item[0]); if (combin == null) { //_logger.Error($"订单号:{orderNumber}sku不存在,导入失败"); return(orderItemList); } else { await _productAttributeManager.ProductAttributeCombinationRepository .EnsurePropertyLoadedAsync(combin, c => c.Product); orderItem.IsCombin = true; orderItem.Product = combin.Product; orderItem.Combin = combin; orderItem.Quantity = Convert.ToInt32(item[1]); } } orderItemList.Add(orderItem); } } catch (Exception) { //_logger.Error($"订单号:{orderNumber}sku不存在,导入失败"); return(orderItemList); } return(orderItemList); }
/// <summary> /// Sku 是否已存在 /// </summary> /// <param name="input"></param> /// <param name="combinDto"></param> /// <returns></returns> private async Task IsCombinSkuExisted(CreateOrUpdateProductInput input, AttributeCombinationDto combinDto) { // sku重复性判断 var existedCombin = await _productAttributeManager.FindCombinationBySkuAsync(combinDto.Sku); if (existedCombin != null && combinDto.Sku == existedCombin.Sku) { // 重复sku是否在同一个商品中 if (existedCombin.ProductId != input.Id) { throw new UserFriendlyException($"Sku : {combinDto.Sku} 已存在"); } // 已存在的sku是否发生改变 var existedCombinDto = input.AttributeCombinations .FirstOrDefault(a => a.Id == existedCombin.Id); if (existedCombinDto.Sku == existedCombin.Sku) { throw new UserFriendlyException($"Sku : {combinDto.Sku} 已存在"); } } }