yzh
2022-05-10 07ac2c7ec9680f936a4393b923785242b799daa0
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
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
<%@ WebHandler Language="C#" Class="GwOrderHandler" %>
using Dao;
using Model;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
 
public class GwOrderHandler : PageHandler<SysUser>
{
    private GwOrderDao _Dao = new GwOrderDao();
    private GwSpDao _GwSpDao = new GwSpDao();
    private GwClientDao _GwClientDao = new GwClientDao();
    private GwOpGroupDao _GwOpGroupDao = new GwOpGroupDao();
    private GwProductDao _GwProductDao = new GwProductDao();
    private SysXhDao _SysXhDao = new SysXhDao();
    private SysFlowDao _SysFlowDao = new SysFlowDao();
    private SysFlowNodeDao _SysFlowNodeDao = new SysFlowNodeDao();
 
    private SysFlowDao _SysFlowDaoDao = new SysFlowDao();   //流程定义
    private GwOrderAuditDao _GwOrderAuditDao = new GwOrderAuditDao();   //订单审核
 
    private List<GwOp> _OpList;
    private List<GwOpGroup> _GroupList;
    private List<GwProduct> _ProductList;   //产品及产品分类
    //private List<GwProduct> _ProductClassList;  //产品分类
 
    public override JsonPageResult ProcessRequestInternal(PageContext<SysUser> context)
    {
        string @string = context.GetString("action");
        switch (@string)
        {
            case "delete":
                return this.Delete(context);    //删除
            case "update":
                return this.Update(context);    //修改
            case "add":
                return this.Add(context);       //添加
            case "listComplete":
                return this.ListComplete(context);      //查询已完成订单(审核通过、审核不通过、取消)
            case "listAudit":
                return this.ListAudit(context);      //查询待审核订单(待审核、审核中)
            case "gwOrderList":
                return this.GwOrderList(context);      //订单列表
            case "get":
                return this.Get(context);      //获取记录信息
            case "cancel":
                return this.Cancel(context);      //取消    
            case "audit":
                return this.Audit(context);      //订单审核
 
            default:
                throw new Exception("Invalid Action=" + @string);
        }
    }
 
    //加载已完成订单(审核通过、审核不通过、取消)
    private JsonPageResult ListComplete(PageContext<SysUser> context)
    {
        //Console.WriteLine("List.............[" + context.GetInt("name") + "][" + context.GetInt("classes") + "]");
        string spId = context.GetString("spId");
        string clientId = context.GetString("clientId");
        string clientName = context.GetString("clientName");
        int flag = context.GetInt("flag");
        DateTime startDate = context.GetDateTime("startDate");
        DateTime endDate = context.GetDateTime("endDate");
 
        int recordCount = 0;
        int pageSize = context.GetInt("pageSize", 50);
        int pageIndex = context.GetInt("pageIndex", 1);
 
        List<GwOrder> list = _Dao.LoadInfoList(spId, clientId, clientName, flag, startDate, endDate, pageSize, pageIndex, out recordCount);
 
        string str1 = "";
        if (list != null && list.Count > 0)
        {
 
            int num = 0;
            foreach (GwOrder bean in list)
            {
                ++num;
 
                str1 += "<tr><td>" + bean.OrderId + "</td>";
                str1 = str1 + "<td>" + bean.SpId + "</td>";
                str1 = str1 + "<td>" + bean.ClientId + "-" + bean.ClientName + "</td>";
                str1 = str1 + "<td>" + ProductToName(bean.ProductId) + "</td>";
                //str1 = str1 + "<td>" + bean.ComboId + "</td>";
                str1 = str1 + "<td>" + bean.BasicNum + "</td>";
                str1 = str1 + "<td>" + bean.GivingNum + "</td>";
                str1 = str1 + string.Format("<td>{0}元/条</td>", (object)(Convert.ToDecimal(bean.Price) / new Decimal(1000)));
                str1 = str1 + "<td>" + bean.OrderNumTotal + "</td>";
                str1 = str1 + string.Format("<td>{0}元</td>", (object)(Convert.ToDecimal(bean.OrderAmountTotal) / new Decimal(1000)));;
                str1 = str1 + "<td>" + bean.BeforeBalanceNum + "</td>";
                str1 = str1 + "<td>" + bean.Creator + "</td>";
                str1 = str1 + "<td>" + bean.CreateTime + "</td>";
                str1 = str1 + "<td>" + StatusToName(bean.Status) + "</td>";
                //str1 = str1 + "<td>" + bean.Remark + "</td>";
 
                str1 += "<td  class=\"text-right\">";
                str1 += string.Format("<a href=\"javascript:;\" data-orderid=\"{0}\" class=\"action-modal-detail btn  btn-success btn-xs\"><i class=\"fa fa-search\"></i>&nbsp;查看</a> ", (object) bean.OrderId);
                str1 += "</td>";
                str1 += "</tr>";
            }
        }
        else
            str1 += "<tr><td colspan=\"14\" style=\"padding-left:5px; text-align: center;\">暂无信息</td></tr>";
 
        return new JsonPageResult(true,  new
        {
            Table = str1.ToString(),
            TotalCount = recordCount
        });
    }
 
