mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 21:03:26 +08:00
【优化】优化推荐商品的计算规则,使每次推荐商品的数据进行随机处理,展示不同推荐商品。
This commit is contained in:
@@ -901,54 +901,18 @@ namespace CoreCms.Net.Repository
|
||||
|
||||
if (isRecommend)
|
||||
{
|
||||
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()
|
||||
{
|
||||
id = good.id,
|
||||
name = good.name,
|
||||
brief = good.brief,
|
||||
image = !SqlFunc.IsNullOrEmpty(good.image) ? good.image : EmptyOrNullImagePath.GoodImage,
|
||||
video = good.video,
|
||||
goodsCategoryId = good.goodsCategoryId,
|
||||
goodsTypeId = good.goodsTypeId,
|
||||
brandId = good.brandId,
|
||||
isNomalVirtual = good.isNomalVirtual,
|
||||
unit = good.unit,
|
||||
commentsCount = good.commentsCount,
|
||||
viewCount = good.viewCount,
|
||||
buyCount = SqlFunc.Subqueryable<CoreCmsOrderItem>()
|
||||
.LeftJoin<CoreCmsOrder>((sOrderItem, sOrder) => sOrder.orderId == sOrderItem.orderId)
|
||||
.Where((sOrderItem, sOrder) => sOrderItem.goodsId == good.id && (sOrder.payStatus == (int)GlobalEnumVars.OrderPayStatus.Yes || sOrder.payStatus == (int)GlobalEnumVars.OrderPayStatus.PartialYes))
|
||||
.Sum(p => p.nums),
|
||||
sort = good.sort,
|
||||
labelIds = good.labelIds,
|
||||
createTime = good.createTime,
|
||||
isRecommend = good.isRecommend,
|
||||
isHot = good.isHot,
|
||||
price = pd.price,
|
||||
mktprice = pd.mktprice,
|
||||
stock = pd.stock,
|
||||
pointsDeduction = pd.pointsDeduction,
|
||||
points = pd.points,
|
||||
weight = pd.weight,
|
||||
initialSales = good.initialSales,
|
||||
})
|
||||
.MergeTable()
|
||||
.OrderBy(p => p.createTime, OrderByType.Desc)
|
||||
.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var ids = await DbClient.Queryable<CoreCmsGoods>().Where(p => p.isDel == false && p.isMarketable == true)
|
||||
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())
|
||||
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())
|
||||
@@ -956,39 +920,97 @@ namespace CoreCms.Net.Repository
|
||||
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,
|
||||
brief = good.brief,
|
||||
image = !SqlFunc.IsNullOrEmpty(good.image) ? good.image : EmptyOrNullImagePath.GoodImage,
|
||||
video = good.video,
|
||||
goodsCategoryId = good.goodsCategoryId,
|
||||
goodsTypeId = good.goodsTypeId,
|
||||
brandId = good.brandId,
|
||||
isNomalVirtual = good.isNomalVirtual,
|
||||
unit = good.unit,
|
||||
commentsCount = good.commentsCount,
|
||||
viewCount = good.viewCount,
|
||||
buyCount = SqlFunc.Subqueryable<CoreCmsOrderItem>()
|
||||
.LeftJoin<CoreCmsOrder>((sOrderItem, sOrder) => sOrder.orderId == sOrderItem.orderId)
|
||||
.Where((sOrderItem, sOrder) => sOrderItem.goodsId == good.id && (sOrder.payStatus == (int)GlobalEnumVars.OrderPayStatus.Yes || sOrder.payStatus == (int)GlobalEnumVars.OrderPayStatus.PartialYes))
|
||||
.Sum(p => p.nums),
|
||||
sort = good.sort,
|
||||
labelIds = good.labelIds,
|
||||
createTime = good.createTime,
|
||||
isRecommend = good.isRecommend,
|
||||
isHot = good.isHot,
|
||||
price = pd.price,
|
||||
mktprice = pd.mktprice,
|
||||
stock = pd.stock,
|
||||
pointsDeduction = pd.pointsDeduction,
|
||||
points = pd.points,
|
||||
weight = pd.weight,
|
||||
initialSales = good.initialSales,
|
||||
})
|
||||
.MergeTable()
|
||||
.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()) return list;
|
||||
{
|
||||
for (int i = 0; i < number; i++)
|
||||
{
|
||||
var id = GetRandomNumber(ids);
|
||||
while (dbIds.Contains(id))//判断集合中有没有生成的随机数,如果有,则重新生成一个随机数,直到生成的随机数list集合中没有才退出循环
|
||||
{
|
||||
id = good.id,
|
||||
name = good.name,
|
||||
brief = good.brief,
|
||||
image = !SqlFunc.IsNullOrEmpty(good.image) ? good.image : EmptyOrNullImagePath.GoodImage,
|
||||
video = good.video,
|
||||
goodsCategoryId = good.goodsCategoryId,
|
||||
goodsTypeId = good.goodsTypeId,
|
||||
brandId = good.brandId,
|
||||
isNomalVirtual = good.isNomalVirtual,
|
||||
unit = good.unit,
|
||||
commentsCount = good.commentsCount,
|
||||
viewCount = good.viewCount,
|
||||
buyCount = SqlFunc.Subqueryable<CoreCmsOrderItem>()
|
||||
.LeftJoin<CoreCmsOrder>((sOrderItem, sOrder) => sOrder.orderId == sOrderItem.orderId)
|
||||
.Where((sOrderItem, sOrder) => sOrderItem.goodsId == good.id && (sOrder.payStatus == (int)GlobalEnumVars.OrderPayStatus.Yes || sOrder.payStatus == (int)GlobalEnumVars.OrderPayStatus.PartialYes))
|
||||
.Sum(p => p.nums),
|
||||
sort = good.sort,
|
||||
labelIds = good.labelIds,
|
||||
createTime = good.createTime,
|
||||
isRecommend = good.isRecommend,
|
||||
isHot = good.isHot,
|
||||
price = pd.price,
|
||||
mktprice = pd.mktprice,
|
||||
stock = pd.stock,
|
||||
pointsDeduction = pd.pointsDeduction,
|
||||
points = pd.points,
|
||||
weight = pd.weight,
|
||||
initialSales = good.initialSales,
|
||||
})
|
||||
.MergeTable()
|
||||
.Where(p => dbIds.Contains(p.id)).ToListAsync();
|
||||
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
|
||||
{
|
||||
id = good.id,
|
||||
name = good.name,
|
||||
brief = good.brief,
|
||||
image = !SqlFunc.IsNullOrEmpty(good.image) ? good.image : EmptyOrNullImagePath.GoodImage,
|
||||
video = good.video,
|
||||
goodsCategoryId = good.goodsCategoryId,
|
||||
goodsTypeId = good.goodsTypeId,
|
||||
brandId = good.brandId,
|
||||
isNomalVirtual = good.isNomalVirtual,
|
||||
unit = good.unit,
|
||||
commentsCount = good.commentsCount,
|
||||
viewCount = good.viewCount,
|
||||
buyCount = SqlFunc.Subqueryable<CoreCmsOrderItem>()
|
||||
.LeftJoin<CoreCmsOrder>((sOrderItem, sOrder) => sOrder.orderId == sOrderItem.orderId)
|
||||
.Where((sOrderItem, sOrder) => sOrderItem.goodsId == good.id && (sOrder.payStatus == (int)GlobalEnumVars.OrderPayStatus.Yes || sOrder.payStatus == (int)GlobalEnumVars.OrderPayStatus.PartialYes))
|
||||
.Sum(p => p.nums),
|
||||
sort = good.sort,
|
||||
labelIds = good.labelIds,
|
||||
createTime = good.createTime,
|
||||
isRecommend = good.isRecommend,
|
||||
isHot = good.isHot,
|
||||
price = pd.price,
|
||||
mktprice = pd.mktprice,
|
||||
stock = pd.stock,
|
||||
pointsDeduction = pd.pointsDeduction,
|
||||
points = pd.points,
|
||||
weight = pd.weight,
|
||||
initialSales = good.initialSales,
|
||||
})
|
||||
.MergeTable()
|
||||
.Where(p => dbIds.Contains(p.id)).ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user