wzp
2022-10-25 1961452ebc018cf758924f26d9c7aa0b31495227
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
<%@ WebHandler Language="C#" Class="GwClientHandler" %>
using System;
using System.Linq;
using System.Web;
using Dao;
using Model;
using Common;
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using Newtonsoft.Json;
 
 
 
 
public class GwClientHandler : PageHandler<Model.SysUser>
{
 
    private UserDao _SysUserDao = new UserDao();
    private List<SysUser> _SysUserList;
 
    private int _userId = -1;
    private string _userType = "";
    private string _account = "";
    private string initPwd = ConfigurationManager.AppSettings["initPwd"];
 
    public override JsonPageResult ProcessRequestInternal(PageContext<Model.SysUser> context)
    {
        string action = context.GetString("action");
 
        _userId = context.SessionObject.UserID;
        _userType = context.SessionObject.UserType;
        _account = context.SessionObject.Account;
 
        switch (action)
        {
            case "clientSpList":
                return this.GetGwspList(context);
 
            case "loadGwClientPageList":
                return LoadGwClientPageList(context);
            case "save":
                return Save(context);
 
            case "delete":
                return Delete(context);
 
            case "update":
                return Update(context);
 
            case "get":
                return Get(context);
 
            case "getWhite":
                return GetWhite(context);
 
            case "getBlack":
                return GetBlack(context);
 
            case "updateWhite":
                return UpdateWhite(context);
 
            case "updateBlack":
                return UpdateBlack(context);
            //批量分配客户的个性产品
            case "batchUpdateClientProduct":
                return BatchUpdateClientProduct(context);
            //重置密码
            case "resetPwd":
                return ResetPwd(context);
            //修改密码
            case "updatePwd":
                return UpdatePwd(context);
            //获取客户分配个性产品
            case "getPersonalityProduct":
                return GetPersonalityProduct(context);
            //修改分配个性产品
            case "updateProduct":
                return UpdateProduct(context);
            //启用或停用
            case "updateStatus":
                return UpdateStatus(context);
            //获取Token:未实现生成Token
            case "getToken":
                return GetToken(context);
 
            default:
                throw new Exception("Invalid Action=" + action);
        }
    }
    private Dao.GwClientDao _Dao = new Dao.GwClientDao();
    private GwSpDao _GwSpDao = new GwSpDao();
 
 
    /// <summary>
    /// 加载代理商账号列表
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private JsonPageResult LoadGwClientPageList(PageContext<Model.SysUser> context)
    {
        string ClientID = context.GetString("ClientID");
        string Company = context.GetString("Company");
        string ClientName = context.GetString("ClientName");
        string Telephone = context.GetString("Telephone");
        string Salesman = context.GetString("Salesman");
        string SupportStaff = context.GetString("SupportStaff");
        string ProductId = context.GetString("ProductId");
        int IsEnable = context.GetInt("IsEnable", -1);
        int pageIndex = context.GetInt("pageIndex", 1);
 
        string Agent = context.GetString("Agent");
        int recordCount = 0;
        int pageSize = context.GetInt("pageSize", 20);
        string serverIp = ConfigurationManager.AppSettings["serverIp"];
        string clientPort = ConfigurationManager.AppSettings["clientPort"];
 
        string str = "";
        using (GwClientDao dao = new GwClientDao())
        {
            string permissionsSQL = dao.GetClientPermissions(_userId, _userType, "gwc");
            var list = dao.LoadInfoList(out recordCount, pageIndex, pageSize, ClientID, ClientName, Telephone, Agent, Company, Salesman, SupportStaff, ProductId, IsEnable, permissionsSQL);
 
            if (list != null && list.Count > 0)
            {
                foreach (Model.GwClient item in list)
                {
                    string Certification_StatusResult = "未认证";
                    if (item.Certification_Status == 1)
                    {
                        Certification_StatusResult = "已认证";
                    }
                    //edit:yangzh by 20220511
                    //str += @"<tr ><td>" + item.ClientID + "</td><td>" + item.Company + "</td><td>" + item.ClientName + "</td><td>" + item.Telephone + "</td><td>" + item.Top_up_Amount_Total + "元</td><td>" + item.Agent + "</td><td>" + Certification_StatusResult + "</td>";
                    //str += @"<tr ><td>" + item.ClientID + "</td><td>" + item.Company + "</td><td>" + item.ClientName + "</td><td>" + item.Telephone + "</td><td>" + item.Balance/1000 + "元</td><td>" + item.Top_up_Amount_Total/1000 + "元</td><td>" + item.Agent + "</td><td>" + Certification_StatusResult + "</td>";
                    //str += @"<tr ><td  rowspan='1' ><input type='checkbox' name='checkbox' value='" + item.ClientID + "'/></td><td>" + item.ClientID + "</td><td>" + item.Company + "</td><td>" + item.ClientName + "</td><td>" + item.Telephone + "</td><td>" + item.Balance/1000 + "元</td><td>" + item.Top_up_Amount_Total/1000 + "元</td><td>" + SysUserName(string.IsNullOrEmpty(item.Salesman)? 0: int.Parse(item.Salesman) ) + "</td><td>" + Certification_StatusResult + "</td>";
                    str += @"<tr ><td  rowspan='1' ><input type='checkbox' name='checkbox' value='" + item.ClientID + "'/></td><td>" + item.ClientID + "</td><td>" + item.Company + "</td><td>" + item.ClientName + "</td><td>" + item.Telephone + "</td><td>" + item.Balance/1000 + "</td><td>" + item.Top_up_Amount_Total/1000 + "</td><td>" + SysUserName(string.IsNullOrEmpty(item.Salesman)? 0: int.Parse(item.Salesman) ) + "</td>"
                            + "<td>" + item.ProductIds + "</td>"
                            + "<td>"+ (item.Is_Enable == 1 ? "<span class='label label-primary'>启用</span>" : "<span class='label label-default'>停用</span>") + "</td>";
 
                    str += @"<td>";
 
                    if (item.Is_Enable == 1)
                    {
                        //string loginStr = "http://" + serverIp + ":" + clientPort + "/Attachedlogin.aspx?action=Attachedlogin&account=" + item.Account + "&password=" + item.Password;
                        string token = DESEncrypt.Encrypt(item.Password);//对称加密
                        string loginStr = "http://" + serverIp + ":" + clientPort + "/Attachedlogin.aspx?action=Attachedlogin&account=" + item.Account+"&token="+token ;
                        str += string.Format("<a class=\"action-modal-login btn btn-success btn-xs \" href=\"javascript:;\" data-url=\"{0}\" data-id=\"{1}\" target=\"_blank\">", (object)loginStr, (object)item.ClientID);
                        str += "&nbsp;登录</a>&nbsp;";
 
                        str += string.Format(@"<a class=""action-modal-edit btn btn-xs btn-primary"" href=""javascript:;"" data-id=""{0}"">", item.ClientID);
                        str += @"编辑";
                        str += @"</a>&nbsp;";
 
                        str += string.Format(@"<a class=""action-modal-white btn btn-xs btn-primary"" href=""javascript:;"" data-id=""{0}"">", item.ClientID);
                        str += @"白名单";
                        str += @"</a>&nbsp;";
 
                        //str += string.Format(@"<a class=""action-modal-black btn btn-xs btn-primary"" href=""javascript:;"" data-id=""{0}"">", item.ClientID);
                        //str += @"黑名单";
                        //str += @"</a>&nbsp;";
 
                        //str += string.Format(@"<a class=""action-modal-resetPwd btn btn-xs btn-primary"" href=""javascript:;"" data-id=""{0}"">", item.ClientID);
                        //str += @"重置密码";
                        //str += @"</a>&nbsp;";
 
                        str += string.Format(@"<a class=""action-modal-updatePwd btn btn-xs btn-primary"" href=""javascript:;"" data-id=""{0}"">", item.ClientID);
                        str += @"修改密码";
                        str += @"</a>&nbsp;";
 
                        str += string.Format(@"<a class=""action-modal-updateProduct btn btn-xs btn-primary"" href=""javascript:;"" data-id=""{0}"">", item.ClientID);
                        str += @"修改产品";
                        str += @"</a>&nbsp;";
 
                        str += string.Format(@"<a class=""action-modal-orderCreate btn btn-xs btn-primary"" href=""javascript:;"" data-id=""{0}"">", item.ClientID);
                        str += @"充值";
                        str += @"</a>&nbsp;";
                    }
 
                    str += string.Format(@"<a class=""action-modal-orderLog btn btn-xs btn-primary"" href=""javascript:;"" data-id=""{0}"">", item.ClientID);
                    str += @"充值日志";
                    str += @"</a>&nbsp;";
 
                    if(item.Is_Enable == 1)
                    {
                        str += string.Format(@"<a class=""action-modal-updateStatus btn btn-xs btn-default"" href=""javascript:;"" data-id=""{0}"" data-status=0 >", item.ClientID);
                        str += @"<i class='fa fa-toggle-on'></i>停用</a>&nbsp;";
 
                    }
                    else
                    {
                        str += string.Format(@"<a class=""action-modal-updateStatus btn btn-xs btn-primary"" href=""javascript:;"" data-id=""{0}"" data-status=1 >", item.ClientID);
                        str += @"<i class='fa fa-toggle-off'></i>启用</a>&nbsp;";
 
                    }
 
                    if (item.Is_Enable == 0)
                    {
                        str += string.Format(@"<a class=""action-delete btn btn-xs btn-default"" href=""javascript:;"" data-id=""{0}"">", item.ClientID);
                        str += @"删除";
                        str += @"</a>";
                    }
 
                    str += @"</td>";
                    str += @"</tr>";
                }
            }
            else
            {
                str += @"<tr><td colspan=""11"">暂无信息</td></tr>";
            }
 
        }
        return new JsonPageResult(true, new { Table = str.ToString(), TotalCount = recordCount });
    }
 
 
 
 
    //add 2017-10-21
    private JsonPageResult GetGwspList(PageContext<Model.SysUser> context)
    {
        string clientID = context.GetString("clientID");
        Model.GwClient gwClient = new GwClientDao().Get(clientID);
        StringBuilder stringBuilder = new StringBuilder();
        using (GwSpDao gwSpDao = new GwSpDao())
        {
            List<Model.GwSp> list = gwSpDao.LoadSpList(clientID);
            if (list.Count != 0)
            {
                stringBuilder.AppendFormat("<option value=\"{0}\" selected>{1}</option>", (object)0, (object)"请选择账号");
                foreach (Model.GwSp gwSp in list)
                {
                    if (Convert.ToString(980001) == gwSp.SpID)
                        stringBuilder.AppendFormat("<option value=\"{0}\" selected>{1}-{2}</option>", (object)gwSp.SpID, (object)gwSp.ClientID, (object)gwSp.SpID);
                    else
                        stringBuilder.AppendFormat("<option value=\"{0}\">{1}-{2}</option>", (object)gwSp.SpID, (object)gwSp.ClientID, (object)gwSp.SpID);
                }
            }
        }
        return new JsonPageResult(true, (object)new
        {
            Datasp = stringBuilder.ToString(),
            get = gwClient
        });
    }
 
