Browse Source

管理员管理客户模块

zhaozhiqiang 5 years ago
parent
commit
6ce6117e16

+ 172 - 0
codegit/CallCenterApi/CallCenterApi.BLL/ManagementUser.cs

@@ -0,0 +1,172 @@
1
+using CallCenterApi.Model;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Data;
5
+using System.Linq;
6
+using System.Text;
7
+using System.Threading.Tasks;
8
+
9
+namespace CallCenterApi.BLL
10
+{
11
+  public   class ManagementUser
12
+    {
13
+        private readonly DAL.ManagementUser dal = new DAL.ManagementUser();
14
+        /// <summary>
15
+        /// 获得数据列表
16
+        /// </summary>
17
+        public List<Model.ManagementUser> DataTableToList(DataTable dt)
18
+        {
19
+            List<Model.ManagementUser> modelList = new List<Model.ManagementUser>();
20
+            int rowsCount = dt.Rows.Count;
21
+            if (rowsCount > 0)
22
+            {
23
+                Model.ManagementUser model;
24
+                for (int n = 0; n < rowsCount; n++)
25
+                {
26
+                    model = dal.DataRowToModelarchives(dt.Rows[n]);
27
+                    if (model != null)
28
+                    {
29
+                        modelList.Add(model);
30
+                    }
31
+                }
32
+            }
33
+            return modelList;
34
+        }
35
+        /// <summary>
36
+        /// 根据Openid 获取用户
37
+        /// </summary>
38
+        /// <param name="openid"></param>
39
+        /// <returns></returns>
40
+        public Model.ManagementUser GetModelByOpenid(string openid)
41
+        {
42
+            return dal.GetModelByOpenid(openid);
43
+        }
44
+        /// <summary>
45
+        /// 更新一条数据
46
+        /// </summary>
47
+        public bool Update(Model.ManagementUser model)
48
+        {
49
+            return dal.Update(model);
50
+        }
51
+        /// <summary>
52
+        ///根据名称 得到一个对象实体
53
+        /// </summary>
54
+        public Model.ManagementUser GetModel(string username)
55
+        {
56
+            return dal.GetModel(username);
57
+        }
58
+        /// <summary>
59
+        ///根据名称 得到一个对象实体
60
+        /// </summary>
61
+        public Model.ManagementUser GetModelname(string username)
62
+        {
63
+            return dal.GetModelname(username);
64
+        }
65
+        /// <summary>
66
+        ///根据id 得到一个对象实体
67
+        /// </summary>
68
+        public Model.ManagementUser GetModels(int id)
69
+        {
70
+            return dal.GetModels(id);
71
+        }
72
+        /// <summary>
73
+        /// 增加一条数据
74
+        /// </summary>
75
+        public int Add(Model.ManagementUser model)
76
+        {
77
+            return dal.Add(model);
78
+        }
79
+        /// <summary>
80
+        /// 获得数据列表
81
+        /// </summary>
82
+        public List<Model.ManagementUser> GetModelList(string strWhere)
83
+        {
84
+            DataSet ds = dal.GetList(strWhere);
85
+            return DataTableToList(ds.Tables[0]);
86
+        }
87
+       
88
+        /// <summary>
89
+        /// 删除一条管理员数据
90
+        /// </summary>
91
+        public bool DeleteList(string F_UserIdlist)
92
+        {
93
+            return dal.DeleteList(F_UserIdlist);
94
+        }
95
+        /// <summary>
96
+        /// 获取管理员与客户关联信息
97
+        /// </summary>
98
+        /// <returns></returns>
99
+        public DataSet GetManageCustomer()
100
+        {
101
+            return dal.GetManageCustomer();
102
+        }
103
+        /// <summary>
104
+        /// 添加管理员与客户关联表数据
105
+        /// </summary>
106
+        /// <returns></returns>
107
+        public int AddManageCustomer(ManageCustomer model)
108
+        {
109
+            return dal.AddManageCustomer(model);
110
+        }
111
+        /// <summary>
112
+        /// 得到一个档案物资对象实体
113
+        /// </summary>
114
+        public CallCenterApi.Model.ManageCustomer GetManageCustomerModel(int id)
115
+        {
116
+            return dal.GetManageCustomerModel(id);
117
+        }
118
+        /// <summary>
119
+        /// 修改管理员与客户关联数据
120
+        /// </summary>
121
+        /// <param name="model"></param>
122
+        /// <returns></returns>
123
+        public bool UpdateManageCustomer(ManageCustomer model)
124
+        {
125
+            return dal.UpdateManageCustomer(model);
126
+        }
127
+        /// <summary>
128
+        /// 根据用户名密码得到一个对象实体
129
+        /// </summary>
130
+        public Model.ManagementUser GetManageCustomerModelwx(string username, string userpower)
131
+        {
132
+
133
+            return dal.GetManageCustomerModelwx(username,userpower);
134
+        }
135
+        /// <summary>
136
+        /// 获得数据列表
137
+        /// </summary>
138
+        public List<CallCenterApi.Model.ManageCustomer> GetManageCustomerModelList(string strWhere)
139
+        {
140
+            DataSet ds = dal.GetmanagecustomerList(strWhere);
141
+            return DataTableToList1(ds.Tables[0]);
142
+        }
143
+        /// <summary>
144
+        /// 获得数据列表
145
+        /// </summary>
146
+        public List<Model.ManageCustomer> DataTableToList1(DataTable dt)
147
+        {
148
+            List<Model.ManageCustomer> modelList = new List<Model.ManageCustomer>();
149
+            int rowsCount = dt.Rows.Count;
150
+            if (rowsCount > 0)
151
+            {
152
+                Model.ManageCustomer model;
153
+                for (int n = 0; n < rowsCount; n++)
154
+                {
155
+                    model = dal.DataRowToModelarchives1(dt.Rows[n]);
156
+                    if (model != null)
157
+                    {
158
+                        modelList.Add(model);
159
+                    }
160
+                }
161
+            }
162
+            return modelList;
163
+        }
164
+        /// <summary>
165
+        /// 删除一条管理员与客户关联数据
166
+        /// </summary>
167
+        public bool DeleteManaList(string ids)
168
+        {
169
+            return dal.DeleteManaList(ids);
170
+        }
171
+    }
172
+}

