Bez popisu

ChatController.cs 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using CallCenterApi.Interface.Controllers.Base;
  8. using System.Data;
  9. using CallCenter.Utility;
  10. using CallCenterApi.DB;
  11. using CallCenterAPI.WechatSDK;
  12. using CallCenterAPI.WechatSDK.Models;
  13. using CallCenterApi.Common;
  14. namespace CallCenterApi.Interface.Controllers
  15. {
  16. public class ChatController : BaseController
  17. {
  18. // GET: Chat
  19. /// <summary>
  20. /// 获取微信openid
  21. /// </summary>
  22. /// <param name="login"></param>
  23. /// <returns></returns>
  24. public ActionResult GetOpenId(WxLoginDto wld)
  25. {
  26. wld.RedirectUrl = RequestString.GetUrlReferrer();
  27. if (string.IsNullOrEmpty(wld.OpenId))
  28. {
  29. var temp = WxHelper.GetUserInfo(wld);
  30. if (string.IsNullOrWhiteSpace(temp.OpenId))
  31. {
  32. return Redirect("请求", temp.RedirectUrl);
  33. }
  34. wld.OpenId = temp.OpenId;
  35. wld.UserInfo = temp.UserInfo;
  36. }
  37. var model = new BLL.T_Chat_User().GetModelList(" F_OpenId='" + wld.OpenId + "'").FirstOrDefault();
  38. if (model == null)
  39. {
  40. model = new Model.T_Chat_User();
  41. model.F_OpenId = wld.OpenId;
  42. model.F_Account = wld.OpenId;
  43. model.F_Name = wld.UserInfo.nickname;
  44. model.F_HeadImgUrl = wld.UserInfo.headimgurl;
  45. model.F_Type = 2;
  46. model.F_State = 0;
  47. model.F_IsDelete = 0;
  48. model.F_CreateTime = DateTime.Now;
  49. new BLL.T_Chat_User().Add(model);
  50. }
  51. return Success("成功", wld.OpenId);
  52. }
  53. /// <summary>
  54. /// 获取用户列表
  55. /// </summary>
  56. /// <returns></returns>
  57. [Authority]
  58. public ActionResult GetUserList(int isdc = 0)
  59. {
  60. DataTable dt = new DataTable();
  61. string sql = " and F_IsDelete=0 ";
  62. string strcode = HttpUtility.UrlDecode(RequestString.GetQueryString("code"));
  63. string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
  64. string strpageindex = RequestString.GetQueryString("page");
  65. int pageindex = 1;
  66. string strpagesize = RequestString.GetQueryString("pagesize");
  67. int pagesize = 10;
  68. if (strcode.Trim() != "" && strcode != "undefined")
  69. {
  70. sql += " and F_MainUserCode = '" + strcode.Trim() + "' ";
  71. }
  72. if (strname.Trim() != "" && strname != "undefined")
  73. {
  74. sql += " and F_Name like '%" + strname + "%' ";
  75. }
  76. if (strpageindex.Trim() != "")
  77. {
  78. pageindex = Convert.ToInt32(strpageindex);
  79. }
  80. if (strpagesize.Trim() != "")
  81. {
  82. pagesize = Convert.ToInt32(strpagesize);
  83. }
  84. string cols = "*,dbo.GetUserName(F_MainUserCode) as UserName";
  85. if (isdc > 0)
  86. {
  87. var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Chat_User where 1=1 " + sql).Tables[0];
  88. var msg = new NPOIHelper().ExportToExcel("用户列表", dtdc);
  89. if (msg == "")
  90. {
  91. return Success("导出成功");
  92. }
  93. else
  94. {
  95. return Error("导出失败");
  96. }
  97. }
  98. int recordCount = 0;
  99. dt = BLL.PagerBLL.GetListPager(
  100. "T_Chat_User",
  101. "F_Id",
  102. cols,
  103. sql,
  104. "ORDER BY F_CreateTime DESC",
  105. pagesize,
  106. pageindex,
  107. true,
  108. out recordCount);
  109. var obj = new
  110. {
  111. state = "success",
  112. message = "成功",
  113. rows = dt,
  114. total = recordCount
  115. };
  116. return Content(obj.ToJson());
  117. }
  118. /// <summary>
  119. /// 获取消息列表
  120. /// </summary>
  121. /// <returns></returns>
  122. [Authority]
  123. public ActionResult GetMessageList(int isdc = 0)
  124. {
  125. DataTable dt = new DataTable();
  126. string sql = " and F_IsDelete=0 ";
  127. string strcususer = HttpUtility.UrlDecode(RequestString.GetQueryString("cususer"));
  128. string strseruser = HttpUtility.UrlDecode(RequestString.GetQueryString("seruser"));
  129. string strpageindex = RequestString.GetQueryString("page");
  130. int pageindex = 1;
  131. string strpagesize = RequestString.GetQueryString("pagesize");
  132. int pagesize = 10;
  133. if (strcususer.Trim() != "" && strcususer != "undefined")
  134. {
  135. sql += " and (F_FromUser = '" + strcususer.Trim() + "' or F_ToUser = '" + strcususer.Trim() + "' )";
  136. }
  137. if (strseruser.Trim() != "" && strseruser != "undefined")
  138. {
  139. sql += " and (F_FromUser = '" + strseruser.Trim() + "' or F_ToUser = '" + strseruser.Trim() + "' )";
  140. }
  141. if (strpageindex.Trim() != "")
  142. {
  143. pageindex = Convert.ToInt32(strpageindex);
  144. }
  145. if (strpagesize.Trim() != "")
  146. {
  147. pagesize = Convert.ToInt32(strpagesize);
  148. }
  149. string cols = "*";
  150. if (isdc > 0)
  151. {
  152. var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Chat_Message where 1=1 " + sql).Tables[0];
  153. var msg = new NPOIHelper().ExportToExcel("用户列表", dtdc);
  154. if (msg == "")
  155. {
  156. return Success("导出成功");
  157. }
  158. else
  159. {
  160. return Error("导出失败");
  161. }
  162. }
  163. int recordCount = 0;
  164. dt = BLL.PagerBLL.GetListPager(
  165. "T_Chat_Message",
  166. "F_Id",
  167. cols,
  168. sql,
  169. "ORDER BY F_CreateTime DESC",
  170. pagesize,
  171. pageindex,
  172. true,
  173. out recordCount);
  174. var obj = new
  175. {
  176. state = "success",
  177. message = "成功",
  178. rows = dt,
  179. total = recordCount
  180. };
  181. return Content(obj.ToJson());
  182. }
  183. /// <summary>
  184. /// 获取IP列表
  185. /// </summary>
  186. /// <returns></returns>
  187. [Authority]
  188. public ActionResult GetIPList(int isdc = 0)
  189. {
  190. DataTable dt = new DataTable();
  191. string sql = " and F_IsDelete=0 ";
  192. string strcode = HttpUtility.UrlDecode(RequestString.GetQueryString("code"));
  193. string strip = HttpUtility.UrlDecode(RequestString.GetQueryString("ip"));
  194. int type = RequestString.GetInt("type",0);
  195. string strpageindex = RequestString.GetQueryString("page");
  196. int pageindex = 1;
  197. string strpagesize = RequestString.GetQueryString("pagesize");
  198. int pagesize = 10;
  199. if (strcode.Trim() != "" && strcode != "undefined")
  200. {
  201. sql += " and F_OpenId like '%" + strcode.Trim() + "%' ";
  202. }
  203. if (strip.Trim() != "" && strip != "undefined")
  204. {
  205. sql += " and F_IP like '%" + strip.Trim() + "%' ";
  206. }
  207. if (type != 0)
  208. {
  209. sql += " and F_Type = '" + type + "' ";
  210. }
  211. if (strpageindex.Trim() != "")
  212. {
  213. pageindex = Convert.ToInt32(strpageindex);
  214. }
  215. if (strpagesize.Trim() != "")
  216. {
  217. pagesize = Convert.ToInt32(strpagesize);
  218. }
  219. string cols = "*";
  220. if (isdc > 0)
  221. {
  222. var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Chat_IPList where 1=1 " + sql).Tables[0];
  223. var msg = new NPOIHelper().ExportToExcel("用户IP列表", dtdc);
  224. if (msg == "")
  225. {
  226. return Success("导出成功");
  227. }
  228. else
  229. {
  230. return Error("导出失败");
  231. }
  232. }
  233. int recordCount = 0;
  234. dt = BLL.PagerBLL.GetListPager(
  235. "T_Chat_IPList",
  236. "F_Id",
  237. cols,
  238. sql,
  239. "ORDER BY F_CreateTime DESC",
  240. pagesize,
  241. pageindex,
  242. true,
  243. out recordCount);
  244. var obj = new
  245. {
  246. state = "success",
  247. message = "成功",
  248. rows = dt,
  249. total = recordCount
  250. };
  251. return Content(obj.ToJson());
  252. }
  253. /// <summary>
  254. /// 获取联系列表
  255. /// </summary>
  256. /// <returns></returns>
  257. [Authority]
  258. public ActionResult GetInOutList(int isdc = 0)
  259. {
  260. DataTable dt = new DataTable();
  261. string sql = " and F_IsDelete=0 ";
  262. string strcode = HttpUtility.UrlDecode(RequestString.GetQueryString("code"));
  263. string strip = HttpUtility.UrlDecode(RequestString.GetQueryString("ip"));
  264. int type = RequestString.GetInt("type", 0);
  265. string strpageindex = RequestString.GetQueryString("page");
  266. int pageindex = 1;
  267. string strpagesize = RequestString.GetQueryString("pagesize");
  268. int pagesize = 10;
  269. if (strcode.Trim() != "" && strcode != "undefined")
  270. {
  271. sql += " and F_OpenId like '%" + strcode.Trim() + "%' ";
  272. }
  273. if (strip.Trim() != "" && strip != "undefined")
  274. {
  275. sql += " and F_IP like '%" + strip.Trim() + "%' ";
  276. }
  277. if (type != 0)
  278. {
  279. sql += " and F_Type = '" + type + "' ";
  280. }
  281. if (strpageindex.Trim() != "")
  282. {
  283. pageindex = Convert.ToInt32(strpageindex);
  284. }
  285. if (strpagesize.Trim() != "")
  286. {
  287. pagesize = Convert.ToInt32(strpagesize);
  288. }
  289. string cols = "*";
  290. if (isdc > 0)
  291. {
  292. var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Chat_InOut where 1=1 " + sql).Tables[0];
  293. var msg = new NPOIHelper().ExportToExcel("联系列表", dtdc);
  294. if (msg == "")
  295. {
  296. return Success("导出成功");
  297. }
  298. else
  299. {
  300. return Error("导出失败");
  301. }
  302. }
  303. int recordCount = 0;
  304. dt = BLL.PagerBLL.GetListPager(
  305. "T_Chat_InOut",
  306. "F_Id",
  307. cols,
  308. sql,
  309. "ORDER BY F_InTime DESC",
  310. pagesize,
  311. pageindex,
  312. true,
  313. out recordCount);
  314. var obj = new
  315. {
  316. state = "success",
  317. message = "成功",
  318. rows = dt,
  319. total = recordCount
  320. };
  321. return Content(obj.ToJson());
  322. }
  323. /// <summary>
  324. /// 获取黑名单IP列表
  325. /// </summary>
  326. /// <returns></returns>
  327. [Authority]
  328. public ActionResult GetBlackIPList(int isdc = 0)
  329. {
  330. DataTable dt = new DataTable();
  331. string sql = " and F_IsDelete=0 ";
  332. string strip = HttpUtility.UrlDecode(RequestString.GetQueryString("ip"));
  333. string strpageindex = RequestString.GetQueryString("page");
  334. int pageindex = 1;
  335. string strpagesize = RequestString.GetQueryString("pagesize");
  336. int pagesize = 10;
  337. if (strip.Trim() != "" && strip != "undefined")
  338. {
  339. sql += " and F_IP like '%" + strip + "%' ";
  340. }
  341. if (strpageindex.Trim() != "")
  342. {
  343. pageindex = Convert.ToInt32(strpageindex);
  344. }
  345. if (strpagesize.Trim() != "")
  346. {
  347. pagesize = Convert.ToInt32(strpagesize);
  348. }
  349. string cols = "*,dbo.GetUserName(F_CreateUser) as UserName";
  350. if (isdc > 0)
  351. {
  352. var dtdc = DbHelperSQL.Query(" select " + cols + " from T_Chat_IPBlackList where 1=1 " + sql).Tables[0];
  353. var msg = new NPOIHelper().ExportToExcel("黑名单IP列表", dtdc);
  354. if (msg == "")
  355. {
  356. return Success("导出成功");
  357. }
  358. else
  359. {
  360. return Error("导出失败");
  361. }
  362. }
  363. int recordCount = 0;
  364. dt = BLL.PagerBLL.GetListPager(
  365. "T_Chat_IPBlackList",
  366. "F_Id",
  367. cols,
  368. sql,
  369. "ORDER BY F_CreateTime DESC",
  370. pagesize,
  371. pageindex,
  372. true,
  373. out recordCount);
  374. var obj = new
  375. {
  376. state = "success",
  377. message = "成功",
  378. rows = dt,
  379. total = recordCount
  380. };
  381. return Content(obj.ToJson());
  382. }
  383. /// <summary>
  384. /// 获取黑名单IP
  385. /// </summary>
  386. /// <param name="areaId"></param>
  387. /// <returns></returns>
  388. [Authority]
  389. public ActionResult GetBlackIP()
  390. {
  391. int id = RequestString.GetInt("id", 0);
  392. Model.T_Chat_IPBlackList dModel = new BLL.T_Chat_IPBlackList().GetModel(id);
  393. return Success("成功", dModel);
  394. }
  395. /// <summary>
  396. /// 添加/编辑黑名单IP
  397. /// </summary>
  398. /// <param name="input"></param>
  399. /// <returns></returns>
  400. [HttpPost]
  401. [Authority]
  402. public ActionResult AddBlackIP()
  403. {
  404. int id = RequestString.GetInt("id", 0);
  405. string ip = RequestString.GetFormString("ip");
  406. string remark = RequestString.GetFormString("remark");
  407. string starttime = RequestString.GetFormString("starttime");
  408. string endtime = RequestString.GetFormString("endtime");
  409. Model.T_Chat_IPBlackList dModel = new Model.T_Chat_IPBlackList();
  410. if (id == 0)
  411. {
  412. var list = new BLL.T_Chat_IPBlackList().GetModelList(" F_IP='" + ip + "' and F_IsDelete=0 ");
  413. if (list.Count > 0)
  414. {
  415. return Error("已经存在此IP");
  416. }
  417. else
  418. {
  419. dModel.F_IP = ip;
  420. dModel.F_Remark = remark;
  421. if (!string.IsNullOrEmpty(starttime))
  422. {
  423. dModel.F_StartTime = DateTime.Parse(starttime);
  424. }
  425. if (!string.IsNullOrEmpty(endtime))
  426. {
  427. dModel.F_EndTime = DateTime.Parse(endtime);
  428. }
  429. dModel.F_State = 1;
  430. dModel.F_IsDelete = 0;
  431. dModel.F_CreateUser = User.F_UserCode;
  432. dModel.F_CreateTime = DateTime.Now;
  433. int n = new BLL.T_Chat_IPBlackList().Add(dModel);
  434. if (n > 0)
  435. return Success("添加成功", n);
  436. else
  437. return Error("添加失败");
  438. }
  439. }
  440. else
  441. {
  442. dModel = new BLL.T_Chat_IPBlackList().GetModel(id);
  443. if (dModel != null)
  444. {
  445. var list = new BLL.T_Chat_IPBlackList().GetModelList(" F_IP='" + ip + "' and F_IsDelete=0 and F_Id!='" + id + "' ");
  446. if (list.Count > 0)
  447. {
  448. return Error("已经存在此IP");
  449. }
  450. else
  451. {
  452. dModel.F_IP = ip;
  453. dModel.F_Remark = remark;
  454. if (!string.IsNullOrEmpty(starttime))
  455. {
  456. dModel.F_StartTime = DateTime.Parse(starttime);
  457. }
  458. if (!string.IsNullOrEmpty(endtime))
  459. {
  460. dModel.F_EndTime = DateTime.Parse(endtime);
  461. }
  462. if (new BLL.T_Chat_IPBlackList().Update(dModel))
  463. return Success("修改成功");
  464. else
  465. return Error("修改失败");
  466. }
  467. }
  468. else
  469. {
  470. return Error("修改失败");
  471. }
  472. }
  473. }
  474. /// <summary>
  475. /// 删除黑名单IP
  476. /// </summary>
  477. /// <param name="ids"></param>
  478. /// <returns></returns>
  479. [Authority]
  480. public ActionResult DelBlackIP(string[] ids)
  481. {
  482. if (ids == null || ids.Length <= 0)
  483. {
  484. return Error("请选择要删除的黑名单IP");
  485. }
  486. var idStr = string.Join(",", ids);
  487. if (string.IsNullOrEmpty(idStr.Trim()))
  488. {
  489. return Error("请选择要删除的黑名单IP");
  490. }
  491. int n = DbHelperSQL.ExecuteSql(" update T_Chat_IPBlackList set F_IsDelete=1,F_DeleteUser='" + User.F_UserCode + "',F_DeleteTime=getdate() where F_Id in (" + idStr + ")");
  492. if (n > 0)
  493. {
  494. return Success("删除成功");
  495. }
  496. return Error("删除失败");
  497. }
  498. }
  499. }