wzp
2021-09-16 f73f7f06ed1cbdca4a1d7c127ca89829b6f2433c
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
<%@ WebHandler Language="C#" Class="GwClientHandler" %>
using System;
using System.Web;
using Dao;
using Common;
 
using System.Collections.Generic;
using System.Configuration;
using System.Text;
using System.Text.RegularExpressions;
 
 
 
public class GwClientHandler : PageHandler<Model.SysUser>
{
    public override JsonPageResult ProcessRequestInternal(PageContext<Model.SysUser> context)
    {
        string action = context.GetString("action");
 
        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);
 
            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 ClientName = context.GetString("ClientName");
        string Telephone = context.GetString("Telephone");
        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())
        {
            var list = dao.LoadInfoList(out recordCount, pageIndex, pageSize, ClientID, ClientName, Telephone, Agent);
                
            if (list != null && list.Count > 0)
            {
                foreach (Model.GwClient item in list)
                {
                    str += @"<tr ><td>" + item.ClientID + "</td><td>" + item.ClientName + "</td><td>" + item.Telephone + "</td><td>" +item.TotalAmount / 1000 + "元/" + item.Balance / 1000 + "元</td><td>" + item.Agent + "</td><td>" + item.Remark + "</td>";
 
                    str += @"<td>";
                    string loginStr = "http://" + serverIp + ":" + clientPort + "/Attachedlogin.aspx?action=Attachedlogin&account=" + item.Account + "&password=" + item.Password;
                    str += string.Format("<a class=\"action-modal-login btn btn-success btn-xs \" href=\"{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-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=""8"">暂无信息</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));
    }
 
    /// <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 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 permissionData = Newtonsoft.Json.JsonConvert.SerializeObject(context.GetString("permissionData").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("联系人/联系电话,不能为空!");
        }
 
 
        var client = new Model.GwClient();
 
        client.Id = id;
        client.ClientID = clientID;
        client.Password = password;
        client.ClientName = clientName;
        client.Address = address;
        client.Remark = remark;
        client.Telephone = telephone;
        client.Agent = agent;
        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 permissionData = Newtonsoft.Json.JsonConvert.SerializeObject(context.GetString("permissionData").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))
        {
            throw new ArgumentException("客户名称不能为空!");
        }
 
        if (_Dao.IsIDExists(clientID))
        {
            throw new ArgumentException("客户账号已经存在!");
        }
 
        var client = new Model.GwClient();
        client.ClientID = clientID;
        client.Password = password;
        
        client.ClientName = clientName;
        client.Address = address;
        client.Remark = remark;
        client.Telephone = telephone;
        client.Agent = agent;
        client.PermissionData = permissionData;
        client.ParentId = context.OperatorID;
        
        _Dao.Add(client);
 
        return new JsonPageResult(true, "创建客户成功!");
    }