diff --git a/ARW.Model/Dto/Api/GoodsManager/GoodsComments/GoodsCommentApiDto.cs b/ARW.Model/Dto/Api/GoodsManager/GoodsComments/GoodsCommentApiDto.cs index 248ab58..2ffb2f5 100644 --- a/ARW.Model/Dto/Api/GoodsManager/GoodsComments/GoodsCommentApiDto.cs +++ b/ARW.Model/Dto/Api/GoodsManager/GoodsComments/GoodsCommentApiDto.cs @@ -19,7 +19,9 @@ namespace ARW.Model.Dto.Api.GoodsManager.GoodsComments [Required(ErrorMessage = "商品Id不能为空")] public long SpuId { get; set; } - public int? GoodsCommentRatingType { get; set; } + public int CommentLevel { get; set; } + + public bool HasImage { get; set; } } diff --git a/ARW.Service/Api/BusinessService/GoodsManager/GoodsComments/GoodsCommentServiceApi.cs b/ARW.Service/Api/BusinessService/GoodsManager/GoodsComments/GoodsCommentServiceApi.cs index 59bbb50..3a7b66a 100644 --- a/ARW.Service/Api/BusinessService/GoodsManager/GoodsComments/GoodsCommentServiceApi.cs +++ b/ARW.Service/Api/BusinessService/GoodsManager/GoodsComments/GoodsCommentServiceApi.cs @@ -52,14 +52,15 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.GoodsComments predicate = predicate.AndIF(parm.ShopGuid != null, s => s.ShopGuid == parm.ShopGuid); predicate = predicate.AndIF(parm.SpuId != 0, s => s.GoodsGuid == parm.SpuId); - predicate = predicate.AndIF(parm.GoodsCommentRatingType != null, s => s.GoodsCommentRatingType == parm.GoodsCommentRatingType); + predicate = predicate.AndIF(parm.CommentLevel != 0, s => s.GoodsCommentRatingType == parm.CommentLevel); + predicate = predicate.AndIF(parm.HasImage == true, s => s.GoodsCommentImages != "" && s.GoodsCommentImages != null); var query = _GoodsCommentRepository .Queryable() .LeftJoin((s, c) => s.ShopGuid == c.ShopGuid) .LeftJoin((s, c, d) => s.GoodsGuid == d.GoodsGuid) .LeftJoin((s, c, d, f) => s.CustomerGuid == f.CustomerGuid) .Where(predicate.ToExpression()) - .OrderBy(s => s.GoodsCommentSort, OrderByType.Desc) + .OrderBy(s => s.GoodsCommentSort, OrderByType.Asc) .Select((s, c, d, f) => new GoodsCommentVoApi { Uid = s.GoodsCommentId, @@ -120,7 +121,7 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.GoodsComments /// /// /// - public async Task GetGoodsDetailsComments(GoodsCommentDtoApi parm) + public async Task> GetGoodsDetailsComments(GoodsCommentDtoApi parm) { var query = _GoodsCommentRepository @@ -143,7 +144,7 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.GoodsComments GoodsDetailInfo = "", }).Take(1); - return await query.ToJsonAsync(); + return await query.ToListAsync(); } @@ -158,7 +159,7 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.GoodsComments var query = _GoodsCommentRepository .Queryable() .Select((s) => new GoodsCommentCountApiVo - { + { CommentCount = SqlFunc.Subqueryable().Where(s => s.GoodsGuid == parm.SpuId).Count(), BadCount = SqlFunc.Subqueryable().Where(s => s.GoodsCommentRatingType == 3 && s.GoodsGuid == parm.SpuId).Count(), MiddleCount = SqlFunc.Subqueryable().Where(s => s.GoodsCommentRatingType == 2 && s.GoodsGuid == parm.SpuId).Count(), @@ -167,7 +168,13 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.GoodsComments }); var res = await query.FirstAsync(); - res.GoodRate = Math.Round((decimal)res.GoodCount / res.CommentCount, 4) * 100; + if (res != null) + { + if (res.GoodCount > 0) + { + res.GoodRate = Math.Round((decimal)res.GoodCount / res.CommentCount, 4) * 100; + } + } return res; } diff --git a/ARW.Service/Api/IBusinessService/GoodsManager/GoodsComments/IGoodsCommentServiceApi.cs b/ARW.Service/Api/IBusinessService/GoodsManager/GoodsComments/IGoodsCommentServiceApi.cs index 502f71f..d07651d 100644 --- a/ARW.Service/Api/IBusinessService/GoodsManager/GoodsComments/IGoodsCommentServiceApi.cs +++ b/ARW.Service/Api/IBusinessService/GoodsManager/GoodsComments/IGoodsCommentServiceApi.cs @@ -30,7 +30,7 @@ namespace ARW.Service.Api.IBusinessService.GoodsManager.GoodsComments /// /// /// - Task GetGoodsDetailsComments(GoodsCommentDtoApi parm); + Task> GetGoodsDetailsComments(GoodsCommentDtoApi parm); /// diff --git a/ARW.WebApi/Controllers/Api/GoodsManager/GoodsComments/GoodsCommentApiController.cs b/ARW.WebApi/Controllers/Api/GoodsManager/GoodsComments/GoodsCommentApiController.cs index 164eb36..e6ae4c7 100644 --- a/ARW.WebApi/Controllers/Api/GoodsManager/GoodsComments/GoodsCommentApiController.cs +++ b/ARW.WebApi/Controllers/Api/GoodsManager/GoodsComments/GoodsCommentApiController.cs @@ -63,18 +63,7 @@ namespace ARW.WebApi.Controllers.Api.GoodsManager.GoodsComments //if (parm == null) throw new CustomException("参数错误!"); var res = await _GoodsCommentServiceApi.GetGoodsDetailsComments(parm); - - if (res != "[]") - { - res = res.Remove(0, 1); - res = res.Substring(0, res.Length - 1); - var data = res.FromJSON(); - return SUCCESS(data); - } - else - { - return SUCCESS(res); - } + return SUCCESS(res); }