username@email.com
2024-03-25 99e2324eea7af7dd8da898277abd6f2cbb32e3f2
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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
/***********************************************************************
 *            Project: baifenBinfa
 *        ProjectName: 百分兵法管理系统                               
 *                Web: http://chuanyin.com                     
 *             Author:                                        
 *              Email:                               
 *         CreateTime: 202403/02   
 *        Description: 暂无
 ***********************************************************************/
 
 
using System;
using System.Linq;
using System.Threading.Tasks;
using CoreCms.Net.Auth.HttpContextUser;
using CoreCms.Net.Caching.AutoMate.RedisCache;
using CoreCms.Net.Configuration;
using CoreCms.Net.IServices;
using CoreCms.Net.Loging;
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.Mvc;
using Newtonsoft.Json;
using SqlSugar;
 
namespace CoreCms.Net.Web.WebApi.Controllers
{
    /// <summary>
    /// 订单调用接口数据
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrderController : ControllerBase
    {
        private readonly IHttpContextUser _user;
        private readonly ICoreCmsOrderServices _orderServices;
        private readonly ICoreCmsBillAftersalesServices _aftersalesServices;
        private readonly ICoreCmsSettingServices _settingServices;
        private readonly ICoreCmsAreaServices _areaServices;
        private readonly ICoreCmsBillReshipServices _reshipServices;
        private readonly ICoreCmsShipServices _shipServices;
        private readonly ICoreCmsLogisticsServices _logisticsServices;
        private readonly ICoreCmsOrderDistributionModelServices _orderDistributionModelServices;
        private readonly IRedisOperationRepository _redisOperationRepository;
        private readonly ICoreCmsUserServices _userServices;
        private readonly ICoreCmsClerkServices _clerkServices;
        private readonly ICoreCmsInvoiceServices _invoiceServices;
 
 
        /// <summary>
        /// 构造函数
        /// </summary>
        public OrderController(IHttpContextUser user
        , ICoreCmsOrderServices orderServices
        , ICoreCmsBillAftersalesServices aftersalesServices
        , ICoreCmsSettingServices settingServices
        , ICoreCmsAreaServices areaServices
        , ICoreCmsBillReshipServices reshipServices, ICoreCmsShipServices shipServices, ICoreCmsLogisticsServices logisticsServices, ICoreCmsOrderDistributionModelServices orderDistributionModelServices, IRedisOperationRepository redisOperationRepository, ICoreCmsUserServices userServices, ICoreCmsClerkServices clerkServices, ICoreCmsInvoiceServices invoiceServices)
        {
            _user = user;
            _orderServices = orderServices;
            _aftersalesServices = aftersalesServices;
            _settingServices = settingServices;
            _areaServices = areaServices;
            _reshipServices = reshipServices;
            _shipServices = shipServices;
            _logisticsServices = logisticsServices;
            _orderDistributionModelServices = orderDistributionModelServices;
            _redisOperationRepository = redisOperationRepository;
            _userServices = userServices;
            _clerkServices = clerkServices;
            _invoiceServices = invoiceServices;
        }
 
 
        //公共接口====================================================================================================
 
        #region 发票模糊查询==================================================
        /// <summary>
        /// 发票模糊查询
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> GetOrderTypeModel([FromBody] GetTaxCodePost entity)
        {
            var jm = await _orderServices.GetTaxCode(entity.name);
            return jm;
        }
        #endregion
 
        #region 获取不同类型营销下单支持的配送方式==================================================
        /// <summary>
        /// 获取不同类型营销下单支持的配送方式
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> GetOrderDistributionModel([FromBody] FMIntId entity)
        {
            var jm = new WebApiCallBack() { status = true };
 
            var cache = await _orderDistributionModelServices.GetCaChe();
            var model = cache.Find(p => p.orderType == entity.id);
            if (model == null)
            {
                jm.data = new
                {
                    isOpenMailing = true,
                    isOpenHomeDelivery = true,
                    isOpenSelfDelivery = true
                };
            }
            else
            {
                jm.data = new
                {
                    model.isOpenMailing,
                    model.isOpenHomeDelivery,
                    model.isOpenSelfDelivery
                };
            }
 
            return jm;
        }
        #endregion
 
        //验证接口====================================================================================================
 
        #region 发票模糊查询==================================================
        /// <summary>
        /// 发票模糊查询
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> GetTaxCode([FromBody] GetTaxCodePost entity)
        {
            var jm = await _orderServices.GetTaxCode(entity.name);
            return jm;
        }
        #endregion
 
        #region 创建订单==================================================
        /// <summary>
        /// 创建订单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> CreateOrder([FromBody] CreateOrder entity)
        {
            var jm = new WebApiCallBack();
 
            var lockKey = "LOCK_CreateOrder:user_" + _user.ID;
            var lockHolder = Guid.NewGuid().ToString("N"); //锁持有者
            var redisUserLock = await _redisOperationRepository.LockTakeAsync(lockKey, lockHolder, TimeSpan.FromSeconds(10));
            if (redisUserLock)
            {
                try
                {
                    var type = entity.receiptType;
                    switch (type)
                    {
                        case (int)GlobalEnumVars.OrderReceiptType.Logistics:
                        case (int)GlobalEnumVars.OrderReceiptType.IntraCityService:
                            {
                                //收货地址id
                                if (entity.ushipId == 0)
                                {
                                    jm.data = 13001;
                                    jm.msg = GlobalErrorCodeVars.Code13001;
                                    return jm;
                                }
                                break;
                            }
                        case (int)GlobalEnumVars.OrderReceiptType.SelfDelivery:
                            {
                                //提货门店
                                if (entity.storeId == 0)
                                {
                                    jm.data = 13001;
                                    jm.msg = GlobalErrorCodeVars.Code13001;
                                    return jm;
                                }
 
                                //提货人姓名 提货人电话
                                if (string.IsNullOrEmpty(entity.ladingName))
                                {
                                    jm.data = 13001;
                                    jm.msg = "请输入提货人姓名";
                                    return jm;
                                }
 
                                if (string.IsNullOrEmpty(entity.ladingMobile))
                                {
                                    jm.data = 13001;
                                    jm.msg = "请输入提货人电话";
                                    return jm;
                                }
                                break;
                            }
                        default:
                            jm.data = 13001;
                            jm.msg = "未查询到配送方式";
                            return jm;
                    }
 
                    if (string.IsNullOrEmpty(entity.cartIds))
                    {
                        jm.data = 10000;
                        jm.msg = GlobalErrorCodeVars.Code10000;
                        return jm;
                    }
 
                    jm = await _orderServices.ToAdd(_user.ID, entity.orderType, entity.cartIds, entity.receiptType,
                        entity.ushipId, entity.storeId, entity.ladingName, entity.ladingMobile, entity.memo,
                        entity.point, entity.couponCode, entity.source, entity.scene, entity.taxType, entity.taxName,
                        entity.taxCode, entity.objectId, entity.teamId, entity.requireOrder, entity.requiredFundType,
                        entity.traceId);
                }
                catch (Exception e)
                {
                    jm.msg = "数据处理异常";
                    jm.otherData = e;
                }
                finally
                {
                    await _redisOperationRepository.LockReleaseAsync(lockKey, lockHolder);
                }
            }
            else
            {
                jm.msg = "当前请求太频繁_请稍后再试";
            }
            return jm;
        }
        #endregion
 
        #region 订单预览==================================================
        /// <summary>
        /// 订单预览
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> OrderDetails([FromBody] FMStringId entity)
        {
            var jm = new WebApiCallBack();
 
            var userId = _user.ID;
            if ((string)entity.data == "merchant")
            {
                var allConfigs = await _settingServices.GetConfigDictionaries();
                var shopManagerMobile = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopManagerMobile);
                var user = await _userServices.QueryByClauseAsync(p => p.id == userId);
 
                if (user == null)
                {
                    jm.status = false;
                    jm.msg = "用户获取失败";
                    return jm;
                }
                var isShopManager = !string.IsNullOrEmpty(shopManagerMobile) && shopManagerMobile.Contains(user.mobile);
 
                var store = await _clerkServices.QueryByClauseAsync(p => p.userId == userId);
                if (store == null && isShopManager == false)
                {
                    jm.status = false;
                    jm.msg = "你不是店员或管理员";
                    return jm;
                }
                else
                {
                    userId = 0;
                }
            }
            jm = await _orderServices.GetOrderInfoByOrderId(entity.id, userId);
            return jm;
        }
        #endregion
 
