示例#1
0
        /// <summary>
        /// 添加商品属性
        /// </summary>
        /// <param name="infos"></param>
        /// <param name="goods"></param>
        /// <param name="ids"></param>
        protected virtual void AddGoodsProperty(IList <GoodsPropertyEntity> infos, GoodsEntity goods, IDictionary <long, object> ids)
        {
            if (string.IsNullOrEmpty(hfPropertyValue.Value))
            {
                return;
            }
            var arrayList = hfPropertyValue.Value.Replace("\\", "\\\\").DeserializeJson <IList <IDictionary <string, object> > >();

            foreach (Dictionary <string, object> dictionary in arrayList)
            {
                if (ids.ContainsKey(dictionary["PropertyId"].Convert <long>()))
                {
                    continue;
                }
                var info = new GoodsPropertyEntity {
                    Product = new ProductEntity {
                        Id = 0
                    }
                };
                foreach (var o in dictionary)
                {
                    if (SaveType == SaveType.Add && o.Key.Equals("Id"))
                    {
                        continue;
                    }
                    var name = o.Key.Equals("PropertyId") ? "Property.Id" : o.Key;
                    Winner.Creator.Get <IProperty>().SetValue(info, name, o.Value);
                }
                infos.Add(info);
            }
        }
示例#2
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <returns></returns>
        protected override ProductEntity FillEntity()
        {
            var info = base.FillEntity();

            info.Sku = GetSku();
            info.SetProperty(it => it.Sku);
            var goodsProperties = GetGoodsProperties();

            if (info.SkuJsons != null)
            {
                foreach (var json in info.SkuJsons)
                {
                    var goodsProperty = goodsProperties.FirstOrDefault(it =>
                                                                       it.Property != null && it.Property.Id == json.Id &&
                                                                       it.Product != null && it.Product.Id == RequestId);
                    if (goodsProperty != null && goodsProperty.Value == json.Value)
                    {
                        continue;
                    }
                    if (goodsProperty == null)
                    {
                        goodsProperty = new GoodsPropertyEntity
                        {
                            Value = json.Value,
                            Goods = new GoodsEntity {
                                Id = GoodsId
                            },
                            Product  = info,
                            Property = new PropertyEntity {
                                Id = json.Id
                            },
                            SaveType = SaveType.Add
                        };
                    }
                    else
                    {
                        goodsProperty.Value = json.Value;
                        goodsProperty.SetProperty(it => it.Value);
                        goodsProperty.SaveType = SaveType.Modify;
                    }
                    info.GoodsProperties = info.GoodsProperties ?? new List <GoodsPropertyEntity>();
                    info.GoodsProperties.Add(goodsProperty);
                }
                foreach (var goodsProperty in goodsProperties)
                {
                    if (info.SkuJsons.Count(it => it.Id == goodsProperty.Property.Id) == 0)
                    {
                        goodsProperty.SaveType = SaveType.Remove;
                        info.GoodsProperties   = info.GoodsProperties ?? new List <GoodsPropertyEntity>();
                        info.GoodsProperties.Add(goodsProperty);
                    }
                }
            }
            return(info);
        }
示例#3
0
        /// <summary>
        /// 填充商品扩展属性
        /// </summary>
        /// <param name="file"></param>
        /// <param name="goods"></param>
        /// <param name="category"></param>
        protected virtual void FillGoodsProperties(FileInfo file, GoodsEntity goods, CategoryEntity category)
        {
            var table = GetImportTable(file.FullName, "Sheet2");

            if (table == null)
            {
                return;
            }
            goods.GoodsProperties = goods.GoodsProperties ?? new List <GoodsPropertyEntity>();
            var i = 0;

            foreach (DataRow row in table.Rows)
            {
                i++;
                if (i == 1)
                {
                    continue;
                }
                foreach (DataColumn col in table.Columns)
                {
                    foreach (var product in goods.Products)
                    {
                        var goodsProperty = new GoodsPropertyEntity
                        {
                            Goods    = goods,
                            Product  = product,
                            SaveType = SaveType.Add
                        };
                        if (category.CategoryProperties == null)
                        {
                            continue;
                        }
                        var property =
                            category.CategoryProperties.FirstOrDefault(
                                it => it.Name == col.ColumnName && it.IsUsed);
                        if (property == null)
                        {
                            continue;
                        }
                        goodsProperty.Property = property;
                        goodsProperty.Value    = row[col.ColumnName].Convert <string>();
                        if (!string.IsNullOrEmpty(goodsProperty.Value))
                        {
                            goods.GoodsProperties.Add(goodsProperty);
                        }
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// 填充产品字段
        /// </summary>
        /// <param name="table"></param>
        /// <param name="goods"></param>
        /// <param name="product"></param>
        /// <param name="row"></param>
        /// <param name="category"></param>
        protected virtual void FillProductColumn(DataTable table, GoodsEntity goods, ProductEntity product, DataRow row, CategoryEntity category)
        {
            var sku = new List <string>();

            foreach (DataColumn col in table.Columns)
            {
                switch (col.ColumnName)
                {
                case "名称":
                    product.Name = row[col.ColumnName].Convert <string>().Trim();
                    break;

                case "面价":
                    product.Price = row[col.ColumnName].Convert <decimal>();
                    break;

                case "底价":
                    product.Cost = row[col.ColumnName].Convert <decimal>();
                    break;

                case "起订数量":
                    product.OrderMinCount = row[col.ColumnName].Convert <int>();
                    break;

                case "订购步长数量":
                    product.OrderStepCount = row[col.ColumnName].Convert <int>();
                    break;

                case "数量":
                    product.Count = row[col.ColumnName].Convert <int>();
                    break;

                case "商家编码":
                    product.DataId = row[col.ColumnName].Convert <string>();
                    break;

                default:
                    if (category.CategoryProperties == null)
                    {
                        continue;
                    }
                    var property =
                        category.CategoryProperties.FirstOrDefault(
                            it => it.Name == col.ColumnName && it.IsSku && it.IsUsed);
                    if (property == null)
                    {
                        continue;
                    }
                    var rowValue = row[col.ColumnName].Convert <string>();
                    if (string.IsNullOrEmpty(rowValue))
                    {
                        continue;
                    }
                    if (property.IsSku)
                    {
                        var value = string.Format("Id:\"{0}\",Name:\"{1}\",Value:\"{2}\"", property.Id,
                                                  property.Name, rowValue);
                        sku.Add("{" + value + "}");
                    }
                    goods.GoodsProperties = goods.GoodsProperties ?? new List <GoodsPropertyEntity>();
                    var goodsProperty = new GoodsPropertyEntity
                    {
                        Goods    = goods,
                        Value    = rowValue,
                        Property = property,
                        Product  = product,
                        SaveType = SaveType.Add
                    };

                    goods.GoodsProperties.Add(goodsProperty);
                    break;
                }
            }
            if (sku.Count > 0)
            {
                product.Sku = "[" + string.Join(",", sku.ToArray()) + "]";
            }
        }