+ 506 - 0
codegit/CallCenterApi/CallCenterApi.DAL/ManagementUser.cs

@@ -0,0 +1,506 @@
1
+using CallCenterApi.DB;
2
+using CallCenterApi.Model;
3
+using System;
4
+using System.Collections.Generic;
5
+using System.Data;
6
+using System.Data.SqlClient;
7
+using System.Linq;
8
+using System.Reflection;
9
+using System.Text;
10
+using System.Threading.Tasks;
11
+
12
+namespace CallCenterApi.DAL
13
+{
14
+   public  class ManagementUser
15
+    {
16
+        /// <summary>
17
+        /// 得到一个管理员账号对象实体
18
+        /// </summary>
19
+        public CallCenterApi.Model.ManagementUser DataRowToModelarchives(DataRow row)
20
+        {
21
+            Model.ManagementUser model = new Model.ManagementUser();//主表字段
22
+            if (row != null)
23
+            {
24
+                #region 主表信息======================
25
+                //利用反射获得属性的所有公共属性
26
+                Type modelType = model.GetType();
27
+                for (int i = 0; i < row.Table.Columns.Count; i++)
28
+                {
29
+                    PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
30
+                    if (proInfo != null && row[i] != DBNull.Value)
31
+                    {
32
+                        //用索引值设置属性值
33
+                        proInfo.SetValue(model, row[i], null);
34
+                    }
35
+                }
36
+                #endregion
37
+            }
38
+            return model;
39
+        }
40
+
41
+        /// <summary>
42
+        /// 根据Openid 获取用户
43
+        /// </summary>
44
+        /// <param name="openid"></param>
45
+        /// <returns></returns>
46
+        public Model.ManagementUser GetModelByOpenid(string openid)
47
+        {
48
+
49
+            StringBuilder strSql = new StringBuilder();
50
+            strSql.Append("select  top 1 * from ManagementUser ");
51
+            strSql.Append(" where openid=@openid");
52
+            SqlParameter[] parameters = {
53
+                    new SqlParameter("@openid", SqlDbType.VarChar,300)
54
+            };
55
+            parameters[0].Value = openid;
56
+
57
+            Model.ManagementUser model = new Model.ManagementUser();
58
+            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
59
+            if (ds.Tables[0].Rows.Count > 0)
60
+            {
61
+                return DataRowToModel(ds.Tables[0].Rows[0]);
62
+            }
63
+            else
64
+            {
65
+                return null;
66
+            }
67
+        }
68
+        /// <summary>
69
+        /// 得到一个对象实体
70
+        /// </summary>
71
+        public Model.ManagementUser DataRowToModel(DataRow row)
72
+        {
73
+            Model.ManagementUser model = new Model.ManagementUser();
74
+            if (row != null)
75
+            {
76
+                if (row["id"] != null)
77
+                {
78
+                    model.id =Convert.ToInt32(row["id"]);
79
+                }
80
+                if (row["username"] != null)
81
+                {
82
+                    model.username = row["username"].ToString();
83
+                }
84
+                if (row["userpower"] != null)
85
+                {
86
+                    model.userpower = row["userpower"].ToString();
87
+                }
88
+                if (row["handleper"] != null)
89
+                {
90
+                    model.handleper = row["handleper"].ToString();
91
+                }
92
+
93
+                if (row["handdate"] != null)
94
+                {
95
+                    model.handdate =Convert.ToDateTime(row["handdate"]);
96
+                }
97
+                if (row["ifdeler"] != null)
98
+                {
99
+                    model.ifdeler = Convert.ToInt32(row["ifdeler"]);
100
+                }
101
+
102
+                if (row["openid"] != null)
103
+                {
104
+                    model.openid = row["openid"].ToString();
105
+                }
106
+
107
+            }
108
+            return model;
109
+        }
110
+
111
+        /// <summary>
112
+        /// 更新一条数据
113
+        /// </summary>
114
+        public bool Update(Model.ManagementUser model)
115
+        {
116
+            StringBuilder strSql = new StringBuilder();
117
+            strSql.Append("update ManagementUser set ");
118
+            strSql.Append("username=@username,");
119
+            strSql.Append("userpower=@userpower,");
120
+            strSql.Append("handleper=@handleper,");
121
+            strSql.Append("handdate=@handdate,");
122
+            strSql.Append("ifdeler=@ifdeler,");
123
+            strSql.Append("openid=@openid");
124
+
125
+            strSql.Append(" where id=@id ");
126
+            SqlParameter[] parameters = {
127
+                    new SqlParameter("@username", SqlDbType.VarChar,100),
128
+                    new SqlParameter("@userpower", SqlDbType.VarChar,200),
129
+                    new SqlParameter("@handleper", SqlDbType.VarChar,100),
130
+                    new SqlParameter("@handdate", SqlDbType.DateTime),
131
+                    new SqlParameter("@ifdeler", SqlDbType.Int,4),
132
+                    new SqlParameter("@openid", SqlDbType.VarChar,300),
133
+                    new SqlParameter("@id",SqlDbType.Int,4)};
134
+            parameters[0].Value = model.username;
135
+            parameters[1].Value = model.userpower;
136
+            parameters[2].Value = model.handleper;
137
+            parameters[3].Value = model.handdate;
138
+            parameters[4].Value = model.ifdeler;
139
+            parameters[5].Value = model.openid;
140
+            parameters[6].Value = model.id;
141
+
142
+            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
143
+            if (rows > 0)
144
+            {
145
+                return true;
146
+            }
147
+            else
148
+            {
149
+                return false;
150
+            }
151
+        }
152
+        /// <summary>
153
+        /// 根据名称得到一个对象实体
154
+        /// </summary>
155
+        public Model.ManagementUser GetModel(string username)
156
+        {
157
+
158
+            StringBuilder strSql = new StringBuilder();
159
+            strSql.Append("select  top 1 * from ManagementUser ");
160
+            strSql.Append(" where username=@username");
161
+            SqlParameter[] parameters = {
162
+                    new SqlParameter("@username", SqlDbType.NVarChar,100)
163
+            };
164
+            parameters[0].Value = username;
165
+
166
+            Model.T_Sys_UserAccount model = new Model.T_Sys_UserAccount();
167
+            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
168
+            if (ds.Tables[0].Rows.Count > 0)
169
+            {
170
+                return DataRowToModel(ds.Tables[0].Rows[0]);
171
+            }
172
+            else
173
+            {
174
+                return null;
175
+            }
176
+        }
177
+        /// <summary>
178
+        /// 根据名称得到一个对象实体
179
+        /// </summary>
180
+        public Model.ManagementUser GetModelname(string username)
181
+        {
182
+
183
+            StringBuilder strSql = new StringBuilder();
184
+            strSql.Append("select  top 1 * from ManagementUser ");
185
+            strSql.Append(" where username like  @username");
186
+            SqlParameter[] parameters = {
187
+                    new SqlParameter("@username", SqlDbType.NVarChar,100)
188
+            };
189
+            parameters[0].Value = username;
190
+
191
+            Model.T_Sys_UserAccount model = new Model.T_Sys_UserAccount();
192
+            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
193
+            if (ds.Tables[0].Rows.Count > 0)
194
+            {
195
+                return DataRowToModel(ds.Tables[0].Rows[0]);
196
+            }
197
+            else
198
+            {
199
+                return null;
200
+            }
201
+        }
202
+        /// <summary>
203
+        /// 根据id得到一个对象实体
204
+        /// </summary>
205
+        public Model.ManagementUser GetModels(int id)
206
+        {
207
+
208
+            StringBuilder strSql = new StringBuilder();
209
+            strSql.Append("select  top 1 * from ManagementUser ");
210
+            strSql.Append(" where id=@id");
211
+            SqlParameter[] parameters = {
212
+                    new SqlParameter("@id", SqlDbType.Int,4)
213
+            };
214
+            parameters[0].Value = id;
215
+            
216
+            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
217
+            if (ds.Tables[0].Rows.Count > 0)
218
+            {
219
+                return DataRowToModel(ds.Tables[0].Rows[0]);
220
+            }
221
+            else
222
+            {
223
+                return null;
224
+            }
225
+        }
226
+        /// <summary>
227
+        /// 根据用户名密码得到一个对象实体
228
+        /// </summary>
229
+        public Model.ManagementUser GetManageCustomerModelwx(string username, string userpower)
230
+        {
231
+
232
+            StringBuilder strSql = new StringBuilder();
233
+            strSql.Append("select  top 1 * from ManagementUser ");
234
+            strSql.Append("  where username=@username and userpower=@userpower");
235
+            SqlParameter[] parameters = {
236
+                    new SqlParameter("@username", SqlDbType.NVarChar,100),
237
+                     new SqlParameter("@userpower", SqlDbType.NVarChar,200)
238
+            };
239
+            parameters[0].Value = username;
240
+            parameters[1].Value = userpower;
241
+
242
+            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
243
+            if (ds.Tables[0].Rows.Count > 0)
244
+            {
245
+                return DataRowToModel(ds.Tables[0].Rows[0]);
246
+            }
247
+            else
248
+            {
249
+                return null;
250
+            }
251
+
252
+        }
253
+        /// <summary>
254
+        /// 增加一条数据
255
+        /// </summary>
256
+        public int Add(Model.ManagementUser model)
257
+        {
258
+            StringBuilder strSql = new StringBuilder();
259
+            strSql.Append("insert into ManagementUser(");
260
+            strSql.Append(" username, userpower, handleper,handdate,ifdeler,openid)");
261
+            strSql.Append(" values (");
262
+            strSql.Append("@username,@userpower,@handleper,@handdate,@ifdeler,@openid)");
263
+            strSql.Append(";select @@IDENTITY");
264
+            SqlParameter[] parameters = {
265
+                    new SqlParameter("@username", SqlDbType.VarChar,100),
266
+                    new SqlParameter("@userpower", SqlDbType.VarChar,200),
267
+                    new SqlParameter("@handleper", SqlDbType.VarChar,100),
268
+                    new SqlParameter("@handdate", SqlDbType.DateTime),
269
+                    new SqlParameter("@ifdeler", SqlDbType.Int,4),
270
+                    new SqlParameter("@openid", SqlDbType.VarChar,300)};
271
+            parameters[0].Value = model.username;
272
+            parameters[1].Value = model.userpower;
273
+            parameters[2].Value = model.handleper;
274
+            parameters[3].Value = model.handdate;
275
+            parameters[4].Value = model.ifdeler;
276
+            parameters[5].Value = model.openid;
277
+
278
+            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
279
+            if (obj == null)
280
+            {
281
+                return 0;
282
+            }
283
+            else
284
+            {
285
+                return Convert.ToInt32(obj);
286
+            }
287
+        }
288
+        /// <summary>
289
+        /// 获得数据列表
290
+        /// </summary>
291
+        public DataSet GetList(string strWhere)
292
+        {
293
+            StringBuilder strSql = new StringBuilder();
294
+            strSql.Append("select id,username, userpower, handleper,handdate,ifdeler,openid ");
295
+            strSql.Append(" FROM ManagementUser ");
296
+            if (strWhere.Trim() != "")
297
+            {
298
+                strSql.Append(" where " + strWhere);
299
+            }
300
+            return DbHelperSQL.Query(strSql.ToString());
301
+        }
302
+        /// <summary>
303
+        /// 批量删除数据
304
+        /// </summary>
305
+        public bool DeleteList(string ids)
306
+        {
307
+            StringBuilder strSql = new StringBuilder();
308
+            strSql.Append("update ManagementUser set ifdeler=1");
309
+            strSql.Append(" where id in (" + ids + ")  ");
310
+            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
311
+            if (rows > 0)
312
+            {
313
+                return true;
314
+            }
315
+            else
316
+            {
317
+                return false;
318
+            }
319
+        }
320
+        /// <summary>
321
+        /// 获取管理员与客户关联信息
322
+        /// </summary>
323
+        /// <returns></returns>
324
+        public DataSet GetManageCustomer()
325
+        {
326
+            StringBuilder strSql = new StringBuilder();
327
+            strSql.Append(" select a.*,b.username,c.F_CompanyName from ManageCustomer a left join ManagementUser b on a.mangid=b.id left join T_Cus_CustomerBaseNew c on a.cusmid=c.F_CustomerId ");
328
+          
329
+            var ds = DbHelperSQL.Query(strSql.ToString());
330
+
331
+            return ds;
332
+        }
333
+        /// <summary>
334
+        /// 添加管理员用户与客户关联信息
335
+        /// </summary>
336
+        /// <returns></returns>
337
+        public int AddManageCustomer(ManageCustomer model)
338
+        {
339
+
340
+            StringBuilder strSql = new StringBuilder();
341
+            strSql.Append("insert into ManageCustomer(");
342
+            strSql.Append(" mangid,cusmid)");
343
+            strSql.Append(" values (");
344
+            strSql.Append("@mangid,@cusmid)");
345
+            strSql.Append(";select @@IDENTITY");
346
+            SqlParameter[] parameters = {
347
+                    new SqlParameter("@mangid", SqlDbType.Int ,4),
348
+                    new SqlParameter("@cusmid", SqlDbType.Int ,4)};
349
+            parameters[0].Value = model.mangid;
350
+            parameters[1].Value = model.cusmid;
351
+
352
+            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
353
+            if (obj == null)
354
+            {
355
+                return 0;
356
+            }
357
+            else
358
+            {
359
+                return Convert.ToInt32(obj);
360
+            }
361
+        }
362
+
363
+        /// <summary>
364
+        /// 根据id得到一个对象实体
365
+        /// </summary>
366
+        public Model.ManageCustomer GetManageCustomerModel(int id)
367
+        {
368
+
369
+            StringBuilder strSql = new StringBuilder();
370
+            strSql.Append("select  top 1 a.*,b.username,c.F_CompanyName,c.F_CustomerCode from ManageCustomer a left join ManagementUser b on a.mangid=b.id left join T_Cus_CustomerBaseNew c on a.cusmid=c.F_CustomerId  ");
371
+            strSql.Append(" where a.id=@id");
372
+            SqlParameter[] parameters = {
373
+                    new SqlParameter("@id", SqlDbType.Int,4)
374
+            };
375
+            parameters[0].Value = id;
376
+
377
+            Model.ManageCustomer model = new Model.ManageCustomer();
378
+            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
379
+            if (ds.Tables[0].Rows.Count > 0)
380
+            {
381
+                return DataRowToModelcustomerBorrow(ds.Tables[0].Rows[0]);
382
+            }
383
+            else
384
+            {
385
+                return null;
386
+            }
387
+        }
388
+      
389
+        /// <summary>
390
+        /// 获取管理员与客户关联表实体
391
+        /// </summary>
392
+        /// <param name="id"></param>
393
+        /// <returns></returns>
394
+        public Model.ManageCustomer DataRowToModelcustomerBorrow(DataRow row)
395
+        {
396
+            Model.ManageCustomer model = new Model.ManageCustomer();//主表字段
397
+            if (row != null)
398
+            {
399
+                #region 主表信息======================
400
+                //利用反射获得属性的所有公共属性
401
+                Type modelType = model.GetType();
402
+                for (int i = 0; i < row.Table.Columns.Count; i++)
403
+                {
404
+                    PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
405
+                    if (proInfo != null && row[i] != DBNull.Value)
406
+                    {
407
+                        //用索引值设置属性值
408
+                        proInfo.SetValue(model, row[i], null);
409
+                    }
410
+                }
411
+                #endregion
412
+            }
413
+            return model;
414
+        }
415
+        /// <summary>
416
+        /// 修改管理员与客户关联数据
417
+        /// </summary>
418
+        /// <param name="model"></param>
419
+        /// <returns></returns>
420
+        public bool UpdateManageCustomer(ManageCustomer model)
421
+        {
422
+            StringBuilder strSql = new StringBuilder();
423
+            strSql.Append("update ManageCustomer set ");
424
+            strSql.Append("mangid=@mangid,");
425
+            strSql.Append("cusmid=@cusmid");
426
+            strSql.Append(" where id=@id");
427
+            SqlParameter[] parameters = {
428
+                    new SqlParameter("@mangid", SqlDbType.Int ,4),
429
+                    new SqlParameter("@cusmid", SqlDbType.Int,4),
430
+                    new SqlParameter("@id", SqlDbType.Int,4)};
431
+            parameters[0].Value = model.mangid;
432
+            parameters[1].Value = model.cusmid;
433
+            parameters[2].Value = model.id;
434
+            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
435
+            if (rows > 0)
436
+            {
437
+                return true;
438
+            }
439
+            else
440
+            {
441
+                return false;
442
+            }
443
+        }
444
+        /// <summary>
445
+        /// 得到一个管理员账号对象实体
446
+        /// </summary>
447
+        public CallCenterApi.Model.ManageCustomer DataRowToModelarchives1(DataRow row)
448
+        {
449
+            Model.ManageCustomer model = new Model.ManageCustomer();//主表字段
450
+            if (row != null)
451
+            {
452
+                #region 主表信息======================
453
+                //利用反射获得属性的所有公共属性
454
+                Type modelType = model.GetType();
455
+                for (int i = 0; i < row.Table.Columns.Count; i++)
456
+                {
457
+                    PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
458
+                    if (proInfo != null && row[i] != DBNull.Value)
459
+                    {
460
+                        //用索引值设置属性值
461
+                        proInfo.SetValue(model, row[i], null);
462
+                    }
463
+                }
464
+                #endregion
465
+            }
466
+            return model;
467
+        }
468
+        /// <summary>
469
+        /// 批量删除数据
470
+        /// </summary>
471
+        public bool DeleteManaList(string ids)
472
+        {
473
+            StringBuilder strSql = new StringBuilder();
474
+            strSql.Append("delete from ManageCustomer ");
475
+            strSql.Append(" where id in (@id)");
476
+            SqlParameter[] parameters = {
477
+                    new SqlParameter("@id", SqlDbType.Int,4)
478
+            };
479
+            parameters[0].Value = ids;
480
+
481
+            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
482
+            if (rows > 0)
483
+            {
484
+                return true;
485
+            }
486
+            else
487
+            {
488
+                return false;
489
+            }
490
+        }
491
+        /// <summary>
492
+        /// 获得数据列表
493
+        /// </summary>
494
+        public DataSet GetmanagecustomerList(string strWhere)
495
+        {
496
+            StringBuilder strSql = new StringBuilder();
497
+            strSql.Append("select  a.*,b.username,c.F_CompanyName,c.F_CustomerCode from ManageCustomer a left join ManagementUser b on a.mangid=b.id left join T_Cus_CustomerBaseNew c on a.cusmid=c.F_CustomerId  ");
498
+           
499
+            if (strWhere.Trim() != "")
500
+            {
501
+                strSql.Append(" where " + strWhere);
502
+            }
503
+            return DbHelperSQL.Query(strSql.ToString());
504
+        }
505
+    }
506
+}

