public ActionResult ModifyProduct(string productCode, string sku) { try { if (string.IsNullOrEmpty(productCode)) { return(this.HandleError("无法找到该商品")); } SkuAttributeViewModel model = base.GetProductItem(productCode, sku); if (model == null) { return(this.HandleError("无法找到该商品")); } return(this.HandleSuccess("ok", model)); } catch (Exception ex) { return(HandleError(ex)); } }
public static SkuAttributeViewModel AsSkuAttributeViewModelD(this IList <ProductSkuEntity> entities, decimal exchangeRate, IList <PromotionEntity> promotions, string selectedSku = "", ItemViewSupporter dto = null) { if (entities == null || !entities.Any()) { return(null); } SkuAttributeViewModel model = new SkuAttributeViewModel(); #region 元数据组装 var template = entities.FirstOrDefault(); if (template == null) { return(null); } if (dto != null) { model.ProductName = dto.Name; var firstOrDefault = dto.Images.FirstOrDefault(); if (firstOrDefault != null) { model.ImgUrl = firstOrDefault.ImagePath.GetImageSmallUrl(); } model.InitPrice = promotions.FirstOrDefault(m => m.Sku == template.Sku).GetSalePrice(dto.MinPriceOriginal, exchangeRate).ToNumberRoundString(); //(GetDisplayPrice(promotions.FirstOrDefault(m => m.Sku == template.Sku), (template.MinPrice)) *exchangeRate).ToNumberRoundString(); //dto.MinPrice.ToNumberRoundString(); //dto.SkuDtos.ToList().Min(d=>d.Price) var skuDto = dto.SkuDtos.ToList().OrderBy(d => d.Price).FirstOrDefault(); model.TaxAmount = TotalTaxHelper.GetTotalTaxAmount(TotalTaxHelper.GetRealTaxType(skuDto.ReportStatus, skuDto.IsCrossBorderEBTax, promotions.FirstOrDefault(m => m.Sku == skuDto.Sku).GetSalePrice(skuDto.Price, null)), promotions.FirstOrDefault(m => m.Sku == skuDto.Sku).GetSalePrice(skuDto.Price, null), skuDto.CBEBTaxRate, skuDto.ConsumerTaxRate, skuDto.VATTaxRate, skuDto.PPATaxRate).ToNumberRound(); model.IsDutyOnSeller = dto.IsDutyOnSeller; model.RealTaxType = TotalTaxHelper.GetRealTaxType(skuDto.ReportStatus, skuDto.IsCrossBorderEBTax, promotions.FirstOrDefault(m => m.Sku == skuDto.Sku).GetSalePrice(skuDto.Price, exchangeRate)); } else { model.ProductName = template.Name; model.ImgUrl = ""; model.InitPrice = promotions.FirstOrDefault(m => m.Sku == template.Sku).GetSalePrice(template.MinPrice, exchangeRate).ToNumberRoundString(); //(GetDisplayPrice(promotions.FirstOrDefault(m => m.Sku == template.Sku), (template.MinPrice)) *exchangeRate).ToNumberRoundString(); //dto.MinPrice.ToNumberRoundString();//template.MinPrice.ToNumberRoundString(); } model.MainName = template.MainDicValue; model.MainCode = template.MainDicKey; model.SubName = template.SubDicValue; model.SubCode = template.SubDicKey; #endregion List <MainSkuAttribute> mainList = new List <MainSkuAttribute>(); List <SubSkuAttribute> subList = new List <SubSkuAttribute>(); //只有一个销售属性 if (string.IsNullOrEmpty(model.SubCode) && string.IsNullOrEmpty(model.SubName)) { mainList = entities.DistinctBy(d => new { d.MainKey, d.MainValue }).Select(n => new MainSkuAttribute() { MetaCode = n.MainDicKey, Id = n.MainKey, Name = n.MainValue, NetWeightUnit = n.NetWeightUnit, Sku = n.Sku, Flag = n.Qty == 0 ? -1 : (!string.IsNullOrEmpty(selectedSku) && selectedSku == n.Sku) == true ? 1 : 0, ForOrder = n.Qty, Price = promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate),//(GetDisplayPrice(promotions.FirstOrDefault(m => m.Sku == n.Sku), (n.Price)) * exchangeRate).ToNumberRound(), OriginalPrice = (n.Price * exchangeRate).ToNumberRound(), Promotion = GetPromotionItem(promotions.FirstOrDefault(m => m.Sku == n.Sku), exchangeRate), TaxAmount = TotalTaxHelper.GetTotalTaxAmount(TotalTaxHelper.GetRealTaxType(n.ReportStatus, n.IsCrossBorderEBTax, promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate)), promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate), n.CBEBTaxRate, n.ConsumerTaxRate, n.VATTaxRate, n.PPATaxRate).ToNumberRound(), IsDutyOnSeller = n.IsDutyOnSeller, RealTaxType = TotalTaxHelper.GetRealTaxType(n.ReportStatus, n.IsCrossBorderEBTax, promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate)), SubAttributes = new List <SubSkuAttribute>(0) }).OrderBy(n => n.Id.As(0)).ToList(); } else { var comparer1 = Equality <SubSkuAttribute> .CreateComparer(p => p.Id); subList = entities.DistinctBy(d => new { d.SubKey, d.SubValue }).Select(ss => new SubSkuAttribute() { Flag = -1, Id = ss.SubKey, MetaCode = ss.SubDicKey, Name = ss.SubValue, }).OrderBy(nn => nn.Id.As(0)).ToList(); mainList = entities.DistinctBy(d => new { d.MainKey, d.MainValue }).Select(n => new MainSkuAttribute() { MetaCode = n.MainDicKey, Id = n.MainKey, Name = n.MainValue, Flag = entities.Where(s => s.MainKey == n.MainKey && s.MainDicKey == n.MainDicKey).Any(nn => nn.Sku == selectedSku) ? 1 : 0, NetWeightUnit = n.NetWeightUnit, Sku = "", ForOrder = n.Qty, Price = promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate), OriginalPrice = (n.Price * exchangeRate).ToNumberRound(), Promotion = GetPromotionItem(promotions.FirstOrDefault(m => m.Sku == n.Sku), exchangeRate), TaxAmount = TotalTaxHelper.GetTotalTaxAmount(TotalTaxHelper.GetRealTaxType(n.ReportStatus, n.IsCrossBorderEBTax, promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate)), promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate), n.CBEBTaxRate, n.ConsumerTaxRate, n.VATTaxRate, n.PPATaxRate).ToNumberRound(), IsDutyOnSeller = n.IsDutyOnSeller, RealTaxType = TotalTaxHelper.GetRealTaxType(n.ReportStatus, n.IsCrossBorderEBTax, promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(n.Price, exchangeRate)), SubAttributes = entities.Where(s => s.MainKey == n.MainKey && s.MainDicKey == n.MainDicKey).Select(ss => new SubSkuAttribute() { Flag = ss.Qty == 0 ? -1 : (!string.IsNullOrEmpty(selectedSku) && selectedSku == ss.Sku) == true ? 1 : 0, ForOrder = ss.Qty, Id = ss.SubKey, MetaCode = ss.SubDicKey, Name = ss.SubValue, Price = promotions.FirstOrDefault(m => m.Sku == n.Sku).GetSalePrice(ss.Price, exchangeRate),//(GetDisplayPrice(promotions.FirstOrDefault(m => m.Sku == n.Sku), (ss.Price))).ToNumberRound(), OriginalPrice = (ss.Price * exchangeRate).ToNumberRound(), Promotion = GetPromotionItem(promotions.FirstOrDefault(m => m.Sku == n.Sku), exchangeRate), Sku = ss.Sku, TaxAmount = TotalTaxHelper.GetTotalTaxAmount(TotalTaxHelper.GetRealTaxType(ss.ReportStatus, ss.IsCrossBorderEBTax, promotions.FirstOrDefault(m => m.Sku == ss.Sku).GetSalePrice(ss.Price, exchangeRate)), promotions.FirstOrDefault(m => m.Sku == ss.Sku).GetSalePrice(ss.Price, exchangeRate), ss.CBEBTaxRate, ss.ConsumerTaxRate, ss.VATTaxRate, ss.PPATaxRate).ToNumberRound(), IsDutyOnSeller = ss.IsDutyOnSeller, RealTaxType = TotalTaxHelper.GetRealTaxType(ss.ReportStatus, ss.IsCrossBorderEBTax, promotions.FirstOrDefault(m => m.Sku == ss.Sku).GetSalePrice(ss.Price, exchangeRate)) }).ToList().Union <SubSkuAttribute>(subList, comparer1).OrderBy(nn => nn.Id.As(0)).ToList() }).ToList(); } model.MainAttributes = mainList; model.SubAttributes = subList; //如果为净重 增加单位 if (model.MainName != null && model.MainName != "") { if (model.MainName.Equals("净重") || model.MainName.Equals("淨重") || model.MainName.Equals("净含量") || model.MainName.Equals("凈含量")) { for (int i = 0; i < model.MainAttributes.Count; i++) { var mainAttribute = model.MainAttributes[i]; //当数值带有小数点,且末尾有0,则清小数点后空末尾处的0,然后再拼接单位 string number = mainAttribute.Name; if (string.IsNullOrEmpty(number)) { number = "0"; } double result = 0; if (Double.TryParse(number, out result)) { mainAttribute.Name = string.Format("{0}{1}", result, mainAttribute.NetWeightUnit); } else { mainAttribute.Name = "抱歉,数据有误!"; }; } } } return(model); }