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
{
///
/// 商品评价控制器
///
/// @author admin
/// @date 2023-07-15
///
[Verify]
[Route("business/[controller]")]
public class GoodsCommentController : BaseController
{
private readonly IGoodsCommentService _GoodsCommentService;
private readonly IShopService _ShopService;
///
/// 依赖注入
///
/// 商品评价服务
public GoodsCommentController(IGoodsCommentService GoodsCommentService, IShopService shopService)
{
_GoodsCommentService = GoodsCommentService;
_ShopService = shopService;
}
///
/// 获取商品评价列表
///
/// 查询参数
///
[HttpGet("getGoodsCommentList")]
[ActionPermissionFilter(Permission = "business:goodscomment:list")]
public async Task 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);
}
///
/// 添加或修改商品评价
///
///
///
[HttpPost("addOrUpdateGoodsComment")]
[ActionPermissionFilter(Permission = "business:goodscomment:addOrUpdate")]
[Log(Title = "添加或修改商品评价", BusinessType = BusinessType.ADDORUPDATE)]
public async Task AddOrUpdateGoodsComment([FromBody] GoodsCommentDto parm)
{
if (parm == null) { throw new CustomException("请求参数错误"); }
var modal = new GoodsComment();
if (parm.GoodsCommentId != 0) modal = parm.Adapt().ToUpdate(HttpContext);
else modal = parm.Adapt().ToCreate(HttpContext);
var res = await _GoodsCommentService.AddOrUpdateGoodsComment(modal);
return SUCCESS(res);
}
///
/// 删除商品评价
///
///
[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("删除成功!");
}
///
/// 回复商品评价
///
///
[HttpPut("recover")]
[ActionPermissionFilter(Permission = "business:goodscomment:recover")]
public async Task RecoverGoodsComment([FromBody] GoodsCommentRecoverDto param)
{
var res = await _GoodsCommentService.Recover(param);
return SUCCESS(res);
}
}
}