102 lines
3.7 KiB
C#
102 lines
3.7 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.Admin.WebApi.Controllers;
|
|
using ARW.Model.Dto.Api.Custom.GoodsCollections;
|
|
using ARW.Service.Api.IBusinessService.Custom.GoodsCollections;
|
|
using ARW.Model.Models.Business.Custom.GoodsCollections;
|
|
using ARW.Model.Vo.Api.Custom.GoodsCollections;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Geocoding;
|
|
using ARW.Model.Dto.Business.Custom.GoodsCollections;
|
|
using ARW.Service.Business.IBusinessService.Custom.GoodsCollections;
|
|
using ARW.Admin.WebApi.Framework;
|
|
|
|
namespace ARW.WebApi.Controllers.Api.Custom.GoodsCollections
|
|
{
|
|
/// <summary>
|
|
/// 商品收藏控制器Api
|
|
///
|
|
/// @author lwh
|
|
/// @date 2023-10-22
|
|
/// </summary>
|
|
[Verify]
|
|
[Route("api/[controller]")]
|
|
public class GoodsCollectionApiController : BaseController
|
|
{
|
|
private readonly IGoodsCollectionServiceApi _GoodsCollectionServiceApi;
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
/// <param name="GoodsCollectionServiceApi">商品收藏商品收藏Api服务</param>
|
|
public GoodsCollectionApiController(IGoodsCollectionServiceApi GoodsCollectionServiceApi)
|
|
{
|
|
_GoodsCollectionServiceApi = GoodsCollectionServiceApi;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取商品收藏列表(Api)
|
|
/// </summary>
|
|
/// <param name="parm">查询参数</param>
|
|
/// <returns></returns>
|
|
[HttpGet("getGoodsCollectionList")]
|
|
public async Task<IActionResult> GetGoodsCollectionListApi([FromQuery] GoodsCollectionQueryDtoApi parm)
|
|
{
|
|
var user = JwtUtil.GetLoginUser(App.HttpContext);
|
|
parm.CustomerGuid = user.UserId;
|
|
|
|
var res = await _GoodsCollectionServiceApi.GetGoodsCollectionListApi(parm);
|
|
return SUCCESS(res);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 添加或修改商品收藏
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("addOrUpdateGoodsCollection")]
|
|
[Log(Title = "添加或修改商品收藏", BusinessType = BusinessType.ADDORUPDATE)]
|
|
public async Task<IActionResult> AddOrUpdateGoodsCollection([FromBody] GoodsCollectionDto parm)
|
|
{
|
|
if (parm == null) { throw new CustomException("请求参数错误"); }
|
|
var user = JwtUtil.GetLoginUser(App.HttpContext);
|
|
parm.CustomerGuid = user.UserId;
|
|
|
|
var modal = new GoodsCollection();
|
|
if (parm.GoodsCollectionId != 0) modal = parm.Adapt<GoodsCollection>().ToUpdate(HttpContext);
|
|
else modal = parm.Adapt<GoodsCollection>().ToCreate(HttpContext);
|
|
|
|
var res = await _GoodsCollectionServiceApi.AddOrUpdateGoodsCollection(modal);
|
|
return SUCCESS(res);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 删除商品收藏
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("CancelGoodsCollection")]
|
|
[Log(Title = "商品收藏删除", BusinessType = BusinessType.DELETE)]
|
|
public async Task<IActionResult> CancelGoodsCollection([FromBody] GoodsCollectionDto parm)
|
|
{
|
|
var user = JwtUtil.GetLoginUser(App.HttpContext);
|
|
//long[] idsArr = Tools.SpitLongArrary(ids);
|
|
//if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
|
var response = await _GoodsCollectionServiceApi.DeleteAsync(s => s.GoodsGuid == parm.GoodsGuid && s.CustomerGuid == user.UserId);
|
|
return SUCCESS("删除成功!");
|
|
}
|
|
|
|
|
|
}
|
|
}
|