/// <summary> /// 添加商品 /// </summary> /// <param name="productInfo">商品信息</param> /// <param name="stockNumber">库存数量</param> /// <param name="stockLimit">库存警戒线</param> /// <param name="productAttributeList">商品属性列表</param> /// <returns></returns> public static int AddProduct(ProductInfo productInfo, int stockNumber, int stockLimit, List<ProductAttributeInfo> productAttributeList) { //创建商品 int pid = CreateProduct(productInfo); if (pid > 0) { //创建商品库存 CreateProductStock(pid, stockNumber, stockLimit); //创建商品属性 if (productAttributeList != null) { foreach (ProductAttributeInfo productAttributeInfo in productAttributeList) { productAttributeInfo.Pid = pid; CreateProductAttribute(productAttributeInfo); } } } return pid; }
/// <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.Find(x => x.AttrValueId == productSKUItemInfo.AttrValueId) == null) { 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]); } } } }
/// <summary> /// 更新商品 /// </summary> /// <param name="productInfo">商品信息</param> public static void UpdateProduct(ProductInfo productInfo) { BrnShop.Data.Products.UpdateProduct(productInfo); }
/// <summary> /// 更新商品 /// </summary> /// <param name="productInfo">商品信息</param> /// <param name="stockNumber">库存数量</param> /// <param name="stockLimit">库存警戒线</param> public static void UpdateProduct(ProductInfo productInfo, int stockNumber, int stockLimit) { UpdateProduct(productInfo); UpdateProductStock(productInfo.Pid, stockNumber, stockLimit); }
/// <summary> /// 创建商品 /// </summary> /// <param name="productInfo">商品信息</param> /// <returns>商品id</returns> public static int CreateProduct(ProductInfo productInfo) { return BrnShop.Data.Products.CreateProduct(productInfo); }
/// <summary> /// 创建商品 /// </summary> /// <param name="productInfo">商品信息</param> /// <returns>商品id</returns> public int CreateProduct(ProductInfo productInfo) { DbParameter[] parms = { GenerateInParam("@psn",SqlDbType.Char,30,productInfo.PSN), GenerateInParam("@cateid",SqlDbType.SmallInt,2,productInfo.CateId), GenerateInParam("@brandid",SqlDbType.Int,4,productInfo.BrandId), GenerateInParam("@skugid",SqlDbType.Int,4,productInfo.SKUGid), GenerateInParam("@name",SqlDbType.NVarChar,200,productInfo.Name), GenerateInParam("@shopprice",SqlDbType.Decimal,4,productInfo.ShopPrice), GenerateInParam("@marketprice",SqlDbType.Decimal,4,productInfo.MarketPrice), GenerateInParam("@costprice",SqlDbType.Decimal,4,productInfo.CostPrice), GenerateInParam("@state",SqlDbType.TinyInt,1,productInfo.State), GenerateInParam("@isbest",SqlDbType.TinyInt,1,productInfo.IsBest), GenerateInParam("@ishot",SqlDbType.TinyInt,1,productInfo.IsHot), GenerateInParam("@isnew",SqlDbType.TinyInt,1,productInfo.IsNew), GenerateInParam("@displayorder",SqlDbType.Int,4,productInfo.DisplayOrder), GenerateInParam("@weight",SqlDbType.Int,4,productInfo.Weight), GenerateInParam("@showimg",SqlDbType.NVarChar,100,productInfo.ShowImg), GenerateInParam("@salecount",SqlDbType.Int,4,productInfo.SaleCount), GenerateInParam("@visitcount",SqlDbType.Int,4,productInfo.VisitCount), GenerateInParam("@reviewcount",SqlDbType.Int,4,productInfo.ReviewCount), GenerateInParam("@star1",SqlDbType.Int,4,productInfo.Star1), GenerateInParam("@star2",SqlDbType.Int,4,productInfo.Star2), GenerateInParam("@star3",SqlDbType.Int,4,productInfo.Star3), GenerateInParam("@star4",SqlDbType.Int,4,productInfo.Star4), GenerateInParam("@star5",SqlDbType.Int,4,productInfo.Star5), GenerateInParam("@addtime",SqlDbType.DateTime,8,productInfo.AddTime), GenerateInParam("@description",SqlDbType.NText,0,productInfo.Description) }; string commandText = string.Format(@"INSERT INTO [{0}products]([psn],[cateid],[brandid],[skugid],[name],[shopprice],[marketprice],[costprice],[state],[isbest],[ishot],[isnew], [weight],[displayorder],[showimg],[salecount],[visitcount],[reviewcount],[star1],[star2],[star3],[star4],[star5],[addtime],[description]) VALUES(@psn,@cateid,@brandid,@skugid,@name,@shopprice,@marketprice,@costprice,@state,@isbest,@ishot,@isnew, @weight,@displayorder,@showimg,@salecount,@visitcount,@reviewcount,@star1,@star2,@star3,@star4,@star5,@addtime,@description); SELECT SCOPE_IDENTITY();", RDBSHelper.RDBSTablePre); return TypeHelper.ObjectToInt(RDBSHelper.ExecuteScalar(CommandType.Text, commandText, parms), -1); }
/// <summary> /// 更新商品 /// </summary> public void UpdateProduct(ProductInfo productInfo) { DbParameter[] parms = { GenerateInParam("@psn",SqlDbType.Char,30,productInfo.PSN), GenerateInParam("@cateid",SqlDbType.SmallInt,2,productInfo.CateId), GenerateInParam("@brandid",SqlDbType.Int,4,productInfo.BrandId), GenerateInParam("@skugid",SqlDbType.Int,4,productInfo.SKUGid), GenerateInParam("@name",SqlDbType.NVarChar,200,productInfo.Name), GenerateInParam("@shopprice",SqlDbType.Decimal,4,productInfo.ShopPrice), GenerateInParam("@marketprice",SqlDbType.Decimal,4,productInfo.MarketPrice), GenerateInParam("@costprice",SqlDbType.Decimal,4,productInfo.CostPrice), GenerateInParam("@state",SqlDbType.TinyInt,1,productInfo.State), GenerateInParam("@isbest",SqlDbType.TinyInt,1,productInfo.IsBest), GenerateInParam("@ishot",SqlDbType.TinyInt,1,productInfo.IsHot), GenerateInParam("@isnew",SqlDbType.TinyInt,1,productInfo.IsNew), GenerateInParam("@displayorder",SqlDbType.Int,4,productInfo.DisplayOrder), GenerateInParam("@weight",SqlDbType.Int,4,productInfo.Weight), GenerateInParam("@showimg",SqlDbType.NVarChar,100,productInfo.ShowImg), GenerateInParam("@salecount",SqlDbType.Int,4,productInfo.SaleCount), GenerateInParam("@visitcount",SqlDbType.Int,4,productInfo.VisitCount), GenerateInParam("@reviewcount",SqlDbType.Int,4,productInfo.ReviewCount), GenerateInParam("@star1",SqlDbType.Int,4,productInfo.Star1), GenerateInParam("@star2",SqlDbType.Int,4,productInfo.Star2), GenerateInParam("@star3",SqlDbType.Int,4,productInfo.Star3), GenerateInParam("@star4",SqlDbType.Int,4,productInfo.Star4), GenerateInParam("@star5",SqlDbType.Int,4,productInfo.Star5), GenerateInParam("@addtime",SqlDbType.DateTime,8,productInfo.AddTime), GenerateInParam("@description",SqlDbType.NText,0,productInfo.Description), GenerateInParam("@pid",SqlDbType.Int,4,productInfo.Pid) }; string commandText = string.Format(@"UPDATE [{0}products] SET [psn]=@psn,[cateid]=@cateid,[brandid]=@brandid,[skugid]=@skugid,[name]=@name,[shopprice]=@shopprice,[marketprice]=@marketprice,[costprice]=@costprice, [state]=@state,[isbest]=@isbest,[ishot]=@ishot,[isnew]=@isnew,[displayorder]=@displayorder,[weight]=@weight,[showimg]=@showimg,[salecount]=@salecount,[visitcount]=@visitcount,[reviewcount]=@reviewcount, [star1]=@star1,[star2]=@star2,[star3]=@star3,[star4]=@star4,[star5]=@star5,[addtime]=@addtime,[description]=@description WHERE [pid]=@pid", RDBSHelper.RDBSTablePre); RDBSHelper.ExecuteNonQuery(CommandType.Text, commandText, parms); }
/// <summary> /// 创建商品 /// </summary> /// <param name="productInfo">商品信息</param> /// <returns>商品id</returns> public static int CreateProduct(ProductInfo productInfo) { int pid = BrnShop.Core.BSPData.RDBS.CreateProduct(productInfo); if (_productnosql != null && pid > 0) { productInfo.Pid = pid; _productnosql.CreateProduct(productInfo); } return pid; }
/// <summary> /// 从IDataReader创建ProductInfo /// </summary> public static ProductInfo BuildProductFromReader(IDataReader reader) { ProductInfo productInfo = new ProductInfo(); productInfo.Pid = TypeHelper.ObjectToInt(reader["pid"]); productInfo.PSN = reader["psn"].ToString(); productInfo.CateId = TypeHelper.ObjectToInt(reader["cateid"]); productInfo.BrandId = TypeHelper.ObjectToInt(reader["brandid"]); productInfo.SKUGid = TypeHelper.ObjectToInt(reader["skugid"]); productInfo.Name = reader["name"].ToString(); productInfo.ShopPrice = TypeHelper.ObjectToDecimal(reader["shopprice"]); productInfo.MarketPrice = TypeHelper.ObjectToDecimal(reader["marketprice"]); productInfo.CostPrice = TypeHelper.ObjectToDecimal(reader["costprice"]); productInfo.State = TypeHelper.ObjectToInt(reader["state"]); productInfo.IsBest = TypeHelper.ObjectToInt(reader["isbest"]); productInfo.IsHot = TypeHelper.ObjectToInt(reader["ishot"]); productInfo.IsNew = TypeHelper.ObjectToInt(reader["isnew"]); productInfo.DisplayOrder = TypeHelper.ObjectToInt(reader["displayorder"]); productInfo.Weight = TypeHelper.ObjectToInt(reader["weight"]); productInfo.ShowImg = reader["showimg"].ToString(); productInfo.SaleCount = TypeHelper.ObjectToInt(reader["salecount"]); productInfo.VisitCount = TypeHelper.ObjectToInt(reader["visitcount"]); productInfo.ReviewCount = TypeHelper.ObjectToInt(reader["reviewcount"]); productInfo.Star1 = TypeHelper.ObjectToInt(reader["star1"]); productInfo.Star2 = TypeHelper.ObjectToInt(reader["star2"]); productInfo.Star3 = TypeHelper.ObjectToInt(reader["star3"]); productInfo.Star4 = TypeHelper.ObjectToInt(reader["star4"]); productInfo.Star5 = TypeHelper.ObjectToInt(reader["star5"]); productInfo.AddTime = TypeHelper.ObjectToDateTime(reader["addtime"]); productInfo.Description = reader["description"].ToString(); return productInfo; }
/// <summary> /// 更新商品 /// </summary> public static void UpdateProduct(ProductInfo productInfo) { BrnShop.Core.BSPData.RDBS.UpdateProduct(productInfo); if (_productnosql != null) _productnosql.UpdateProduct(productInfo); }
public ActionResult AddProduct(AddProductModel model) { if (AdminProducts.AdminGetProductIdByName(model.ProductName) > 0) ModelState.AddModelError("ProductName", "名称已经存在"); if (ModelState.IsValid) { ProductInfo productInfo = new ProductInfo() { PSN = model.PSN ?? "", CateId = model.CateId, BrandId = model.BrandId, SKUGid = 0, Name = model.ProductName, ShopPrice = model.ShopPrice, MarketPrice = model.MarketPrice, CostPrice = model.CostPrice, State = model.State, IsBest = model.IsBest == true ? 1 : 0, IsHot = model.IsHot == true ? 1 : 0, IsNew = model.IsNew == true ? 1 : 0, DisplayOrder = model.DisplayOrder, Weight = model.Weight, ShowImg = "", Description = model.Description ?? "", AddTime = DateTime.Now, }; //属性处理 List<ProductAttributeInfo> productAttributeList = new List<ProductAttributeInfo>(); if (model.AttrValueIdList != null && model.AttrValueIdList.Length > 0) { for (int i = 0; i < model.AttrValueIdList.Length; i++) { int attrId = model.AttrIdList[i];//属性id int attrValueId = model.AttrValueIdList[i];//属性值id string inputValue = model.AttrInputValueList[i];//属性输入值 if (attrId > 0 && attrValueId > 0) { productAttributeList.Add(new ProductAttributeInfo { AttrId = attrId, AttrValueId = attrValueId, InputValue = inputValue ?? "" }); } } } AdminProducts.AddProduct(productInfo, model.StockNumber, model.StockLimit, productAttributeList); AddAdminOperateLog("添加普通商品", "添加普通商品,商品为:" + model.ProductName); string backUrl = null; if (productInfo.State == (int)ProductState.OnSale) backUrl = Url.Action("onsaleproductlist"); else backUrl = Url.Action("outsaleproductlist"); return PromptView(backUrl, "普通商品添加成功"); } ViewData["referer"] = ShopUtils.GetAdminRefererCookie(); return View(model); }
public ActionResult AddSKU(AddSKUModel model) { if (AdminProducts.AdminGetProductIdByName(model.ProductName) > 0) ModelState.AddModelError("ProductName", "名称已经存在"); if (model.AttrIdList == null || model.AttrIdList.Length < 1) ModelState.AddModelError("CateId", "请选择SKU"); if (ModelState.IsValid) { //商品信息 ProductInfo productInfo = new ProductInfo() { PSN = "", CateId = model.CateId, BrandId = model.BrandId, SKUGid = 0, Name = model.ProductName, ShopPrice = model.ShopPrice, MarketPrice = model.MarketPrice, CostPrice = model.CostPrice, State = (int)ProductState.OutSale,//设为下架状态 IsBest = model.IsBest == true ? 1 : 0, IsHot = model.IsHot == true ? 1 : 0, IsNew = model.IsNew == true ? 1 : 0, DisplayOrder = model.DisplayOrder, Weight = model.Weight, ShowImg = "", Description = model.Description ?? "", AddTime = DateTime.Now }; //SKU处理 List<ProductSKUItemInfo> productSKUItemList = new List<ProductSKUItemInfo>(); for (int i = 0; i < model.AttrIdList.Length; i++) { int attrId = model.AttrIdList[i];//属性id int attrValueId = model.AttrValueIdList[i];//属性值id string inputValue = model.AttrInputValueList[i];//属性输入值 if (attrId > 0 && attrValueId > 0) { productSKUItemList.Add(new ProductSKUItemInfo() { AttrId = attrId, AttrValueId = attrValueId, InputValue = inputValue ?? "" }); } } AdminProducts.AddSKU(productInfo, productSKUItemList); AddAdminOperateLog("添加SKU商品", "添加SKU商品,商品为:" + model.ProductName); return PromptView(Url.Action("outsaleproductlist"), "SKU商品添加成功"); } ViewData["referer"] = ShopUtils.GetAdminRefererCookie(); return View(model); }