    //加载待审核订单(待审核、审核中)
    private JsonPageResult ListAudit(PageContext<SysUser> context)
    {
        string spId = context.GetString("spId");
        string clientId = context.GetString("clientId");
        string clientName = context.GetString("clientName");
        int flag = context.GetInt("flag");
        DateTime startDate = context.GetDateTime("startDate");
        DateTime endDate = context.GetDateTime("endDate");
 
        int recordCount = 0;
        int pageSize = context.GetInt("pageSize", 50);
        int pageIndex = context.GetInt("pageIndex", 1);
 
        List<GwOrder> list = _Dao.LoadInfoList(spId, clientId, clientName, flag, startDate, endDate, pageSize, pageIndex, out recordCount);
 
        string str1 = "";
        if (list != null && list.Count > 0)
        {
 
            int num = 0;
            foreach (GwOrder bean in list)
            {
                ++num;
 
                str1 += "<tr><td>" + bean.OrderId + "</td>";
                str1 = str1 + "<td>" + bean.SpId + "</td>";
                str1 = str1 + "<td>" + bean.ClientId + "-" + bean.ClientName + "</td>";
                str1 = str1 + "<td>" + ProductToName(bean.ProductId) + "</td>";
                //str1 = str1 + "<td>" + bean.ComboId + "</td>";
                str1 = str1 + "<td>" + bean.BasicNum + "</td>";
                str1 = str1 + "<td>" + bean.GivingNum + "</td>";
                str1 = str1 + string.Format("<td>{0}元/条</td>", (object)(Convert.ToDecimal(bean.Price) / new Decimal(1000)));
                str1 = str1 + "<td>" + bean.OrderNumTotal + "</td>";
                str1 = str1 + string.Format("<td>{0}元</td>", (object)(Convert.ToDecimal(bean.OrderAmountTotal) / new Decimal(1000)));;
                str1 = str1 + "<td>" + bean.BeforeBalanceNum + "</td>";
                str1 = str1 + "<td>" + bean.Creator + "</td>";
                str1 = str1 + "<td>" + bean.CreateTime + "</td>";
                str1 = str1 + "<td>" + StatusToName(bean.Status) + "</td>";
                //str1 = str1 + "<td>" + bean.Remark + "</td>";
 
                str1 += "<td  class=\"text-right\">";
                str1 += string.Format("<a href=\"javascript:;\" data-orderid=\"{0}\" class=\"action-modal-detail btn  btn-success btn-xs\"><i class=\"fa fa-search\"></i>&nbsp;查看</a> ", (object) bean.OrderId);
                str1 += string.Format("<a href=\"javascript:;\" data-orderid=\"{0}\" class=\"action-modal-audit btn  btn-success btn-xs\"><i class=\"fa fa-search\"></i>&nbsp;审核</a> ", (object) bean.OrderId);
                if(bean.Status == 0) {
                    str1 += string.Format("<a href=\"javascript:;\" data-orderid=\"{0}\" class=\"action-modal-cancel btn  btn-success btn-xs\"><i class=\"fa fa-search\"></i>&nbsp;取消</a> ", (object) bean.OrderId);
                }
                str1 += "</td>";
                str1 += "</tr>";
            }
        }
        else
            str1 += "<tr><td colspan=\"14\" style=\"padding-left:5px; text-align: center;\">暂无信息</td></tr>";
 
        return new JsonPageResult(true,  new
        {
            Table = str1.ToString(),
            TotalCount = recordCount
        });
    }
 
