feat 添加商品评论对接接口

This commit is contained in:
lwh 2023-07-19 12:20:19 +08:00
parent 14a1dfcd6d
commit cee6867ac7
4 changed files with 18 additions and 20 deletions

View File

@ -19,7 +19,9 @@ namespace ARW.Model.Dto.Api.GoodsManager.GoodsComments
[Required(ErrorMessage = "商品Id不能为空")] [Required(ErrorMessage = "商品Id不能为空")]
public long SpuId { get; set; } public long SpuId { get; set; }
public int? GoodsCommentRatingType { get; set; } public int CommentLevel { get; set; }
public bool HasImage { get; set; }
} }

View File

@ -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.ShopGuid != null, s => s.ShopGuid == parm.ShopGuid);
predicate = predicate.AndIF(parm.SpuId != 0, s => s.GoodsGuid == parm.SpuId); 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 var query = _GoodsCommentRepository
.Queryable() .Queryable()
.LeftJoin<Shop>((s, c) => s.ShopGuid == c.ShopGuid) .LeftJoin<Shop>((s, c) => s.ShopGuid == c.ShopGuid)
.LeftJoin<Goods>((s, c, d) => s.GoodsGuid == d.GoodsGuid) .LeftJoin<Goods>((s, c, d) => s.GoodsGuid == d.GoodsGuid)
.LeftJoin<Customer>((s, c, d, f) => s.CustomerGuid == f.CustomerGuid) .LeftJoin<Customer>((s, c, d, f) => s.CustomerGuid == f.CustomerGuid)
.Where(predicate.ToExpression()) .Where(predicate.ToExpression())
.OrderBy(s => s.GoodsCommentSort, OrderByType.Desc) .OrderBy(s => s.GoodsCommentSort, OrderByType.Asc)
.Select((s, c, d, f) => new GoodsCommentVoApi .Select((s, c, d, f) => new GoodsCommentVoApi
{ {
Uid = s.GoodsCommentId, Uid = s.GoodsCommentId,
@ -120,7 +121,7 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.GoodsComments
/// </summary> /// </summary>
/// <param name="parm"></param> /// <param name="parm"></param>
/// <returns></returns> /// <returns></returns>
public async Task<string> GetGoodsDetailsComments(GoodsCommentDtoApi parm) public async Task<List<GoodsCommentVoApi>> GetGoodsDetailsComments(GoodsCommentDtoApi parm)
{ {
var query = _GoodsCommentRepository var query = _GoodsCommentRepository
@ -143,7 +144,7 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.GoodsComments
GoodsDetailInfo = "", GoodsDetailInfo = "",
}).Take(1); }).Take(1);
return await query.ToJsonAsync(); return await query.ToListAsync();
} }
@ -158,7 +159,7 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.GoodsComments
var query = _GoodsCommentRepository var query = _GoodsCommentRepository
.Queryable() .Queryable()
.Select((s) => new GoodsCommentCountApiVo .Select((s) => new GoodsCommentCountApiVo
{ {
CommentCount = SqlFunc.Subqueryable<GoodsComment>().Where(s => s.GoodsGuid == parm.SpuId).Count(), CommentCount = SqlFunc.Subqueryable<GoodsComment>().Where(s => s.GoodsGuid == parm.SpuId).Count(),
BadCount = SqlFunc.Subqueryable<GoodsComment>().Where(s => s.GoodsCommentRatingType == 3 && s.GoodsGuid == parm.SpuId).Count(), BadCount = SqlFunc.Subqueryable<GoodsComment>().Where(s => s.GoodsCommentRatingType == 3 && s.GoodsGuid == parm.SpuId).Count(),
MiddleCount = SqlFunc.Subqueryable<GoodsComment>().Where(s => s.GoodsCommentRatingType == 2 && s.GoodsGuid == parm.SpuId).Count(), MiddleCount = SqlFunc.Subqueryable<GoodsComment>().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(); 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; return res;
} }

View File

@ -30,7 +30,7 @@ namespace ARW.Service.Api.IBusinessService.GoodsManager.GoodsComments
/// </summary> /// </summary>
/// <param name="parm"></param> /// <param name="parm"></param>
/// <returns></returns> /// <returns></returns>
Task<string> GetGoodsDetailsComments(GoodsCommentDtoApi parm); Task<List<GoodsCommentVoApi>> GetGoodsDetailsComments(GoodsCommentDtoApi parm);
/// <summary> /// <summary>

View File

@ -63,18 +63,7 @@ namespace ARW.WebApi.Controllers.Api.GoodsManager.GoodsComments
//if (parm == null) throw new CustomException("参数错误!"); //if (parm == null) throw new CustomException("参数错误!");
var res = await _GoodsCommentServiceApi.GetGoodsDetailsComments(parm); var res = await _GoodsCommentServiceApi.GetGoodsDetailsComments(parm);
return SUCCESS(res);
if (res != "[]")
{
res = res.Remove(0, 1);
res = res.Substring(0, res.Length - 1);
var data = res.FromJSON<GoodsCommentVoApi>();
return SUCCESS(data);
}
else
{
return SUCCESS(res);
}
} }