        #region 订单是否支付状态查询==================================================
        /// <summary>
        /// 订单预览
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> CheckOrderIsPaid([FromBody] FMStringId entity)
        {
            var jm = new WebApiCallBack();
 
            var lockKey = "LOCK_CheckOrderIsPaid:user_" + _user.ID;
            var lockHolder = Guid.NewGuid().ToString("N"); //锁持有者
            var redisUserLock = await _redisOperationRepository.LockTakeAsync(lockKey, lockHolder, TimeSpan.FromSeconds(5));
            if (redisUserLock)
            {
                try
                {
                    if (string.IsNullOrEmpty(entity.id))
                    {
                        jm.msg = "支付单编号不能为空";
                        return jm;
                    }
                    var bl = await _orderServices.ExistsAsync(p => p.orderId == entity.id && (p.payStatus == (int)GlobalEnumVars.OrderPayStatus.Yes || p.payStatus == (int)GlobalEnumVars.OrderPayStatus.PartialYes), true);
                    jm.status = true;
                    jm.data = bl;
                }
                catch (Exception e)
                {
                    jm.msg = "数据处理异常";
                    jm.otherData = e;
                    NLogUtil.WriteFileLog(NLog.LogLevel.Error, LogType.ApiRequest, "用户支付支付", JsonConvert.SerializeObject(jm));
                }
                finally
                {
                    await _redisOperationRepository.LockReleaseAsync(lockKey, lockHolder);
                }
            }
            else
            {
                jm.msg = "当前请求太频繁_请稍后再试";
            }
            return jm;
        }
        #endregion
 