    //end
 
 
    private JsonPageResult UpdateWhite(PageContext<Model.SysUser> context)
    {
        string clientID = context.GetString("clientID");
        string mobileData = context.GetString("mobileData");
 
        _Dao.UpdateWhiteList(clientID, mobileData);
 
        return new JsonPageResult(true, "客户白名单保存成功!");
    }
 
    private JsonPageResult UpdateBlack(PageContext<Model.SysUser> context)
    {
        string clientID = context.GetString("clientID");
        string mobileData = context.GetString("mobileData");
 
        _Dao.UpdateBlackList(clientID, mobileData);
 
        return new JsonPageResult(true, "客户黑名单保存成功!");
    }
 
    private JsonPageResult GetWhite(PageContext<Model.SysUser> context)
    {
        string clientID = context.GetString("clientID");
 
        return new JsonPageResult(true, _Dao.GetWhiteList(clientID));
    }
 
    private JsonPageResult GetBlack(PageContext<Model.SysUser> context)
    {
        string clientID = context.GetString("clientID");
 
        return new JsonPageResult(true, _Dao.GetBlackList(clientID));
    }
 
    //根据客户账号生成Token
    private JsonPageResult GetToken(PageContext<Model.SysUser> context)
    {
        string clientID = context.GetString("clientID");
        if (string.IsNullOrEmpty(clientID) )
        {
            throw new ArgumentException("客户账号参数异常!");
        }
 
        //生成Token
        string token = clientID;
 
        return new JsonPageResult(true, token);
    }
 
 
    //重置密码
    private JsonPageResult ResetPwd(PageContext<Model.SysUser> context)
    {
        string clientID = context.GetString("clientID");
        string password = string.IsNullOrEmpty(initPwd ) ? "123456" : initPwd;
 
        //密码MD5加密,
        password = DataHelper.MD5Hex(password);
 
        _Dao.UpdatePassword(clientID, password);
 
        return new JsonPageResult(true, "重置密码成功!");
    }
 
