示例#1
0
        private Dictionary <string, List <CharacteristicItem> > GetCharacterisDic(TaeItemDetailGetResponse productDetail)
        {
            var characteristics = new Dictionary <string, List <CharacteristicItem> >();

            if (productDetail.Data.SkuInfo != null)
            {
                productDetail.Data.SkuInfo.SkuProps.ForEach(s =>
                {
                    var list = new List <CharacteristicItem>();
                    s.Values.ForEach(pv =>
                    {
                        //定义并获取商品的属性信息
                        var productPropertiy         = new CharacteristicItem();
                        productPropertiy.Propkey     = s.PropId + ":" + pv.ValueId;
                        productPropertiy.ActualValue = s.PropName + ":" + pv.Name;
                        productPropertiy.Remark      = pv.Name;
                        productPropertiy.ImageUrl    = pv.ImgUrl;
                        productPropertiy.IsSelected  = false; // 是否当前项是被选中
                        list.Add(productPropertiy);
                    });
                    characteristics.Add(s.PropName, list);
                });
            }
            return(characteristics);
        }
示例#2
0
 private void UpdateUnitPrice(List <SkuItem> skus, TaeItemDetailGetResponse productDetail)
 {
     if (productDetail.Data.SkuInfo != null)
     {
         if (skus.Count > 0)
         {
             var sortSkus = skus.OrderBy(s => s.Price).ToList();
             var minPrice = sortSkus[0].Price;
             if (minPrice < this.UnitPrice.Value)
             {
                 this.UnitPrice = minPrice;
             }
         }
     }
     else
     {
         var promotionPrice = productDetail.Data.PriceInfo.ItemPrice.PromotionPrice;
         if (promotionPrice != null)
         {
             this.UnitPrice = GetPrice(promotionPrice);
         }
         else
         {
             var price = productDetail.Data.PriceInfo.ItemPrice.Price;
             this.UnitPrice = GetPrice(price);
         }
     }
 }
示例#3
0
        private List <string> GetAltPropertyNames(TaeItemDetailGetResponse productDetail, Dictionary <string, string> keysEn, Dictionary <string, string> valuesEn)
        {
            var properyNames = new List <string>();

            properyNames = productDetail.Data.ItemInfo.ItemProps.Select(p =>
            {
                string key = null, value = null;
                if (!string.IsNullOrEmpty(p.Name))
                {
                    if (!keysEn.TryGetValue(p.Name, out key))
                    {
                        key = p.Name;
                    }
                }
                if (!string.IsNullOrEmpty(p.Value))
                {
                    if (!valuesEn.TryGetValue(p.Value, out value))
                    {
                        value = p.Value;
                    }
                }
                return(key + ":" + value);
            }).ToList();
            return(properyNames);
        }
示例#4
0
        private List <ItemImg> GetItemImages(TaeItemDetailGetResponse productDetail)
        {
            var itemImgs = new List <ItemImg>();

            for (int pi = 0; pi < productDetail.Data.ItemInfo.Pics.Count; pi++)//处理图片
            {
                var proImage = new ItemImg();
                proImage.Id       = pi;
                proImage.Position = pi;
                proImage.Url      = productDetail.Data.ItemInfo.Pics[pi];
                itemImgs.Add(proImage);
            }
            return(itemImgs);
        }
示例#5
0
        private Dictionary <string, string> GetProductProperties(TaeItemDetailGetResponse productDetail)
        {
            var dic = new Dictionary <string, string>();

            try
            {
                if (productDetail.Data != null && productDetail.Data.ItemInfo != null &&
                    productDetail.Data.ItemInfo.ItemProps != null)
                {
                    dic = productDetail.Data.ItemInfo.ItemProps.ToDictionary(a => a.Name,
                                                                             b => b.Value);
                }
            }
            catch { }
            return(dic);
        }
