예제 #1
0
        public ActionResult EditProduct(EditProductModel model, int pid = -1)
        {
            ProductInfo productInfo = AdminProducts.AdminGetProductById(pid);

            if (productInfo == null)
            {
                return(PromptView("商品不存在"));
            }

            int pid2 = AdminProducts.AdminGetProductIdByName(model.ProductName);

            if (pid2 > 0 && pid2 != pid)
            {
                ModelState.AddModelError("ProductName", "名称已经存在");
            }

            if (ModelState.IsValid)
            {
                productInfo.PSN          = model.PSN ?? "";
                productInfo.BrandId      = model.BrandId;
                productInfo.StoreCid     = model.StoreCid;
                productInfo.StoreSTid    = model.StoreSTid;
                productInfo.Name         = model.ProductName;
                productInfo.ShopPrice    = model.ShopPrice;
                productInfo.MarketPrice  = model.MarketPrice;
                productInfo.CostPrice    = model.CostPrice;
                productInfo.State        = model.State;
                productInfo.IsBest       = model.IsBest == true ? 1 : 0;
                productInfo.IsHot        = model.IsHot == true ? 1 : 0;
                productInfo.IsNew        = model.IsNew == true ? 1 : 0;
                productInfo.DisplayOrder = model.DisplayOrder;
                productInfo.Weight       = model.Weight;
                productInfo.Description  = model.Description ?? "";
                productInfo.Spec         = model.Spec ?? "";

                AdminProducts.UpdateProduct(productInfo, model.StockNumber, model.StockLimit);
                AddMallAdminLog("修改商品", "修改商品,商品ID为:" + pid);
                return(PromptView("商品修改成功"));
            }


            //商品属性列表
            List <ProductAttributeInfo> productAttributeList = Products.GetProductAttributeList(pid);

            //商品sku项列表
            DataTable productSKUItemList = AdminProducts.GetProductSKUItemList(productInfo.Pid);

            ViewData["pid"]                  = productInfo.Pid;
            ViewData["storeId"]              = productInfo.StoreId;
            ViewData["storeName"]            = AdminStores.GetStoreById(productInfo.StoreId).Name;
            ViewData["cateId"]               = productInfo.CateId;
            ViewData["categoryName"]         = AdminCategories.GetCategoryById(productInfo.CateId).Name;
            ViewData["productAttributeList"] = productAttributeList;
            ViewData["productSKUItemList"]   = productSKUItemList;
            ViewData["referer"]              = MallUtils.GetMallAdminRefererCookie();

            return(View(model));
        }
예제 #2
0
        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,
                    StoreId      = model.StoreId,
                    StoreCid     = model.StoreCid,
                    StoreSTid    = model.StoreSTid,
                    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);
                AddMallAdminLog("添加SKU商品", "添加SKU商品,商品为:" + model.ProductName);

                return(PromptView(Url.Action("outsaleproductlist"), "SKU商品添加成功"));
            }
            ViewData["referer"] = MallUtils.GetMallAdminRefererCookie();
            return(View(model));
        }
예제 #3
0
        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,
                    StoreId      = model.StoreId,
                    StoreCid     = model.StoreCid,
                    StoreSTid    = model.StoreSTid,
                    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);
                AddMallAdminLog("添加普通商品", "添加普通商品,商品为:" + 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"] = MallUtils.GetMallAdminRefererCookie();
            return(View(model));
        }