    //修改密码
    private JsonPageResult UpdatePwd(PageContext<Model.SysUser> context)
    {
        string clientID = context.GetString("clientID");
        string newPwd = context.GetString("newPwd");
 
        if (string.IsNullOrEmpty(newPwd) || !System.Text.RegularExpressions.Regex.IsMatch(newPwd, @"[a-zA-Z0-9]{4,10}"))
        {
            throw new ArgumentException("登录密码不能为空,且必须为4-10位英文或数字字符组合!");
        }
        GwClient gwClient = _Dao.Get(clientID);
 
        //密码MD5加密,
        newPwd += gwClient.Salt;
        newPwd = DataHelper.MD5Hex(newPwd);
 
        _Dao.UpdatePassword(clientID, newPwd);
 
        return new JsonPageResult(true, "修改密码成功!");
    }
 
    //获取客户个性产品
    private JsonPageResult GetPersonalityProduct(PageContext<Model.SysUser> context)
    {
        string clientId = context.GetString("clientId");
 
        return new JsonPageResult(true, _Dao.GetPersonalityProduct(clientId).Keys);
    }
 
    //修改分配个性产品:修改确认
    private JsonPageResult UpdateProduct(PageContext<SysUser> context)
    {
        //context.CheckRight("1042", FailedOperation.PromptOnly);
        string @string = context.GetString("productIdArray");
        string clientId = context.GetString("clientId");
        string[] productIdArray = JsonConvert.DeserializeObject<string[]>(@string);
        if (productIdArray == null)
            throw new ArgumentException("个性分配产品数据异常!");
        if (string.IsNullOrEmpty(clientId) )
            throw new ArgumentException("客户账号参数异常!");
        this._Dao.UpdateProduct(clientId, productIdArray);
        return new JsonPageResult(true, (object) "修改分配个性产品成功!");
    }
 