        #region 获取订单不同状态的数量==================================================
        /// <summary>
        /// 获取订单不同状态的数量
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> GetOrderStatusNum([FromBody] GetOrderStatusNumPost entity)
        {
            var jm = new WebApiCallBack();
 
            if (string.IsNullOrEmpty(entity.ids))
            {
                jm.msg = "请提交要查询的订单统计类型";
            }
            var ids = CommonHelper.StringToIntArray(entity.ids);
            jm = await _orderServices.GetOrderStatusNum(_user.ID, ids, entity.isAfterSale);
            return jm;
 
        }
        #endregion
 
        #region 获取个人订单列表=======================================================
 
        /// <summary>
        /// 获取个人订单列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> GetOrderList([FromBody] GetOrderListPost entity)
        {
            var jm = await _orderServices.GetOrderList(entity.status, _user.ID, entity.page, entity.limit);
            return jm;
        }
 
        #endregion
 
        #region 取消订单====================================================
 
        /// <summary>
        /// 取消订单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> CancelOrder([FromBody] FMStringId entity)
        {
            var jm = new WebApiCallBack();
 
            if (string.IsNullOrEmpty(entity.id))
            {
                jm.msg = "请提交要取消的订单号";
                return jm;
            }
            var ids = entity.id.Split(",");
            jm = await _orderServices.CancelOrder(ids, _user.ID);
            return jm;
 
        }
        #endregion
 
        #region 删除订单====================================================
 
        /// <summary>
        /// 删除订单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> DeleteOrder([FromBody] FMStringId entity)
        {
            var jm = new WebApiCallBack();
 
            if (string.IsNullOrEmpty(entity.id))
            {
                jm.msg = "请提交要取消的订单号";
                return jm;
            }
            var ids = entity.id.Split(",");
            jm.status = await _orderServices.DeleteAsync(p => ids.Contains(p.orderId) && p.userId == _user.ID);
            jm.msg = jm.status ? "删除成功" : "删除失败";
            return jm;
 
        }
        #endregion
 
