feat 添加商品评价

This commit is contained in:
lwh 2023-07-17 02:08:00 +08:00
parent d8b7c7f379
commit aa3f9191f9
10 changed files with 748 additions and 15 deletions

View File

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using ARW.Model.Models.Business.GoodsManager.GoodsComments;
namespace ARW.Model.Dto.Business.GoodsManager.GoodsComments
{
/// <summary>
/// 商品评价输入对象
///
/// @author admin
/// @date 2023-07-15
/// </summary>
public class GoodsCommentDto
{
public int GoodsCommentId { get; set; }
public long GoodsCommentGuid { get; set; }
[Required(ErrorMessage = "店铺guid不能为空")]
public long ShopGuid { get; set; }
[Required(ErrorMessage = "客户guid不能为空")]
public long CustomerGuid { get; set; }
[Required(ErrorMessage = "订单guid不能为空")]
public long OrderGuid { get; set; }
[Required(ErrorMessage = "商品guid不能为空")]
public long GoodsGuid { get; set; }
[Required(ErrorMessage = "订单商品guid不能为空")]
public long OrderGoodsGuid { get; set; }
[Required(ErrorMessage = "评分分数不能为空")]
public float GoodsCommentRating { get; set; }
[Required(ErrorMessage = "评分类型不能为空")]
public int GoodsCommentRatingType { get; set; }
[Required(ErrorMessage = "评价内容不能为空")]
public string GoodsCommentContent { get; set; }
public string GoodsCommentImages { get; set; }
[Required(ErrorMessage = "回复状态不能为空")]
public int GoodsCommentRecoverStatus { get; set; }
public string GoodsCommentRecoverContent { get; set; }
[Required(ErrorMessage = "显示状态不能为空")]
public int GoodsCommentStatus { get; set; }
[Required(ErrorMessage = "排序不能为空")]
public int GoodsCommentSort { get; set; }
}
/// <summary>
/// 商品评价查询对象
///
/// @author admin
/// @date 2023-07-15
/// </summary>
public class GoodsCommentQueryDto : PagerInfo
{
public string ShopName { get; set; }
public string GoodsName { get; set; }
public long? ShopGuid { get; set; }
public int? GoodsCommentRatingType { get; set; }
public int? GoodsCommentStatus { get; set; }
public int? GoodsCommentRecoverStatus { get; set; }
public string ids { get; set; }
}
/// <summary>
///
/// @author admin
/// @date 2023-07-17
/// 回复对象
/// </summary>
public class GoodsCommentRecoverDto
{
[Required(ErrorMessage = "id不能为空")]
public int GoodsCommentId { get; set; }
[Required(ErrorMessage = "回复内容不能为空")]
public string GoodsCommentRecoverContent { get; set; }
}
}

View File

