mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 17:43:26 +08:00
【新增】新增根据不同类型获取商品的接口。类型包含(新品,评论数,销量,价格,推荐,特价优惠,综合销量)
This commit is contained in:
@@ -2364,5 +2364,116 @@ namespace CoreCms.Net.Repository
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 根据类型获取商品数据(用于PC,H5)
|
||||
|
||||
/// <summary>
|
||||
/// 根据类型获取商品数据(用于PC,H5)
|
||||
/// </summary>
|
||||
/// <param name="predicate">条件表达式树</param>
|
||||
/// <param name="take">获取数量</param>
|
||||
/// <param name="orderByPredicate">排序字段</param>
|
||||
/// <param name="orderByType">排序顺序</param>
|
||||
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
||||
/// <param name="isDataCache">是否缓存</param>
|
||||
/// <param name="cacheTimes">缓存时间(分钟)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<GoodListDTO>> QueryListByTypeAsync(Expression<Func<GoodListDTO, bool>> predicate, int take,
|
||||
Expression<Func<GoodListDTO, object>> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue)
|
||||
{
|
||||
List<GoodListDTO> page;
|
||||
if (blUseNoLock)
|
||||
{
|
||||
page = 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.isMarketable == true && good.isDel == false)
|
||||
.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,
|
||||
isInActivity = SqlFunc.Subqueryable<CoreCmsPromotion>().Where(o => o.parameters.Contains(good.id.ToString())).Any()
|
||||
})
|
||||
.With(SqlWith.NoLock)
|
||||
.MergeTable()
|
||||
.WhereIF(predicate != null, predicate)
|
||||
.OrderByIF(orderByPredicate != null, orderByPredicate, orderByType)
|
||||
.Take(take)
|
||||
.WithCacheIF(isDataCache, cacheTimes)
|
||||
.ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
page = 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.isMarketable == true && good.isDel == false)
|
||||
.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,
|
||||
isInActivity = SqlFunc.Subqueryable<CoreCmsPromotion>().Where(o => o.parameters.Contains(good.id.ToString())).Any()
|
||||
})
|
||||
.MergeTable()
|
||||
.WhereIF(predicate != null, predicate)
|
||||
.OrderByIF(orderByPredicate != null, orderByPredicate, orderByType)
|
||||
.WithCacheIF(isDataCache, cacheTimes)
|
||||
.Take(take).ToListAsync();
|
||||
}
|
||||
return page;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user