移动系统liao
2024-09-23 78028cee453a5878835a27f884ae36c0900fe8f7
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
/***********************************************************************
 *            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.Entities.Expression;
using CoreCms.Net.Model.FromBody;
using CoreCms.Net.Model.ViewModels.DTO;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Utility.Extensions;
using CoreCms.Net.Utility.Helper;
using Microsoft.AspNetCore.Authorization;
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 StoreController : ControllerBase
    {
        private readonly IHttpContextUser _user;
        private readonly ICoreCmsStoreServices _storeServices;
        private readonly ICoreCmsClerkServices _clerkServices;
        private readonly ICoreCmsSettingServices _settingServices;
        private readonly ICoreCmsBillLadingServices _billLadingServices;
        private readonly ICoreCmsOrderServices _orderServices;
        private readonly ICoreCmsUserServices _userServices;
 
 
        /// <summary>
        /// 构造函数
        /// </summary>
        public StoreController(IHttpContextUser user
            , ICoreCmsStoreServices storeServices
            , ICoreCmsClerkServices clerkServices
            , ICoreCmsSettingServices settingServices
            , ICoreCmsBillLadingServices billLadingServices, ICoreCmsOrderServices orderServices, ICoreCmsUserServices userServices)
        {
            _user = user;
            _storeServices = storeServices;
            _clerkServices = clerkServices;
            _settingServices = settingServices;
            _billLadingServices = billLadingServices;
            _orderServices = orderServices;
            _userServices = userServices;
        }
 
        //公共接口======================================================================================================
 
        #region 获取默认的门店
        /// <summary>
        /// 获取默认的门店
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> GetDefaultStore()
        {
            var jm = new WebApiCallBack();
 
            var ship = await _storeServices.QueryByClauseAsync(p => p.isDefault == true, true, true);
            jm.status = true;
            jm.data = ship;
 
            return jm;
        }
        #endregion
 
        #region 获取门店列表数据
        /// <summary>
        /// 获取门店列表数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> GetStoreList([FromBody] FMGetStoreQueryPageByCoordinate entity)
        {
            var jm = new WebApiCallBack();
            try
            {
                var where = PredicateBuilder.True<CoreCmsStore>();
 
                if (!string.IsNullOrEmpty(entity.key))
                {
                    where = where.And(p => p.storeName.Contains(entity.key));
                }
 
                jm.status = true;
 
                var data = await _storeServices.QueryPageAsyncByCoordinate(where, p => p.distance, OrderByType.Asc, entity.page, entity.limit, entity.latitude, entity.longitude);
 
                foreach (var item in data)
                {
                    if (item.distance > 0)
                    {
                        if (item.distance > 1000)
                        {
                            item.distanceStr = Math.Round(item.distance / 1000, 2) + "km";
                        }
                        else
                        {
                            item.distanceStr = Math.Round(item.distance, 2) + "m";
                        }
                    }
                    else
                    {
                        item.distanceStr = "";
                    }
                }
                jm.data = data;
                jm.otherData = new
                {
                    totalCount = data.TotalCount,
                    totalPages = data.TotalPages,
                };
            }
            catch (Exception e)
            {
 
                jm.msg = GlobalConstVars.DataHandleEx;
                jm.data = e.ToString();
            }
            return jm;
        }
        #endregion
 
        #region 获取推荐关键词
        /// <summary>
        /// 获取推荐关键词
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> GetRecommendKeys()
        {
            var jm = new WebApiCallBack();
 
            var allConfigs = await _settingServices.GetConfigDictionaries();
            var recommendKeysStr = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.RecommendKeys);
            jm.status = true;
            jm.msg = "获取成功";
            jm.data = !string.IsNullOrEmpty(recommendKeysStr) ? recommendKeysStr.Split("|") : new string[] { };
 
            return jm;
        }
        #endregion
 
        #region 判断是否开启门店自提
        /// <summary>
        /// 判断是否开启门店自提
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> GetStoreSwitch()
        {
            var jm = new WebApiCallBack { status = true, msg = "获取成功" };
 
            var allConfigs = await _settingServices.GetConfigDictionaries();
            jm.data = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.StoreSwitch).ObjectToInt(2); ;
            return jm;
        }
        #endregion
 
        #region 根据序列获取门店数据
        /// <summary>
        /// 根据序列获取门店数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebApiCallBack> GetStoreById([FromBody] FMIntId entity)
        {
            var jm = new WebApiCallBack
            {
                status = true,
                msg = "获取成功",
                data = await _storeServices.QueryByClauseAsync(p => p.id == entity.id)
            };
            return jm;
        }
        #endregion
 
        //验证接口======================================================================================================
 
        #region 判断是否是商家,店员,开启商家中心
        /// <summary>
        /// 判断是否是商家,店员,开启商家中心
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> IsClerk()
        {
            var jm = await _clerkServices.IsClerk(_user.ID);
            return jm;
        }
        #endregion
 
        #region 根据用户序列获取门店数据
        /// <summary>
        /// 根据用户序列获取门店数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> GetStoreByUserId([FromBody] FMIntId entity)
        {
            var jm = new WebApiCallBack();
 
            var allConfigs = await _settingServices.GetConfigDictionaries();
            var shopManagerMobile = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopManagerMobile);
 
            var user = await _userServices.QueryByClauseAsync(p => p.id == _user.ID);
            if (user == null)
            {
                jm.status = false;
                jm.msg = "用户获取失败";
                return jm;
            }
 
            var isManager = !string.IsNullOrEmpty(shopManagerMobile) && shopManagerMobile.Contains(user.mobile);
 
            if (entity.id == 0 && isManager)
            {
                var latlong = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipCoordinate);
                var latLongArray = !string.IsNullOrEmpty(latlong) ? latlong.Split(",") : new string[2];
                jm.status = true;
                jm.data = new CoreCmsStore
                {
                    id = 0,
                    storeName = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopName),
                    //mobile = p.mobile,
                    //linkMan = p.linkMan,
                    //logoImage = p.logoImage,
                    //areaId = p.areaId,
                    address = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipAddress),
                    //coordinate = p.coordinate,
                    latitude = latLongArray[0],
                    longitude = latLongArray[1],
                    //isDefault = p.isDefault,
                    //createTime = p.createTime,
                    //updateTime = p.updateTime,
 
                };
            }
            else if (entity.id > 0 && isManager)
            {
                jm.status = true;
                jm.data = await _storeServices.QueryByClauseAsync(p => p.id == entity.id);
            }
            else
            {
                jm.status = true;
                jm.data = await _storeServices.GetStoreByUserId(_user.ID, entity.id);
            }
            return jm;
        }
        #endregion
 
        #region 获取单个用户能管理的门店列表
        /// <summary>
        /// 获取单个用户能管理的门店列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> GetStoreListForUser([FromBody] FMGetStoreQueryPageByCoordinate entity)
        {
            var jm = new WebApiCallBack();
            try
            {
                var where = PredicateBuilder.True<CoreCmsStore>();
 
                var allConfigs = await _settingServices.GetConfigDictionaries();
                var shopManagerMobile = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopManagerMobile);
 
                var user = await _userServices.QueryByClauseAsync(p => p.id == _user.ID);
                if (user == null)
                {
                    jm.status = false;
                    jm.msg = "用户获取失败";
                    return jm;
                }
 
                var isManager = !string.IsNullOrEmpty(shopManagerMobile) && shopManagerMobile.Contains(user.mobile);
                if (!isManager)
                {
                    var stroes = await _clerkServices.QueryListByClauseAsync(p => p.userId == _user.ID);
                    var stroeIds = stroes.Select(p => p.storeId).ToList();
                    where = where.And(p => stroeIds.Contains(p.id));
                }
 
                jm.status = true;
 
                var data = await _storeServices.QueryPageAsyncByCoordinate(where, p => p.distance, OrderByType.Asc, entity.page, entity.limit, entity.latitude, entity.longitude);
 
                foreach (var item in data)
                {
                    if (item.distance > 0)
                    {
                        if (item.distance > 1000)
                        {
                            item.distanceStr = Math.Round(item.distance / 1000, 2) + "km";
                        }
                        else
                        {
                            item.distanceStr = Math.Round(item.distance, 2) + "m";
                        }
                    }
                    else
                    {
                        item.distanceStr = "";
                    }
                }
 
                jm.data = data;
                jm.otherData = new
                {
                    totalCount = data.TotalCount,
                    totalPages = data.TotalPages,
                };
            }
            catch (Exception e)
            {
 
                jm.msg = GlobalConstVars.DataHandleEx;
                jm.data = e.ToString();
            }
            return jm;
        }
        #endregion
 
        #region 获取个人订单列表
 
        /// <summary>
        /// 获取个人订单列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> GetOrderPageByMerchant([FromBody] GetOrderPageByMerchantPost entity)
        {
            var jm = new WebApiCallBack();
 
            var store = await _clerkServices.IsClerk(_user.ID);
            if (store != null && store.otherData.ObjectToBool())
            {
                jm = await _orderServices.GetOrderPageByMerchant(entity.dateType, entity.date, entity.status, entity.receiptType, entity.storeId, entity.page, entity.limit);
            }
            else
            {
                jm.status = false;
                jm.msg = "你不是店员";
            }
 
            return jm;
        }
 
        #endregion
 
        #region 搜索订单
 
        /// <summary>
        /// 搜索订单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> GetOrderPageByMerchantSearch([FromBody] GetOrderPageByMerchantSearcgPost entity)
        {
            var jm = new WebApiCallBack();
 
            var store = await _clerkServices.IsClerk(_user.ID);
            if (store != null && store.otherData.ObjectToBool())
            {
                jm = await _orderServices.GetOrderPageByMerchantSearch(entity.keyword, entity.status, entity.receiptType, entity.storeId, entity.page, entity.limit);
            }
            else
            {
                jm.status = false;
                jm.msg = "你不是店员";
            }
 
            return jm;
        }
 
        #endregion
 
 
        #region 店铺提货单列表
        /// <summary>
        /// 店铺提货单列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> StoreLadingList([FromBody] FMPageByIntId entity)
        {
            var jm = await _billLadingServices.GetStoreLadingList(_user.ID, entity.id, entity.page, entity.limit);
            return jm;
        }
        #endregion
 
        #region 删除提货单数据
        /// <summary>
        /// 删除提货单数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> LadingDelete([FromBody] FMStringId entity)
        {
            var jm = await _billLadingServices.LadingDelete(entity.id, _user.ID);
            return jm;
        }
        #endregion
 
        #region 获取单个提货单详情
        /// <summary>
        /// 获取单个提货单详情
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> LadingInfo([FromBody] FMStringId entity)
        {
            var jm = new WebApiCallBack();
 
            if (string.IsNullOrEmpty(entity.id))
            {
                jm.msg = "请提交查询数据关键词";
                return jm;
            }
            jm = await _billLadingServices.GetInfo(entity.id, _user.ID);
 
            return jm;
        }
        #endregion
 
        #region 核销订单
        /// <summary>
        /// 核销订单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> Lading([FromBody] FMStringId entity)
        {
            var jm = new WebApiCallBack();
 
            if (string.IsNullOrEmpty(entity.id))
            {
                jm.msg = "请提交查询数据关键词";
                return jm;
            }
            var array = entity.id.Split(",");
            var result = await _billLadingServices.LadingOperating(array, _user.ID);
            jm.status = result.code == 0;
            jm.msg = result.msg;
 
            return jm;
        }
        #endregion
 
 
    }
}