+ 475 - 0
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/MageCus/MageCusController.cs

@@ -0,0 +1,475 @@
1
+using CallCenterApi.DB;
2
+using CallCenterApi.Interface.Controllers.Base;
3
+using CallCenterApi.Interface.Models.Input;
4
+using CallCenterApi.Model;
5
+using System;
6
+using System.Collections.Generic;
7
+using System.Data;
8
+using System.Linq;
9
+using System.Web;
10
+using System.Web.Mvc;
11
+
12
+namespace CallCenterApi.Interface.Controllers.MageCus
13
+{
14
+    public class MageCusController : BaseController
15
+    {
16
+        BLL.ManagementUser muserbll = new BLL.ManagementUser();
17
+        BLL.T_Cus_CustomerBaseNew customnew = new BLL.T_Cus_CustomerBaseNew();
18
+        /// <summary>
19
+        /// 分页显示管理员账号信息
20
+        /// </summary>
21
+        /// <param name="PageIndex"></param>
22
+        /// <param name="PageSize"></param>
23
+        /// <param name="username"></param>
24
+        /// <returns></returns>
25
+        public ActionResult GetManagementcus(int PageIndex, int PageSize, string username)
26
+        {
27
+            #region 分页显示管理员账号信息
28
+            if (PageIndex == 0)
29
+            {
30
+                PageIndex = 1;
31
+            }
32
+            if (PageSize == 0)
33
+            {
34
+                PageSize = 10;
35
+            }
36
+            var sql = "";
37
+            ///按名称模糊查询
38
+            if (username != null)
39
+            {
40
+                if (username != "")
41
+                {
42
+                    sql += "  and username like '%" + username + "%' ";
43
+                }
44
+
45
+            }
46
+            Model.PageData<Model.ManagementUser> pageModel = new Model.PageData<Model.ManagementUser>();
47
+            var recordCount = 0;
48
+            var dt = BLL.PagerBLL.GetListPager(
49
+                 "ManagementUser",
50
+                 "ManagementUser.id",
51
+                 "*",
52
+                 sql,
53
+                 "ORDER BY ManagementUser.id desc ",
54
+                 PageSize,
55
+                 PageIndex,
56
+                 true,
57
+                 out recordCount);
58
+            List<Model.ManagementUser> modelList = new BLL.ManagementUser().DataTableToList(dt);
59
+            var list = new List<Model.ManagementUser>();
60
+            foreach (var item in modelList)
61
+            {
62
+                list.Add(new Model.ManagementUser
63
+                {
64
+                    id = item.id,
65
+                    username = item.username,
66
+                    userpower = item.userpower,
67
+                    handdate = item.handdate,
68
+                    handleper = item.handleper,
69
+                    ifdeler = item.ifdeler,
70
+                    openid = item.openid
71
+                });
72
+            }
73
+            var obj = new
74
+            {
75
+                rows = list,
76
+                total = recordCount
77
+            };
78
+            return Success("成功", obj);
79
+            #endregion
80
+        }
81
+        /// <summary>
82
+        /// 登陆
83
+        /// </summary>
84
+        /// <param name="username"></param>
85
+        /// <param name="userpower"></param>
86
+        /// <param name="openid"></param>
87
+        /// <returns></returns>
88
+        public ActionResult Login(string username, string userpower, string openid)
89
+        {
90
+            #region 把其他OpenId更新为空
91
+            var userAccount = muserbll.GetModelByOpenid(openid);
92
+            if (userAccount != null)
93
+            {
94
+                userAccount.openid = "";
95
+                muserbll.Update(userAccount);
96
+            }
97
+            #endregion
98
+            
99
+            Dictionary<string, string> paras_Customer = new Dictionary<string, string>();
100
+            string sql_Customer = " select * from ManagementUser (NOLOCK) where username=@username and userpower=@userpower  ";//and ifdeler = 0 
101
+            paras_Customer.Add("@username", username);
102
+            paras_Customer.Add("@userpower", userpower);
103
+            var dt_Customer = DbHelperSQL.Query(sql_Customer, paras_Customer).Tables[0];
104
+
105
+            if (dt_Customer != null && dt_Customer.Rows.Count > 0)
106
+            {
107
+                
108
+                //var customer = customerBaseBLL.GetModel(login.UserCode);  //20180926 次方法查询有漏洞
109
+                var customer = muserbll.DataTableToList(dt_Customer).ToList().FirstOrDefault();
110
+                customer.openid = openid;
111
+                if (customer.ifdeler == 0)
112
+                {
113
+                    #region 新加 - 登录后同时获取用户账号,openid,和角色
114
+                    //5--业主(客户档案会员) 
115
+                    //int UserType = 5;
116
+                    var obj = new
117
+                    {
118
+                        openid = openid,
119
+                        username = username,
120
+                        userpower = userpower
121
+                    };
122
+                    #endregion
123
+                    if (muserbll.Update(customer))
124
+                        return Success("绑定成功!", obj);
125
+                    else
126
+                        return Error("绑定失败!");
127
+                }
128
+                else {
129
+                    return Error("该账户被禁用!");
130
+                }
131
+            }
132
+            return Error("账号或密码错误或者没有注册,请重新登录");
133
+        }
134
+        //[Authority]
135
+        //添加用户信息
136
+        public ActionResult AddUsers(ManagementUserInput input)
137
+        {
138
+            Model.ManagementUser ManagementUsertModel = new Model.ManagementUser();
139
+            //用户名不能重复
140
+            string username = input.username.Trim();
141
+            //用户名与客户信息表编号也不能重复
142
+            Model.T_Cus_CustomerBaseNew cusmodel = customnew.GetModelcuscode(username);
143
+            if (cusmodel != null)
144
+                return Error("客户名已存在");
145
+            Model.ManagementUser uModel = new BLL.ManagementUser().GetModel(username);
146
+            if (uModel != null)
147
+            {
148
+                if (uModel.ifdeler == 0)
149
+                {
150
+                    return Error("该用户名已存在");
151
+                }
152
+                else {
153
+                    return Error("该账户被禁用");
154
+                }
155
+            }
156
+            else
157
+            {
158
+               ManagementUsertModel.username = username;
159
+            }
160
+            ManagementUsertModel.handleper = CurrentUser.UserData.F_UserCode;//  "000";//
161
+            ManagementUsertModel.handdate = DateTime.Now;
162
+            ManagementUsertModel.ifdeler = 0;
163
+            if (input.userpower != null)
164
+                    ManagementUsertModel.userpower = input.userpower.Trim();
165
+              
166
+            if (muserbll.Add(ManagementUsertModel) > 0)
167
+                    return Success("新增成功!");
168
+                else
169
+                    return Error("新增失败!");
170
+        
171
+        }
172
+        /// <summary>
173
+        /// 获取详情
174
+        /// </summary>
175
+        /// <param name="id"></param>
176
+        /// <returns></returns>
177
+        public ActionResult GetModelarchives(int id)
178
+        {
179
+            var model = muserbll.GetModels(id);
180
+            if (model == null)
181
+                return Error("该信息不存在");
182
+            //根据id获取过关联的客户信息
183
+            var manacustomer = muserbll.GetManageCustomerModelList(" mangid="+id);
184
+            string companyname = "";
185
+            int a = 1;
186
+            foreach (var item in manacustomer)
187
+            {
188
+                companyname += item.F_CompanyName;
189
+                if (a < manacustomer.Count)
190
+
191
+                {
192
+                    companyname += ",";
193
+                }
194
+                a++;
195
+            }
196
+            var obj = new Model.ManagementUser
197
+            {
198
+                id = model.id,
199
+                username = model.username,
200
+                userpower = model.userpower,
201
+                handdate = model.handdate,
202
+                handleper = model.handleper,
203
+                ifdeler = model.ifdeler,
204
+                openid = model.openid,
205
+                companyname = companyname
206
+            };
207
+            return Success("获取成功", obj);
208
+        }
209
+        //修改用户信息
210
+        public ActionResult EditUsers(ManagementUserInput input)
211
+        {
212
+           
213
+           Model.ManagementUser ManagementUsertModel = muserbll.GetModelList("  id = " + input.id).FirstOrDefault();
214
+           if (ManagementUsertModel == null)
215
+               return Error("获取用户失败");
216
+
217
+            //用户名不能重复
218
+            string username = input.username.Trim();
219
+
220
+            //用户名与客户信息表编号也不能重复
221
+            Model.T_Cus_CustomerBaseNew cusmodel = customnew.GetModelcuscode(username);
222
+            if (cusmodel != null)
223
+                return Error("客户名已存在");
224
+            Model.ManagementUser uModel = new BLL.ManagementUser().GetModel(username);
225
+            if (uModel != null)
226
+            {
227
+                if (uModel.id != input.id)
228
+                {
229
+                    if (uModel != null)
230
+                    {
231
+                        if (uModel.ifdeler == 0)
232
+                        {
233
+                            return Error("该用户名已存在");
234
+                        }
235
+                        else
236
+                        {
237
+                            return Error("该账户被禁用");
238
+                        }
239
+                    }
240
+                    else
241
+                    {
242
+                        ManagementUsertModel.username = username;
243
+                    }
244
+                }
245
+                else
246
+                {
247
+                    ManagementUsertModel.username = username;
248
+                }
249
+            }
250
+            else {
251
+                ManagementUsertModel.username = username;
252
+            }
253
+           
254
+
255
+            ManagementUsertModel.handleper =  CurrentUser.UserData.F_UserCode;//;//"900";//
256
+            ManagementUsertModel.handdate = DateTime.Now;
257
+            ManagementUsertModel.ifdeler = 0;
258
+            if (input.userpower != null)
259
+                ManagementUsertModel.userpower = input.userpower.Trim();
260
+
261
+
262
+            if (muserbll.Update(ManagementUsertModel))
263
+                        return  Success("编辑成功!");
264
+                    else
265
+                        return  Error("编辑失败!");
266
+               
267
+            
268
+        }
269
+        //[Authority]
270
+        //删除用户
271
+        public ActionResult DeleteUsers(string ids)
272
+        {
273
+            
274
+                if (ids == null || ids=="")
275
+                    return Error("请选择用户");
276
+                
277
+                if (string.IsNullOrEmpty(ids))
278
+                    return Error("请选择用户");
279
+                if (muserbll.DeleteList(ids))
280
+                    return Success("删除成功");
281
+                else
282
+                    return Error("删除失败");
283
+         
284
+        }
285
+        /// <summary>
286
+        /// 根据名称获取管理员信息
287
+        /// </summary>
288
+        /// <param name="username"></param>
289
+        /// <returns></returns>
290
+        public ActionResult GetModelManageuser(string username)
291
+        {
292
+
293
+            string sql = "";
294
+            var list = new List<Model.ManagementUser>();
295
+            if (username == null || username == "")
296
+            {
297
+                sql += " ifdeler=0";
298
+
299
+            }
300
+            else
301
+            {
302
+                sql += " ifdeler=0 ";
303
+                sql += $" and username like '%" + username.Trim() + "%'";
304
+            }
305
+            if (!string.IsNullOrWhiteSpace(sql))
306
+            {
307
+                list = muserbll.GetModelList(sql);
308
+            }
309
+          
310
+            if (list.Count > 0)
311
+                return Success("根据名称获取管理员信息", list);
312
+            else
313
+                return Success("没有获取到管理员信息,请重新搜索", list);
314
+        }
315
+        /// <summary>
316
+        /// 获取管理员和客户关联信息
317
+        /// </summary>
318
+        /// <returns></returns>
319
+        public ActionResult GetManageCustomer(int PageIndex, int PageSize)
320
+        {
321
+            //DataTable dt = new DataTable();
322
+            //dt = muserbll.GetManageCustomer().Tables[0];
323
+            //return Success("加载成功", dt);
324
+            #region 分页显示管理员账号信息
325
+            if (PageIndex == 0)
326
+            {
327
+                PageIndex = 1;
328
+            }
329
+            if (PageSize == 0)
330
+            {
331
+                PageSize = 10;
332
+            }
333
+            var sql = " ";
334
+           
335
+            Model.PageData<Model.ManageCustomer> pageModel = new Model.PageData<Model.ManageCustomer>();
336
+            var recordCount = 0;
337
+            var dt = BLL.PagerBLL.GetListPager(
338
+                 "( select a.*,b.username,c.F_CompanyName,c.F_CustomerCode from ManageCustomer a  left join ManagementUser b on a.mangid=b.id  left join T_Cus_CustomerBaseNew c on a.cusmid=c.F_CustomerId ) d",
339
+                 "d.id",
340
+                 "*",
341
+                 sql,
342
+                 "ORDER BY d.id desc ",
343
+                 PageSize,
344
+                 PageIndex,
345
+                 true,
346
+                 out recordCount);
347
+            List<Model.ManageCustomer> modelList = new BLL.ManagementUser().DataTableToList1(dt);
348
+            var list = new List<Model.ManageCustomer>();
349
+            foreach (var item in modelList)
350
+            {
351
+                list.Add(new Model.ManageCustomer
352
+                {
353
+                    id = item.id,
354
+                    username = item.username,
355
+                    mangid=item.mangid,
356
+                    cusmid=item.cusmid,
357
+                    F_CompanyName=item.F_CompanyName,
358
+                    F_CustomerCode=item.F_CustomerCode
359
+                });
360
+            }
361
+            var obj = new
362
+            {
363
+                rows = list,
364
+                total = recordCount
365
+            };
366
+            return Success("成功", obj);
367
+            #endregion
368
+        }
369
+        //添加关联信息
370
+        public ActionResult AddManageCustomer(int mangid,string cusmid)
371
+        {
372
+
373
+            string[] arrStr = cusmid.Split(',');
374
+            foreach (var item in arrStr)
375
+            {
376
+                Model.ManageCustomer ManageCustomerModel = new Model.ManageCustomer();
377
+                ManageCustomerModel.mangid = mangid;
378
+
379
+                ManageCustomerModel.cusmid =Convert.ToInt32(item);
380
+
381
+                if (muserbll.AddManageCustomer(ManageCustomerModel) > 0)
382
+                {
383
+
384
+                }
385
+                else
386
+                {
387
+                    return Error("新增失败!");
388
+                }
389
+                    
390
+            }
391
+            return Success("新增成功!");
392
+
393
+        }
394
+        /// <summary>
395
+        /// 获取管理员客户关联数据详情
396
+        /// </summary>
397
+        /// <param name="id"></param>
398
+        /// <returns></returns>
399
+        public ActionResult GetManageCustomerModel(int id)
400
+        {
401
+            var model = muserbll.GetManageCustomerModel(id);
402
+            if (model == null)
403
+                return Error("该信息不存在");
404
+            var obj = new Model.ManageCustomer
405
+            {
406
+                id = model.id,
407
+                cusmid=model.cusmid,
408
+                mangid=model.mangid,
409
+                username=model.username,
410
+                F_CompanyName=model.F_CompanyName,
411
+                F_CustomerCode=model.F_CustomerCode
412
+                
413
+            };
414
+            return Success("获取成功", obj);
415
+        }
416
+        /// <summary>
417
+        /// 修改管理员客户关联数据信息
418
+        /// </summary>
419
+        /// <param name="mangid"></param>
420
+        /// <param name="cusmid"></param>
421
+        /// <param name="id"></param>
422
+        /// <returns></returns>
423
+        public ActionResult UpdateManageCustomer(int mangid, int cusmid,int id)
424
+        {
425
+            Model.ManageCustomer ManageCustomerModel = new Model.ManageCustomer();
426
+            ManageCustomerModel.mangid = mangid;
427
+
428
+            ManageCustomerModel.cusmid = cusmid;
429
+            ManageCustomerModel.id = id;
430
+            if (muserbll.UpdateManageCustomer(ManageCustomerModel))
431
+                return Success("修改成功!");
432
+            else
433
+                return Error("修改失败!");
434
+        }
435
+        /// <summary>
436
+        /// 根据用户名获取所管理的客户
437
+        /// </summary>
438
+        /// <param name="username"></param>
439
+        /// <returns></returns>
440
+        public ActionResult GetManageCustomername(string username)
441
+        {
442
+            ManagementUser mause = muserbll.GetModelname(username);
443
+            int id = 0;
444
+            if (mause != null)
445
+            {
446
+                id = mause.id;
447
+            }
448
+            string sql = "";
449
+            if (id > 0)
450
+            {
451
+                sql += " mangid=" + id;
452
+            }
453
+            var maulist = muserbll.GetManageCustomerModelList(sql);
454
+            return Success("获取成功", maulist);
455
+        }
456
+        /// <summary>
457
+        /// 删除管理员账号与客户关联表数据
458
+        /// </summary>
459
+        /// <param name="ids"></param>
460
+        /// <returns></returns>
461
+        public ActionResult DeleManageCust(string ids)
462
+        {
463
+            if (ids == null || ids == "")
464
+                return Error("请选择数据");
465
+
466
+            if (string.IsNullOrEmpty(ids))
467
+                return Error("请选择数据");
468
+            if (muserbll.DeleteManaList(ids))
469
+                return Success("删除成功");
470
+            else
471
+                return Error("删除失败");
472
+
473
+          }
474
+    }
475
+}