    private JsonPageResult GwOrderList(PageContext<SysUser> context)
    {
        /**
    string string1 = context.GetString("SpID");
    string string2 = context.GetString("ClientID");
    string string3 = context.GetString("ClientName");
    string str1 = context.GetString("sDate");
    string str2 = context.GetString("EndTime");
    if (string.IsNullOrEmpty(str1))
        str1 = DateTime.Now.AddDays(-1.0).ToString("yyyy-MM-dd");
    if (string.IsNullOrEmpty(str2))
        str2 = DateTime.Now.ToString("yyyy-MM-dd");
        **/
 
 
        string spId = context.GetString("spId");
        string clientId = context.GetString("clientId");
        string clientName = context.GetString("clientName");
        int flag = context.GetInt("flag");
        //string startDate = context.GetString("startDate");
        //string endDate = context.GetString("endDate");
        DateTime startDate = context.GetDateTime("startDate");
        DateTime endDate = context.GetDateTime("endDate");
 
        int recordCount = 0;
        int pageSize = context.GetInt("pageSize", 50);
        int pageIndex = context.GetInt("pageIndex", 1);
 
        //List<GwOrder> list = _Dao.LoadInfoList(spId, clientId, clientName, flag, Convert.ToDateTime(startDate), Convert.ToDateTime(endDate).AddDays(1.0), pageSize, pageIndex, out recordCount);
        List<GwOrder> list = _Dao.LoadInfoList(spId, clientId, clientName, flag, startDate, endDate.AddDays(1.0), pageSize, pageIndex, out recordCount);
 
        string str1 = "";
        if (list != null && list.Count > 0)
        {
 
            int num = 0;
            foreach (GwOrder bean in list)
            {
                ++num;
 
                str1 += "<tr><td>" + bean.OrderId + "</td>";
                str1 = str1 + "<td>" + bean.SpId + "</td>";
                str1 = str1 + "<td>" + bean.ClientId + "-" + bean.ClientName + "</td>";
                str1 = str1 + "<td>" + ProductToName(bean.ProductId) + "</td>";
                //str1 = str1 + "<td>" + bean.ComboId + "</td>";
                str1 = str1 + "<td>" + bean.BasicNum + "</td>";
                str1 = str1 + "<td>" + bean.GivingNum + "</td>";
                str1 = str1 + string.Format("<td>{0}元/条</td>", (object)(Convert.ToDecimal(bean.Price) / new Decimal(1000)));
                str1 = str1 + "<td>" + bean.OrderNumTotal + "</td>";
                str1 = str1 + string.Format("<td>{0}元</td>", (object)(Convert.ToDecimal(bean.OrderAmountTotal) / new Decimal(1000)));;
                str1 = str1 + "<td>" + bean.BeforeBalanceNum + "</td>";
                str1 = str1 + "<td>" + bean.Creator + "</td>";
                str1 = str1 + "<td>" + bean.CreateTime + "</td>";
                str1 = str1 + "<td>" + StatusToName(bean.Status) + "</td>";
                //str1 = str1 + "<td>" + bean.Remark + "</td>";
 
                str1 += "<td  class=\"text-right\">";
                str1 += string.Format("<a href=\"javascript:;\" data-orderid=\"{0}\" class=\"action-modal-detail btn  btn-success btn-xs\"><i class=\"fa fa-search\"></i>&nbsp;查看</a> ", (object) bean.OrderId);
                //str1 += string.Format("<a href=\"javascript:;\" data-orderid=\"{0}\" class=\"action-modal-audit btn  btn-success btn-xs\"><i class=\"fa fa-search\"></i>&nbsp;审核</a> ", (object) bean.OrderId);
                //if(bean.Status == 0) {
                //    str1 += string.Format("<a href=\"javascript:;\" data-orderid=\"{0}\" class=\"action-modal-cancel btn  btn-success btn-xs\"><i class=\"fa fa-search\"></i>&nbsp;取消</a> ", (object) bean.OrderId);
                //}
                str1 += "</td>";
                str1 += "</tr>";
            }
        }
        else
            str1 += "<tr><td colspan=\"14\" style=\"padding-left:5px; text-align: center;\">暂无信息</td></tr>";
 
        return new JsonPageResult(true,  new
        {
            Table = str1.ToString(),
            TotalCount = recordCount
        });
    }
 
 
    //删除信息
    private JsonPageResult Delete(PageContext<SysUser> context)
    {
        string orderId = context.GetString("orderId");
 
        GwOrder gwOrder = this._Dao.Get(orderId);
        if (gwOrder.Status !=0)
            throw new ArgumentException("该订单已处理,无法删除!");
        this._Dao.Delete(orderId);
        return new JsonPageResult(true, "删除信息成功!");
 
    }
 
 
    //取消信息
    private JsonPageResult Cancel(PageContext<SysUser> context)
    {
        string orderId = context.GetString("orderId");
        int status = context.GetInt("status");
 
 
        GwOrder gwOrder = this._Dao.Get(orderId);
        if (gwOrder==null)
            throw new ArgumentException("该订单记录不存在!");
        if (gwOrder.Status !=0)
            throw new ArgumentException("该订单已处理,无法取消!");
 
        //status:0-待审核(已提交);1-审核中;2-审核通过;3-审核不通过;4-取消;
        this._Dao.UpdateStatus(status, orderId);
        return new JsonPageResult(true, "取消信息成功!");
 
    }
 
 
    //订单审核
    private JsonPageResult Audit(PageContext<SysUser> context)
    {
        string spId = context.GetString("spId");
        string orderId = context.GetString("orderId");
        int basicNum = context.GetInt("basicNum");
        int givingNum = context.GetInt("givingNum");
        string clientId = "";
        int payAmount = 0;
        int tmpPayAmount = Math.Max((int) (context.GetDecimal("payAmount", new Decimal(4, 0, 0, false, (byte) 2)) * new Decimal(1000)), 1);
        payAmount = tmpPayAmount;
        //double price = context.GetDecimal(price);
        int num = Math.Max((int) (context.GetDecimal("price", new Decimal(4, 0, 0, false, (byte) 2)) * new Decimal(1000)), 1);
        string remark = context.GetString("remark");
        int status = context.GetInt("status");  //0-审核不通过;1-审核通过
        string auditReason = context.GetString("auditReason");
        DateTime createTime = DateTime.Now;
        string creator = context.OperatorID;
 
        string beforeFlowCode = null;   //之前的流程编码
        int nowSort = 0;
        string nowFlowCode = null;   //当前的流程编码
        int nextSort = 0;
        string nextFlowCode = null;   //下一个流程编码
 
 
        GwOrder gwOrder = this._Dao.Get(orderId);
        if (gwOrder==null)
            throw new ArgumentException("该订单记录不存在!");
        if (gwOrder.Status !=0 && gwOrder.Status !=1)
            throw new ArgumentException("该订单已处理,操作失败!");
 
        clientId = gwOrder.ClientId;
 
        //获取订单审核流程
        string flowGroup = null;    //流程组合
        string[] flowGroupS = null;
        string[] flowCodeS = null;
        string flowCode = null;
        int sort = 0;
        string flowNodeCode = null;
        int orderStatus = 0;    //订单状态
 
        SysFlow SysFlow = new SysFlow();
        SysFlow.FlowCode = "F_DDSH";    //订单流程
        SysFlow.Status = 1;    //状态:0-禁用;1-启用
 
        SysFlow sysFlow = _SysFlowDao.Get(SysFlow);
        if (sysFlow == null)
        {
            throw new ArgumentException("订单审核流程不存在,请系统管理配置!");
        }
 
        //例:1#KHSH|2#CWSH
        flowGroup = sysFlow.FlowGroup;
 
 
        GwOrderAudit gworderAudit = new GwOrderAudit();
        //gworderAudit.AuditStatus = 1;
        gworderAudit.OrderId = orderId;
        List<GwOrderAudit> gworderAuditList = _GwOrderAuditDao.List(gworderAudit);
        if(gworderAuditList==null || gworderAuditList.Count<=0 )
        {
            //获取审核流程的第一环节
            nowSort = 0;
        }
        else
        {
            //获取审核流程的下环节
            GwOrderAudit gwOrderAudit = gworderAuditList[0];
            nowSort = gwOrderAudit.AuditSort;
 
        }
 
        //获取审核流程的第一环节流程代码
        nowFlowCode = getNextFlowCode(flowGroup, nowSort);
 
        if(string.IsNullOrEmpty(nowFlowCode))
        {
            //当前处理没有流程代码
            throw new ArgumentException("流程处理已完成,请联系管理员!");
        }
        else
        {
            object[] tmpFlowCode = splitFlowCodes(nowFlowCode);
            if(tmpFlowCode==null)
            {
                throw new ArgumentException("流程代码串格式错误,请联系管理员!");
            }
            else
            {
                nowSort = int.Parse(tmpFlowCode[0].ToString() );
                flowCode = tmpFlowCode[1].ToString();
            }
 
 
            //获取用户权限
            SysFlowNode newSysFlowNode = new SysFlowNode();
            newSysFlowNode.BusinessType = 1;   //业务类型:1-充值;99-其他
            newSysFlowNode.FlowNodeCode = flowCode;
            newSysFlowNode.UserId = creator;
 
            List<SysFlowNode> newSysFlowNodeList = _SysFlowNodeDao.IsAuth(newSysFlowNode);
            if(newSysFlowNodeList==null || newSysFlowNodeList.Count <=0 )
            {
                throw new ArgumentException("用户无审核权限,请联系管理员!");
            }
            else
            {
                nextSort = nowSort + 1;
                //获取审核流程的第一环节流程代码
                nextFlowCode = getNextFlowCode(flowGroup, nextSort);
 
            }
 
        }
 
        //保存订单审核表
        string auditId = _SysXhDao.getXh("GW_ORDER_AUDIT");  //获取生成订单审核ID
        this._GwOrderAuditDao.Add(new GwOrderAudit()
        {
            AuditId = auditId,
            OrderId = orderId,
            AuditSort = nowSort,
            AuditStatus = status,
            Auditor = creator,
            AuditReason = auditReason,
            AuditTime = createTime
 
        });
 
        //审核不通过
        if (status==0)
        {
 
            orderStatus = 3;
            //status:0-待审核(已提交);1-审核中;2-审核通过;3-审核不通过;4-取消;
            this._Dao.UpdateStatus(orderStatus, orderId);
 
        }
        else if(status==1)
        {
            int beforeBasicNum = 0;
            int beforeGivingNum = 0;
            int balance = 0;
            int topUpAmountTotal = 0;
            if (string.IsNullOrEmpty(nextFlowCode))
            {
                orderStatus = 2;
 
                //获取账号信息
                GwSp gwSp = _GwSpDao.Get(spId);
 
                beforeBasicNum = gwSp.BasicNum;
                beforeGivingNum = gwSp.GivingNum;
                //balance = Convert.ToInt32(gwSp.Balance);
 
                //获取客户信息
                GwClient gwClient = _GwClientDao.Get(gwSp.ClientID);
                balance =  int.Parse(gwClient.Balance.ToString() );
                topUpAmountTotal = int.Parse(gwClient.Top_up_Amount_Total.ToString() );
 
                //为1-预付费
                if (gwSp.ChargeType==1 && (balance + payAmount) < num * basicNum)
                {
                    throw new ArgumentException("客户余额及充值金额不足购买,请调整后提交!");
                }
 
                //gwSp.Balance = balance - num * basicNum;
                //gwSp.BasicNum = beforeBasicNum + basicNum;
                //gwSp.GivingNum = beforeGivingNum + givingNum;
 
                _GwSpDao.UpdateBalanceByOrder(balance - num * basicNum
                    , beforeBasicNum + basicNum
                    , beforeGivingNum + givingNum
                    , spId
                    );
 
 
                //有充值金额时,更新客户累计充值金额(厘)
                if (payAmount > 0) {
                    //GwClient gwClient = new GwClient();
                    gwClient = new GwClient();
                    gwClient.Top_up_Amount_Total = topUpAmountTotal + payAmount;    //累计金额:单位(厘)
                    gwClient.Balance = ((balance + payAmount) - num * basicNum) ;   //账户余额:单位(厘)
                    gwClient.ClientID = clientId;
 
                    _GwClientDao.UpdateClientAmount(gwClient);
                }
            }
            else
            {
                orderStatus = 1;
            }
            //status:0-待审核(已提交);1-审核中;2-审核通过;3-审核不通过;4-取消;
            //this._Dao.UpdateStatus(orderStatus, orderId);
 
            //获取订单
            //GwOrder newGwOrder = _Dao.Get(orderId);
            //newGwOrder.BasicNum = basicNum;
            //newGwOrder.GivingNum = givingNum;
            //newGwOrder.OrderNumTotal = basicNum + givingNum;
            //newGwOrder.OrderAmountTotal = basicNum * num ;
            //newGwOrder.BeforeBalanceNum = beforeGivingNum + beforeGivingNum;
            //newGwOrder.Status = orderStatus;
            //更新订单
            _Dao.UpdateBalanceAndStatus(basicNum, givingNum, basicNum + givingNum, basicNum * num, payAmount,  beforeGivingNum + beforeGivingNum, orderStatus, orderId );
 
            //Dao.Update(newGwOrder);
 
        }
 
        //判断订单审核流程是否都审核通过且是最后审核环节。
 
        //是最后审核环节时,更新客户账号余额条数。
 
        //不是最后审核环节时,站内通知
 
        //status:0-待审核(已提交);1-审核中;2-审核通过;3-审核不通过;4-取消;
        //this._Dao.UpdateStatus(status, orderId);
 
        return new JsonPageResult(true, "审核操作成功!");
 
    }
 