    //更新信息启用或停用
    private JsonPageResult UpdateStatus(PageContext<SysUser> context)
    {
        string clientId = context.GetString("clientId");
        string isEnable = context.GetString("isEnable");
 
        this._Dao.UpdateStatus(clientId, isEnable);
        return new JsonPageResult(true, "更新信息状态成功!");
 
    }
 
    /// <summary>
    /// 通过账号名获取代理商信息
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private JsonPageResult Get(PageContext<Model.SysUser> context)
    {
        string clientID = context.GetString("clientID");
 
        return new JsonPageResult(true, _Dao.Get(clientID));
    }
 
    private JsonPageResult Delete(PageContext<Model.SysUser> context)
    {
        string clientID = context.GetString("clientID");
 
        if (string.IsNullOrEmpty(clientID))//add
            throw new ArgumentException("你的账号信息获取失败!");//add
 
        if (this._GwSpDao.ClientCount(clientID) > 0)//add
            throw new ArgumentException("你删除的客户下有账号正在使用,请先删除此客户下正在使用的账号!");//add
 
        _Dao.Delete(clientID);
 
        return new JsonPageResult(true, "删除客户资料成功!");
    }
 
 
    /// <summary>
    /// 保存客户资料
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private JsonPageResult Update(PageContext<Model.SysUser> context)
    {
        int id = Int32.Parse(context.GetString("id"));
        string clientID = context.GetString("clientID");
        string company = context.GetString("company");
        //string password = context.GetString("password");
        string clientName = context.GetString("clientName");
        string address = context.GetString("address");
        string telephone = context.GetString("telephone");
        string remark = context.GetString("remark");
        string agent = context.GetString("agent");
        string salesman = context.GetString("salesman");
        string customerManager = context.GetString("customerManager");
        string supportStaff = context.GetString("supportStaff");
        string financialStaff = context.GetString("financialStaff");
        string chargeType = context.GetString("chargeType");
        string smsStatusReport = context.GetString("smsStatusReport");
        
 
        string isEnableWhite = context.GetString("isEnableWhite");
        string isEnableBlack = context.GetString("isEnableBlack");
        string isRemoteLoginNotice = context.GetString("isRemoteLoginNotice");
        string isMobileCaptcha = context.GetString("isMobileCaptcha");
        string isHideMobile = context.GetString("isHideMobile");
        string isDisplayStatus = context.GetString("isDisplayStatus");
        string isLoginIpRestrict = context.GetString("isLoginIpRestrict");
        string isLoginIpAllowGather = context.GetString("isLoginIpAllowGather");
        string isLoginCityRestrict = context.GetString("isLoginCityRestrict");
        string isLoginCityAllowGather = context.GetString("isLoginCityAllowGather");
 
        string data = context.GetString("permissionData");
        if(data.Contains("1"))
        {
            data += ",sp.aspx,GwTaskSmssend,SpPrePattern.aspx";
        }
        if(data.Contains("2"))
        {
            data += ",molog.aspx,mtlog.aspx#stat,mtlog.aspx,statis.aspx";
        }
        string permissionData = Newtonsoft.Json.JsonConvert.SerializeObject(data.Split(','));
 
        if (string.IsNullOrEmpty(clientID))
        {
            throw new ArgumentException("客户账号不能为空,且必须为公司名称!");
        }
 
        /**
        if (string.IsNullOrEmpty(password) || !System.Text.RegularExpressions.Regex.IsMatch(password, @"[a-zA-Z0-9]{4,10}"))
        {
            throw new ArgumentException("客户密码不能为空,且必须为4-10位英文或数字字符组合!");
        }**/
 
        if (string.IsNullOrEmpty(clientName) || string.IsNullOrEmpty(telephone))
        {
            throw new ArgumentException("联系人/联系电话,不能为空!");
        }
 
        if (string.IsNullOrEmpty(customerManager))
        {
            throw new ArgumentException("归属客户经理不能为空,请选择!");
        }
 
        if (string.IsNullOrEmpty(salesman))
        {
            throw new ArgumentException("归属业务员不能为空,请选择!");
        }
 
        if (string.IsNullOrEmpty(supportStaff))
        {
            throw new ArgumentException("归属客服人员不能为空,请选择!");
        }
 
        if (string.IsNullOrEmpty(financialStaff))
        {
            throw new ArgumentException("归属财务人员不能为空,请选择!");
        }
 
        if (string.IsNullOrEmpty(chargeType))
        {
            throw new ArgumentException("计费方式不能为空,请选择!");
        }
 
        if (string.IsNullOrEmpty(smsStatusReport))
        {
            throw new ArgumentException("短信是否支持显示状态报告不能为空,请选择!");
        }
 
        /**
        if (string.IsNullOrEmpty(mmsStatusReport))
        {
            throw new ArgumentException("彩信是否支持显示状态报告不能为空,请选择!");
        }**/
 
        /**
        //编辑时不支持个性密码
        string savePassword = "";
        if (!string.IsNullOrEmpty(clientID))
        {
            GwClient gwClient = this._Dao.Get(clientID);
            savePassword = (gwClient.Password == password ? gwClient.Password : DataHelper.MD5Hex(password) );
        }
        else
        {
            savePassword = DataHelper.MD5Hex(password);
        }
 
        **/
 
        var client = new Model.GwClient();
 
        client.Id = id;
        client.ClientID = clientID;
        client.Company = company;
        //client.Password = password;
        //client.Password = savePassword;
 
        client.ClientName = clientName;
        client.Address = address;
        client.Remark = remark;
        client.Telephone = telephone;
        client.Agent = agent;
 
        client.CustomerManager = customerManager;
        client.Salesman = salesman;
        client.SupportStaff = supportStaff;
        client.FinancialStaff = financialStaff;
        client.ChargeType = string.IsNullOrEmpty(chargeType) ? 0 : int.Parse(chargeType);
        client.SmsStatusReport = string.IsNullOrEmpty(smsStatusReport) ? 0 : int.Parse(smsStatusReport);
        
 
        client.IsEnableWhite = string.IsNullOrEmpty(isEnableWhite) ? 0 : int.Parse(isEnableWhite);
        client.IsEnableBlack = string.IsNullOrEmpty(isEnableBlack) ? 0 : int.Parse(isEnableBlack);
        client.IsRemoteLoginNotice = string.IsNullOrEmpty(isRemoteLoginNotice) ? 0 : int.Parse(isRemoteLoginNotice);
        client.IsMobileCaptcha = string.IsNullOrEmpty(isMobileCaptcha) ? 0 : int.Parse(isMobileCaptcha);
        client.IsHideMobile = string.IsNullOrEmpty(isHideMobile) ? 0 : int.Parse(isHideMobile);
        client.IsDisplayStatus = string.IsNullOrEmpty(isDisplayStatus) ? 0 : int.Parse(isDisplayStatus);
        client.IsLoginIpRestrict = string.IsNullOrEmpty(isLoginIpRestrict) ? 0 : int.Parse(isLoginIpRestrict);
        client.IsLoginIpAllowGather = isLoginIpAllowGather;
        client.IsLoginCityRestrict = string.IsNullOrEmpty(isLoginCityRestrict) ? 0 : int.Parse(isLoginCityRestrict);
        client.IsLoginCityAllowGather = isLoginCityAllowGather;
 
        client.PermissionData = permissionData;
 
        _Dao.Update(client);
 
        return new JsonPageResult(true, "修改客户资料成功!");
    }
 
