Files
coreshoppro/CoreCms.Net.Web.WebApi/Controllers/CartController.cs
JianWeie 05df55d7ec # 2022-02-09
### 1.3.5 开源社区版(会员专业版同步修改):
无
### 0.1.5 会员专业版:
【升级】nuget升级常用组件到最新版本。
【修复】服务商品列表图片组件从image调整为u--image组件。#I4RUC6
【优化】规范coreshop-goods.vue组件for循环未定义key的问题。
【修复】修复因升级uview版本导致【商品选项卡goodTabBar组件】切换失效的问题。
【新增】微信自定义交易组件增加【商品审核结果回调】,【类目审核结果回调】微信服务器消息推送处理。
【优化】调整自定义交易组件sku价格为decimal(18, 2)类型,方便小数处理。
【优化】微信自定义交易组件增加图片同步至微信侧功能。
【优化】重命名一些方法名称大小写。
【新增】首页设计轮播图增加高度设置功能。#I4SWEA
【修复】优化在苹果6/7/8plus及安卓一些机型出现分享海报弹窗文字被遮挡的问题。#I4SWCA
2022-02-09 02:07:06 +08:00

143 lines
4.9 KiB
C#

/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2021/1/31 21:45:10
* Description: 暂无
***********************************************************************/
using CoreCms.Net.Auth.HttpContextUser;
using CoreCms.Net.IServices;
using CoreCms.Net.Model.FromBody;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Model.ViewModels.DTO;
using CoreCms.Net.Utility.Helper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using CoreCms.Net.Configuration;
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 freeFreight = entity.receiptType != 1;
//获取数据
var jm = await _cartServices.GetCartInfos(_user.ID, ids, entity.type, entity.areaId, entity.point, entity.couponCode, freeFreight, entity.receiptType, 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> 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 使==================================================
}
}