        #region 确认签收订单====================================================
        /// <summary>
        /// 确认签收订单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> OrderConfirm([FromBody] FMStringId entity)
        {
            var jm = new WebApiCallBack();
 
            if (string.IsNullOrEmpty(entity.id))
            {
                jm.msg = "请提交要确认签收的订单号";
                return jm;
            }
            jm = await _orderServices.ConfirmOrder(entity.id, Convert.ToInt32(entity.data));
            return jm;
 
        }
        #endregion
 
        #region 添加售后单=======================================================
 
        /// <summary>
        /// 添加售后单
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> AddAftersales([FromBody] ToAddBillAfterSalesPost entity)
        {
            var jm = new WebApiCallBack();
 
            jm.otherData = entity;
            if (string.IsNullOrEmpty(entity.orderId))
            {
                jm.msg = GlobalErrorCodeVars.Code13100;
                jm.code = 13100;
                return jm;
            }
            if (entity.type == 0)
            {
                jm.msg = GlobalErrorCodeVars.Code10051;
                jm.code = 10051;
                return jm;
            }
            jm = await _aftersalesServices.ToAdd(_user.ID, entity.orderId, entity.type, entity.items, entity.images,
                entity.reason, entity.refund);
            jm.otherData = entity;
            return jm;
 
        }
 
        #endregion
 
        #region 获取售后单列表=======================================================
 
        /// <summary>
        /// 获取售后单列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> AftersalesList([FromBody] FMPageByStringId entity)
        {
            var jm = new WebApiCallBack();
 
            jm.status = true;
            jm.msg = "数据获取成功";
 
            var where = PredicateBuilder.True<CoreCmsBillAftersales>();
            where = where.And(p => p.userId == _user.ID);
            if (!string.IsNullOrEmpty(entity.id))
            {
                where = where.And(p => p.orderId == entity.id);
            }
            var data = await _aftersalesServices.QueryPageAsync(where, p => p.createTime, OrderByType.Desc, entity.page, entity.limit);
 
            jm.data = new
            {
                list = data,
                page = data.PageIndex,
                totalPage = data.TotalPages,
                hasNextPage = data.HasNextPage
            };
 
            return jm;
 
        }
 
        #endregion
 
        #region 获取单个售后单详情
 