@ -0,0 +1,150 @@
using System;
using System.Collections.Generic;
using SqlSugar;
using OfficeOpenXml.Attributes;
using Newtonsoft.Json;
namespace ARW.Model.Models.Business.GoodsManager.GoodsComments
{
/// <summary>
/// 商品评价,数据实体对象
///
/// @author admin
/// @date 2023-07-15
/// </summary>
[SugarTable("tb_goods_comment")]
public class GoodsComment : BusinessBase
{
/// <summary>
/// 描述 :
/// 空值 : false
/// </summary>
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "goods_comment_id")]
public int GoodsCommentId { get; set; }
/// <summary>
/// 描述 :
/// 空值 : false
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(IsPrimaryKey = true, IsIdentity = false, ColumnName = "goods_comment_guid")]
public long GoodsCommentGuid { get; set; }
/// <summary>
/// 描述 :店铺guid
/// 空值 : false
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(ColumnName = "shop_guid")]
public long ShopGuid { get; set; }
/// <summary>
/// 描述 :客户guid
/// 空值 : false
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(ColumnName = "customer_guid")]
public long CustomerGuid { get; set; }
/// <summary>
/// 描述 :订单guid
/// 空值 : false
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(ColumnName = "order_guid")]
public long OrderGuid { get; set; }
/// <summary>
/// 描述 :商品guid
/// 空值 : false
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(ColumnName = "goods_guid")]
public long GoodsGuid { get; set; }
/// <summary>
/// 描述 :订单商品guid
/// 空值 : false
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
[SugarColumn(ColumnName = "order_goods_guid")]
public long OrderGoodsGuid { get; set; }
/// <summary>
/// 描述 :评分分数
/// 空值 : false
/// </summary>
[SugarColumn(ColumnName = "goods_comment_rating")]
public float GoodsCommentRating { get; set; }
/// <summary>
/// 描述 :评分类型
/// 空值 : false
/// </summary>
[SugarColumn(ColumnName = "goods_comment_rating_type")]
public int GoodsCommentRatingType { get; set; }
/// <summary>
/// 描述 :评价内容
/// 空值 : false
/// </summary>
[SugarColumn(ColumnName = "goods_comment_content")]
public string GoodsCommentContent { get; set; }
/// <summary>
/// 描述 :评价图片
/// 空值 : true
/// </summary>
[SugarColumn(ColumnName = "goods_comment_images")]
public string GoodsCommentImages { get; set; }
/// <summary>
/// 描述 :回复状态
/// 空值 : false
/// </summary>
[SugarColumn(ColumnName = "goods_comment_recover_status")]
public int GoodsCommentRecoverStatus { get; set; }
/// <summary>
/// 描述 :回复内容
/// 空值 : true
/// </summary>
[SugarColumn(ColumnName = "goods_comment_recover_content")]
public string GoodsCommentRecoverContent { get; set; }
/// <summary>
/// 描述 :显示状态
/// 空值 : false
/// </summary>
[SugarColumn(ColumnName = "goods_comment_status")]
public int GoodsCommentStatus { get; set; }
/// <summary>
/// 描述 :排序
/// 空值 : false
/// </summary>
[SugarColumn(ColumnName = "goods_comment_sort")]
public int GoodsCommentSort { get; set; }
}
}

View File

