/// <summary> /// 删除店铺分类 /// </summary> /// <param name="storeId">店铺id</param> /// <param name="storeCid">店铺分类id</param> /// <returns>-2代表店铺分类不存在,-1代表有子店铺分类,0代表店铺分类下还有商品,1代表删除成功</returns> public static int DeleteStoreClassByStoreIdAndStoreCid(int storeId, int storeCid) { List <StoreClassInfo> storeClassList = NStore.Data.Stores.GetStoreClassList(storeId); StoreClassInfo storeClassInfo = storeClassList.Find(x => x.StoreCid == storeCid); if (storeClassInfo == null) { return(-2); } if (storeClassInfo.HasChild == 1) { return(-1); } if (AdminProducts.AdminGetStoreClassProductCount(storeCid) > 0) { return(0); } NStore.Data.Stores.DeleteStoreClassById(storeCid); if (storeClassInfo.Layer > 1 && storeClassList.FindAll(x => x.ParentId == storeClassInfo.ParentId).Count == 1) { StoreClassInfo parentStoreClassInfo = storeClassList.Find(x => x.StoreCid == storeClassInfo.ParentId); parentStoreClassInfo.HasChild = 0; NStore.Data.Stores.UpdateStoreClass(parentStoreClassInfo); } NStore.Core.BMACache.Remove(CacheKeys.MALL_STORE_CLASSLIST + storeId); return(1); }
public ActionResult AddStoreClass(StoreClassModel model) { if (AdminStores.GetStoreCidByStoreIdAndName(WorkContext.StoreId, model.StoreClassName) > 0) { ModelState.AddModelError("StoreClassName", "名称已经存在"); } if (model.ParentId != 0 && AdminStores.GetStoreClassByStoreIdAndStoreCid(WorkContext.StoreId, model.ParentId) == null) { ModelState.AddModelError("ParentId", "父分类不存在"); } if (ModelState.IsValid) { StoreClassInfo storeClassInfo = new StoreClassInfo() { StoreId = WorkContext.StoreId, DisplayOrder = model.DisplayOrder, Name = model.StoreClassName, ParentId = model.ParentId }; AdminStores.CreateStoreClass(storeClassInfo); AddStoreAdminLog("添加店铺分类", "添加店铺分类,店铺分类为:" + model.StoreClassName); return(PromptView("店铺分类添加成功")); } LoadStoreClass(WorkContext.StoreId); return(View(model)); }
/// <summary> /// 店铺分类 /// </summary> public ActionResult Class() { //店铺分类id int storeCid = GetRouteInt("storeCid"); if (storeCid == 0) { storeCid = WebHelper.GetQueryInt("storeCid"); } //排序列 int sortColumn = GetRouteInt("sortColumn"); if (sortColumn == 0) { sortColumn = WebHelper.GetQueryInt("sortColumn"); } //排序方向 int sortDirection = GetRouteInt("sortDirection"); if (sortDirection == 0) { sortDirection = WebHelper.GetQueryInt("sortDirection"); } //当前页数 int page = GetRouteInt("page"); if (page == 0) { page = WebHelper.GetQueryInt("page"); } //店铺分类信息 StoreClassInfo storeClassInfo = Stores.GetStoreClassByStoreIdAndStoreCid(WorkContext.StoreId, storeCid); if (storeClassInfo == null) { return(View("~/views/shared/prompt.cshtml", new PromptModel("/", "此店铺分类不存在"))); } //分页对象 PageModel pageModel = new PageModel(20, page, Products.GetStoreClassProductCount(storeCid, 0, 0)); //视图对象 StoreClassModel model = new StoreClassModel() { StoreCid = storeCid, SortColumn = sortColumn, SortDirection = sortDirection, PageModel = pageModel, ProductList = Products.GetStoreClassProductList(pageModel.PageSize, pageModel.PageNumber, storeCid, 0, 0, sortColumn, sortDirection), StoreClassInfo = storeClassInfo }; return(View(model)); }
/// <summary> /// 更新店铺分类 /// </summary> public static void UpdateStoreClass(StoreClassInfo storeClassInfo, int oldParentId) { if (storeClassInfo.ParentId != oldParentId)//父分类改变时 { int changeLayer = 0; List <StoreClassInfo> storeClassList = NStore.Data.Stores.GetStoreClassList(storeClassInfo.StoreId); StoreClassInfo oldParentStoreClassInfo = storeClassList.Find(x => x.StoreCid == oldParentId); //旧的父分类 if (storeClassInfo.ParentId > 0) //非顶层分类时 { StoreClassInfo newParentStoreClassInfo = storeClassList.Find(x => x.StoreCid == storeClassInfo.ParentId); //新的父分类 if (oldParentStoreClassInfo == null) { changeLayer = newParentStoreClassInfo.Layer - 1; } else { changeLayer = newParentStoreClassInfo.Layer - oldParentStoreClassInfo.Layer; } storeClassInfo.Layer = newParentStoreClassInfo.Layer + 1; storeClassInfo.Path = newParentStoreClassInfo.Path + "," + storeClassInfo.StoreCid; if (newParentStoreClassInfo.HasChild == 0) { newParentStoreClassInfo.HasChild = 1; NStore.Data.Stores.UpdateStoreClass(newParentStoreClassInfo); } } else//顶层分类时 { changeLayer = 1 - oldParentStoreClassInfo.Layer; storeClassInfo.Layer = 1; storeClassInfo.Path = storeClassInfo.StoreCid.ToString(); } if (oldParentId > 0 && storeClassList.FindAll(x => x.ParentId == oldParentId).Count == 1) { oldParentStoreClassInfo.HasChild = 0; NStore.Data.Stores.UpdateStoreClass(oldParentStoreClassInfo); } foreach (StoreClassInfo info in storeClassList.FindAll(x => x.ParentId == storeClassInfo.StoreCid)) { UpdateChildStoreClassLayerAndPath(storeClassList, info, changeLayer, storeClassInfo.Path); } } NStore.Data.Stores.UpdateStoreClass(storeClassInfo); NStore.Core.BMACache.Remove(CacheKeys.MALL_STORE_CLASSLIST + storeClassInfo.StoreId); }
public ActionResult EditStoreClass(StoreClassModel model, int storeCid = -1) { StoreClassInfo storeClassInfo = AdminStores.GetStoreClassByStoreIdAndStoreCid(WorkContext.StoreId, storeCid); if (storeClassInfo == null) { return(PromptView("此店铺分类不存在")); } int storeCid2 = AdminStores.GetStoreCidByStoreIdAndName(WorkContext.StoreId, model.StoreClassName); if (storeCid2 > 0 && storeCid2 != storeCid) { ModelState.AddModelError("StoreClassName", "名称已经存在"); } if (model.ParentId == storeClassInfo.StoreCid) { ModelState.AddModelError("ParentId", "不能将自己作为父分类"); } if (model.ParentId != 0 && AdminStores.GetStoreClassByStoreIdAndStoreCid(WorkContext.StoreId, model.ParentId) == null) { ModelState.AddModelError("ParentId", "父分类不存在"); } if (model.ParentId != 0 && AdminStores.GetChildStoreClassList(WorkContext.StoreId, storeCid, true).Exists(x => x.StoreCid == model.ParentId)) { ModelState.AddModelError("ParentId", "不能将分类调整到自己的子分类下"); } if (ModelState.IsValid) { int oldParentId = storeClassInfo.ParentId; storeClassInfo.ParentId = model.ParentId; storeClassInfo.Name = model.StoreClassName; storeClassInfo.DisplayOrder = model.DisplayOrder; AdminStores.UpdateStoreClass(storeClassInfo, oldParentId); AddStoreAdminLog("修改店铺分类", "修改店铺分类,店铺分类ID为:" + storeCid); return(PromptView("商品修改成功")); } LoadStoreClass(WorkContext.StoreId); return(View(model)); }
/// <summary> /// 创建店铺分类 /// </summary> public int CreateStoreClass(StoreClassInfo storeClassInfo) { DbParameter[] parms = { GenerateInParam("@storeid", SqlDbType.Int, 4, storeClassInfo.StoreId), GenerateInParam("@displayorder", SqlDbType.Int, 4, storeClassInfo.DisplayOrder), GenerateInParam("@name", SqlDbType.NChar, 60, storeClassInfo.Name), GenerateInParam("@parentid", SqlDbType.Int, 4, storeClassInfo.ParentId), GenerateInParam("@layer", SqlDbType.TinyInt, 1, storeClassInfo.Layer), GenerateInParam("@haschild", SqlDbType.TinyInt, 1, storeClassInfo.HasChild), GenerateInParam("@path", SqlDbType.Char, 100, storeClassInfo.Path) }; string commandText = string.Format("INSERT INTO [{0}storeclasses]([storeid],[displayorder],[name],[parentid],[layer],[haschild],[path]) VALUES(@storeid,@displayorder,@name,@parentid,@layer,@haschild,@path);SELECT SCOPE_IDENTITY()", RDBSHelper.RDBSTablePre); return(TypeHelper.ObjectToInt(RDBSHelper.ExecuteScalar(CommandType.Text, commandText, parms), -1)); }
/// <summary> /// 更新店铺分类 /// </summary> public void UpdateStoreClass(StoreClassInfo storeClassInfo) { DbParameter[] parms = { GenerateInParam("@storeid", SqlDbType.Int, 4, storeClassInfo.StoreId), GenerateInParam("@displayorder", SqlDbType.Int, 4, storeClassInfo.DisplayOrder), GenerateInParam("@name", SqlDbType.NChar, 60, storeClassInfo.Name), GenerateInParam("@parentid", SqlDbType.Int, 4, storeClassInfo.ParentId), GenerateInParam("@layer", SqlDbType.TinyInt, 1, storeClassInfo.Layer), GenerateInParam("@haschild", SqlDbType.TinyInt, 1, storeClassInfo.HasChild), GenerateInParam("@path", SqlDbType.Char, 100, storeClassInfo.Path), GenerateInParam("@storecid", SqlDbType.Int, 4, storeClassInfo.StoreCid) }; string commandText = string.Format("UPDATE [{0}storeclasses] SET [storeid]=@storeid,[displayorder]=@displayorder,[name]=@name,[parentId]=@parentId,[layer]=@layer,[haschild]=@haschild,[path]=@path WHERE [storecid]=@storecid", RDBSHelper.RDBSTablePre); RDBSHelper.ExecuteNonQuery(CommandType.Text, commandText, parms); }
public ActionResult EditStoreClass(int storeCid = -1) { StoreClassInfo storeClassInfo = AdminStores.GetStoreClassByStoreIdAndStoreCid(WorkContext.StoreId, storeCid); if (storeClassInfo == null) { return(PromptView("此店铺分类不存在")); } StoreClassModel model = new StoreClassModel(); model.StoreClassName = storeClassInfo.Name; model.ParentId = storeClassInfo.ParentId; model.DisplayOrder = storeClassInfo.DisplayOrder; LoadStoreClass(WorkContext.StoreId); return(View(model)); }
/// <summary> /// 获得店铺分类列表 /// </summary> /// <param name="storeId">店铺id</param> /// <returns></returns> public static List <StoreClassInfo> GetStoreClassList(int storeId) { List <StoreClassInfo> storeClassList = new List <StoreClassInfo>(); IDataReader reader = BrnMall.Core.BMAData.RDBS.GetStoreClassList(storeId); while (reader.Read()) { StoreClassInfo storeClassInfo = new StoreClassInfo(); storeClassInfo.StoreCid = TypeHelper.ObjectToInt(reader["storecid"]); storeClassInfo.StoreId = TypeHelper.ObjectToInt(reader["storeid"]); storeClassInfo.DisplayOrder = TypeHelper.ObjectToInt(reader["displayorder"]); storeClassInfo.Name = reader["name"].ToString(); storeClassInfo.ParentId = TypeHelper.ObjectToInt(reader["parentid"]); storeClassInfo.Layer = TypeHelper.ObjectToInt(reader["layer"]); storeClassInfo.HasChild = TypeHelper.ObjectToInt(reader["haschild"]); storeClassInfo.Path = reader["path"].ToString(); storeClassList.Add(storeClassInfo); } reader.Close(); return(storeClassList); }
/// <summary> /// 创建店铺分类 /// </summary> public static void CreateStoreClass(StoreClassInfo storeClassInfo) { if (storeClassInfo.ParentId > 0) { List <StoreClassInfo> storeClassList = NStore.Data.Stores.GetStoreClassList(storeClassInfo.StoreId); StoreClassInfo parentStoreClassInfo = storeClassList.Find(x => x.StoreCid == storeClassInfo.ParentId); storeClassInfo.Layer = parentStoreClassInfo.Layer + 1; storeClassInfo.HasChild = 0; storeClassInfo.Path = ""; int storeCid = NStore.Data.Stores.CreateStoreClass(storeClassInfo); storeClassInfo.StoreCid = storeCid; storeClassInfo.Path = parentStoreClassInfo.Path + "," + storeCid; NStore.Data.Stores.UpdateStoreClass(storeClassInfo); if (parentStoreClassInfo.HasChild == 0) { parentStoreClassInfo.HasChild = 1; NStore.Data.Stores.UpdateStoreClass(parentStoreClassInfo); } } else { storeClassInfo.Layer = 1; storeClassInfo.HasChild = 0; storeClassInfo.Path = ""; int storeCid = NStore.Data.Stores.CreateStoreClass(storeClassInfo); storeClassInfo.StoreCid = storeCid; storeClassInfo.Path = storeCid.ToString(); NStore.Data.Stores.UpdateStoreClass(storeClassInfo); } NStore.Core.BMACache.Remove(CacheKeys.MALL_STORE_CLASSLIST + storeClassInfo.StoreId); }
/// <summary> /// 递归更新店铺分类及其子店铺分类的级别和路径 /// </summary> /// <param name="storeClassList">店铺分类列表</param> /// <param name="storeClassInfo">店铺分类信息</param> /// <param name="changeLayer">变化的级别</param> /// <param name="parentPath">父路径</param> private static void UpdateChildStoreClassLayerAndPath(List <StoreClassInfo> storeClassList, StoreClassInfo storeClassInfo, int changeLayer, string parentPath) { storeClassInfo.Layer = storeClassInfo.Layer + changeLayer; storeClassInfo.Path = parentPath + "," + storeClassInfo.StoreCid; NStore.Data.Stores.UpdateStoreClass(storeClassInfo); foreach (StoreClassInfo info in storeClassList.FindAll(x => x.ParentId == storeClassInfo.StoreCid)) { UpdateChildStoreClassLayerAndPath(storeClassList, info, changeLayer, storeClassInfo.Path); } }
/// <summary> /// 店铺搜索 /// </summary> public ActionResult Search() { //搜索词 string keyword = WebHelper.GetQueryString("keyword"); if (keyword.Length > 0 && !SecureHelper.IsSafeSqlString(keyword)) { return(View("~/views/shared/prompt.cshtml", new PromptModel(WorkContext.UrlReferrer, "您搜索的商品不存在"))); } //判断搜索词是否为店铺分类名称,如果是则重定向到店铺分类页面 int storeCid = Stores.GetStoreCidByStoreIdAndName(WorkContext.StoreId, keyword); if (storeCid > 0) { return(Redirect(Url.Action("class", new RouteValueDictionary { { "storeId", WorkContext.StoreId }, { "storeCid", storeCid } }))); } //店铺分类id storeCid = WebHelper.GetQueryInt("storeCid"); //店铺分类信息 StoreClassInfo storeClassInfo = null; if (storeCid > 0) { storeClassInfo = Stores.GetStoreClassByStoreIdAndStoreCid(WorkContext.StoreId, storeCid); if (storeClassInfo == null) { return(View("~/views/shared/prompt.cshtml", new PromptModel("/", "此店铺分类不存在"))); } } //开始价格 int startPrice = WebHelper.GetQueryInt("startPrice"); //结束价格 int endPrice = WebHelper.GetQueryInt("endPrice"); //排序列 int sortColumn = WebHelper.GetQueryInt("sortColumn"); //排序方向 int sortDirection = WebHelper.GetQueryInt("sortDirection"); //当前页数 int page = WebHelper.GetQueryInt("page"); //分页对象 PageModel pageModel = new PageModel(20, page, Searches.GetSearchStoreProductCount(keyword, WorkContext.StoreId, storeCid, startPrice, endPrice)); //视图对象 StoreSearchModel model = new StoreSearchModel() { Word = keyword, StoreCid = storeCid, StartPrice = startPrice, EndPrice = endPrice, SortColumn = sortColumn, SortDirection = sortDirection, PageModel = pageModel, ProductList = Searches.SearchStoreProducts(pageModel.PageSize, pageModel.PageNumber, keyword, WorkContext.StoreId, storeCid, startPrice, endPrice, sortColumn, sortDirection), StoreClassInfo = storeClassInfo }; //异步保存搜索历史 Asyn.UpdateSearchHistory(WorkContext.Uid, keyword); return(View(model)); }
/// <summary> /// 更新店铺分类 /// </summary> public static void UpdateStoreClass(StoreClassInfo storeClassInfo) { BrnMall.Core.BMAData.RDBS.UpdateStoreClass(storeClassInfo); }
/// <summary> /// 创建店铺分类 /// </summary> public static int CreateStoreClass(StoreClassInfo storeClassInfo) { return(BrnMall.Core.BMAData.RDBS.CreateStoreClass(storeClassInfo)); }
/// <summary> /// 店铺搜索 /// </summary> public ActionResult Search() { //搜索词 string word = WebHelper.GetQueryString("word"); if (word.Length == 0) { return(View("~/views/shared/prompt.cshtml", new PromptModel(WorkContext.UrlReferrer, "请输入搜索词"))); } //异步保存搜索历史 Asyn.UpdateSearchHistory(WorkContext.Uid, word); //判断搜索词是否为店铺分类名称,如果是则重定向到店铺分类页面 int storeCid = Stores.GetStoreCidByStoreIdAndName(WorkContext.StoreId, word); if (storeCid > 0) { return(Redirect(Url.Action("class", new RouteValueDictionary { { "storeId", WorkContext.StoreId }, { "storeCid", storeCid } }))); } //店铺分类id storeCid = WebHelper.GetQueryInt("storeCid"); //店铺分类信息 StoreClassInfo storeClassInfo = null; if (storeCid > 0) { storeClassInfo = Stores.GetStoreClassByStoreIdAndStoreCid(WorkContext.StoreId, storeCid); if (storeClassInfo == null) { return(View("~/views/shared/prompt.cshtml", new PromptModel("/", "此店铺分类不存在"))); } } //开始价格 int startPrice = WebHelper.GetQueryInt("startPrice"); //结束价格 int endPrice = WebHelper.GetQueryInt("endPrice"); //排序列 int sortColumn = WebHelper.GetQueryInt("sortColumn"); //排序方向 int sortDirection = WebHelper.GetQueryInt("sortDirection"); //当前页数 int page = WebHelper.GetQueryInt("page"); //检查当前页数 if (page < 1) { page = 1; } //商品总数量 int totalCount = 0; //商品列表 List <PartProductInfo> productList = null; Searches.SearchStoreProducts(20, page, word, WorkContext.StoreId, storeCid, startPrice, endPrice, sortColumn, sortDirection, ref totalCount, ref productList); if (productList == null || productList.Count < 1) { return(View("~/views/shared/prompt.cshtml", new PromptModel(WorkContext.UrlReferrer, "您搜索的商品不存在"))); } //分页对象 PageModel pageModel = new PageModel(20, page, totalCount); //视图对象 StoreSearchModel model = new StoreSearchModel() { Word = word, StoreCid = storeCid, StartPrice = startPrice, EndPrice = endPrice, SortColumn = sortColumn, SortDirection = sortDirection, PageModel = pageModel, ProductList = productList, StoreClassInfo = storeClassInfo }; return(View(model)); }