+ 26 - 0
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/customer/CustomerNewController.cs

@@ -183,6 +183,32 @@ namespace CallCenterApi.Interface.Controllers.customer
183 183
                 return Success("没有获取到相关公司,请重新搜索", list);
184 184
         }
185 185
         /// <summary>
186
+        /// 根据名称搜索公司
187
+        /// </summary>
188
+        public ActionResult GetListBycompany(string company)
189
+        {
190
+            string sql = "";
191
+            var list = new List<Model.T_Cus_CustomerBaseNew>();
192
+            if (company == null || company == "")
193
+            {
194
+                sql += " F_DeleteFlag=0";
195
+               
196
+            }
197
+            else
198
+            {
199
+                sql += " F_DeleteFlag=0";
200
+                sql += $" and F_CompanyName like '%" + company.Trim() + "%'";
201
+            }
202
+            if (!string.IsNullOrWhiteSpace(sql))
203
+            {
204
+                list = cusbll.GetModelList(sql);
205
+            }
206
+            if (list.Count > 0)
207
+                return Success("根据公司名称获取公司信息", list);
208
+            else
209
+                return Success("没有获取到相关公司,请重新搜索", list);
210
+        }
211
+        /// <summary>
186 212
         /// 获取客户信息
187 213
         /// </summary>