示例#6
0
        public OutlineProduct(string numIid, long cid, TaeItemDetailGetResponse productDetail, bool needTranslate)
        {
            this.ProductId         = long.Parse(numIid);
            this.TbProductId       = numIid;
            this.OriginalUnitPrice = 0;
            this.OriginCode        = "CN";
            this.ProductName       = productDetail.Data.ItemInfo.Title;
            //todo confirm shippingfee
            this.ShippingFee = GetShippingFee(productDetail.Data.DeliveryInfo);
            SetIsShippingFee();
            this.ProductUrl = GetProductUrl(productDetail.Data.SellerInfo.SellerType, numIid);

            this.Cid          = cid;
            this.ShopName     = productDetail.Data.SellerInfo.ShopName;
            this.VendorName   = productDetail.Data.SellerInfo.SellerNick;
            this.ProductImage = productDetail.Data.ItemInfo.Pics[0];
            if (productDetail.Data.DeliveryInfo != null)
            {
                this.Location         = GetStateFromLocation(productDetail.Data.DeliveryInfo.Location);
                this.AroundwWarehouse = productDetail.Data.DeliveryInfo.Location;
            }

            this.Site        = "taobao";
            this.PriceSymbol = "¥";
            //todo change to our warehouse

            int stock = 0;

            if (int.TryParse(productDetail.Data.StockInfo.ItemQuantity, out stock))
            {
                this.ProductStock = stock;
            }

            this.ProductProperties = GetProductProperties(productDetail);
            this.Description       = GetDescription(productDetail);
            this.ItemImgs          = GetItemImages(productDetail);

            ProcessProduct(productDetail, needTranslate);

            if (this.ProductUrl.Contains("taobao.net"))
            {
                this.ProductUrl = this.ProductUrl.Replace("taobao.net", "taobao.com");
            }
            //todo UpdateProductDetailWithPromotion
            //for reset price
        }
示例#7
0
        private string GetDescription(TaeItemDetailGetResponse productDetail)
        {
            StringBuilder content = new StringBuilder("<p>");

            if (productDetail != null && productDetail.Data != null && productDetail.Data.MobileDescInfo != null &&
                productDetail.Data.MobileDescInfo.DescList != null)
            {
                productDetail.Data.MobileDescInfo.DescList.ForEach(img =>
                {
                    if ("img".Equals(img.Label, StringComparison.OrdinalIgnoreCase))
                    {
                        content.Append("<img align=\"absmiddle\" src=\"").Append(img.Content).Append("\">");
                    }
                });
            }
            content.Append("</p>");

            return(content.ToString());
        }
示例#8
0
        public void ProcessProduct(TaeItemDetailGetResponse productDetail, bool needTranslate = false)
        {
            this.OriginalUnitPrice = GetPrice(productDetail.Data.PriceInfo.ItemPrice.Price);
            this.UnitPrice         = this.OriginalUnitPrice;
            this.Characteristics   = GetCharacterisDic(productDetail);
            this.Skus = GetSkuItems(productDetail);

            UpdateUnitPrice(this.Skus, productDetail);

            this.PropertyNames = new List <string>();
            if (needTranslate)
            {
                List <string> keys   = new List <string>();
                List <string> values = new List <string>();
                foreach (var character in this.Characteristics)
                {
                    keys.Add(character.Key);
                    foreach (var vd in character.Value)
                    {
                        values.Add(vd.ActualValue);
                        values.Add(vd.Remark);
                    }
                }
                productDetail.Data.ItemInfo.ItemProps.ForEach(p =>
                {
                    keys.Add(p.Name);
                    values.Add(p.Value);
                });
                var keysEn   = Translate.TranslationToEn(keys, true);
                var valuesEn = Translate.TranslationToEn(values, false);

                this.AltCharacteristics = GetAltCharacteristics(productDetail, keysEn, valuesEn);
                this.AltPropertyNames   = GetAltPropertyNames(productDetail, keysEn, valuesEn);
            }
            else
            {
                this.PropertyNames = productDetail.Data.ItemInfo.ItemProps.Select(p => p.Name + ":" + p.Value).ToList();
            }
        }
