From 14a1dfcd6d0eb8b5587154864d590e890704ceab Mon Sep 17 00:00:00 2001 From: lwh <2679599887@qq.com> Date: Tue, 18 Jul 2023 13:15:44 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=AF=84=E4=BB=B7=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GoodsComments/GoodsCommentApiDto.cs | 38 ++++ .../GoodsComments/GoodsCommentApiVo.cs | 101 ++++++++++ .../GoodsComments/GoodsCommentCountApiVo.cs | 50 +++++ .../GoodsComments/GoodsCommentServiceApi.cs | 178 ++++++++++++++++++ .../GoodsComments/IGoodsCommentServiceApi.cs | 44 +++++ .../GoodsCommentApiController.cs | 94 +++++++++ .../wwwroot/CodeGenTemplate/TplServiceApi.txt | 2 +- 7 files changed, 506 insertions(+), 1 deletion(-) create mode 100644 ARW.Model/Dto/Api/GoodsManager/GoodsComments/GoodsCommentApiDto.cs create mode 100644 ARW.Model/Vo/Api/GoodsManager/GoodsComments/GoodsCommentApiVo.cs create mode 100644 ARW.Model/Vo/Api/GoodsManager/GoodsComments/GoodsCommentCountApiVo.cs create mode 100644 ARW.Service/Api/BusinessService/GoodsManager/GoodsComments/GoodsCommentServiceApi.cs create mode 100644 ARW.Service/Api/IBusinessService/GoodsManager/GoodsComments/IGoodsCommentServiceApi.cs create mode 100644 ARW.WebApi/Controllers/Api/GoodsManager/GoodsComments/GoodsCommentApiController.cs diff --git a/ARW.Model/Dto/Api/GoodsManager/GoodsComments/GoodsCommentApiDto.cs b/ARW.Model/Dto/Api/GoodsManager/GoodsComments/GoodsCommentApiDto.cs new file mode 100644 index 0000000..248ab58 --- /dev/null +++ b/ARW.Model/Dto/Api/GoodsManager/GoodsComments/GoodsCommentApiDto.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using ARW.Model.Models.Business.GoodsManager.GoodsComments; + +namespace ARW.Model.Dto.Api.GoodsManager.GoodsComments +{ + + /// + /// 商品评价查询对象Api + /// + /// @author admin + /// @date 2023-07-17 + /// + public class GoodsCommentQueryDtoApi : PagerInfo + { + public long? ShopGuid { get; set; } + + [Required(ErrorMessage = "商品Id不能为空")] + public long SpuId { get; set; } + + public int? GoodsCommentRatingType { get; set; } + } + + + /// + /// 商品详情页评价输入对象Api + /// + /// @author admin + /// @date 2023-07-17 + /// + public class GoodsCommentDtoApi + { + [Required(ErrorMessage = "商品Id不能为空")] + public long SpuId { get; set; } + } + +} diff --git a/ARW.Model/Vo/Api/GoodsManager/GoodsComments/GoodsCommentApiVo.cs b/ARW.Model/Vo/Api/GoodsManager/GoodsComments/GoodsCommentApiVo.cs new file mode 100644 index 0000000..f853553 --- /dev/null +++ b/ARW.Model/Vo/Api/GoodsManager/GoodsComments/GoodsCommentApiVo.cs @@ -0,0 +1,101 @@ +using Newtonsoft.Json; +using OfficeOpenXml.Attributes; +using SqlSugar; +using System; +using System.Collections.Generic; + +namespace ARW.Model.Vo.Api.GoodsManager.GoodsComments +{ + /// + /// 商品评价展示对象Api + /// + /// @author admin + /// @date 2023-07-17 + /// + public class GoodsCommentVoApi + { + /// + /// 评价Id + /// + public int Uid { get; set; } + + /// + /// 描述 : 商品Id + /// + [JsonConverter(typeof(ValueToStringConverter))] + public long SpuId { get; set; } + + + /// + /// 描述 : 商品SkuId + /// + [JsonConverter(typeof(ValueToStringConverter))] + public long SkuId { get; set; } + + + /// + /// 描述 : 商品规格 + /// + public long SpecInfo { get; set; } + + /// + /// 描述 :评分分数 + /// + public float CommentScore { get; set; } + + /// + /// 描述 :评价内容 + /// + public string CommentContent { get; set; } + + /// + /// 描述 :评价图片 + /// + public string GoodsCommentImages { get; set; } + + /// + /// 描述 :评价 + /// + public List CommentResources { get; set; } + + + /// + /// 描述 : 评价用户名称 + /// + public string UserName { get; set; } + + + /// + /// 描述 :评价用户头像 + /// + public string UserHeadUrl { get; set; } + + + /// + /// 描述 : 是否匿名 + /// + public int IsAnonymity { get; set; } + + + /// + /// 描述 : 回复 + /// + public string SellerReply { get; set; } + + /// + /// 商品所选Sku + /// + public string GoodsDetailInfo { get; set; } + + public string CommentTime { get; set; } + } + + public class ResourcesItem + { + public string Src { get; set; } + public string Type { get; set; } + public string CoverSrc { get; set; } + } + + +} diff --git a/ARW.Model/Vo/Api/GoodsManager/GoodsComments/GoodsCommentCountApiVo.cs b/ARW.Model/Vo/Api/GoodsManager/GoodsComments/GoodsCommentCountApiVo.cs new file mode 100644 index 0000000..7f92522 --- /dev/null +++ b/ARW.Model/Vo/Api/GoodsManager/GoodsComments/GoodsCommentCountApiVo.cs @@ -0,0 +1,50 @@ +using Newtonsoft.Json; +using OfficeOpenXml.Attributes; +using SqlSugar; +using System; +using System.Collections.Generic; + +namespace ARW.Model.Vo.Api.GoodsManager.GoodsComments +{ + /// + /// 商品详情页评论数展示对象Api + /// + /// @author lwh + /// @date 2023-07-18 + /// + public class GoodsCommentCountApiVo + { + /// + /// 评价总数 + /// + public int CommentCount { get; set; } + + /// + /// 描述 : 差评总数 + /// + public int BadCount { get; set; } + + + /// + /// 描述 : 中评总数 + /// + public int MiddleCount { get; set; } + + /// + /// 描述 : 好评总数 + /// + public int GoodCount { get; set; } + + /// + /// 描述 : 带图总数 + /// + public int HasImageCount { get; set; } + + /// + /// 好评率 + /// + public decimal GoodRate { get; set; } + + } + +} diff --git a/ARW.Service/Api/BusinessService/GoodsManager/GoodsComments/GoodsCommentServiceApi.cs b/ARW.Service/Api/BusinessService/GoodsManager/GoodsComments/GoodsCommentServiceApi.cs new file mode 100644 index 0000000..59bbb50 --- /dev/null +++ b/ARW.Service/Api/BusinessService/GoodsManager/GoodsComments/GoodsCommentServiceApi.cs @@ -0,0 +1,178 @@ +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 +{ + /// + /// 商品评价接口实现类Api + /// + /// @author admin + /// @date 2023-07-17 + /// + [AppService(ServiceType = typeof(IGoodsCommentServiceApi), ServiceLifetime = LifeTime.Transient)] + public class GoodsCommentServiceImplApi : BaseService, IGoodsCommentServiceApi + { + private readonly GoodsCommentRepository _GoodsCommentRepository; + + public GoodsCommentServiceImplApi(GoodsCommentRepository GoodsCommentRepository) + { + this._GoodsCommentRepository = GoodsCommentRepository; + } + + #region Api接口代码 + + + /// + /// 查询商品评价列表(Api) + /// + /// + /// + public async Task> GetGoodsCommentListApi(GoodsCommentQueryDtoApi parm) + { + //开始拼装查询条件d + var predicate = Expressionable.Create(); + + 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); + 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) + .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(); + 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; + } + + /// + /// 查询商品评价详情(Api) + /// + /// + /// + public async Task GetGoodsDetailsComments(GoodsCommentDtoApi parm) + { + + 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(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.ToJsonAsync(); + } + + + /// + /// 获取商品详情页评论数(Api) + /// + /// + /// + public async Task GetGoodsDetailsCommentsCount(GoodsCommentDtoApi parm) + { + + 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(), + GoodCount = SqlFunc.Subqueryable().Where(s => s.GoodsCommentRatingType == 1 && s.GoodsGuid == parm.SpuId).Count(), + HasImageCount = SqlFunc.Subqueryable().Where(s => s.GoodsCommentImages != "" && s.GoodsCommentImages != null && s.GoodsGuid == parm.SpuId).Count() + }); + + var res = await query.FirstAsync(); + res.GoodRate = Math.Round((decimal)res.GoodCount / res.CommentCount, 4) * 100; + + return res; + } + + #endregion + + } +} diff --git a/ARW.Service/Api/IBusinessService/GoodsManager/GoodsComments/IGoodsCommentServiceApi.cs b/ARW.Service/Api/IBusinessService/GoodsManager/GoodsComments/IGoodsCommentServiceApi.cs new file mode 100644 index 0000000..502f71f --- /dev/null +++ b/ARW.Service/Api/IBusinessService/GoodsManager/GoodsComments/IGoodsCommentServiceApi.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ARW.Model; +using ARW.Model.Dto.Api.GoodsManager.GoodsComments; +using ARW.Model.Models.Business.GoodsManager.GoodsComments; +using ARW.Model.Vo.Api.GoodsManager.GoodsComments; + +namespace ARW.Service.Api.IBusinessService.GoodsManager.GoodsComments +{ + /// + /// 商品评价接口类Api + /// + /// @author admin + /// @date 2023-07-17 + /// + public interface IGoodsCommentServiceApi : IBaseService + { + /// + /// 获取商品评价分页列表(Api) + /// + /// + /// + Task> GetGoodsCommentListApi(GoodsCommentQueryDtoApi parm); + + /// + /// 获取商品评价详情(Api) + /// + /// + /// + Task GetGoodsDetailsComments(GoodsCommentDtoApi parm); + + + /// + /// 获取商品详情页评论数(Api) + /// + /// + /// + Task GetGoodsDetailsCommentsCount(GoodsCommentDtoApi parm); + + } +} diff --git a/ARW.WebApi/Controllers/Api/GoodsManager/GoodsComments/GoodsCommentApiController.cs b/ARW.WebApi/Controllers/Api/GoodsManager/GoodsComments/GoodsCommentApiController.cs new file mode 100644 index 0000000..164eb36 --- /dev/null +++ b/ARW.WebApi/Controllers/Api/GoodsManager/GoodsComments/GoodsCommentApiController.cs @@ -0,0 +1,94 @@ +using Infrastructure; +using Infrastructure.Attribute; +using Infrastructure.Enums; +using Infrastructure.Model; +using Mapster; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using ARW.Admin.WebApi.Extensions; +using ARW.Admin.WebApi.Filters; +using ARW.Common; +using ARW.Admin.WebApi.Controllers; +using ARW.Model.Dto.Api.GoodsManager.GoodsComments; +using ARW.Service.Api.IBusinessService.GoodsManager.GoodsComments; +using ARW.Model.Models.Business.GoodsManager.GoodsComments; +using ARW.Model.Vo.Api.GoodsManager.GoodsComments; +using Microsoft.AspNetCore.Authorization; +using Geocoding; + +namespace ARW.WebApi.Controllers.Api.GoodsManager.GoodsComments +{ + /// + /// 商品评价控制器Api + /// + /// @author admin + /// @date 2023-07-17 + /// + //[Verify] + [Route("api/[controller]")] + public class GoodsCommentApiController : BaseController + { + private readonly IGoodsCommentServiceApi _GoodsCommentServiceApi; + + /// + /// 依赖注入 + /// + /// 商品评价商品评价Api服务 + public GoodsCommentApiController(IGoodsCommentServiceApi GoodsCommentServiceApi) + { + _GoodsCommentServiceApi = GoodsCommentServiceApi; + } + + + /// + /// 获取商品评价列表(Api) + /// + /// 查询参数 + /// + [HttpGet("getGoodsCommentList")] + public async Task GetGoodsCommentListApi([FromQuery] GoodsCommentQueryDtoApi parm) + { + var res = await _GoodsCommentServiceApi.GetGoodsCommentListApi(parm); + return SUCCESS(res); + } + + /// + /// 获取商品详情页评论(Api) + /// + /// 查询参数 + /// + [HttpGet("getGoodsDetailsComments")] + public async Task GetGoodsDetailsComments([FromQuery] GoodsCommentDtoApi parm) + { + //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); + } + } + + + /// + /// 获取商品详情页评论数(Api) + /// + /// 查询参数 + /// + [HttpGet("getGoodsDetailsCommentsCount")] + public async Task GetGoodsDetailsCommentsCount([FromQuery] GoodsCommentDtoApi parm) + { + var res = await _GoodsCommentServiceApi.GetGoodsDetailsCommentsCount(parm); + return SUCCESS(res); + } + + } +} diff --git a/ARW.WebApi/wwwroot/CodeGenTemplate/TplServiceApi.txt b/ARW.WebApi/wwwroot/CodeGenTemplate/TplServiceApi.txt index 587dab1..881ed76 100644 --- a/ARW.WebApi/wwwroot/CodeGenTemplate/TplServiceApi.txt +++ b/ARW.WebApi/wwwroot/CodeGenTemplate/TplServiceApi.txt @@ -147,7 +147,7 @@ $end }).Take(1); - return query.ToJsonAsync(); + return await query.ToJsonAsync(); }