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不能为空")]
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.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<Shop>((s, c) => s.ShopGuid == c.ShopGuid)
.LeftJoin<Goods>((s, c, d) => s.GoodsGuid == d.GoodsGuid)
.LeftJoin<Customer>((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
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public async Task<string> GetGoodsDetailsComments(GoodsCommentDtoApi parm)
public async Task<List<GoodsCommentVoApi>> 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();
}
@ -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;
}

View File

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

View File

@ -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<GoodsCommentVoApi>();
return SUCCESS(data);
}
else
{
return SUCCESS(res);
}
return SUCCESS(res);
}