示例#9
0
        private List <SkuItem> GetSkuItems(TaeItemDetailGetResponse productDetail)
        {
            var skus = new List <SkuItem>();

            var characteristics = this.Characteristics;

            if (productDetail.Data.SkuInfo != null)
            {
                #region get skus
                List <string> spIds = productDetail.Data.SkuInfo.SkuProps.Select(sp => sp.PropId).ToList();

                //all combination
                List <KeyValuePair <string, string> > allPvs = GetSkusByProps(characteristics.Values.ToList(), null, 0);

                if (allPvs != null && allPvs.Count > 0)
                {
                    //format pv
                    var pvMapSkuList = new List <PvMapSku>();
                    productDetail.Data.SkuInfo.PvMapSkuList.ForEach(pm =>
                    {
                        string formatPv   = "";
                        List <string> pvs = pm.Pv.Split(';').ToList();
                        spIds.ForEach(id =>
                        {
                            if (!string.IsNullOrEmpty(formatPv))
                            {
                                formatPv += ";";
                            }
                            formatPv += pvs.Single(p => p.StartsWith(id));
                        });
                        var pvMapSku = new PvMapSku()
                        {
                            Pv    = formatPv,
                            SkuId = pm.SkuId
                        };
                        pvMapSkuList.Add(pvMapSku);
                    });

                    allPvs.ForEach(pv =>
                    {
                        var pvMap = pvMapSkuList.SingleOrDefault(pm => pm.Pv.Equals(pv.Key));
                        if (pvMap != null)
                        {
                            var skuPrice = productDetail.Data.PriceInfo.SkuPriceList.SingleOrDefault(price => price.SkuId == pvMap.SkuId);
                            var skuStock = productDetail.Data.StockInfo.SkuQuantityList.SingleOrDefault(stock => stock.SkuId == pvMap.SkuId);
                            var sku      = new SkuItem();
                            sku.Price    = this.UnitPrice.Value;

                            if (skuPrice != null && skuStock != null)
                            {
                                if (skuPrice.PromotionPrice != null)
                                {
                                    sku.Price = double.Parse(skuPrice.PromotionPrice.Price);
                                }
                                else
                                {
                                    sku.Price = double.Parse(skuPrice.Price.Price);
                                }
                                sku.OriginalPrice = double.Parse(skuPrice.Price.Price);
                            }
                            sku.Properties       = pvMap.Pv;
                            sku.PropertiesName   = pv.Value;
                            sku.SkuId            = Int64.Parse(pvMap.SkuId);
                            sku.WithHoldQuantity = sku.Quantity;
                            skus.Add(sku);
                        }
                        else
                        {
                            var sku              = new SkuItem();
                            sku.Price            = this.UnitPrice.Value;
                            sku.Properties       = pv.Key;
                            sku.Quantity         = 0;
                            sku.PropertiesName   = pv.Value;
                            sku.SkuId            = 0;
                            sku.WithHoldQuantity = 0;
                            skus.Add(sku);
                        }
                    });
                }

                #endregion
            }
            return(skus);
        }
示例#10
0
        private Dictionary <string, List <CharacteristicItem> > GetAltCharacteristics(TaeItemDetailGetResponse productDetail, Dictionary <string, string> keysEn, Dictionary <string, string> valuesEn)
        {
            var newCharacteristics = new Dictionary <string, List <CharacteristicItem> >();

            if (this.Characteristics.Count > 0)
            {
                foreach (var character in this.Characteristics)
                {
                    string result;
                    var    valuejson = JsonConvert.SerializeObject(character);

                    KeyValuePair <string, List <CharacteristicItem> > cloneCharacter = JsonConvert.DeserializeObject <KeyValuePair <string, List <CharacteristicItem> > >(valuejson);
                    foreach (var vd in cloneCharacter.Value)
                    {
                        //translate value
                        if (!string.IsNullOrEmpty(vd.ActualValue) && valuesEn.TryGetValue(vd.ActualValue, out result))
                        {
                            vd.ActualValue = result;
                            result         = null;
                        }

                        if (!string.IsNullOrEmpty(vd.Remark) && valuesEn.TryGetValue(vd.Remark, out result))
                        {
                            vd.Remark = result;
                        }
                    }

                    if (keysEn.TryGetValue(character.Key, out result))
                    {
                        newCharacteristics.Add(result, cloneCharacter.Value);
                    }
                    else
                    {
                        newCharacteristics.Add(character.Key, cloneCharacter.Value);
                    }
                }
            }
            return(newCharacteristics);
        }