diff --git a/CoreCms.Net.Configuration/GlobalEnumVars.cs b/CoreCms.Net.Configuration/GlobalEnumVars.cs
index 5984c32b..e4cfb621 100644
--- a/CoreCms.Net.Configuration/GlobalEnumVars.cs
+++ b/CoreCms.Net.Configuration/GlobalEnumVars.cs
@@ -1485,6 +1485,54 @@ namespace CoreCms.Net.Configuration
Detail = 2,
}
+ ///
+ /// 获取商品列表的type类型
+ ///
+ public enum SearchGoodType
+ {
+ ///
+ /// 新品
+ ///
+ [Description("新品")]
+ New = 1,
+
+ ///
+ /// 评论数
+ ///
+ [Description("评论数")]
+ Comment = 2,
+
+ ///
+ /// 销量
+ ///
+ [Description("销量")]
+ Sales = 3,
+
+ ///
+ /// 价格
+ ///
+ [Description("价格")]
+ Price = 4,
+
+ ///
+ /// 推荐
+ ///
+ [Description("推荐")]
+ Recommend = 5,
+
+ ///
+ /// 特价优惠
+ ///
+ [Description("特价优惠")]
+ Discounts = 6,
+
+ ///
+ /// 综合销量(初始销量+真实销量)
+ ///
+ [Description("综合销量")]
+ CombinedSalesVolume = 7,
+
+ }
#endregion
diff --git a/CoreCms.Net.DTO/ComponentsDTO/GoodListDTO.cs b/CoreCms.Net.DTO/ComponentsDTO/GoodListDTO.cs
index 94a59479..bdcab540 100644
--- a/CoreCms.Net.DTO/ComponentsDTO/GoodListDTO.cs
+++ b/CoreCms.Net.DTO/ComponentsDTO/GoodListDTO.cs
@@ -14,6 +14,10 @@ namespace CoreCms.Net.DTO.ComponentsDTO
///
public class GoodListDTO
{
+ public GoodListDTO()
+ {
+ }
+
///
/// 商品ID
///
@@ -146,5 +150,10 @@ namespace CoreCms.Net.DTO.ComponentsDTO
public System.Int32 stock { get; set; }
+ ///
+ /// 是否参与营销(优惠券,满减,秒杀,团购)
+ ///
+ public bool isInActivity { get; set; }
+
}
}
diff --git a/CoreCms.Net.IRepository/Good/ICoreCmsGoodsRepository.cs b/CoreCms.Net.IRepository/Good/ICoreCmsGoodsRepository.cs
index afa44a55..5dadb01a 100644
--- a/CoreCms.Net.IRepository/Good/ICoreCmsGoodsRepository.cs
+++ b/CoreCms.Net.IRepository/Good/ICoreCmsGoodsRepository.cs
@@ -227,5 +227,21 @@ namespace CoreCms.Net.IRepository
Task> QueryListByComponentsAsync(Expression> predicate, int take, string orderByType = "", bool blUseNoLock = false,
bool isDataCache = false, int cacheTimes = int.MaxValue);
+
+ ///
+ /// 根据类型获取商品数据(用于PC,H5)
+ ///
+ /// 条件表达式树
+ /// 获取数量
+ /// 排序字段
+ /// 排序顺序
+ /// 是否使用WITH(NOLOCK)
+ /// 是否缓存
+ /// 缓存时间(分钟)
+ ///
+ Task> QueryListByTypeAsync(Expression> predicate, int take,
+ Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false,
+ bool isDataCache = false, int cacheTimes = int.MaxValue);
+
}
}
\ No newline at end of file
diff --git a/CoreCms.Net.IServices/Good/ICoreCmsGoodsServices.cs b/CoreCms.Net.IServices/Good/ICoreCmsGoodsServices.cs
index d0429daf..0fce15bb 100644
--- a/CoreCms.Net.IServices/Good/ICoreCmsGoodsServices.cs
+++ b/CoreCms.Net.IServices/Good/ICoreCmsGoodsServices.cs
@@ -317,5 +317,21 @@ namespace CoreCms.Net.IServices
Task> QueryListByComponentsAsync(Expression> predicate, int take, string orderByType = "", bool blUseNoLock = false,
bool isDataCache = false, int cacheTimes = int.MaxValue);
+
+ ///
+ /// 根据类型获取商品数据(用于PC,H5)
+ ///
+ /// 条件表达式树
+ /// 获取数量
+ /// 排序字段
+ /// 排序顺序
+ /// 是否使用WITH(NOLOCK)
+ /// 是否缓存
+ /// 缓存时间(分钟)
+ ///
+ Task> QueryListByTypeAsync(Expression> predicate, int take,
+ Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false,
+ bool isDataCache = false, int cacheTimes = int.MaxValue);
+
}
}
\ No newline at end of file
diff --git a/CoreCms.Net.Model/FromBody/FMGoods.cs b/CoreCms.Net.Model/FromBody/FMGoods.cs
index 01e81b40..c29e4f6c 100644
--- a/CoreCms.Net.Model/FromBody/FMGoods.cs
+++ b/CoreCms.Net.Model/FromBody/FMGoods.cs
@@ -10,6 +10,7 @@
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
using CoreCms.Net.Model.Entities;
namespace CoreCms.Net.Model.FromBody
@@ -120,4 +121,30 @@ namespace CoreCms.Net.Model.FromBody
public string type { get; set; }
public int groupId { get; set; } = 0;
}
+
+
+ ///
+ /// 根据不同类型获取商品提交参数
+ ///
+ public class FMGetGoodByType
+ {
+ ///
+ /// 类型
+ ///
+ [Required(ErrorMessage = "请输入类型")]
+ public int type { get; set; }
+
+ ///
+ /// 数量
+ ///
+ [Required(ErrorMessage = "请输入数量")]
+ public int num { get; set; } = 0;
+
+ ///
+ /// 排序方式
+ ///
+ [Required(ErrorMessage = "请输入排序方式")]
+ public string orderby { get; set; }
+ }
+
}
\ No newline at end of file
diff --git a/CoreCms.Net.Repository/Good/CoreCmsGoodsRepository.cs b/CoreCms.Net.Repository/Good/CoreCmsGoodsRepository.cs
index a977ce07..2d51dba3 100644
--- a/CoreCms.Net.Repository/Good/CoreCmsGoodsRepository.cs
+++ b/CoreCms.Net.Repository/Good/CoreCmsGoodsRepository.cs
@@ -2364,5 +2364,116 @@ namespace CoreCms.Net.Repository
}
#endregion
+
+ #region 根据类型获取商品数据(用于PC,H5)
+
+ ///
+ /// 根据类型获取商品数据(用于PC,H5)
+ ///
+ /// 条件表达式树
+ /// 获取数量
+ /// 排序字段
+ /// 排序顺序
+ /// 是否使用WITH(NOLOCK)
+ /// 是否缓存
+ /// 缓存时间(分钟)
+ ///
+ public async Task> QueryListByTypeAsync(Expression> predicate, int take,
+ Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue)
+ {
+ List page;
+ if (blUseNoLock)
+ {
+ page = await DbClient.Queryable((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()
+ .LeftJoin((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().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((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()
+ .LeftJoin((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().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
+
}
}
diff --git a/CoreCms.Net.Services/Good/CoreCmsGoodsServices.cs b/CoreCms.Net.Services/Good/CoreCmsGoodsServices.cs
index 20de0531..aaf752c5 100644
--- a/CoreCms.Net.Services/Good/CoreCmsGoodsServices.cs
+++ b/CoreCms.Net.Services/Good/CoreCmsGoodsServices.cs
@@ -1014,7 +1014,7 @@ namespace CoreCms.Net.Services
string orderBy = "", int pageIndex = 1, int pageSize = 20, bool blUseNoLock = false)
{
return await _dal.QueryPageByDTOAsync(predicate, orderBy, pageIndex, pageSize, blUseNoLock);
- }
+ }
#endregion
///
@@ -1118,5 +1118,20 @@ namespace CoreCms.Net.Services
}
+ ///
+ /// 根据类型获取商品数据(用于PC,H5)
+ ///
+ /// 条件表达式树
+ /// 获取数量
+ /// 排序字段
+ /// 排序顺序
+ /// 是否使用WITH(NOLOCK)
+ /// 是否缓存
+ /// 缓存时间(分钟)
+ public async Task> QueryListByTypeAsync(Expression> predicate, int take, Expression> orderByPredicate, OrderByType orderByType,
+ bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue)
+ {
+ return await _dal.QueryListByTypeAsync(predicate, take, orderByPredicate, orderByType, blUseNoLock, isDataCache, cacheTimes);
+ }
}
}
diff --git a/CoreCms.Net.Web.WebApi/Controllers/GoodController.cs b/CoreCms.Net.Web.WebApi/Controllers/GoodController.cs
index 89dd412b..36a17cd8 100644
--- a/CoreCms.Net.Web.WebApi/Controllers/GoodController.cs
+++ b/CoreCms.Net.Web.WebApi/Controllers/GoodController.cs
@@ -448,6 +448,52 @@ namespace CoreCms.Net.Web.WebApi.Controllers
#endregion
+ #region 根据不同类型获取不同商品数据==================================================
+ ///
+ /// 根据不同类型获取不同商品数据
+ ///
+ ///
+ [HttpPost]
+ public async Task GetGoodsByType([FromBody] FMGetGoodByType entity)
+ {
+ var list = new List();
+
+ 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======================================================================
///