Exemple #1
0
        /// <summary>
        /// 添加SKU
        /// </summary>
        /// <param name="productInfo">商品信息</param>
        /// <param name="productSKUItemList">商品SKU项列表</param>
        public static void AddSKU(ProductInfo productInfo, List <ProductSKUItemInfo> productSKUItemList)
        {
            List <ProductSKUItemInfo> attrList      = new List <ProductSKUItemInfo>();
            List <ProductSKUItemInfo> attrValueList = new List <ProductSKUItemInfo>();

            foreach (ProductSKUItemInfo productSKUItemInfo in productSKUItemList)
            {
                if (!attrValueList.Exists(x => x.AttrValueId == productSKUItemInfo.AttrValueId && x.InputValue == productSKUItemInfo.InputValue))
                {
                    attrValueList.Add(productSKUItemInfo);
                }
            }
            foreach (ProductSKUItemInfo productSKUItemInfo in attrValueList)
            {
                if (attrList.Find(x => x.AttrId == productSKUItemInfo.AttrId) == null)
                {
                    attrList.Add(productSKUItemInfo);
                }
            }

            //sku数量
            int skuCount = 1;

            for (var i = 0; i < attrList.Count; i++)
            {
                skuCount = skuCount * attrValueList.FindAll(x => x.AttrId == attrList[i].AttrId).Count;
            }


            //sku项数量
            int skuItemCount = productSKUItemList.Count / skuCount;

            //sku组id
            int skuGid = TypeHelper.StringToInt(Randoms.CreateRandomValue(8));

            while (IsExistSKUGid(skuGid))
            {
                skuGid = TypeHelper.StringToInt(Randoms.CreateRandomValue(8));
            }
            productInfo.SKUGid = skuGid;

            //商品原始名称
            string oName = productInfo.Name;

            //循环创建商品,商品属性,商品sku项s
            for (int i = 0; i < skuCount; i++)
            {
                //格式化商品名称
                StringBuilder pName = new StringBuilder(oName);
                for (int j = skuItemCount * i; j < skuItemCount * (i + 1); j++)
                {
                    AttributeValueInfo attributeValueInfo = AdminCategories.GetAttributeValueById(productSKUItemList[j].AttrValueId);
                    if (attributeValueInfo.IsInput == 0)
                    {
                        pName.AppendFormat(" {0}", attributeValueInfo.AttrValue);
                    }
                    else
                    {
                        pName.AppendFormat(" {0}", productSKUItemList[j].InputValue);
                    }
                }
                productInfo.Name = pName.ToString();
                int pid = AddProduct(productInfo, 0, 0, null);//创建商品及其属性
                if (pid > 0)
                {
                    //创建商品sku项
                    for (int j = skuItemCount * i; j < skuItemCount * (i + 1); j++)
                    {
                        productSKUItemList[j].Pid    = pid;
                        productSKUItemList[j].SKUGid = skuGid;
                        CreateProductSKUItem(productSKUItemList[j]);
                    }
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// 生成用户盐值
 /// </summary>
 /// <returns></returns>
 public static string GenerateUserSalt()
 {
     return(Randoms.CreateRandomValue(6));
 }