mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 17:43:26 +08:00
【优化】优化推荐商品的计算规则,使每次推荐商品的数据进行随机处理,展示不同推荐商品。
This commit is contained in:
@@ -900,11 +900,27 @@ namespace CoreCms.Net.Repository
|
||||
var list = new List<GoodListDTO>();
|
||||
|
||||
if (isRecommend)
|
||||
{
|
||||
var ids = await DbClient.Queryable<CoreCmsGoods>().Where(p => p.isDel == false && p.isMarketable == true && p.isRecommend == true)
|
||||
.Select(p => p.id).ToArrayAsync();
|
||||
var dbIds = new List<int>();
|
||||
if (!ids.Any()) return list;
|
||||
{
|
||||
for (int i = 0; i < number; i++)
|
||||
{
|
||||
var id = GetRandomNumber(ids);
|
||||
while (dbIds.Contains(id))//判断集合中有没有生成的随机数,如果有,则重新生成一个随机数,直到生成的随机数list集合中没有才退出循环
|
||||
{
|
||||
id = GetRandomNumber(ids);
|
||||
}
|
||||
dbIds.Add(id);
|
||||
}
|
||||
if (dbIds.Any())
|
||||
{
|
||||
list = await DbClient.Queryable<CoreCmsGoods, CoreCmsProducts>((good, pd) => new JoinQueryInfos(
|
||||
JoinType.Left, good.id == pd.goodsId))
|
||||
.Where((good, pd) => pd.isDefalut == true && pd.isDel == false && good.isRecommend == true && good.isDel == false && good.isMarketable == true)
|
||||
.Select((good, pd) => new GoodListDTO()
|
||||
.Select((good, pd) => new GoodListDTO
|
||||
{
|
||||
id = good.id,
|
||||
name = good.name,
|
||||
@@ -936,19 +952,25 @@ namespace CoreCms.Net.Repository
|
||||
initialSales = good.initialSales,
|
||||
})
|
||||
.MergeTable()
|
||||
.OrderBy(p => p.createTime, OrderByType.Desc)
|
||||
.ToListAsync();
|
||||
.Where(p => dbIds.Contains(p.id)).ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var ids = await DbClient.Queryable<CoreCmsGoods>().Where(p => p.isDel == false && p.isMarketable == true)
|
||||
.Select(p => p.id).ToArrayAsync();
|
||||
var dbIds = new List<int>();
|
||||
if (ids.Any())
|
||||
if (!ids.Any()) return list;
|
||||
{
|
||||
for (int i = 0; i < number; i++)
|
||||
{
|
||||
var id = GetRandomNumber(ids);
|
||||
while (dbIds.Contains(id))//判断集合中有没有生成的随机数,如果有,则重新生成一个随机数,直到生成的随机数list集合中没有才退出循环
|
||||
{
|
||||
id = GetRandomNumber(ids);
|
||||
}
|
||||
dbIds.Add(id);
|
||||
}
|
||||
if (dbIds.Any())
|
||||
|
||||
Reference in New Issue
Block a user