    //添加信息
    private JsonPageResult Add(PageContext<SysUser> context)
    {
 
        string spId = context.GetString("spId");
        string clientId = context.GetString("clientId");
        string productId = context.GetString("productId");
        //string comboId = context.GetString("comboId");
        int basicNum = context.GetInt("basicNum", 0);
        int givingNum = context.GetInt("givingNum", 0);
        int price = 0;
 
        int orderNumTotal = context.GetInt("orderNumTotal", 0);
        int orderAmountTotal = context.GetInt("orderAmountTotal", 0);
        int payAmount = 0;
        int beforeBalanceNum = context.GetInt("beforeBalanceNum", 0);
        //客服人员提交订单时的状态为1-审核中。
        int status = 1; //0-待审核(已提交);1-审核中;2-审核通过;3-审核不通过;4-取消;申请订单在未审核情况下可以取消。
        string remark = context.GetString("remark");
        DateTime createTime = DateTime.Now;
        string creator = context.OperatorID;
 
        int tmpPayAmount = Math.Max((int) (context.GetDecimal("payAmount", new Decimal(4, 0, 0, false, (byte) 2)) * new Decimal(1000)), 0);
        payAmount = tmpPayAmount;
        int num = Math.Max((int) (context.GetDecimal("price", new Decimal(4, 0, 0, false, (byte) 2)) * new Decimal(1000)), 0);
        price = num;
 
        //校验
        if (!string.IsNullOrEmpty(context.GetString("price")) && !Regex.IsMatch(context.GetString("price"), "^[0-9]*$") && price<=0 )
            throw new Exception("参考单价不能小于等于0");
        if (!string.IsNullOrEmpty(context.GetString("basicNum")) && !Regex.IsMatch(context.GetString("basicNum"), "^[0-9]*$"))
            throw new Exception("基本条数必须为整数");
        if (!string.IsNullOrEmpty(context.GetString("givingNum")) && !Regex.IsMatch(context.GetString("givingNum"), "^[0-9]*$"))
            throw new Exception("赠送条数必须为整数");
 
        if (string.IsNullOrEmpty(clientId))
        {
            throw new ArgumentException("客户不能为空!");
        }
        if (string.IsNullOrEmpty(spId))
        {
            throw new ArgumentException("账号不能为空!");
        }
 
        if (basicNum<=0 && givingNum <= 0 && payAmount <=0)
        {
            throw new ArgumentException("充值金额或基本条数或赠送条数必须大于零!");
        }
 
        //获取账号信息
        GwSp gwSp = _GwSpDao.Get(spId);
        int balance = 0;
        if (gwSp == null)
        {
            throw new ArgumentException("账号不存在!");
        }
        else if (gwSp.Status==0)
        {
            throw new ArgumentException("账号已禁用!");
        }
 
 
        //获取客户信息
        GwClient gwClient = _GwClientDao.Get(gwSp.ClientID);
        balance =  int.Parse(gwClient.Balance.ToString() );
 
        //为1-预付费
        if (gwSp.ChargeType==1 && (balance + payAmount) < num * basicNum)
        {
            throw new ArgumentException("客户余额及充值金额不足购买,请调整后提交!");
        }
 
        //获取订单审核流程
        string flowGroup = null;
        string[] flowGroupS = null;
        string[] flowCodeS = null;
        string flowCode = null;
        int sort = 0;
        string flowNodeCode = null;
        SysFlow SysFlow = new SysFlow();
        SysFlow.FlowCode = "F_DDSH";    //订单流程
        SysFlow.Status = 1;    //状态:0-禁用;1-启用
 
        SysFlow sysFlow = _SysFlowDao.Get(SysFlow);
        if (sysFlow == null)
        {
            throw new ArgumentException("订单审核流程不存在!");
        }
 
        flowGroup = sysFlow.FlowGroup;
        //流程组合为空时
        if (string.IsNullOrEmpty(flowGroup))
        {
            status = 2; //0-待审核(已提交);1-审核中;2-审核通过;3-审核不通过;4-取消;
        }
        else
        {
            status = 1; //0-待审核(已提交);1-审核中;2-审核通过;3-审核不通过;4-取消;
 
            flowGroupS = flowGroup.Split('|');
            if(flowGroupS.Length >0)
            {
                flowCode = flowGroupS[0];
                if (!string.IsNullOrEmpty(flowCode))
                {
                    flowCodeS = flowCode.Split('#');
                }
            }
 
            if(flowCodeS!=null && flowCodeS.Length == 2)
            {
                sort = int.Parse(flowCodeS[0]);   //序号
                flowNodeCode = flowCodeS[1];   //序号
            }
            else
            {
                throw new ArgumentException("流程组合格式错误!");
            }
        }
 
        //获取用户权限
        SysFlowNode sysFlowNode = new SysFlowNode();
        sysFlowNode.BusinessType = 1;   //业务类型:1-充值;99-其他
        sysFlowNode.FlowNodeCode = flowNodeCode;
        sysFlowNode.UserId = creator;
 
        List<SysFlowNode> sysFlowNodeList = _SysFlowNodeDao.IsAuth(sysFlowNode);
        if(sysFlowNodeList==null || sysFlowNodeList.Count <=0 )
        {
            throw new ArgumentException("用户没有充值权限,请联系管理员!");
        }
 
        productId = gwSp.ProductId;
        price = gwSp.Price;
 
        orderNumTotal = basicNum + givingNum;
        orderAmountTotal = basicNum * price;
 
 
        string orderId = _SysXhDao.getXh("GW_ORDER");  //获取生成订单ID
        this._Dao.Add(new GwOrder()
        {
            OrderId = orderId,
            SpId = spId,
            ClientId = clientId,
            ProductId = productId,
            //ComboId = comboId,
            BasicNum = basicNum,
            GivingNum = givingNum,
            Price = price,    //单价换算
            OrderNumTotal = orderNumTotal,
            OrderAmountTotal = orderAmountTotal,
            PayAmount = payAmount,
            BeforeBalanceNum = beforeBalanceNum,
            Status = status,
            Remark = remark,
            CreateTime = createTime,
            Creator = creator
 
        });
 
        //流程组合为空时
        if (!string.IsNullOrEmpty(flowGroup))
        {
            string auditId = _SysXhDao.getXh("GW_ORDER_AUDIT");  //获取生成订单审核ID
            this._GwOrderAuditDao.Add(new GwOrderAudit()
            {
                AuditId = auditId,
                OrderId = orderId,
                AuditSort = sort,
                AuditStatus = status,
                Auditor = creator,
                //AuditReason = null,
                AuditTime = createTime
 
            });
        }
 
 
        return new JsonPageResult(true, "生成订单信息成功!");
    }
 
