mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 20:13:26 +08:00
170 lines
5.7 KiB
C#
170 lines
5.7 KiB
C#
/***********************************************************************
|
|
* Project: CoreCms
|
|
* ProjectName: 核心内容管理系统
|
|
* Web: https://www.corecms.net
|
|
* Author: 大灰灰
|
|
* Email: jianweie@163.com
|
|
* CreateTime: 2021/1/31 21:45:10
|
|
* Description: 暂无
|
|
***********************************************************************/
|
|
|
|
using System.Linq;
|
|
using CoreCms.Net.Auth.HttpContextUser;
|
|
using CoreCms.Net.IServices;
|
|
using CoreCms.Net.Model.FromBody;
|
|
using CoreCms.Net.Utility.Helper;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Threading.Tasks;
|
|
using CoreCms.Net.Configuration;
|
|
using CoreCms.Net.Model.ViewModels.DTO;
|
|
using CoreCms.Net.Model.ViewModels.UI;
|
|
|
|
namespace CoreCms.Net.Web.WebApi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 购物车操作
|
|
/// </summary>
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class CartController : ControllerBase
|
|
{
|
|
private readonly IHttpContextUser _user;
|
|
private readonly ICoreCmsCartServices _cartServices;
|
|
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
public CartController(IHttpContextUser user, ICoreCmsCartServices cartServices)
|
|
{
|
|
_user = user;
|
|
_cartServices = cartServices;
|
|
}
|
|
|
|
//公共接口====================================================================================================
|
|
|
|
//验证接口====================================================================================================
|
|
|
|
#region 添加单个货品到购物车
|
|
|
|
/// <summary>
|
|
/// 添加单个货品到购物车
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Authorize]
|
|
public async Task<WebApiCallBack> AddCart([FromBody] FMCartAdd entity)
|
|
{
|
|
var jm = await _cartServices.Add(_user.ID, entity.ProductId, entity.Nums, entity.type, entity.cartType, entity.objectId);
|
|
return jm;
|
|
}
|
|
|
|
#endregion 添加单个货品到购物车
|
|
|
|
#region 获取购物车列表======================================================================
|
|
|
|
/// <summary>
|
|
/// 获取购物车列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Authorize]
|
|
public async Task<WebApiCallBack> GetList([FromBody] FMCartGetList entity)
|
|
{
|
|
var ids = CommonHelper.StringToIntArray(entity.ids);
|
|
|
|
//获取数据
|
|
var jm = await _cartServices.GetCartInfos(_user.ID, ids, entity.type, entity.areaId, entity.point, entity.couponCode, entity.receiptType, entity.userShipId, entity.objectId);
|
|
|
|
return jm;
|
|
}
|
|
|
|
#endregion 获取购物车列表======================================================================
|
|
|
|
#region 删除购物车信息
|
|
|
|
/// <summary>
|
|
/// 获取购物车列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Authorize]
|
|
public async Task<WebApiCallBack> DoDelete([FromBody] FMIntId entity)
|
|
{
|
|
var jm = new WebApiCallBack();
|
|
|
|
if (entity.id <= 0)
|
|
{
|
|
jm.msg = "请提交要删除的货品";
|
|
return jm;
|
|
}
|
|
jm = await _cartServices.DeleteByIdsAsync(entity.id, _user.ID);
|
|
|
|
return jm;
|
|
}
|
|
|
|
#endregion 删除购物车信息
|
|
|
|
#region 批量删除购物车信息
|
|
|
|
/// <summary>
|
|
/// 批量删除购物车信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Authorize]
|
|
public async Task<WebApiCallBack> DoDeleteByIds([FromBody] FMArrayIntIds entity)
|
|
{
|
|
var jm = new WebApiCallBack();
|
|
|
|
if (entity.id.Length <= 0)
|
|
{
|
|
jm.msg = "请提交要删除的货品";
|
|
return jm;
|
|
}
|
|
var bl = await _cartServices.DeleteAsync(p => entity.id.Contains(p.id) && p.userId == _user.ID);
|
|
jm.status = bl;
|
|
jm.msg = jm.status ? "删除成功" : "删除失败";
|
|
jm.code = bl ? 0 : 1;
|
|
return jm;
|
|
}
|
|
|
|
#endregion 删除购物车信息
|
|
|
|
#region 设置购物车商品数量
|
|
|
|
/// <summary>
|
|
/// 设置购物车商品数量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Authorize]
|
|
public async Task<WebApiCallBack> SetCartNum([FromBody] FMSetCartNum entity)
|
|
{
|
|
var jm = await _cartServices.SetCartNum(entity.id, entity.nums, _user.ID, (int)GlobalEnumVars.CartSetNumType.Set, (int)GlobalEnumVars.OrderType.Common);
|
|
return jm;
|
|
}
|
|
|
|
#endregion 设置购物车商品数量
|
|
|
|
#region 根据提交的数据判断哪些购物券可以使用==================================================
|
|
|
|
/// <summary>
|
|
/// 根据提交的数据判断哪些购物券可以使用
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Authorize]
|
|
public async Task<WebApiCallBack> GetCartAvailableCoupon([FromBody] FMCouponForUserCouponPost entity)
|
|
{
|
|
var ids = CommonHelper.StringToIntArray(entity.ids);
|
|
var jm = await _cartServices.GetCartAvailableCoupon(_user.ID, ids);
|
|
return jm;
|
|
}
|
|
|
|
#endregion 根据提交的数据判断哪些购物券可以使用==================================================
|
|
|
|
}
|
|
} |