        /// <summary>
        /// 获取售后单列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> Aftersalesinfo([FromBody] FMStringId entity)
        {
            var jm = new WebApiCallBack { status = true, msg = "数据获取成功" };
 
            var info = await _aftersalesServices.GetInfo(entity.id, _user.ID);
 
            var allConfigs = await _settingServices.GetConfigDictionaries();
 
            var reshipAddress = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipAddress);
            var reshipArea = string.Empty;
            var reshipId = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipAreaId).ObjectToInt(0);
            if (reshipId > 0)
            {
                var result = await _areaServices.GetAreaFullName(reshipId);
                if (result.status)
                {
                    reshipArea = result.data.ToString();
                }
            }
            var reshipMobile = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipMobile);
            var reshipName = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipName);
            var reship = new
            {
                reshipAddress,
                reshipArea,
                reshipMobile,
                reshipName
            };
 
            jm.data = new
            {
                info,
                reship
            };
            return jm;
 
        }
 
        #endregion
 
        #region 提交售后发货快递信息
 
        /// <summary>
        /// 提交售后发货快递信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> SendReship([FromBody] FMBillReshipForSendReshipPost entity)
        {
            var jm = new WebApiCallBack();
 
            if (string.IsNullOrEmpty(entity.reshipId))
            {
                jm.data = jm.msg = GlobalErrorCodeVars.Code13212;
                return jm;
            }
            else if (string.IsNullOrEmpty(entity.logiCode))
            {
                jm.data = jm.msg = GlobalErrorCodeVars.Code13213;
                return jm;
            }
            else if (string.IsNullOrEmpty(entity.logiNo))
            {
                jm.data = jm.msg = GlobalErrorCodeVars.Code13214;
                return jm;
            }
 
 
            var model = await _reshipServices.QueryByIdAsync(entity.reshipId);
            if (model == null)
            {
                jm.data = jm.msg = GlobalErrorCodeVars.Code13211;
                return jm;
            }
 
            var up = await _reshipServices.UpdateAsync(
                p => new CoreCmsBillReship()
                {
                    logiCode = entity.logiCode,
                    logiNo = entity.logiNo,
                    status = (int)GlobalEnumVars.BillReshipStatus.运输中
                }, p => p.reshipId == entity.reshipId);
 
            jm.status = true;
            jm.msg = "数据保存成功";
 
            return jm;
        }
 
        #endregion
 
        #region 获取配送方式列表=======================================================
 
        /// <summary>
        /// 获取配送方式列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public WebApiCallBack GetShip([FromBody] FMIntId entity)
        {
            var jm = new WebApiCallBack();
 
            jm.msg = "暂未设置配送方式";
 
            var ship = _shipServices.GetShip(entity.id);
            if (ship != null)
            {
                jm.status = true;
                jm.data = ship;
                jm.msg = "获取成功";
            }
            return jm;
 
        }
 
        #endregion
 
        #region 前台物流查询接口=======================================================
 
        /// <summary>
        /// 前台物流查询接口
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> LogisticsByApi([FromBody] FMApiLogisticsByApiPost entity)
        {
            var jm = new WebApiCallBack();
 
            if (string.IsNullOrEmpty(entity.code) || string.IsNullOrEmpty(entity.no))
            {
                jm.msg = GlobalErrorCodeVars.Code13225;
                return jm;
            }
 
            var systemLogistics = SystemSettingDictionary.GetSystemLogistics();
            foreach (var p in systemLogistics)
            {
                if (entity.code == p.sKey)
                {
                    jm.msg = p.sDescription + "不支持轨迹查询";
                    return jm;
                }
            }
 
            jm = await _logisticsServices.ExpressPoll(entity.code, entity.no, entity.mobile);
            return jm;
        }
 
        #endregion
 
        #region 检查订单发票是否已经开具=======================================================
 
        /// <summary>
        /// 检查订单发票是否已经开具
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> CheckInvoice([FromBody] FMStringId entity)
        {
            var jm = new WebApiCallBack();
 
            if (string.IsNullOrEmpty(entity.id))
            {
                jm.msg = "请提交订单编码。";
                return jm;
            }
 
            var isHave = await _invoiceServices.ExistsAsync(p => p.sourceId == entity.id && p.category == (int)GlobalEnumVars.OrderTaxCategory.Order);
 
            jm.status = true;
            jm.data = isHave;
 
            return jm;
        }
 
        #endregion
 
 
        #region 提交发票申请=======================================================
 
        /// <summary>
        /// 提交发票申请
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<WebApiCallBack> SubmitInvoiceApply([FromBody] FMSubmitInvoiceApply entity)
        {
            var jm = new WebApiCallBack();
 
 
            if (entity.type == 3 && string.IsNullOrEmpty(entity.code))
            {
                jm.msg = "企业发票申请必须填写纳税人识别号";
                return jm;
            }
 
            var isHave = await _invoiceServices.ExistsAsync(p => p.sourceId == entity.orderId && p.category == (int)GlobalEnumVars.OrderTaxCategory.Order);
            if (isHave)
            {
                jm.msg = "此订单已经存在发票信息。";
                return jm;
            }
 
            var order = await _orderServices.QueryByClauseAsync(p => p.orderId == entity.orderId);
            if (order == null)
            {
                jm.msg = "订单查询失败。";
                return jm;
            }
 
            if (order.userId != _user.ID)
            {
                jm.msg = "你无权申请发票。";
                return jm;
            }
 
            //组装发票信息
            var taxInfo = new CoreCmsInvoice
            {
                category = (int)GlobalEnumVars.OrderTaxCategory.Order,
                sourceId = order.orderId,
                userId = order.userId,
                type = entity.type,
                title = entity.name,
                taxNumber = entity.code,
                amount = order.orderAmount,
                status = (int)GlobalEnumVars.OrderTaxStatus.No,
                createTime = DateTime.Now
            };
 
            var bl = await _invoiceServices.InsertAsync(taxInfo) > 0;
 
            jm.status = true;
            jm.data = bl;
 
            return jm;
        }
 
        #endregion
 
 
 
 
 
    }
}