    //更新信息
    private JsonPageResult Update(PageContext<SysUser> context)
    {
        string orderId = context.GetString("orderId");
        string spId = context.GetString("spId");
        string clientId = context.GetString("clientId");
        string productId = context.GetString("productId");
        string comboId = context.GetString("clientId");
        int basicNum = context.GetInt("basicNum", 0);
        int givingNum = context.GetInt("givingNum", 0);
        int price = 0;
 
        int orderNumTotal = context.GetInt("orderNumTotal", 0);
        int orderAmountTotal = context.GetInt("orderAmountTotal", 0);
        int payAmount = 0;
        int beforeBalanceNum = context.GetInt("beforeBalanceNum", 0);
        int status = 0;
        string remark = context.GetString("remark");
        DateTime createTime = DateTime.Now;
        string creator = context.OperatorID;
 
        int tmpPayAmount = Math.Max((int) (context.GetDecimal("payAmount", new Decimal(4, 0, 0, false, (byte) 2)) * new Decimal(1000)), 0);
        payAmount = tmpPayAmount;
 
        int num = Math.Max((int) (context.GetDecimal("price", new Decimal(4, 0, 0, false, (byte) 2)) * new Decimal(1000)), 0);
        price = num;
 
        //校验
        if (!string.IsNullOrEmpty(context.GetString("price")) && !Regex.IsMatch(context.GetString("price"), "^[0-9]*$") && price<=0 )
            throw new Exception("参考单价不能小于等于0");
        if (!string.IsNullOrEmpty(context.GetString("basicNum")) && !Regex.IsMatch(context.GetString("basicNum"), "^[0-9]*$"))
            throw new Exception("基本条数必须为整数");
        if (!string.IsNullOrEmpty(context.GetString("givingNum")) && !Regex.IsMatch(context.GetString("givingNum"), "^[0-9]*$"))
            throw new Exception("赠送条数必须为整数");
 
        if (string.IsNullOrEmpty(clientId))
        {
            throw new ArgumentException("客户不能为空!");
        }
        if (string.IsNullOrEmpty(spId))
        {
            throw new ArgumentException("账号不能为空!");
        }
 
        if (basicNum<=0 && givingNum <= 0)
        {
            throw new ArgumentException("基本条数或赠送条数必须大于零!");
        }
 
        this._Dao.Update(new GwOrder()
        {
            OrderId = orderId,
            SpId = spId,
            ClientId = clientId,
            ProductId = productId,
            ComboId = comboId,
            BasicNum = basicNum,
            GivingNum = givingNum,
            Price = price,    //单价换算
            OrderNumTotal = orderNumTotal,
            OrderAmountTotal = orderAmountTotal,
            PayAmount = payAmount,
            BeforeBalanceNum = beforeBalanceNum,
            Status = status,
            Remark = remark,
            CreateTime = createTime,
            Creator = creator
 
        });
 
        return new JsonPageResult(true, "信息更新成功!");
    }
 