    ///创建新客户
    private JsonPageResult Save(PageContext<Model.SysUser> context)
    {
        string clientID = context.GetString("clientID");
        string password = context.GetString("password");
        string clientName = context.GetString("clientName");
        string address = context.GetString("address");
        string telephone = context.GetString("telephone");
        string remark = context.GetString("remark");
        string agent = context.GetString("agent");
        string company = context.GetString("company");
        string salesman = context.GetString("salesman");
        string customerManager = context.GetString("customerManager");
        string supportStaff = context.GetString("supportStaff");
        string financialStaff = context.GetString("financialStaff");
        string chargeType = context.GetString("chargeType");
        string smsStatusReport = context.GetString("smsStatusReport");
        string mmsStatusReport = context.GetString("mmsStatusReport");
 
        string isEnableWhite = context.GetString("isEnableWhite");
        string isEnableBlack = context.GetString("isEnableBlack");
        string isRemoteLoginNotice = context.GetString("isRemoteLoginNotice");
        string isMobileCaptcha = context.GetString("isMobileCaptcha");
        string isHideMobile = context.GetString("isHideMobile");
        string isDisplayStatus = context.GetString("isDisplayStatus");
        string isLoginIpRestrict = context.GetString("isLoginIpRestrict");
        string isLoginIpAllowGather = context.GetString("isLoginIpAllowGather");
        string isLoginCityRestrict = context.GetString("isLoginCityRestrict");
        string isLoginCityAllowGather = context.GetString("isLoginCityAllowGather");
 
        string data = context.GetString("permissionData");
        if(data.Contains("1"))
        {
            data += ",sp.aspx,GwTaskSmssend,SpPrePattern.aspx";
        }
        if(data.Contains("2"))
        {
            data += ",molog.aspx,mtlog.aspx#stat,mtlog.aspx,statis.aspx";
        }
        string permissionData = Newtonsoft.Json.JsonConvert.SerializeObject(data.Split(','));
 
        if (string.IsNullOrEmpty(clientID))
        {
            throw new ArgumentException("客户账号不能为空,且必须为公司名称!");
        }
 
        if (string.IsNullOrEmpty(company))
        {
            throw new AggregateException("公司名称不能为空,且必须是全称");
        }
 
        if (string.IsNullOrEmpty(password) || !System.Text.RegularExpressions.Regex.IsMatch(password, @"[a-zA-Z0-9]{4,10}"))
        {
            throw new ArgumentException("客户密码不能为空,且必须为4-10位英文或数字字符组合!");
        }
 
        if (string.IsNullOrEmpty(clientName) || string.IsNullOrEmpty(telephone))
        {
            throw new ArgumentException("联系人/联系电话,不能为空!");
        }
 
        //if (string.IsNullOrEmpty(clientName))
        //{
        //    throw new ArgumentException("客户名称不能为空!");
        //}
 
        if (_Dao.IsIDExists(clientID))
        {
            throw new ArgumentException("客户账号已经存在!");
        }
 
        if (string.IsNullOrEmpty(customerManager))
        {
            throw new ArgumentException("归属客户经理不能为空,请选择!");
        }
 
        if (string.IsNullOrEmpty(salesman))
        {
            throw new ArgumentException("归属业务员不能为空,请选择!");
        }
 
        if (string.IsNullOrEmpty(supportStaff))
        {
            throw new ArgumentException("归属客服人员不能为空,请选择!");
        }
 
        if (string.IsNullOrEmpty(financialStaff))
        {
            throw new ArgumentException("归属财务人员不能为空,请选择!");
        }
 
        if (string.IsNullOrEmpty(chargeType))
        {
            throw new ArgumentException("计费方式不能为空,请选择!");
        }
 
        if (string.IsNullOrEmpty(smsStatusReport))
        {
            throw new ArgumentException("短信是否支持显示状态报告不能为空,请选择!");
        }
        /**
        if (string.IsNullOrEmpty(mmsStatusReport))
        {
            throw new ArgumentException("彩信是否支持显示状态报告不能为空,请选择!");
        }**/
 
        HttpFileCollection _file = HttpContext.Current.Request.Files;
        if (_file.Count > 0)
        {
            long size = _file[0].ContentLength; //文件大小
            string type = _file[0].ContentType; //文件类型
            string name = _file[0].FileName; //文件名
            string _tp = Path.GetExtension(name);//文件扩展名
            if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png")
            {
                Stream stream = _file[0].InputStream;//获取文件流
                string savaName = clientID + "-" + DateTime.Now.ToString("yyyyMMddHHssmm") + _tp; //保存文件。文件名
                string filepath = "\\UploadFile\\" + savaName;
                string path = AppDomain.CurrentDomain.BaseDirectory + filepath;//图片路径
                _file[0].SaveAs(path);
 
                try
                {
                    //创建审核通过的记录
                    Model.GwClientCertification gwClientCertification = new Model.GwClientCertification();
                    gwClientCertification.Client_ID = clientID;
                    gwClientCertification.Certificate_Path = path;
                    gwClientCertification.Client_Classes = 0;//类型:0-企业、1-个人
                    gwClientCertification.Audit_Status = 1;//审核状态,0-待审核,1-通过,2-不通过
                    gwClientCertification.Certification_Time = DateTime.Now;//认证审核时间
                    gwClientCertification.Operator = context.OperatorID;//操作审核人
                    gwClientCertification.Upload_Time = DateTime.Now;//上传时间
                    gwClientCertification.Remark = "管理后台操作创建";
 
                    //保存审核记录
                    GwClientCertificationDao certificationDao = new GwClientCertificationDao();
                    certificationDao.Insert(gwClientCertification);
                }
                catch (Exception ex)
                {
                    return new JsonPageResult(false, "上传图片处理异常:" + ex.Message);
                }
            }
            else
            {
                throw new ArgumentException("文件格式错误,请确认是否为jpg|jpeg|gif|png。");
            }
        }
 
        string salt = DataConverter.getRandom(6);
        password += salt;
        //密码加密
        password = DataHelper.MD5Hex(password);
 
        var client = new Model.GwClient();
        client.ClientID = clientID;
        client.Password = password;
        client.Salt = salt;
 
        client.ClientName = clientName;
        client.Address = address;
        client.Remark = remark;
        client.Telephone = telephone;
        client.Agent = agent;
        client.PermissionData = permissionData;
        client.Client_Parentid = context.OperatorID;
        client.Certification_Status = 1;
        client.Company = company;
        client.CustomerManager = customerManager;
        client.Salesman = salesman;
        client.SupportStaff = supportStaff;
        client.FinancialStaff = financialStaff;
        client.ChargeType = string.IsNullOrEmpty(chargeType) ? 0 : int.Parse(chargeType);
        client.SmsStatusReport = string.IsNullOrEmpty(smsStatusReport) ? 0 : int.Parse(smsStatusReport);
        client.MmsStatusReport = string.IsNullOrEmpty(mmsStatusReport) ? 0 : int.Parse(mmsStatusReport);
 
        client.IsEnableWhite = string.IsNullOrEmpty(isEnableWhite) ? 0 : int.Parse(isEnableWhite);
        client.IsEnableBlack = string.IsNullOrEmpty(isEnableBlack) ? 0 : int.Parse(isEnableBlack);
        client.IsRemoteLoginNotice = string.IsNullOrEmpty(isRemoteLoginNotice) ? 0 : int.Parse(isRemoteLoginNotice);
        client.IsMobileCaptcha = string.IsNullOrEmpty(isMobileCaptcha) ? 0 : int.Parse(isMobileCaptcha);
        client.IsHideMobile = string.IsNullOrEmpty(isHideMobile) ? 0 : int.Parse(isHideMobile);
        client.IsDisplayStatus = string.IsNullOrEmpty(isDisplayStatus) ? 0 : int.Parse(isDisplayStatus);
        client.IsLoginIpRestrict = string.IsNullOrEmpty(isLoginIpRestrict) ? 0 : int.Parse(isLoginIpRestrict);
        client.IsLoginIpAllowGather = isLoginIpAllowGather;
        client.IsLoginCityRestrict = string.IsNullOrEmpty(isLoginCityRestrict) ? 0 : int.Parse(isLoginCityRestrict);
        client.IsLoginCityAllowGather = isLoginCityAllowGather;
 
        _Dao.Add(client);//插入数据库。创建账户
 
        //保存产品记录
        //获取启用的默认的产品
        /**
        //edit:在客户激活时添加记录
        List<string> defaultProductList = GwProductDao.Instance.GetDefaultProduct();
        if (defaultProductList.Count > 0)
        {
            foreach (string productId in defaultProductList)
            {
                GwClientProduct gcp = new GwClientProduct();
                gcp.Id = Guid.NewGuid().ToString();
                gcp.ClientId = clientID;
                gcp.ProductId = productId;
                GwClientProductDao.Instance.Add(gcp);
            }
        }
        **/
 
        return new JsonPageResult(true, "创建账户成功!");
    }
 