188 214
         /// <returns></returns>

+ 40 - 0
codegit/CallCenterApi/CallCenterApi.Model/ManageCustomer.cs

@@ -0,0 +1,40 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+using System.Threading.Tasks;
6
+
7
+namespace CallCenterApi.Model
8
+{
9
+    /// <summary>
10
+    /// 管理员客户关联表
11
+    /// </summary>
12
+    [Serializable]
13
+    public   class ManageCustomer
14
+    {
15
+        /// <summary>
16
+        /// 编号id
17
+        /// </summary>
18
+        public int id { get; set; }
19
+        /// <summary>
20
+        /// 管理员账号id
21
+        /// </summary>
22
+        public int mangid { get; set; }
23
+        /// <summary>
24
+        /// 客户id
25
+        /// </summary>
26
+        public int cusmid { get; set; }
27
+        /// <summary>
28
+        /// 账号名称
29
+        /// </summary>
30
+        public string username { get; set; }
31
+        /// <summary>
32
+        /// 公司名
33
+        /// </summary>
34
+        public string F_CompanyName { get; set; }
35
+        /// <summary>
36
+        /// 公司编号
37
+        /// </summary>
38
+        public string F_CustomerCode { get; set; }
39
+    }
40
+}

+ 46 - 0
codegit/CallCenterApi/CallCenterApi.Model/ManagementUser.cs

@@ -0,0 +1,46 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+using System.Threading.Tasks;
6
+
7
+namespace CallCenterApi.Model
8
+{
9
+    /// <summary>
10
+    /// 管理员账号表管理客户
11
+    /// </summary>
12
+    [Serializable]
13
+   public  class ManagementUser
14
+    {
15
+        #region Model
16
+       
17
+        public int id { get; set; }
18
+        /// <summary>
19
+        /// 账号名称
20
+        /// </summary>
21
+        public string username { get; set; }
22
+        /// <summary>
23
+        /// 密码
24
+        /// </summary>
25
+        public string userpower { get; set; }
26
+        /// <summary>
27
+        /// 操作人
28
+        /// </summary>
29
+        public string handleper { get; set; }
30
+        /// <summary>
31
+        /// 操作时间
32
+        /// </summary>
33
+        public DateTime handdate { get; set; }
34
+        /// <summary>
35
+        /// 是否删除0 未删 1 已删
36
+        /// </summary>
37
+        public int ifdeler { get; set; }
38
+        /// <summary>
39
+        /// 微信登录的openid
40
+        /// </summary>
41
+        public string openid { get; set; }
42
+
43
+        public string companyname;
44
+        #endregion Model
45
+    }
46
+}