username@email.com
2024-04-24 85405ca125ae7c139e7dbc2dc56a997f3f196e30
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/***********************************************************************
 *            Project: baifenBinfa
 *        ProjectName: 百分兵法管理系统                               
 *                Web: http://chuanyin.com                     
 *             Author:                                        
 *              Email:                               
 *         CreateTime: 202403/02   
 *        Description: 暂无
 ***********************************************************************/
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CoreCms.Net.Auth.HttpContextUser;
using CoreCms.Net.Configuration;
using CoreCms.Net.IServices;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.FromBody;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Utility.Extensions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
 
namespace CoreCms.Net.Web.WebApi.Controllers
{
    /// <summary>
    /// 拼团接口
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PinTuanController : ControllerBase
    {
 
        private readonly IHttpContextUser _user;
        private readonly ICoreCmsPinTuanGoodsServices _pinTuanGoodsServices;
        private readonly ICoreCmsPinTuanRuleServices _pinTuanRuleServices;
        private readonly ICoreCmsProductsServices _productsServices;
        private readonly ICoreCmsPinTuanRecordServices _pinTuanRecordServices;
        private readonly ICoreCmsGoodsServices _goodsServices;
 
 
        /// <summary>
        /// 构造函数
        /// </summary>
        public PinTuanController(IHttpContextUser user
            , ICoreCmsPinTuanGoodsServices pinTuanGoodsServices
            , ICoreCmsPinTuanRuleServices pinTuanRuleServices
            , ICoreCmsProductsServices productsServices
            , ICoreCmsPinTuanRecordServices pinTuanRecordServices, ICoreCmsGoodsServices goodsServices)
        {
            _user = user;
            _pinTuanGoodsServices = pinTuanGoodsServices;
            _pinTuanRuleServices = pinTuanRuleServices;
            _productsServices = productsServices;
            _pinTuanRecordServices = pinTuanRecordServices;
            _goodsServices = goodsServices;
        }
 
 
        #region 拼团列表
        /// <summary>
        /// 拼团列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> GetList([FromBody] FMPageByIntId entity)
        {
            WebApiCallBack jm;
 
            var userId = 0;
            if (_user != null)
            {
                userId = _user.ID;
            }
            jm = await _pinTuanRuleServices.GetPinTuanList(userId, entity.page, entity.limit);
            return jm;
        }
 
        #endregion
 
        #region 获取拼团商品信息
        /// <summary>
        /// 获取拼团商品信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> GetGoodsInfo([FromBody] FMIntId entity)
        {
            var jm = new WebApiCallBack();
 
            var userId = 0;
            if (_user != null)
            {
                userId = _user.ID;
            }
 
            var showSku = entity.data.ObjectToBool();
 
            var pinTuanRule = await _pinTuanRuleServices.QueryByClauseAsync(p => p.id == entity.id, true, true);
            if (pinTuanRule == null)
            {
                jm.msg = "拼团获取失败";
                return jm;
            }
            var pinTuanGood = await _pinTuanGoodsServices.QueryByClauseAsync(p => p.ruleId == entity.id, true, true);
 
            jm.status = true;
            jm.msg = "获取详情成功";
            jm.data = await _pinTuanGoodsServices.GetGoodsInfo(pinTuanRule, pinTuanGood.goodsId, userId, true, true, showSku);
 
            return jm;
 
        }
 
        #endregion
 
        #region 获取货品信息
        /// <summary>
        /// 获取货品信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> GetProductInfo([FromBody] FMGetProductInfo entity)
        {
            var jm = new WebApiCallBack();
 
            var products = await _productsServices.GetProductInfo(entity.id, false, 0, entity.type);
            if (products == null)
            {
                jm.msg = GlobalErrorCodeVars.Code10000;
                return jm;
            }
            //把拼团的一些属性等加上
            var info = await _pinTuanRuleServices.QueryMuchFirstAsync<CoreCmsPinTuanRule, CoreCmsPinTuanGoods, CoreCmsPinTuanRule>(
                        (join1, join2) => new object[] { JoinType.Left, join1.id == join2.ruleId },
                        (join1, join2) => join1, (join1, join2) => join2.goodsId == products.goodsId);
 
            if (info == null)
            {
                jm.msg = GlobalErrorCodeVars.Code10000;
                return jm;
            }
            products.pinTuanRule = info;
            jm.status = true;
            jm.data = products;
            return jm;
 
        }
 
        #endregion
 
        #region 根据订单id取拼团信息,用在订单详情页
        /// <summary>
        /// 根据订单id取拼团信息,用在订单详情页
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> GetPinTuanTeam([FromBody] FMGetPinTuanTeamPost entity)
        {
            var jm = new WebApiCallBack();
 
            if (string.IsNullOrEmpty(entity.orderId) && entity.teamId == 0)
            {
                jm.msg = GlobalErrorCodeVars.Code15606;
                return jm;
            }
            jm = await _pinTuanRecordServices.GetTeamList(entity.teamId, entity.orderId);
 
            return jm;
        }
 
        #endregion
 
    }
}