    //分配客户的个性产品
    private JsonPageResult BatchUpdateClientProduct(PageContext<SysUser> context)
    {
        string productId = context.GetString("productId");
        string idArray = context.GetString("idArray");
        if (string.IsNullOrEmpty(productId))
        {
 
            throw new ArgumentException("个性产品不能为空,请选择!");
        }
 
        Model.GwProduct gwProduct = new GwProductDao().Get(productId);
        if (gwProduct == null)
        {
            throw new ArgumentException("指定的个性产品不存在,请重新选择!");
        }
        string clientIds = gwProduct.ClientIds;
 
        List<string> tmpList = new List<string>();
        if(!string.IsNullOrEmpty(clientIds))
        {   //字符串转数组,再数组合并
            tmpList.AddRange( clientIds.Split(',') );
        }
        //数组合并
        tmpList.AddRange( JsonConvert.DeserializeObject<string[]>(context.GetString("idArray")) );
 
        //数组去重
        string[] tmpArray = DelRepeatData(tmpList.ToArray() );
        clientIds = string.Join(",", tmpArray) ;
 
        if (!string.IsNullOrEmpty(clientIds))
        {
            new GwProductDao().UpdateClientIds(clientIds, productId);
        }
 
 
        return new JsonPageResult(true, (object)"批量分配客户个性产品成功!");
    }
 
    /// <summary>  
    /// 移除数组中重复数据  
    /// </summary>  
    /// <param name="array">需要除重的数组</param>  
    /// <returns>不重复数组</returns>  
    public static string[] DelRepeatData(string[] array)
    {
        return array.GroupBy(p => p).Select(p => p.Key).ToArray();
    }
 
 
 
    //获取管理端账户列表
    private List<SysUser> SysUserList
    {
        get
        {
            if (this._SysUserList == null)
            {
 
                using (UserDao sysUserDao = new UserDao())
                {
                    int recordCount = 0;
                    int int1 = 999999999;
                    int int2 = 1;
                    this._SysUserList = sysUserDao.LoadInfoList(out recordCount, int1, int2);
                }
            }
            return this._SysUserList;
        }
    }
 
    //管理端用户ID转名称
    private string SysUserName(int userId)
    {
        if (this.SysUserList == null)
            return string.Empty;
        SysUser sysUser = this._SysUserList.Find((Predicate<SysUser>)(bean => bean.UserID == userId));
        if (sysUser != null)
            return string.Format("{0}", (object)sysUser.UserName);
        return string.Empty;
    }
}