    //根据主键获取产品或产品分类信息
    private JsonPageResult Get(PageContext<SysUser> context)
    {
        return new JsonPageResult(true, this._Dao.Get(context.GetString("orderId")));
    }
 
    //获取通道列表
    private List<GwOp> OpList
    {
        get
        {
            if (this._OpList == null)
            {
                using (GwOpDao gwOpDao = new GwOpDao())
                    this._OpList = gwOpDao.LoadInfoList();
            }
            return this._OpList;
        }
    }
 
    //获取通道组列表
    private List<GwOpGroup> GroupList
    {
        get
        {
            if (this._GroupList == null)
            {
                using (GwOpGroupDao gwOpGroupDao = new GwOpGroupDao())
                    this._GroupList = gwOpGroupDao.GetGroupList();
            }
            return this._GroupList;
        }
    }
 
    //通道ID转换名称
    private string GetOpName(int opID)
    {
        if (this.OpList == null)
            return string.Empty;
        GwOp gwOp = this.OpList.Find((Predicate<GwOp>)(op => op.OpID == opID));
        if (gwOp != null)
            return string.Format("{0}-{1}", (object)gwOp.OpID, (object)gwOp.OpName);
        return string.Empty;
    }
 
    //产品类别转换名称
    private string ClassesToName(int classes)
    {
        if (classes == -1)
            return string.Empty;
        else if(classes == 0)
            return "0-产品分类";
        else if(classes == 1)
            return "1-产品";
 
        return string.Empty;
    }
 
