移动系统liao
2024-10-15 94da0698c01915b1e340415e080aa03050700d97
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/***********************************************************************
 *            Project: baifenBinfa
 *        ProjectName: 百分兵法管理系统                               
 *                Web: http://chuanyin.com                     
 *             Author:                                        
 *              Email:                               
 *         CreateTime: 202403/02   
 *        Description: 暂无
 ***********************************************************************/
 
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;
using CoreCms.Net.IServices.baifenbingfa;
 
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;
        private readonly IBfbfComAPIService _bfbfComAPIService;
 
 
        /// <summary>
        /// 构造函数
        /// </summary>
        public CartController(IHttpContextUser user, ICoreCmsCartServices cartServices,IBfbfComAPIService bfbfComAPIService)
        {
            _user = user;
            _cartServices = cartServices;
            _bfbfComAPIService = bfbfComAPIService;
        }
 
        //公共接口====================================================================================================
 
        //验证接口====================================================================================================
 
        #region 添加单个货品到购物车
 
        /// <summary>
        /// 添加单个货品到购物车
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> AddCart([FromBody] FMCartAdd entity)
        {
            
            if ((await _bfbfComAPIService.IsDictionary(_user.ID)) && ((entity.cartType != 1)&&(entity.cartType!=4)))//1是普通单,4 是秒杀
            {
                //经销商进制发起团购
                return new WebApiCallBack
                {
                    status = false,
                    msg = " 对不起 经销商不可以发起团购或者拼团"
 
                };
            }
        
 
            var jm = await _cartServices.Add(_user.ID, entity.ProductId, entity.Nums, entity.type, entity.cartType, entity.objectId,entity.isCustomizable);
            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, entity.goodsId);
 
            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 根据提交的数据判断哪些购物券可以使用==================================================
 
    }
}