186 lines
7.5 KiB
C#
186 lines
7.5 KiB
C#
using Infrastructure.Attribute;
|
|
using Microsoft.AspNetCore.Http;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ARW.Model;
|
|
using ARW.Repository;
|
|
using ARW.Repository.Business.GoodsManager.GoodsComments;
|
|
using ARW.Service.Api.IBusinessService.GoodsManager.GoodsComments;
|
|
using ARW.Model.Dto.Api.GoodsManager.GoodsComments;
|
|
using ARW.Model.Models.Business.GoodsManager.GoodsComments;
|
|
using ARW.Model.Vo.Api.GoodsManager.GoodsComments;
|
|
using ARW.Model.Models.Business.Custom.Customers;
|
|
using ARW.Model.Models.Business.GoodsManager.Goodss;
|
|
using ARW.Model.Models.Business.ShopManager.Shops;
|
|
using System.IO;
|
|
using ARW.Model.System;
|
|
|
|
namespace ARW.Service.Api.BusinessService.GoodsManager.GoodsComments
|
|
{
|
|
/// <summary>
|
|
/// 商品评价接口实现类Api
|
|
///
|
|
/// @author admin
|
|
/// @date 2023-07-17
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IGoodsCommentServiceApi), ServiceLifetime = LifeTime.Transient)]
|
|
public class GoodsCommentServiceImplApi : BaseService<GoodsComment>, IGoodsCommentServiceApi
|
|
{
|
|
private readonly GoodsCommentRepository _GoodsCommentRepository;
|
|
|
|
public GoodsCommentServiceImplApi(GoodsCommentRepository GoodsCommentRepository)
|
|
{
|
|
this._GoodsCommentRepository = GoodsCommentRepository;
|
|
}
|
|
|
|
#region Api接口代码
|
|
|
|
|
|
/// <summary>
|
|
/// 查询商品评价列表(Api)
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public async Task<PagedInfo<GoodsCommentVoApi>> GetGoodsCommentListApi(GoodsCommentQueryDtoApi parm)
|
|
{
|
|
//开始拼装查询条件d
|
|
var predicate = Expressionable.Create<GoodsComment>();
|
|
|
|
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.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.Asc)
|
|
.Select((s, c, d, f) => new GoodsCommentVoApi
|
|
{
|
|
Uid = s.GoodsCommentId,
|
|
SpuId = s.GoodsGuid,
|
|
CommentScore = s.GoodsCommentRating,
|
|
CommentContent = s.GoodsCommentContent,
|
|
GoodsCommentImages = s.GoodsCommentImages,
|
|
UserName = f.CustomerNickname,
|
|
UserHeadUrl = f.CustomerAvatar,
|
|
SellerReply = s.GoodsCommentRecoverContent,
|
|
GoodsDetailInfo = "",
|
|
CommentTime = s.Create_time.ToString("yyyy/MM/dd HH:mm"),
|
|
});
|
|
|
|
|
|
var list = await query.ToPageAsync(parm);
|
|
|
|
foreach (var item in list.Result)
|
|
{
|
|
if (!string.IsNullOrEmpty(item.GoodsCommentImages))
|
|
{
|
|
var imagesList = item.GoodsCommentImages.Split(',');
|
|
var resourcesList = new List<ResourcesItem>();
|
|
foreach (var image in imagesList)
|
|
{
|
|
var resourcesItem = new ResourcesItem
|
|
{
|
|
Src = image,
|
|
Type = "",
|
|
CoverSrc = ""
|
|
};
|
|
|
|
string extension = Path.GetExtension(image).ToLower();
|
|
|
|
if (extension == ".mp4" || extension == ".avi")
|
|
{
|
|
resourcesItem.Type = "video";
|
|
// 解析视频封面并赋值给 CoverSrc
|
|
// 你可以根据具体需求调用相应的方法来获取视频封面
|
|
//resourcesItem.CoverSrc = GetVideoCover(image);
|
|
}
|
|
else
|
|
{
|
|
resourcesItem.Type = "image";
|
|
}
|
|
|
|
resourcesList.Add(resourcesItem);
|
|
}
|
|
item.CommentResources = resourcesList;
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询商品评价详情(Api)
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public async Task<List<GoodsCommentVoApi>> GetGoodsDetailsComments(GoodsCommentDtoApi parm)
|
|
{
|
|
|
|
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(s => s.GoodsGuid == parm.SpuId)
|
|
.OrderBy(s => s.GoodsCommentSort) // 按 GoodsCommentSort 升序排序
|
|
.Select((s, c, d, f) => new GoodsCommentVoApi
|
|
{
|
|
Uid = s.GoodsCommentId,
|
|
SpuId = s.GoodsGuid,
|
|
CommentScore = s.GoodsCommentRating,
|
|
CommentContent = s.GoodsCommentContent,
|
|
GoodsCommentImages = s.GoodsCommentImages,
|
|
UserName = f.CustomerNickname,
|
|
UserHeadUrl = f.CustomerAvatar,
|
|
SellerReply = s.GoodsCommentRecoverContent,
|
|
GoodsDetailInfo = "",
|
|
}).Take(1);
|
|
|
|
return await query.ToListAsync();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取商品详情页评论数(Api)
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public async Task<GoodsCommentCountApiVo> GetGoodsDetailsCommentsCount(GoodsCommentDtoApi parm)
|
|
{
|
|
|
|
var query = _GoodsCommentRepository
|
|
.Queryable()
|
|
.Select((s) => new GoodsCommentCountApiVo
|
|
{
|
|
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(),
|
|
MiddleCount = SqlFunc.Subqueryable<GoodsComment>().Where(s => s.GoodsCommentRatingType == 2 && s.GoodsGuid == parm.SpuId).Count(),
|
|
GoodCount = SqlFunc.Subqueryable<GoodsComment>().Where(s => s.GoodsCommentRatingType == 1 && s.GoodsGuid == parm.SpuId).Count(),
|
|
HasImageCount = SqlFunc.Subqueryable<GoodsComment>().Where(s => s.GoodsCommentImages != "" && s.GoodsCommentImages != null && s.GoodsGuid == parm.SpuId).Count()
|
|
});
|
|
|
|
var res = await query.FirstAsync();
|
|
if (res != null)
|
|
{
|
|
if (res.GoodCount > 0)
|
|
{
|
|
res.GoodRate = Math.Round((decimal)res.GoodCount / res.CommentCount, 4) * 100;
|
|
}
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|