    //产品是否默认转换名称
    private string IsDefaultToName(int isDefault)
    {
        if (isDefault == -1)
            return string.Empty;
        else if(isDefault == 0)
            return "0-个性化";
        else if(isDefault == 1)
            return "1-系统默认";
 
        return string.Empty;
    }
 
    //启用停用转换名称
    private string IsEnableToName(int isEnable)
    {
        if (isEnable == -1)
            return string.Empty;
        else if(isEnable == 0)
            return "0-停用";
        else if(isEnable == 1)
            return "1-启用";
 
        return string.Empty;
    }
 
    //通道组ID转换名称
    private string GetGroupName(int groupID)
    {
        if (this.GroupList == null)
            return string.Empty;
        GwOpGroup gwOpGroup = this.GroupList.Find((Predicate<GwOpGroup>)(group => group.GroupID == groupID));
        if (gwOpGroup != null)
            return string.Format("{0}-{1}", (object)gwOpGroup.GroupID, (object)gwOpGroup.GroupName);
        return string.Empty;
    }
 
    //订单状态转换名称
    private string StatusToName(int status)
    {
        if (status == -1)
            return string.Empty;
        else if(status == 0)
            return "0-待审核(已提交)";
        else if(status == 1)
            return "1-审核中";
        else if(status == 2)
            return "2-审核通过";
        else if(status == 3)
            return "3-审核不通过";
        else if(status == 4)
            return "4-取消";
 
        return string.Empty;
    }
 
 
    //加载产品及产品分类信息
    private List<GwProduct> ProductAllList()
    {
        GwProduct bean = new GwProduct();
        bean.Classes = -1;
        bean.IsDefault = -1;
        bean.IsEnable = -1;
 
        List<GwProduct> list = _GwProductDao.getAllList(bean);
 
        return list;
    }
 
