mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 17:13:26 +08:00
【新增】新增根据不同类型获取商品的接口。类型包含(新品,评论数,销量,价格,推荐,特价优惠,综合销量)
This commit is contained in:
@@ -1485,6 +1485,54 @@ namespace CoreCms.Net.Configuration
|
|||||||
Detail = 2,
|
Detail = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取商品列表的type类型
|
||||||
|
/// </summary>
|
||||||
|
public enum SearchGoodType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 新品
|
||||||
|
/// </summary>
|
||||||
|
[Description("新品")]
|
||||||
|
New = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 评论数
|
||||||
|
/// </summary>
|
||||||
|
[Description("评论数")]
|
||||||
|
Comment = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 销量
|
||||||
|
/// </summary>
|
||||||
|
[Description("销量")]
|
||||||
|
Sales = 3,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 价格
|
||||||
|
/// </summary>
|
||||||
|
[Description("价格")]
|
||||||
|
Price = 4,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 推荐
|
||||||
|
/// </summary>
|
||||||
|
[Description("推荐")]
|
||||||
|
Recommend = 5,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 特价优惠
|
||||||
|
/// </summary>
|
||||||
|
[Description("特价优惠")]
|
||||||
|
Discounts = 6,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 综合销量(初始销量+真实销量)
|
||||||
|
/// </summary>
|
||||||
|
[Description("综合销量")]
|
||||||
|
CombinedSalesVolume = 7,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ namespace CoreCms.Net.DTO.ComponentsDTO
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class GoodListDTO
|
public class GoodListDTO
|
||||||
{
|
{
|
||||||
|
public GoodListDTO()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 商品ID
|
/// 商品ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -146,5 +150,10 @@ namespace CoreCms.Net.DTO.ComponentsDTO
|
|||||||
public System.Int32 stock { get; set; }
|
public System.Int32 stock { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否参与营销(优惠券,满减,秒杀,团购)
|
||||||
|
/// </summary>
|
||||||
|
public bool isInActivity { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,5 +227,21 @@ namespace CoreCms.Net.IRepository
|
|||||||
Task<List<GoodListDTO>> QueryListByComponentsAsync(Expression<Func<GoodListDTO, bool>> predicate, int take, string orderByType = "", bool blUseNoLock = false,
|
Task<List<GoodListDTO>> QueryListByComponentsAsync(Expression<Func<GoodListDTO, bool>> predicate, int take, string orderByType = "", bool blUseNoLock = false,
|
||||||
bool isDataCache = false, int cacheTimes = int.MaxValue);
|
bool isDataCache = false, int cacheTimes = int.MaxValue);
|
||||||
|
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -317,5 +317,21 @@ namespace CoreCms.Net.IServices
|
|||||||
Task<List<GoodListDTO>> QueryListByComponentsAsync(Expression<Func<GoodListDTO, bool>> predicate, int take, string orderByType = "", bool blUseNoLock = false,
|
Task<List<GoodListDTO>> QueryListByComponentsAsync(Expression<Func<GoodListDTO, bool>> predicate, int take, string orderByType = "", bool blUseNoLock = false,
|
||||||
bool isDataCache = false, int cacheTimes = int.MaxValue);
|
bool isDataCache = false, int cacheTimes = int.MaxValue);
|
||||||
|
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
using CoreCms.Net.Model.Entities;
|
using CoreCms.Net.Model.Entities;
|
||||||
|
|
||||||
namespace CoreCms.Net.Model.FromBody
|
namespace CoreCms.Net.Model.FromBody
|
||||||
@@ -120,4 +121,30 @@ namespace CoreCms.Net.Model.FromBody
|
|||||||
public string type { get; set; }
|
public string type { get; set; }
|
||||||
public int groupId { get; set; } = 0;
|
public int groupId { get; set; } = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据不同类型获取商品提交参数
|
||||||
|
/// </summary>
|
||||||
|
public class FMGetGoodByType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 类型
|
||||||
|
/// </summary>
|
||||||
|
[Required(ErrorMessage = "请输入类型")]
|
||||||
|
public int type { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数量
|
||||||
|
/// </summary>
|
||||||
|
[Required(ErrorMessage = "请输入数量")]
|
||||||
|
public int num { get; set; } = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 排序方式
|
||||||
|
/// </summary>
|
||||||
|
[Required(ErrorMessage = "请输入排序方式")]
|
||||||
|
public string orderby { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2364,5 +2364,116 @@ namespace CoreCms.Net.Repository
|
|||||||
}
|
}
|
||||||
#endregion
|
#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
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1014,7 +1014,7 @@ namespace CoreCms.Net.Services
|
|||||||
string orderBy = "", int pageIndex = 1, int pageSize = 20, bool blUseNoLock = false)
|
string orderBy = "", int pageIndex = 1, int pageSize = 20, bool blUseNoLock = false)
|
||||||
{
|
{
|
||||||
return await _dal.QueryPageByDTOAsync(predicate, orderBy, pageIndex, pageSize, blUseNoLock);
|
return await _dal.QueryPageByDTOAsync(predicate, orderBy, pageIndex, pageSize, blUseNoLock);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1118,5 +1118,20 @@ namespace CoreCms.Net.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
return await _dal.QueryListByTypeAsync(predicate, take, orderByPredicate, orderByType, blUseNoLock, isDataCache, cacheTimes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -448,6 +448,52 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 根据不同类型获取不同商品数据==================================================
|
||||||
|
/// <summary>
|
||||||
|
/// 根据不同类型获取不同商品数据
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<WebApiCallBack> GetGoodsByType([FromBody] FMGetGoodByType entity)
|
||||||
|
{
|
||||||
|
var list = new List<GoodListDTO>();
|
||||||
|
|
||||||
|
var orderBy = entity.orderby switch
|
||||||
|
{
|
||||||
|
"asc" => OrderByType.Asc,
|
||||||
|
"desc" => OrderByType.Desc,
|
||||||
|
_ => OrderByType.Desc
|
||||||
|
};
|
||||||
|
|
||||||
|
list = entity.type switch
|
||||||
|
{
|
||||||
|
//新品
|
||||||
|
(int)GlobalEnumVars.SearchGoodType.New => await _goodsServices.QueryListByTypeAsync(p => p.id > 0, entity.num, p => p.createTime, orderBy, true, true, 20),
|
||||||
|
//评论数
|
||||||
|
(int)GlobalEnumVars.SearchGoodType.Comment => await _goodsServices.QueryListByTypeAsync(p => p.id > 0, entity.num, p => p.commentsCount, orderBy, true, true, 20),
|
||||||
|
//销量
|
||||||
|
(int)GlobalEnumVars.SearchGoodType.Sales => await _goodsServices.QueryListByTypeAsync(p => p.id > 0, entity.num, p => p.buyCount, orderBy, true, true, 20),
|
||||||
|
//价格
|
||||||
|
(int)GlobalEnumVars.SearchGoodType.Price => await _goodsServices.QueryListByTypeAsync(p => p.id > 0, entity.num, p => p.buyCount, orderBy, true, true, 20),
|
||||||
|
//是否推荐
|
||||||
|
(int)GlobalEnumVars.SearchGoodType.Recommend => await _goodsServices.QueryListByTypeAsync(p => p.id > 0, entity.num, p => p.isRecommend, orderBy, true, true, 20),
|
||||||
|
//是否参与优惠
|
||||||
|
(int)GlobalEnumVars.SearchGoodType.Discounts => await _goodsServices.QueryListByTypeAsync(p => p.id > 0, entity.num, p => p.isInActivity, orderBy, true, true, 20),
|
||||||
|
//综合销量
|
||||||
|
(int)GlobalEnumVars.SearchGoodType.CombinedSalesVolume => await _goodsServices.QueryListByTypeAsync(p => p.id > 0, entity.num, p => p.initialSales, orderBy, true, true, 20),
|
||||||
|
_ => await _goodsServices.QueryListByTypeAsync(p => p.id > 0, entity.num, p => p.createTime, orderBy, true, true, 20)
|
||||||
|
};
|
||||||
|
|
||||||
|
var jm = new WebApiCallBack()
|
||||||
|
{
|
||||||
|
status = true,
|
||||||
|
code = 0,
|
||||||
|
msg = "获取成功",
|
||||||
|
data = list
|
||||||
|
};
|
||||||
|
return jm;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region 获取商品sku======================================================================
|
#region 获取商品sku======================================================================
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user