@ -0,0 +1,132 @@
using Newtonsoft.Json;
using OfficeOpenXml.Attributes;
using SqlSugar;
using System;
namespace ARW.Model.Vo.Business.GoodsManager.GoodsComments
{
/// <summary>
/// 商品评价展示对象
///
/// @author admin
/// @date 2023-07-15
/// </summary>
public class GoodsCommentVo
{
/// <summary>
/// 描述 :
/// </summary>
public int GoodsCommentId { get; set; }
/// <summary>
/// 描述 :
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
public long GoodsCommentGuid { get; set; }
/// <summary>
/// 描述 :店铺guid
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
public long ShopGuid { get; set; }
/// <summary>
/// 描述 :店铺名称
/// </summary>
public string ShopName { get; set; }
/// <summary>
/// 描述 :客户guid
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
public long CustomerGuid { get; set; }
/// <summary>
/// 描述 :客户名称
/// </summary>
public string CustomerNickname { get; set; }
/// <summary>
/// 描述 :订单guid
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
public long OrderGuid { get; set; }
/// <summary>
/// 描述 :商品guid
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
public long GoodsGuid { get; set; }
/// <summary>
/// 描述 :商品名称
/// </summary>
public string GoodsName { get; set; }
/// <summary>
/// 描述 :商品图片
/// </summary>
public string GoodsPicture { get; set; }
/// <summary>
/// 描述 :订单商品guid
/// </summary>
[JsonConverter(typeof(ValueToStringConverter))]
public long OrderGoodsGuid { get; set; }
/// <summary>
/// 描述 :评分分数
/// </summary>
public float GoodsCommentRating { get; set; }
/// <summary>
/// 描述 :评分类型
/// </summary>
public int GoodsCommentRatingType { get; set; }
/// <summary>
/// 描述 :评价内容
/// </summary>
public string GoodsCommentContent { get; set; }
/// <summary>
/// 描述 :评价图片
/// </summary>
public string GoodsCommentImages { get; set; }
/// <summary>
/// 描述 :回复状态
/// </summary>
public int GoodsCommentRecoverStatus { get; set; }
/// <summary>
/// 描述 :回复内容
/// </summary>
public string GoodsCommentRecoverContent { get; set; }
/// <summary>
/// 描述 :显示状态
/// </summary>
public int GoodsCommentStatus { get; set; }
/// <summary>
/// 描述 :排序
/// </summary>
public int GoodsCommentSort { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using System;
using Infrastructure.Attribute;
using ARW.Repository.System;
using ARW.Model.Models.Business.GoodsManager.GoodsComments;
namespace ARW.Repository.Business.GoodsManager.GoodsComments
{
/// <summary>
/// 商品评价仓储
///
/// @author admin
/// @date 2023-07-15
/// </summary>
[AppService(ServiceLifetime = LifeTime.Transient)]
public class GoodsCommentRepository : BaseRepository<GoodsComment>
{
#region
#endregion
}
}

View File

@ -0,0 +1,144 @@
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 Infrastructure;
using ARW.Model;
using ARW.Repository;
using ARW.Repository.Business.GoodsManager.GoodsComments;
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsComments;
using ARW.Model.Dto.Business.GoodsManager.GoodsComments;
using ARW.Model.Models.Business.GoodsManager.GoodsComments;
using ARW.Model.Vo.Business.GoodsManager.GoodsComments;
using ARW.Model.Models.Business.ShopManager.Shops;
using ARW.Model.Models.Business.GoodsManager.Goodss;
using ARW.Model.Models.Business.Custom.Customers;
namespace ARW.Service.Business.BusinessService.GoodsManager.GoodsComments
{
/// <summary>
/// 商品评价接口实现类
///
/// @author admin
/// @date 2023-07-15
/// </summary>
[AppService(ServiceType = typeof(IGoodsCommentService), ServiceLifetime = LifeTime.Transient)]
public class GoodsCommentServiceImpl : BaseService<GoodsComment>, IGoodsCommentService
{
private readonly GoodsCommentRepository _GoodsCommentRepository;
public GoodsCommentServiceImpl(GoodsCommentRepository GoodsCommentRepository)
{
this._GoodsCommentRepository = GoodsCommentRepository;
}
#region
/// <summary>
/// 查询商品评价分页列表
/// </summary>
public async Task<PagedInfo<GoodsCommentVo>> GetGoodsCommentList(GoodsCommentQueryDto parm)
{
//开始拼装查询条件d
var predicate = Expressionable.Create<GoodsComment>();
predicate = predicate.AndIF(parm.ShopGuid != null, s => s.ShopGuid == parm.ShopGuid);
predicate = predicate.AndIF(parm.GoodsCommentRecoverStatus != null, s => s.GoodsCommentRecoverStatus == parm.GoodsCommentRecoverStatus);
predicate = predicate.AndIF(parm.GoodsCommentRatingType != null, s => s.GoodsCommentRatingType == parm.GoodsCommentRatingType);
predicate = predicate.AndIF(parm.GoodsCommentStatus != null, s => s.GoodsCommentStatus == parm.GoodsCommentStatus);
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)
.WhereIF(!string.IsNullOrEmpty(parm.ShopName), (s, c, d, f) => c.ShopName.Contains(parm.ShopName))
.WhereIF(!string.IsNullOrEmpty(parm.GoodsName), (s, c, d, f) => d.GoodsName.Contains(parm.GoodsName))
.Where(predicate.ToExpression())
.OrderBy(s => s.GoodsCommentSort, OrderByType.Asc)
.Select((s, c, d, f) => new GoodsCommentVo
{
GoodsCommentId = s.GoodsCommentId,
GoodsCommentGuid = s.GoodsCommentGuid,
ShopGuid = s.ShopGuid,
ShopName = c.ShopName,
CustomerGuid = s.CustomerGuid,
CustomerNickname = f.CustomerNickname,
OrderGuid = s.OrderGuid,
GoodsGuid = s.GoodsGuid,
GoodsName = d.GoodsName,
GoodsPicture = d.GoodsPicture,
OrderGoodsGuid = s.OrderGoodsGuid,
GoodsCommentRating = s.GoodsCommentRating,
GoodsCommentRatingType = s.GoodsCommentRatingType,
GoodsCommentContent = s.GoodsCommentContent,
GoodsCommentImages = s.GoodsCommentImages,
GoodsCommentRecoverStatus = s.GoodsCommentRecoverStatus,
GoodsCommentRecoverContent = s.GoodsCommentRecoverContent,
GoodsCommentStatus = s.GoodsCommentStatus,
GoodsCommentSort = s.GoodsCommentSort,
});
return await query.ToPageAsync(parm);
}
/// <summary>
/// 添加或修改商品评价
/// </summary>
public async Task<string> AddOrUpdateGoodsComment(GoodsComment model)
{
if (model.GoodsCommentRating < 3)
{
model.GoodsCommentRatingType = 3;
}
if (model.GoodsCommentRating < 3.5 && model.GoodsCommentRating >= 2.5)
{
model.GoodsCommentRatingType = 2;
}
if (model.GoodsCommentRating >= 3.5)
{
model.GoodsCommentRatingType = 1;
}
if (model.GoodsCommentId != 0)
{
var response = await _GoodsCommentRepository.UpdateAsync(model);
return "修改成功!";
}
else
{
model.GoodsCommentRecoverStatus = 1;
var response = await _GoodsCommentRepository.InsertReturnSnowflakeIdAsync(model);
return "添加成功!";
}
}
#region Excel处理
#endregion
/// <summary>
/// 回复
/// </summary>
public async Task<string> Recover(GoodsCommentRecoverDto parm)
{
var response = await _GoodsCommentRepository.UpdateAsync(f => new GoodsComment
{
GoodsCommentRecoverContent = parm.GoodsCommentRecoverContent,
GoodsCommentRecoverStatus = 2
}, s => s.GoodsCommentId == parm.GoodsCommentId);
if (response) return "回复成功";
else return "回复失败";
}
#endregion
}
}

View File

@ -289,8 +289,10 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
// 商品类目 // 商品类目
// 拆分上级类目和当前类目(手机/xxxx系列 // 拆分上级类目和当前类目(手机/xxxx系列
var nameArr = Goods.GoodsCategoryName.Split('/'); var nameArr = Goods.GoodsCategoryName.Split('/');
if (nameArr.Length == 0 || nameArr.Length >= 3) throw new CustomException($"商品类目【{Goods.GoodsCategoryName}】格式不正确,参考(手机/xxxx系列)"); if (nameArr.Length == 0 || nameArr.Length >= 3) throw new CustomException($"商品类目【{Goods.GoodsCategoryName}】格式不正确,参考(手机/xxxx系列 或者 手机)");
if (nameArr.Length != 1)
{
// 找出上级类目 // 找出上级类目
var parentGoodsCategory = await _ShopGoodsCategoryRepository.GetFirstAsync( var parentGoodsCategory = await _ShopGoodsCategoryRepository.GetFirstAsync(
s => s.ShopGoodsCategoryName == nameArr.First() && s => s.ShopGoodsCategoryName == nameArr.First() &&
@ -306,6 +308,17 @@ namespace ARW.Service.Business.BusinessService.GoodsManager.Goodss
); );
if (currentGoodsCategory == null) throw new CustomException($"当前商品类目【{nameArr.First()}】不存在"); if (currentGoodsCategory == null) throw new CustomException($"当前商品类目【{nameArr.First()}】不存在");
Goods.ShopGoodsCategoryGuid = currentGoodsCategory.ShopGoodsCategoryGuid; Goods.ShopGoodsCategoryGuid = currentGoodsCategory.ShopGoodsCategoryGuid;
}
else
{
// 找出当前类目
var currentGoodsCategory = await _ShopGoodsCategoryRepository.GetFirstAsync(
s => s.ShopGoodsCategoryName == Goods.GoodsCategoryName &&
s.ShopGuid == Goods.ShopGuid
);
if (currentGoodsCategory == null) throw new CustomException($"当前商品类目【{Goods.GoodsCategoryName}】不存在");
Goods.ShopGoodsCategoryGuid = currentGoodsCategory.ShopGoodsCategoryGuid;
}
// 配送模板 // 配送模板

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ARW.Model;
using ARW.Model.Dto.Business.GoodsManager.GoodsComments;
using ARW.Model.Models.Business.GoodsManager.GoodsComments;
using ARW.Model.Vo.Business.GoodsManager.GoodsComments;
namespace ARW.Service.Business.IBusinessService.GoodsManager.GoodsComments
{
/// <summary>
/// 商品评价接口类
///
/// @author admin
/// @date 2023-07-15
/// </summary>
public interface IGoodsCommentService : IBaseService<GoodsComment>
{
/// <summary>
/// 获取商品评价分页列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
Task<PagedInfo<GoodsCommentVo>> GetGoodsCommentList(GoodsCommentQueryDto parm);
/// <summary>
/// 添加或修改商品评价
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
Task<string> AddOrUpdateGoodsComment(GoodsComment parm);
/// <summary>
/// 回复
/// </summary>
Task<string> Recover(GoodsCommentRecoverDto parm);
}
}

View File

@ -71,6 +71,10 @@ namespace ARW.WebApi.Controllers.Api.Wechat
user = await _customerService.GetFirstAsync(s => s.CustomerGuid == response); user = await _customerService.GetFirstAsync(s => s.CustomerGuid == response);
} }
else
{
user.CustomerLastLoginTime = DateTime.Now;
}
LoginUser loginUser = new LoginUser LoginUser loginUser = new LoginUser
{ {

View File

@ -0,0 +1,120 @@
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.Model.Dto.Business.GoodsManager.GoodsComments;
using ARW.Service.Business.IBusinessService.GoodsManager.GoodsComments;
using ARW.Admin.WebApi.Controllers;
using ARW.Model.Models.Business.GoodsManager.GoodsComments;
using ARW.Model.Vo.Business.GoodsManager.GoodsComments;
using Microsoft.AspNetCore.Authorization;
using ARW.Admin.WebApi.Framework;
using ARW.Service.Business.IBusinessService.ShopManager.Shops;
namespace ARW.WebApi.Controllers.Business.GoodsManager.GoodsComments
{
/// <summary>
/// 商品评价控制器
///
/// @author admin
/// @date 2023-07-15
/// </summary>
[Verify]
[Route("business/[controller]")]
public class GoodsCommentController : BaseController
{
private readonly IGoodsCommentService _GoodsCommentService;
private readonly IShopService _ShopService;
/// <summary>
/// 依赖注入
/// </summary>
/// <param name="GoodsCommentService">商品评价服务</param>
public GoodsCommentController(IGoodsCommentService GoodsCommentService, IShopService shopService)
{
_GoodsCommentService = GoodsCommentService;
_ShopService = shopService;
}
/// <summary>
/// 获取商品评价列表
/// </summary>
/// <param name="parm">查询参数</param>
/// <returns></returns>
[HttpGet("getGoodsCommentList")]
[ActionPermissionFilter(Permission = "business:goodscomment:list")]
public async Task<IActionResult> GetGoodsCommentList([FromQuery] GoodsCommentQueryDto parm)
{
var user = JwtUtil.GetLoginUser(App.HttpContext);
if (user.UserId != 1)
{
var shop = await _ShopService.GetFirstAsync(s => s.ShopUserId == user.UserId);
if (shop == null) throw new Exception("当前用户没有店铺");
parm.ShopGuid = shop.ShopGuid;
}
var res = await _GoodsCommentService.GetGoodsCommentList(parm);
return SUCCESS(res);
}
/// <summary>
/// 添加或修改商品评价
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
[HttpPost("addOrUpdateGoodsComment")]
[ActionPermissionFilter(Permission = "business:goodscomment:addOrUpdate")]
[Log(Title = "添加或修改商品评价", BusinessType = BusinessType.ADDORUPDATE)]
public async Task<IActionResult> AddOrUpdateGoodsComment([FromBody] GoodsCommentDto parm)
{
if (parm == null) { throw new CustomException("请求参数错误"); }
var modal = new GoodsComment();
if (parm.GoodsCommentId != 0) modal = parm.Adapt<GoodsComment>().ToUpdate(HttpContext);
else modal = parm.Adapt<GoodsComment>().ToCreate(HttpContext);
var res = await _GoodsCommentService.AddOrUpdateGoodsComment(modal);
return SUCCESS(res);
}
/// <summary>
/// 删除商品评价
/// </summary>
/// <returns></returns>
[HttpDelete("{ids}")]
[ActionPermissionFilter(Permission = "business:goodscomment:delete")]
[Log(Title = "商品评价删除", BusinessType = BusinessType.DELETE)]
public IActionResult Delete(string ids)
{
long[] idsArr = Tools.SpitLongArrary(ids);
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
var response = _GoodsCommentService.Delete(idsArr);
return SUCCESS("删除成功!");
}
/// <summary>
/// 回复商品评价
/// </summary>
/// <returns></returns>
[HttpPut("recover")]
[ActionPermissionFilter(Permission = "business:goodscomment:recover")]
public async Task<IActionResult> RecoverGoodsComment([FromBody] GoodsCommentRecoverDto param)
{
var res = await _GoodsCommentService.Recover(param);
return SUCCESS(res);
}
}
}