156 lines
5.3 KiB
C#
156 lines
5.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.Admin.WebApi.Controllers;
|
|
using ARW.Model.Dto.Api.Carts;
|
|
using ARW.Service.Api.IBusinessService.Carts;
|
|
using ARW.Model.Models.Business.Carts;
|
|
using ARW.Model.Vo.Api.Carts;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Geocoding;
|
|
using ARW.Service.Business.IBusinessService.Carts;
|
|
using ARW.Model.Dto.Business.Carts;
|
|
using ARW.Admin.WebApi.Framework;
|
|
using System.Reflection;
|
|
|
|
namespace ARW.WebApi.Controllers.Api.Carts
|
|
{
|
|
/// <summary>
|
|
/// 购物车记录控制器Api
|
|
///
|
|
/// @author lwh
|
|
/// @date 2023-07-20
|
|
/// </summary>
|
|
[Verify]
|
|
[Route("api/[controller]")]
|
|
public class CartApiController : BaseController
|
|
{
|
|
private readonly ICartService _CartService;
|
|
private readonly ICartServiceApi _CartServiceApi;
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
/// <param name="CartServiceApi">购物车记录购物车记录Api服务</param>
|
|
/// <param name="CartService">购物车记录购物车记录服务</param>
|
|
public CartApiController(ICartServiceApi CartServiceApi, ICartService CartService)
|
|
{
|
|
_CartServiceApi = CartServiceApi;
|
|
_CartService = CartService;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取购物车记录列表(Api)
|
|
/// </summary>
|
|
/// <param name="parm">查询参数</param>
|
|
/// <returns></returns>
|
|
[HttpGet("getCartList")]
|
|
public async Task<IActionResult> GetCartListApi([FromQuery] CartQueryDtoApi parm)
|
|
{
|
|
var user = JwtUtil.GetLoginUser(App.HttpContext);
|
|
parm.CustomerGuid = user.UserId;
|
|
var res = await _CartServiceApi.GetCartListApi(parm);
|
|
return SUCCESS(res);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加或修改购物车记录
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("addOrUpdateCart")]
|
|
[Log(Title = "添加或修改购物车记录Api", BusinessType = BusinessType.ADDORUPDATE)]
|
|
public async Task<IActionResult> AddOrUpdateCart([FromBody] CartDto parm)
|
|
{
|
|
if (parm == null) { throw new CustomException("请求参数错误"); }
|
|
|
|
var modal = new Cart();
|
|
if (parm.CartId != 0) modal = parm.Adapt<Cart>().ToUpdate(HttpContext);
|
|
else modal = parm.Adapt<Cart>().ToCreate(HttpContext);
|
|
|
|
var user = JwtUtil.GetLoginUser(App.HttpContext);
|
|
modal.CustomerGuid = user.UserId;
|
|
|
|
var res = await _CartService.AddOrUpdateCart(modal);
|
|
return SUCCESS(res);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 修改购物车商品数量
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("updateCartGoodsNum")]
|
|
[Log(Title = "修改购物车商品数量", BusinessType = BusinessType.UPDATE)]
|
|
public async Task<IActionResult> UpdateCartGoodsNum([FromBody] CartGoodsNumDto parm)
|
|
{
|
|
if (parm == null) { throw new CustomException("请求参数错误"); }
|
|
|
|
var res = await _CartServiceApi.UpdateCartGoodsNum(parm);
|
|
return SUCCESS(res);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 修改购物车商品选中状态
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("updateCartGoodsSelect")]
|
|
[Log(Title = "修改购物车选中状态", BusinessType = BusinessType.UPDATE)]
|
|
public async Task<IActionResult> UpdateCartGoodsSelect([FromBody] CartGoodsSelectDto parm)
|
|
{
|
|
if (parm == null) { throw new CustomException("请求参数错误"); }
|
|
|
|
var res = await _CartServiceApi.UpdateCartGoodsSelect(parm);
|
|
return SUCCESS(res);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 全选购物车商品
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("selectAllCartGoods")]
|
|
[Log(Title = "全选购物车商品", BusinessType = BusinessType.UPDATE)]
|
|
public async Task<IActionResult> SelectAllCartGoods([FromBody] CartGoodsSelectDto parm)
|
|
{
|
|
if (parm == null) { throw new CustomException("请求参数错误"); }
|
|
|
|
var user = JwtUtil.GetLoginUser(App.HttpContext);
|
|
parm.CustomerGuid = user.UserId;
|
|
var res = await _CartServiceApi.SelectAllCartGoods(parm);
|
|
return SUCCESS(res);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 删除购物车记录
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpDelete("{ids}")]
|
|
[Log(Title = "购物车记录删除", BusinessType = BusinessType.DELETE)]
|
|
public async Task<IActionResult> Delete(string ids)
|
|
{
|
|
long[] idsArr = Tools.SpitLongArrary(ids);
|
|
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
|
foreach (var item in idsArr)
|
|
{
|
|
await _CartService.DeleteAsync(s => s.CartId == item);
|
|
}
|
|
return SUCCESS("删除成功!");
|
|
}
|
|
|
|
}
|
|
}
|