/// <summary> /// /// </summary> /// <param name="user"></param> /// <returns></returns> public List<Product_Class> GetCategories(BUser user) { List<Product_Class> categories = new List<Product_Class>(); SellercatsListGetRequest req = new SellercatsListGetRequest(); req.Nick = user.Mall_Name; SellercatsListGetResponse response = client.Execute(req); if (response.IsError) { throw new KMJXCException(response.ErrMsg); } if (response.SellerCats != null) { foreach (TB.SellerCat cat in response.SellerCats) { Product_Class category = new Product_Class(); category.Create_Time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); category.Create_User_ID = user.ID; category.Enabled = true; category.Mall_CID = cat.Cid.ToString(); category.Mall_PCID = cat.ParentCid.ToString(); category.Name = cat.Name; category.Parent_ID = 0; category.Product_Class_ID = 0; categories.Add(category); } } return categories; }
/// <summary> /// /// </summary> /// <param name="category"></param> /// <returns></returns> public List<BProperty> GetProperities(Product_Class category,Shop shop) { List<BProperty> properities = new List<BProperty>(); ItempropsGetRequest req = new ItempropsGetRequest(); req.Fields = "pid,name,must,multi,prop_values"; if (category != null && !string.IsNullOrEmpty(category.Mall_CID)) { req.Cid = long.Parse(category.Mall_CID); } else { req.Cid = 0; } //req.IsKeyProp = true; req.IsSaleProp = true; req.IsColorProp = true; req.IsEnumProp = true; req.IsInputProp = true; req.IsItemProp = true; //1=>Taobao //2=>TMall, need to check Mall Type from Shop object req.Type = 1L; ItempropsGetResponse response = client.Execute(req); if (response.IsError) { throw new KMJXCException(response.ErrMsg); } if (response.ItemProps != null) { foreach (TB.ItemProp prop in response.ItemProps) { BProperty pro = new BProperty(); pro.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); pro.MID = prop.Pid.ToString(); pro.Name = prop.Name; pro.CategoryId = category.Product_Class_ID; pro.ID = 0; pro.Shop = new BShop() { ID = category.Shop_ID }; pro.Created_By = new BUser() { ID = category.Create_User_ID }; properities.Add(pro); if (prop.PropValues != null) { foreach (TB.PropValue pv in prop.PropValues) { Product_Spec_Value psv = new Product_Spec_Value(); psv.Name = pv.Name; pro.Values.Add(psv); } } } } return properities; }
/// <summary> /// Create new category /// </summary> /// <param name="category">Product_Class object</param> /// <returns></returns> public bool CreateCategory(BCategory category) { bool result = false; if (category == null) { throw new KMJXCException("输入错误"); } if (string.IsNullOrEmpty(category.Name)) { throw new KMJXCException("类目名不能为空"); } if (this.CurrentUserPermission.ADD_PRODUCT_CLASS == 0) { throw new KMJXCException("没有权限添加类目"); } using (KuanMaiEntities db = new KuanMaiEntities()) { Product_Class pc = new Product_Class(); pc.Create_Time = category.Created; pc.Create_User_ID = this.CurrentUser.ID; pc.Enabled = true; pc.Mall_CID = category.Mall_ID; pc.Mall_PCID = category.Mall_PID; pc.Name = category.Name; pc.Order = category.Order; if (category.Shop == null || category.Shop.ID == 0) { pc.Shop_ID = this.Shop.Shop_ID; } else { pc.Shop_ID = category.Shop.ID; } if (category.Parent == null || category.Parent.ID <= 0) { pc.Parent_ID = 0; } else { pc.Parent_ID = category.Parent.ID; } Product_Class existed = (from ca in db.Product_Class where ca.Name.ToLower() == category.Name.ToLower() && ca.Shop_ID == pc.Shop_ID && ca.Parent_ID==pc.Parent_ID select ca).FirstOrDefault<Product_Class>(); if (existed != null) { if (pc.Parent_ID > 0) { throw new KMJXCException("名为" + category.Name + "的子类目已经存在"); } else { throw new KMJXCException("名为" + category.Name + "的类目已经存在"); } } db.Product_Class.Add(pc); db.SaveChanges(); category.ID = pc.Product_Class_ID; result = true; base.CreateActionLog(new BUserActionLog() { Shop = new BShop { ID = this.Shop.Shop_ID }, Action = new BUserAction() { Action_ID = UserLogAction.CREATE_PRODUCT_CATEGORY }, Description = "" }); } return result; }