mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 16:23:26 +08:00
【修复】修复后台商品按分类查询,未迭代计算下级分类的问题,同时接口端增加多级判断。
This commit is contained in:
@@ -80,6 +80,37 @@ namespace CoreCms.Net.Utility.Helper
|
||||
|
||||
#endregion
|
||||
|
||||
#region 递归获取下级所有序列
|
||||
/// <summary>
|
||||
/// 递归获取下级所有序列
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Description("递归获取下级所有序列")]
|
||||
public static List<int> GetChildIds(List<CoreCmsGoodsCategory> categories, int parentId)
|
||||
{
|
||||
var ids = new List<int> { parentId };
|
||||
ids = GetChildrenIds(categories, parentId, ids);
|
||||
return ids;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 迭代方法
|
||||
/// </summary>
|
||||
/// <param name="oldNavs"></param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
private static List<int> GetChildrenIds(List<CoreCmsGoodsCategory> oldNavs, int parentId, List<int> ids)
|
||||
{
|
||||
var model = oldNavs.Where(p => p.parentId == parentId).ToList();
|
||||
foreach (var item in model)
|
||||
{
|
||||
ids.Add(item.id);
|
||||
GetChildrenIds(oldNavs, item.id, ids);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取可用库存
|
||||
/// <summary>
|
||||
@@ -120,16 +151,9 @@ namespace CoreCms.Net.Utility.Helper
|
||||
return url;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 小程序端获取编码后的分类集合
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 后端判断提交的商品属性值是否符合规则(判断内容,只允许中文,字母,数字,和-,/)
|
||||
|
||||
/// <summary>
|
||||
/// 判断内容,只允许中文,字母,数字,和-,/
|
||||
/// </summary>
|
||||
@@ -139,17 +163,7 @@ namespace CoreCms.Net.Utility.Helper
|
||||
public static bool FilterChar(string inputValue)
|
||||
{
|
||||
return Regex.IsMatch(inputValue, "[`.~!@#$^&*()=|\"{}':;',\\[\\]<>?~!@#¥……&*&;|{}。*-+]+");
|
||||
//return Regex.IsMatch(inputValue, "[`.~!@#$^&*()=|\"{}':;',\\[\\]<>?~!@#¥……&*&;|{}。*-+]+");
|
||||
//if (Regex.IsMatch(inputValue, "[A-Za-z0-9\u4e00-\u9fa5-]+"))
|
||||
//{
|
||||
// return Regex.Match(inputValue, "[A-Za-z0-9\u4e00-\u9fa5-]+").Value;
|
||||
//}
|
||||
//return "";
|
||||
//return Regex.IsMatch(inputValue, "[~!@#$%^&*()_+|<>,.?:;'\\[\\]{}\"]+");
|
||||
|
||||
//return Regex.IsMatch(inputValue, "[A-Za-z0-9\u4e00-\u9fa5-/]+");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
@@ -172,8 +172,18 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
||||
var selectTreeSelectNodeId = Request.Form["selectTree_select_nodeId"].FirstOrDefault().ObjectToInt(0);
|
||||
if (selectTreeSelectNodeId > 0) @where = @where.And(p => p.goodsCategoryId == selectTreeSelectNodeId);
|
||||
//商品分类ID 关联category.id int
|
||||
|
||||
var goodsCategoryId = Request.Form["goodsCategoryId"].FirstOrDefault().ObjectToInt(0);
|
||||
if (goodsCategoryId > 0) @where = @where.And(p => p.goodsCategoryId == goodsCategoryId);
|
||||
if (goodsCategoryId > 0)
|
||||
{
|
||||
//获取全部数据缓存
|
||||
var categories = await _coreCmsGoodsCategoryServices.QueryAsync(true, true);
|
||||
var ids = GoodsHelper.GetChildIds(categories, goodsCategoryId);
|
||||
|
||||
@where = @where.And(p => ids.Contains(p.goodsCategoryId));
|
||||
}
|
||||
|
||||
|
||||
//商品类别ID 关联goods_type.id int
|
||||
var goodsTypeId = Request.Form["goodsTypeId"].FirstOrDefault().ObjectToInt(0);
|
||||
if (goodsTypeId > 0) @where = @where.And(p => p.goodsTypeId == goodsTypeId);
|
||||
|
||||
@@ -25,6 +25,7 @@ using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.DTO;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -195,16 +196,9 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
className = category.name;
|
||||
}
|
||||
|
||||
var childs = await _goodsCategoryServices.QueryListByClauseAsync(p => p.parentId == catId, p => p.sort, OrderByType.Asc, true, true);
|
||||
if (childs.Any())
|
||||
{
|
||||
var ids = childs.Select(p => p.id).ToList();
|
||||
where = where.And(p => ids.Contains(p.goodsCategoryId) || p.goodsCategoryId == catId);
|
||||
}
|
||||
else
|
||||
{
|
||||
where = where.And(p => p.goodsCategoryId == catId);
|
||||
}
|
||||
var categories = await _goodsCategoryServices.QueryAsync(true, true);
|
||||
var ids = GoodsHelper.GetChildIds(categories, catId);
|
||||
where = where.And(p => ids.Contains(p.goodsCategoryId));
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(obj.brandId))
|
||||
|
||||
Reference in New Issue
Block a user