新野县12345_后端

EmailSendController.cs 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.Interface.Controllers.Base;
  4. using CallCenterApi.Interface.Controllers.workorder;
  5. using CallCenterApi.Model;
  6. using LumiSoft.Net.Mail;
  7. using LumiSoft.Net.MIME;
  8. using LumiSoft.Net.POP3.Client;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Web;
  15. using System.Web.Mvc;
  16. namespace CallCenterApi.Interface.Controllers
  17. {
  18. public class EmailSendController : BaseController
  19. {
  20. BLL.T_Email_SendEmail bllEmail = new BLL.T_Email_SendEmail();
  21. /// <summary>
  22. /// 批量发送邮件
  23. /// </summary>
  24. /// <returns></returns>
  25. [Authority]
  26. public ActionResult SendbatchEmail()
  27. {
  28. MailHelper mh = new MailHelper();
  29. mh.MailName = Configs.GetValue("MailName"); //邮箱名称
  30. //mh.MailName = mh.MailUserName.Split('@')[0].ToString(); //名称
  31. mh.MailServer = Configs.GetValue("MailServer"); //"smtp.126.com"; //邮件服务器地址
  32. mh.MailUserName = Configs.GetValue("MailUserName"); //用户名
  33. mh.MailPassword = Configs.GetValue("MailPassword"); //密码
  34. string workOrder = RequestString.GetFormString("workOrder");
  35. int typeId = RequestString.GetInt("typeId", 0);
  36. string emailList = RequestString.GetFormString("email");
  37. string title = RequestString.GetFormString("title");
  38. string content = RequestString.GetFormString("content");
  39. if (!string.IsNullOrEmpty(emailList))
  40. {
  41. int ix = 0; //成功个数
  42. int iy = 0; //失败个数
  43. string[] arrStr = emailList.Split(',');
  44. foreach (string str in arrStr)
  45. {
  46. string strEmail = str;
  47. bool b = mh.Send(strEmail, title, content);
  48. Model.T_Email_EmailList eModel = new BLL.T_Email_EmailList().GetModelByEmail(strEmail);
  49. //接收邮箱名称
  50. string receiveName = string.Empty;
  51. int e_Id = 0;
  52. if (eModel != null)
  53. {
  54. receiveName = eModel.E_Name;
  55. e_Id = eModel.E_Id;
  56. }
  57. Model.T_Email_SendEmail model = new Model.T_Email_SendEmail();
  58. if (b)
  59. {
  60. model.E_IsSucces = 1; //成功
  61. ix++;
  62. }
  63. else
  64. {
  65. model.E_IsSucces = 0; //失败
  66. iy++;
  67. }
  68. model.E_WorkOrderId = workOrder;
  69. model.E_TypeId = typeId;
  70. model.E_SendEmail = mh.MailUserName; //发送邮箱
  71. model.E_SendName = mh.MailUserName.Split('@')[0].ToString(); //发送邮箱名称
  72. model.E_ReceiveEmail = strEmail; //接收邮箱
  73. model.E_ReceiveName = string.IsNullOrEmpty(receiveName) ? strEmail.Split('@')[0].ToString() : receiveName;
  74. model.E_Title = title;
  75. model.E_Content = content;
  76. model.E_AddTime = DateTime.Now;
  77. model.F_UserId = User.F_UserId;
  78. model.F_UserName = User.F_UserCode;
  79. //model.F_UserId = 0;
  80. //model.F_UserName = string.Empty;
  81. new BLL.T_Email_SendEmail().Add(model);
  82. if (e_Id > 0)
  83. {
  84. new BLL.T_Email_EmailList().Delete(eModel.E_Id);
  85. }
  86. }
  87. string result = string.Empty;
  88. if (ix > 0) {
  89. result += "已发送:" + ix;
  90. }
  91. if (iy > 0) {
  92. result += "发送失败:" + iy;
  93. }
  94. if (ix > 0)
  95. {
  96. return Success("发送成功", result);
  97. }
  98. else {
  99. return Error("发送失败");
  100. }
  101. }
  102. else {
  103. return Error("邮箱不能为空");
  104. }
  105. }
  106. /// <summary>
  107. /// 导入邮件
  108. /// </summary>
  109. /// <returns></returns>
  110. [Authority]
  111. public ActionResult ImportEmail()
  112. {
  113. string resultEmail = ""; //输出邮箱
  114. int userId = User.F_UserId;;
  115. HttpPostedFile _upfile = RequestString.GetFile("upFile");
  116. int headrow = 0;
  117. NPOIHelper npoi = new NPOIHelper();
  118. DataTable dt = npoi.ExcelToTable(_upfile, headrow);
  119. foreach (DataRow dr in dt.Rows)
  120. {
  121. headrow = headrow + 1;
  122. if (dr[0].ToString() != "" && dr[1].ToString() != "")
  123. {
  124. Model.T_Email_EmailList model = new Model.T_Email_EmailList();
  125. model.E_Name = dr[0].ToString(); //姓名
  126. model.E_Email = dr[1].ToString(); //邮件
  127. model.E_State = 0; //状态
  128. model.E_AddTime = DateTime.Now; //添加时间
  129. model.F_UserId = userId; //添加用户Id
  130. if (new BLL.T_Email_EmailList().Add(model) <= 0)
  131. {
  132. return Error("第" + headrow + "行,导入失败!");
  133. }
  134. else {
  135. resultEmail += dr[1].ToString() + ","; //邮箱拼接
  136. }
  137. }
  138. else
  139. {
  140. return Error("第" + headrow + "行,第1,2列信息不能为空,未导入");
  141. }
  142. }
  143. return Success("导入成功", resultEmail.Trim(',').ToString());
  144. }
  145. #region 批量获取126邮件,删除,审核,创建邮件工单
  146. /// <summary>
  147. /// 获取邮件信息列表(可以分页)-- 新
  148. /// </summary>
  149. /// <returns></returns>
  150. [Authority]
  151. public ActionResult GetEmailMessageList()
  152. {
  153. BLL.T_Email_EmailMessage_Map bll = new BLL.T_Email_EmailMessage_Map();
  154. int isAudit= RequestString.GetInt("isAudit", 0);
  155. int recordCount = 0;
  156. string strpageindex = RequestString.GetQueryString("page");
  157. int pageindex = 1;
  158. string strpagesize = RequestString.GetQueryString("pagesize");
  159. int pagesize = 10;
  160. if (strpageindex.Trim() != "")
  161. {
  162. pageindex = Convert.ToInt32(strpageindex);
  163. }
  164. if (strpagesize.Trim() != "")
  165. {
  166. pagesize = Convert.ToInt32(strpagesize);
  167. }
  168. //判断
  169. if (pagesize <= 0)
  170. {
  171. return Error("每页记录不能小于2,默认为10");
  172. }
  173. List<EmailrReceive> list = new List<EmailrReceive>();
  174. List<EmailrReceive> lists = new List<EmailrReceive>();
  175. if (isAudit == 1)
  176. {
  177. var Emaillist = bll.DataTableToList(bll.GetList(" 1=1 ").Tables[0]).OrderByDescending(x => x.E_EmailTime); ;
  178. foreach (var p in Emaillist)
  179. {
  180. EmailrReceive modelEmail = new EmailrReceive();
  181. modelEmail.E_EmailId = p.E_EmailId;
  182. modelEmail.E_Email = p.E_SendEmail;
  183. modelEmail.E_Address = p.E_SendName;
  184. modelEmail.E_Title = p.E_Title;
  185. modelEmail.E_EmailTime = Convert.ToDateTime(p.E_EmailTime);
  186. modelEmail.E_Content = p.E_Content;
  187. modelEmail.E_AttachmentsUrl = p.E_AttachmentsUrl;
  188. modelEmail.E_WorkOrderId = p.E_WorkOrderId;
  189. modelEmail.E_IsWorkOrder = p.E_IsWorkOrder;
  190. modelEmail.E_IsAudit = p.E_IsAudit;
  191. list.Add(modelEmail);
  192. }
  193. }
  194. else
  195. {
  196. using (POP3_Client pop3 = new POP3_Client())
  197. {
  198. try
  199. {
  200. pop3.Connect(Configs.GetValue("Email_Server"), int.Parse(Configs.GetValue("Email_Port")), false);
  201. pop3.Login(Configs.GetValue("Email_Name"), Configs.GetValue("Email_Password")); //两个参数,前者为Email的账号,后者为Email的密码
  202. }
  203. catch (Exception ex)
  204. {
  205. return Error("邮箱登录失败,请查看登录配置或是否能访问外网");
  206. }
  207. POP3_ClientMessageCollection messages = pop3.Messages;
  208. for (int i = messages.Count - 1; i >= 0; i--)
  209. {
  210. EmailrReceive model = new EmailrReceive();
  211. POP3_ClientMessage message = messages[i]; //转化为POP3
  212. if (message != null)
  213. {
  214. byte[] messageBytes = message.MessageToByte();
  215. Mail_Message mime_message = Mail_Message.ParseFromByte(messageBytes);
  216. model.E_EmailId = message.UID;
  217. model.E_Email = mime_message.From == null ? " " : mime_message.From[0].DisplayName;
  218. model.E_Address = mime_message.From == null ? " " : mime_message.From[0].Address;
  219. model.E_Title = mime_message.Subject ?? " ";
  220. model.E_EmailTime = mime_message.Date;
  221. model.E_Content = mime_message.BodyText ?? " ";
  222. MIME_Entity[] attachments = mime_message.GetAttachments(true, true);
  223. string Url = string.Empty;
  224. int n = 0;
  225. foreach (MIME_Entity entity in attachments)
  226. {
  227. if (entity.ContentDisposition != null)
  228. {
  229. string fileName = entity.ContentDisposition.Param_FileName;
  230. if (!string.IsNullOrEmpty(fileName))
  231. {
  232. n += 1;
  233. string pathUrl = "/Upload/Email/" + DateTime.Now.ToString("yyyy") + "" + DateTime.Now.ToString("MM") + "/"; // + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";
  234. string path = Server.MapPath("..") + pathUrl;
  235. string fileNames = DateTimeConvert.ToTimetag(mime_message.Date) + n + fileName; //重新命名附件
  236. if (!Directory.Exists(path)) Directory.CreateDirectory(path);
  237. path = Path.Combine(path, fileNames);
  238. MIME_b_SinglepartBase byteObj = (MIME_b_SinglepartBase)entity.Body;
  239. Stream decodedDataStream = byteObj.GetDataStream();
  240. using (FileStream fs = new FileStream(path, FileMode.Create))
  241. {
  242. LumiSoft.Net.Net_Utils.StreamCopy(decodedDataStream, fs, 4000);
  243. }
  244. Url += pathUrl + fileNames + ",";
  245. }
  246. }
  247. }
  248. model.E_AttachmentsUrl = Url.TrimEnd(',');
  249. if (!string.IsNullOrEmpty(message.UID))
  250. {
  251. var listmodel = bll.GetModelList(" E_EmailId='" + message.UID + "'").FirstOrDefault();
  252. model.E_IsWorkOrder = 0;
  253. model.E_IsAudit = 0;
  254. if (listmodel != null)
  255. {
  256. model.E_WorkOrderId = listmodel.E_WorkOrderId;
  257. model.E_IsWorkOrder = listmodel.E_IsWorkOrder;
  258. model.E_IsAudit = listmodel.E_IsAudit;
  259. }
  260. }
  261. list.Add(model);
  262. }
  263. }
  264. }
  265. list = list.Where(a => a.E_IsAudit == isAudit).ToList();
  266. }
  267. var obj = new
  268. {
  269. rows = list.Skip((pageindex - 1) * pagesize).Take(pagesize),
  270. total = list.Count
  271. };
  272. return Content(obj.ToJson());
  273. }
  274. /// <summary>
  275. /// 获取邮件信息列表(可以分页) 暂不使用
  276. /// </summary>
  277. /// <returns></returns>
  278. [Authority]
  279. public ActionResult GetEmailMessage()
  280. {
  281. BLL.T_Email_EmailMessage_Map bll = new BLL.T_Email_EmailMessage_Map();
  282. int recordCount = 0;
  283. string strpageindex = RequestString.GetQueryString("page");
  284. int pageindex = 1;
  285. string strpagesize = RequestString.GetQueryString("pagesize");
  286. int pagesize = 10 - 1;
  287. if (strpageindex.Trim() != "")
  288. {
  289. pageindex = Convert.ToInt32(strpageindex);
  290. }
  291. if (strpagesize.Trim() != "")
  292. {
  293. pagesize = Convert.ToInt32(strpagesize) - 1;
  294. }
  295. //判断
  296. if (pagesize <= 0)
  297. {
  298. return Error("每页记录不能小于2,默认为10");
  299. }
  300. List<EmailrReceive> list = new List<EmailrReceive>();
  301. using (POP3_Client pop3 = new POP3_Client())
  302. {
  303. pop3.Connect(Configs.GetValue("Email_Server"), int.Parse(Configs.GetValue("Email_Port")), false);
  304. pop3.Login(Configs.GetValue("Email_Name"), Configs.GetValue("Email_Password")); //两个参数,前者为Email的账号,后者为Email的密码
  305. POP3_ClientMessageCollection messages = pop3.Messages;
  306. recordCount = messages.Count;
  307. #region 分页判断
  308. int emailcount = messages.Count; //总数
  309. float emailpage2 = emailcount % pagesize;
  310. int emailpage = emailcount / pagesize; //总页数
  311. //判断是否有余数
  312. if (emailpage2 > 0) //(float)emailpage
  313. emailpage = emailpage + 1;
  314. //判断如果当前页为负数或者零时
  315. if (pageindex <= 0)
  316. pageindex = 1;
  317. //判断如果当前页大于总页数时
  318. if (pageindex > emailpage)
  319. pageindex = emailpage;
  320. int start = emailcount - 1 - (pageindex - 1) * pagesize;
  321. int end = emailcount - 1 - pageindex * pagesize;
  322. if (end < 0)
  323. end = 0;
  324. #endregion
  325. for (int i = start; i >= end; i--)
  326. {
  327. EmailrReceive model = new EmailrReceive();
  328. POP3_ClientMessage message = messages[i]; //转化为POP3
  329. if (message != null)
  330. {
  331. byte[] messageBytes = message.MessageToByte();
  332. Mail_Message mime_message = Mail_Message.ParseFromByte(messageBytes);
  333. model.E_EmailId = message.UID;
  334. model.E_Email= mime_message.From == null ? " " : mime_message.From[0].DisplayName;
  335. model.E_Address= mime_message.From == null ? " " : mime_message.From[0].Address;
  336. model.E_Title= mime_message.Subject ?? " ";
  337. model.E_EmailTime= mime_message.Date;
  338. model.E_Content= mime_message.BodyText ?? " ";
  339. MIME_Entity[] attachments = mime_message.GetAttachments(true, true);
  340. string Url = string.Empty;
  341. int n = 0;
  342. foreach (MIME_Entity entity in attachments)
  343. {
  344. if (entity.ContentDisposition != null)
  345. {
  346. string fileName = entity.ContentDisposition.Param_FileName;
  347. if (!string.IsNullOrEmpty(fileName))
  348. {
  349. n += 1;
  350. string pathUrl = "/Upload/Email/" + DateTime.Now.ToString("yyyy") + "" + DateTime.Now.ToString("MM") + "/"; // + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";
  351. string path = Server.MapPath("..") + pathUrl;
  352. string fileNames = DateTimeConvert.ToTimetag(mime_message.Date) + n + fileName; //重新命名附件
  353. if (!Directory.Exists(path)) Directory.CreateDirectory(path);
  354. path = Path.Combine(path, fileNames);
  355. MIME_b_SinglepartBase byteObj = (MIME_b_SinglepartBase)entity.Body;
  356. Stream decodedDataStream = byteObj.GetDataStream();
  357. using (FileStream fs = new FileStream(path, FileMode.Create))
  358. {
  359. LumiSoft.Net.Net_Utils.StreamCopy(decodedDataStream, fs, 4000);
  360. }
  361. Url += pathUrl + fileNames + ",";
  362. }
  363. }
  364. }
  365. model.E_AttachmentsUrl = Url.TrimEnd(',');
  366. if (!string.IsNullOrEmpty(message.UID))
  367. {
  368. var listmodel = bll.GetModelList(" E_EmailId='" + message.UID + "'").FirstOrDefault();
  369. if (listmodel != null)
  370. {
  371. model.E_WorkOrderId = listmodel.E_WorkOrderId;
  372. model.E_IsWorkOrder = listmodel.E_IsWorkOrder;
  373. model.E_IsAudit = listmodel.E_IsAudit;
  374. }
  375. }
  376. list.Add(model);
  377. }
  378. }
  379. }
  380. var obj = new
  381. {
  382. rows = list,
  383. total = recordCount
  384. };
  385. return Content(obj.ToJson());
  386. }
  387. /// <summary>
  388. /// 获取邮件详情ByID
  389. /// </summary>
  390. /// <param name="uid"></param>
  391. /// <returns></returns>
  392. public ActionResult GetEmailInfoById(string uid)
  393. {
  394. BLL.T_Email_EmailMessage_Map bll = new BLL.T_Email_EmailMessage_Map();
  395. List<EmailrReceive> list = new List<EmailrReceive>();
  396. EmailrReceive model = new EmailrReceive();
  397. if (string.IsNullOrEmpty(uid)) {
  398. return Error("参数不能为空");
  399. }
  400. using (POP3_Client pop3 = new POP3_Client())
  401. {
  402. pop3.Connect(Configs.GetValue("Email_Server"), int.Parse(Configs.GetValue("Email_Port")), false);
  403. pop3.Login(Configs.GetValue("Email_Name"), Configs.GetValue("Email_Password")); //两个参数,前者为Email的账号,后者为Email的密码
  404. POP3_ClientMessageCollection messages = pop3.Messages;
  405. for (int i = 0; i < messages.Count; i++)
  406. {
  407. POP3_ClientMessage message = messages[i]; //转化为POP3
  408. if (message != null)
  409. {
  410. byte[] messageBytes = message.MessageToByte();
  411. Mail_Message mime_message = Mail_Message.ParseFromByte(messageBytes);
  412. if (message.UID == uid)
  413. {
  414. model.E_EmailId = message.UID;
  415. model.E_Email = mime_message.From == null ? " " : mime_message.From[0].DisplayName;
  416. model.E_Address = mime_message.From == null ? " " : mime_message.From[0].Address;
  417. model.E_Title = mime_message.Subject ?? " ";
  418. model.E_EmailTime = mime_message.Date;
  419. model.E_Content = mime_message.BodyText ?? " ";
  420. MIME_Entity[] attachments = mime_message.GetAttachments(true, true);
  421. string Url = string.Empty;
  422. int n = 0;
  423. foreach (MIME_Entity entity in attachments)
  424. {
  425. if (entity.ContentDisposition != null)
  426. {
  427. string fileName = entity.ContentDisposition.Param_FileName;
  428. if (!string.IsNullOrEmpty(fileName))
  429. {
  430. n += 1;
  431. string pathUrl = "/Upload/Email/" + DateTime.Now.ToString("yyyy") + "" + DateTime.Now.ToString("MM") + "/"; // + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM") + "/" + DateTime.Now.ToString("dd") + "/";
  432. string path = Server.MapPath("..") + pathUrl;
  433. string fileNames = DateTimeConvert.ToTimetag(mime_message.Date) + n + fileName; //重新命名附件
  434. if (!Directory.Exists(path)) Directory.CreateDirectory(path);
  435. path = Path.Combine(path, fileNames);
  436. MIME_b_SinglepartBase byteObj = (MIME_b_SinglepartBase)entity.Body;
  437. Stream decodedDataStream = byteObj.GetDataStream();
  438. using (FileStream fs = new FileStream(path, FileMode.Create))
  439. {
  440. LumiSoft.Net.Net_Utils.StreamCopy(decodedDataStream, fs, 4000);
  441. }
  442. Url += pathUrl + fileNames + ",";
  443. }
  444. }
  445. }
  446. model.E_AttachmentsUrl = Url.TrimEnd(',');
  447. if (!string.IsNullOrEmpty(message.UID))
  448. {
  449. var listmodel = bll.GetModelList(" E_EmailId='" + message.UID + "'").FirstOrDefault();
  450. if (listmodel != null)
  451. {
  452. model.E_WorkOrderId = listmodel.E_WorkOrderId;
  453. model.E_IsWorkOrder = listmodel.E_IsWorkOrder;
  454. model.E_IsAudit = listmodel.E_IsAudit;
  455. }
  456. }
  457. }
  458. }
  459. }
  460. }
  461. return Success("获取成功", model);
  462. }
  463. /// <summary>
  464. /// 删除邮件信息ById
  465. /// </summary>
  466. /// <param name="uid">邮件唯一标识ID</param>
  467. /// <returns></returns>
  468. [Authority]
  469. public ActionResult DelEmailByID(string uid)
  470. {
  471. if (string.IsNullOrEmpty(uid))
  472. {
  473. return Error("参数为空");
  474. }
  475. using (POP3_Client pop3 = new POP3_Client())
  476. {
  477. pop3.Connect(Configs.GetValue("Email_Server"), int.Parse(Configs.GetValue("Email_Port")), false);
  478. pop3.Login(Configs.GetValue("Email_Name"), Configs.GetValue("Email_Password")); //两个参数,前者为Email的账号,后者为Email的密码
  479. if (pop3.Messages.Count > 0)
  480. {
  481. foreach (POP3_ClientMessage mail in pop3.Messages)
  482. {
  483. try
  484. {
  485. if (uid == mail.UID)
  486. {
  487. mail.MarkForDeletion();
  488. return Success("删除成功");
  489. }
  490. }
  491. catch (Exception ex)
  492. {
  493. return Error("删除失败");
  494. }
  495. }
  496. }
  497. }
  498. return Success("删除成功");
  499. }
  500. /// <summary>
  501. /// 邮件审核(0未审核,1已审核)
  502. /// </summary>
  503. /// <param name="uid">邮件ID</param>
  504. /// <returns></returns>
  505. [Authority]
  506. public ActionResult IsAudit(EmailrReceive input)
  507. {
  508. BLL.T_Email_EmailMessage_Map bll = new BLL.T_Email_EmailMessage_Map();
  509. Model.T_Email_EmailMessage_Map model = new Model.T_Email_EmailMessage_Map();
  510. if (string.IsNullOrEmpty(input.E_EmailId))
  511. {
  512. return Error("邮件Id不能为空");
  513. }
  514. if (string.IsNullOrEmpty(input.E_Email))
  515. {
  516. return Error("邮件不能为空");
  517. }
  518. if (string.IsNullOrEmpty(input.E_Title))
  519. {
  520. return Error("邮件标题不能为空");
  521. }
  522. var listmodel = bll.GetModelList(" E_EmailId='" + input.E_EmailId + "' and E_IsAudit = 1 ").FirstOrDefault();
  523. if (listmodel == null)
  524. {
  525. //邮件未审核 添加
  526. //model.E_Id = 0;
  527. model.E_WorkOrderId = "";
  528. model.E_EmailId = input.E_EmailId;
  529. model.E_IsWorkOrder = 0; //是否已发工单(0未发,1已发)
  530. model.E_IsAudit = 1; //0未审核,1已审核
  531. model.E_SendEmail = input.E_Email;
  532. model.E_SendName = input.E_Email.Split('@')[0].ToString();
  533. model.E_Title = input.E_Title;
  534. model.E_Content = input.E_Content;
  535. model.E_AttachmentsUrl = input.E_AttachmentsUrl;
  536. model.E_AddTime = DateTime.Now;
  537. model.E_EmailTime = input.E_EmailTime;
  538. model.F_UserId = User.F_UserId;
  539. model.F_UserName = User.F_UserCode;
  540. int b = bll.Add(model);
  541. if (b > 0)
  542. {
  543. return Success("审核成功");
  544. }
  545. else {
  546. return Error("审核失败");
  547. }
  548. }
  549. else {
  550. //邮件已审核
  551. return Error("邮件已审核");
  552. }
  553. }
  554. /// <summary>
  555. /// 添加邮件工单(E_IsWorkOrder 0未创建工单,1已创建工单)
  556. /// </summary>
  557. /// <returns></returns>
  558. [Authority]
  559. public ActionResult AddWorkOrderByEmail()
  560. {
  561. string emailid = RequestString.GetFormString("emailid"); //邮件id
  562. int source = RequestString.GetInt("source", 2); //信息来源(2市长信箱)
  563. string cusname = RequestString.GetFormString("cusname"); //投诉人姓名
  564. string cussex = RequestString.GetFormString("cussex"); //投诉人性别
  565. string cusphone = RequestString.GetFormString("cusphone"); //投诉人电话
  566. string cusaddress = RequestString.GetFormString("cusaddress"); //投诉人详细地址
  567. string email = RequestString.GetFormString("email"); //邮箱
  568. string zipcode = RequestString.GetFormString("zipcode"); //邮编
  569. string conname = RequestString.GetFormString("conname"); //联系人姓名
  570. string conphone = RequestString.GetFormString("conphone"); //客户电话
  571. string title = RequestString.GetFormString("title"); //标题
  572. string content = RequestString.GetFormString("content"); //内容
  573. int sourcearea = RequestString.GetInt("sourcearea", 0); //事发地域id
  574. string sourceaddress = RequestString.GetFormString("sourceaddress"); //事发详细地址
  575. string keys = RequestString.GetFormString("keys"); //关键词id(多个用英文逗号, 隔开)
  576. string splituser = RequestString.GetFormString("splituser"); //分管领导id(多个用英文逗号, 隔开)
  577. int type = RequestString.GetInt("type", 9); //类型(9咨询10求助11投诉12建议13表扬14其他)
  578. int bigtype = RequestString.GetInt("bigtype", 0); //大类别
  579. int smalltype = RequestString.GetInt("smalltype", 0); //小类别
  580. int isprotect = RequestString.GetInt("isprotect", 0); //0普通1保密
  581. int level = RequestString.GetInt("level", 1); //1普通2紧急3特急
  582. WorkOrderController wo = new WorkOrderController();
  583. BLL.T_Email_EmailMessage_Map bll = new BLL.T_Email_EmailMessage_Map();
  584. Model.T_Email_EmailMessage_Map model = new Model.T_Email_EmailMessage_Map();
  585. if (string.IsNullOrEmpty(emailid))
  586. {
  587. return Error("邮件Id不能为空");
  588. }
  589. if (string.IsNullOrEmpty(email))
  590. {
  591. return Error("邮件不能为空");
  592. }
  593. if (string.IsNullOrEmpty(title))
  594. {
  595. return Error("标题不能为空");
  596. }
  597. //var modelemailid = bll.GetModelList(" E_EmailId='" + emailid + "' and E_IsAudit = 1 AND ISNULL(E_IsWorkOrder,0) = 0 ").FirstOrDefault();
  598. model = bll.GetModelList(" E_EmailId='" + emailid + "'").FirstOrDefault();
  599. //邮件关联表 信息存在时修改
  600. if (model == null)
  601. {
  602. return Error("操作失败,请先审核邮件");
  603. }
  604. if (model.E_IsAudit == 0)
  605. {
  606. return Error("操作失败,请审核邮件");
  607. }
  608. if (model.E_IsWorkOrder == 1)
  609. {
  610. return Error("操作失败,已提交工单");
  611. }
  612. //新增邮件工单信息
  613. string WorkOrderId = wo.AddWorkOrderBySource(source, cusname, cussex, cusphone, cusaddress, email, zipcode, conname, conphone, title, content, sourcearea, sourceaddress, keys, splituser, type, bigtype, smalltype, isprotect, level);
  614. if (string.IsNullOrEmpty(WorkOrderId))
  615. return Error("操作失败");
  616. //新增邮件关联表信息
  617. //model = bll.GetModelList(" E_EmailId='" + emailid + "'").FirstOrDefault();
  618. model.E_WorkOrderId = WorkOrderId;
  619. model.E_IsWorkOrder = 1;
  620. model.E_AddTime = DateTime.Now;
  621. if (!bll.Update(model))
  622. {
  623. return Error("操作失败");
  624. }
  625. //新增信息T_Sys_Users关联表
  626. var modelUsers = new BLL.T_Sys_Users().GetModel(emailid);
  627. if (modelUsers == null)
  628. {
  629. modelUsers = new Model.T_Sys_Users();
  630. modelUsers.F_OpenId = emailid;
  631. modelUsers.F_Type = 2; //F_Type:1微信OpenId;2邮件Id
  632. modelUsers.F_CreateTime = DateTime.Now;
  633. new BLL.T_Sys_Users().Add(modelUsers);
  634. }
  635. //新增信息T_Sys_Users关联表
  636. var emailuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + emailid + "' and F_Type=2 ").FirstOrDefault();
  637. var modelUserWorkOrder = new BLL.T_Bus_UserWorkOrder().GetModel(WorkOrderId);
  638. if (modelUserWorkOrder == null)
  639. {
  640. Model.T_Bus_UserWorkOrder tbu = new Model.T_Bus_UserWorkOrder();
  641. tbu.F_UserId = emailuser.F_Id;
  642. tbu.F_WorkOrderId = WorkOrderId;
  643. new BLL.T_Bus_UserWorkOrder().Add(tbu);
  644. }
  645. return Success("操作成功");
  646. }
  647. #endregion
  648. #region 内部邮件 - 已发送邮件管理
  649. /// <summary>
  650. /// 获取所有已发送邮箱
  651. /// </summary>
  652. /// <returns></returns>
  653. [Authority]
  654. public ActionResult GetAllList()
  655. {
  656. DataTable dt = new DataTable();
  657. string email = HttpUtility.UrlDecode(RequestString.GetQueryString("email"));
  658. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("strstarttime"));
  659. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("strendtime"));
  660. string strpageindex = RequestString.GetQueryString("page");
  661. int pageindex = 1;
  662. string strpagesize = RequestString.GetQueryString("pagesize");
  663. int pagesize = 10;
  664. string sql = string.Empty;
  665. if (email.Trim() != "")
  666. {
  667. sql += " and E_ReceiveEmail like '%" + email + "%'";
  668. }
  669. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  670. {
  671. sql += " and datediff(day,E_AddTime,'" + strstarttime + "')<=0 ";
  672. }
  673. if (strendtime.Trim() != "" && strendtime != "undefined")
  674. {
  675. sql += " and datediff(day,E_AddTime,'" + strendtime + "')>=0 ";
  676. }
  677. if (strpageindex.Trim() != "")
  678. {
  679. pageindex = Convert.ToInt32(strpageindex);
  680. }
  681. if (strpagesize.Trim() != "")
  682. {
  683. pagesize = Convert.ToInt32(strpagesize);
  684. }
  685. int recordCount = 0;
  686. dt = BLL.PagerBLL.GetListPager(
  687. "T_Email_SendEmail",
  688. "E_Id",
  689. "*",
  690. sql,
  691. "ORDER BY E_Id desc",
  692. pagesize,
  693. pageindex,
  694. true,
  695. out recordCount);
  696. var obj = new
  697. {
  698. rows = dt,
  699. total = recordCount
  700. };
  701. return Content(obj.ToJson());
  702. }
  703. /// <summary>
  704. /// 获取一条详细信息
  705. /// </summary>
  706. /// <param name="infoid"></param>
  707. /// <returns></returns>
  708. [Authority]
  709. public ActionResult GetInfo(string infoid)
  710. {
  711. if (infoid != null && infoid.Trim() != "")
  712. {
  713. Model.T_Email_SendEmail model = bllEmail.GetModel(int.Parse(infoid.Trim()));
  714. if (model != null)
  715. {
  716. return Success("获取成功", model);
  717. }
  718. else
  719. {
  720. return Error("获取失败");
  721. };
  722. }
  723. else
  724. {
  725. return Error("获取参数失败");
  726. }
  727. }
  728. /// <summary>
  729. /// 删除已发送管理 邮箱
  730. /// </summary>
  731. /// <returns></returns>
  732. [Authority]
  733. public ActionResult DelSendEmail(string[] ids)
  734. {
  735. if (ids != null && ids.Length > 0)
  736. {
  737. string idd = " ";
  738. foreach (string str in ids)
  739. {
  740. idd += str + ",";
  741. }
  742. if (bllEmail.DeleteList(idd.TrimEnd(',')))
  743. {
  744. return Success("删除成功");
  745. }
  746. else
  747. return Error("删除失败");
  748. }
  749. else
  750. {
  751. return Error("获取参数失败");
  752. }
  753. }
  754. #endregion
  755. }
  756. }