113 lines
3.6 KiB
C#
113 lines
3.6 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>
|
|
/// 获取Cart详情(Api)
|
|
/// </summary>
|
|
/// <param name="parm">查询参数</param>
|
|
/// <returns></returns>
|
|
[HttpGet("getCartDetails")]
|
|
public async Task<IActionResult> GetCartDetails([FromQuery] CartDtoApi parm)
|
|
{
|
|
//if (parm == null) throw new CustomException("参数错误!");
|
|
|
|
var res = await _CartServiceApi.GetCartDetails(parm);
|
|
|
|
if (res != "[]")
|
|
{
|
|
res = res.Remove(0, 1);
|
|
res = res.Substring(0, res.Length - 1);
|
|
var data = res.FromJSON<CartApiDetailsVo>();
|
|
return SUCCESS(data);
|
|
}
|
|
else
|
|
{
|
|
return SUCCESS(res);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|