121 lines
4.3 KiB
C#
121 lines
4.3 KiB
C#
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);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|