    //获取产品或产品分类列表
    private List<GwProduct> ProductList
    {
        get
        {
            if (this._ProductList == null)
            {
                this._ProductList = this.ProductAllList();
            }
            return this._ProductList;
        }
    }
 
    //产品或产品分类ID转换名称
    private string ProductToName(string productId)
    {
        if (this.ProductList == null)
            return string.Empty;
        GwProduct bean = this.ProductList.Find((Predicate<GwProduct>)(product => product.Id == productId));
        if (bean != null)
            //return string.Format("{0}-{1}", (object)bean.Id, (object)bean.Name);
            return string.Format("{0}", (object)bean.Name);
        return string.Empty;
    }
 
 
    //获取流程组中的下一个流程
    public string getNextFlowCode(string flowGroup, int sort)
    {
        if (string.IsNullOrEmpty(flowGroup) )
        {
            return null;
        }
 
        string[] flowGroups = null;
        string[] flowCodes = null;
        int nextSort = 0;
        string flowCode = null;
        string sortAndFlowCode = null;
        flowGroups = flowGroup.Split('|');
        Console.WriteLine(flowGroups.Length);
        if (flowGroups.Length > 1)
        {
            for (int i=0; i<flowGroups.Length; i++)
            {
                sortAndFlowCode = flowGroups[i];
                if (string.IsNullOrEmpty(sortAndFlowCode))
                {
                    continue;
                }
                else
                {
                    flowCodes = sortAndFlowCode.Split('#');
                    if(flowCodes.Length!=2)
                    {
 
                        throw new ArgumentException("流程组合串存在格式错误!");
                    }
                    else
                    {
                        nextSort = string.IsNullOrEmpty(flowCodes[0])? 0: Convert.ToInt32(flowCodes[0]);   //序号
                        flowCode = flowCodes[1];   //流程代码
 
                        if (nextSort<=sort)
                        {
                            continue;
                        }
 
                        //return flowCode;
                        return sortAndFlowCode;
 
                    }
                }
 
            }
        }
 
        return "";
    }
 
 
    //拆分流程序号和流程代码
    public object[] splitFlowCodes(string sortAndFlowCode)
    {
        if(string.IsNullOrEmpty(sortAndFlowCode) )
        {
            return null;
        }
 
        string[] splitFlowCodes = sortAndFlowCode.Split('#');
        if (splitFlowCodes.Length != 2)
        {
            throw new ArgumentException("流程组合串格式错误!");
 
        }
        else
        {
            return splitFlowCodes;
        }
 
    }
 
}