郑州颐和随访系统

SMSController.cs 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  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 System.Configuration;
  11. using Top.Api;
  12. using Top.Api.Request;
  13. using Top.Api.Response;
  14. using CallCenterApi.Common;
  15. using System.Net;
  16. using System.Text;
  17. using Newtonsoft.Json;
  18. using System.Xml;
  19. using System.IO;
  20. namespace CallCenterApi.Interface.Controllers
  21. {
  22. public class SMSController : BaseController
  23. {
  24. #region 接收短信
  25. string url = "http://47.92.26.244/sms.aspx?";
  26. string account = "yhyy"; string password = "yhyy190903";
  27. /// <summary>
  28. /// 发送短信
  29. /// </summary>
  30. /// <param name="mobile"></param>
  31. /// <param name="time"></param>
  32. /// <param name="timeslot"></param>
  33. /// <param name="department"></param>
  34. /// <param name="doctor"></param>
  35. /// <param name="floor"></param>
  36. /// <param name="name"></param>
  37. /// <param name="content"></param>
  38. /// <param name="type"></param>
  39. /// <returns></returns>
  40. public ActionResult SendSMS(string mobile, string time, string timeslot, string department, string doctor, string floor, string sendTime, string name, string content, int MBID, int sendWay = 0)
  41. {
  42. WebClient web = new WebClient();
  43. web.Encoding = Encoding.UTF8;
  44. content += "【郑州颐和医院】";
  45. url += "action=send&userid=&account=" + account.Trim() + "&password=" + password.Trim() + "&mobile=" + mobile.Trim() + "&content=" + content.Trim() + "& sendTime=" + sendTime.Trim() + "& extno=";
  46. string Dataaa = web.DownloadString(url);//这一句话就能请求到数据了
  47. var result = new CreateOrderReturnResult();
  48. try
  49. {
  50. DataSet ds = new DataSet();
  51. StringReader stream = new StringReader(Dataaa);//读取字符串为数据量
  52. XmlTextReader reader = new XmlTextReader(stream);//对XML的数据流的只进只读访问
  53. ds.ReadXml(reader);//吧数据读入DataSet
  54. DataTable dt = ds.Tables["returnsms"];
  55. result.state = "success";
  56. result.message = "发送成功";
  57. result.data = new SmS();
  58. if (dt.Rows.Count > 0)
  59. {
  60. for (int i = 0; i < dt.Rows.Count; i++)
  61. {
  62. DataRow dr = ds.Tables[0].Rows[i];
  63. result.data.returnstatus = dr["returnstatus"].ToString();
  64. result.data.message = dr["message"].ToString();
  65. result.data.remainpoint = dr["remainpoint"].ToString();
  66. result.data.taskID = dr["taskID"].ToString();
  67. result.data.successCounts = dr["successCounts"].ToString();
  68. }
  69. }
  70. int IsSend = 0;
  71. if (result.data.returnstatus == "Success")
  72. {
  73. IsSend = 1;
  74. }
  75. DateTime DSSendTime = DateTime.Now;
  76. if (!string.IsNullOrEmpty(sendTime.Trim()))
  77. {
  78. DSSendTime = DateTime.Parse(sendTime.Trim());
  79. }
  80. AddSMSList(sendWay, DSSendTime, DSSendTime, IsSend, mobile, content, MBID);
  81. if (result.data.returnstatus != "Success")
  82. {
  83. return Error(result.data.message);
  84. }
  85. }
  86. catch (Exception ex)
  87. {
  88. return Error(ex.Message);
  89. }
  90. return Content(result.ToJson());
  91. }
  92. public class CreateOrderReturnResult
  93. {
  94. public string state { get; set; }
  95. public string message { get; set; }
  96. public SmS data { get; set; }
  97. }
  98. public class SmS
  99. {
  100. public string returnstatus;
  101. public string message;
  102. public string remainpoint;
  103. public string taskID;
  104. public string successCounts;
  105. }
  106. /// <summary>
  107. /// 新增短信模板
  108. /// </summary>
  109. /// <param name="name"></param>
  110. /// <param name="cont"></param>
  111. /// <param name="mName"></param>
  112. /// <returns></returns>
  113. public ActionResult AddTemplate(string name, string cont)
  114. {
  115. int userId = CurrentUser.UserData.F_UserId;
  116. if (userId != 0)
  117. {
  118. Model.T_SMS_Template dModel = new Model.T_SMS_Template();
  119. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  120. string MID = ""; string MName = "";
  121. if (ua != null)
  122. {
  123. MID = ua.F_UserCode;
  124. MName = ua.F_UserName;
  125. }
  126. dModel.Detail = cont.Trim();
  127. dModel.Name = name.Trim();
  128. dModel.MID = MID.Trim();
  129. dModel.MName = MName.Trim();
  130. dModel.CreateDate = DateTime.Now;
  131. dModel.IsEnable = 0;
  132. int b = new BLL.T_SMS_Template().Add(dModel);
  133. if (b > 0)
  134. {
  135. return Success("添加成功");
  136. }
  137. else
  138. {
  139. return Success("添加失败");
  140. }
  141. }
  142. else
  143. return Error("无操作权限!");
  144. }
  145. /// <summary>
  146. /// 修改短信模板
  147. /// </summary>
  148. /// <param name="name"></param>
  149. /// <param name="cont"></param>
  150. /// <param name="mName"></param>
  151. /// <returns></returns>
  152. public ActionResult UpdateTemplate(int id, string name, string cont)
  153. {
  154. int userId = CurrentUser.UserData.F_UserId;
  155. if (userId != 0)
  156. {
  157. if (id <= 0)
  158. return Error("参数错误!");
  159. var model = new BLL.T_SMS_Template().GetModel(id);
  160. if (model == null)
  161. return Error("查询不到此模板!");
  162. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  163. string MID = ""; string MName = "";
  164. if (ua != null)
  165. {
  166. MID = ua.F_UserCode;
  167. MName = ua.F_UserName;
  168. }
  169. model.Detail = cont.Trim();
  170. model.Name = name.Trim();
  171. model.MID = MID.Trim();
  172. model.MName = MName.Trim();
  173. model.CreateDate = DateTime.Now;
  174. model.IsEnable = 0;
  175. if (new BLL.T_SMS_Template().Update(model))
  176. {
  177. return Success("修改成功");
  178. }
  179. else
  180. {
  181. return Error("修改失败");
  182. }
  183. }
  184. else
  185. return Error("无操作权限!");
  186. }
  187. /// <summary>
  188. /// 删除短信模板
  189. /// </summary>
  190. /// <param name="ids"></param>
  191. /// <returns></returns>
  192. public ActionResult DelTemplate(string[] ids)
  193. {
  194. int userId = CurrentUser.UserData.F_UserId;
  195. if (userId != 0)
  196. {
  197. if (ids != null && ids.Length > 0)
  198. {
  199. bool res = true;
  200. string idd = " ";
  201. foreach (string str in ids)
  202. {
  203. idd += str + ",";
  204. }
  205. if (!string.IsNullOrEmpty(idd.Trim()))
  206. {
  207. if (new BLL.T_SMS_Template().DeleteList(idd.TrimEnd(',')))
  208. {
  209. if (new BLL.T_SMS_Template().DeleteList(idd.TrimEnd(',')))
  210. {
  211. return Success("设置成功");
  212. }
  213. else
  214. {
  215. return Error("设置失败");
  216. }
  217. }
  218. else
  219. {
  220. return Error("设置失败");
  221. }
  222. }
  223. else
  224. {
  225. return Error("请选择工单");
  226. }
  227. }
  228. else
  229. {
  230. return Error("获取参数失败");
  231. }
  232. }
  233. else
  234. {
  235. return Error("无操作权限!");
  236. }
  237. }
  238. /// <summary>
  239. /// 删除短信记录列表
  240. /// </summary>
  241. /// <param name="ids"></param>
  242. /// <returns></returns>
  243. public ActionResult DelSMSList(string[] ids)
  244. {
  245. int userId = CurrentUser.UserData.F_UserId;
  246. if (userId != 0)
  247. {
  248. if (ids != null && ids.Length > 0)
  249. {
  250. bool res = true;
  251. string idd = " ";
  252. foreach (string str in ids)
  253. {
  254. idd += str + ",";
  255. }
  256. if (!string.IsNullOrEmpty(idd.Trim()))
  257. {
  258. if (new BLL.T_SMS_List().DeleteList(idd.TrimEnd(',')))
  259. {
  260. if (new BLL.T_SMS_List().DeleteList(idd.TrimEnd(',')))
  261. {
  262. return Success("设置成功");
  263. }
  264. else
  265. {
  266. return Error("设置失败");
  267. }
  268. }
  269. else
  270. {
  271. return Error("设置失败");
  272. }
  273. }
  274. else
  275. {
  276. return Error("请选择工单");
  277. }
  278. }
  279. else
  280. {
  281. return Error("获取参数失败");
  282. }
  283. }
  284. else
  285. {
  286. return Error("无操作权限!");
  287. }
  288. }
  289. /// <summary>
  290. /// 获取短信模板列表
  291. /// </summary>
  292. /// <returns></returns>
  293. public ActionResult GetTemplateList(string name, string keywords,int page=1,int pagesize=5)
  294. {
  295. int userId = CurrentUser.UserData.F_UserId;
  296. if (userId != 0)
  297. {
  298. DataTable dt = new DataTable();
  299. string sql = $" and IsEnable=0";
  300. if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
  301. sql += $" and ( Detail like '%" + keywords.Trim() + "%'or Name like '%" + keywords.Trim() + "%' or MName like '%" + keywords.Trim() + "%' ) ";
  302. if (!string.IsNullOrWhiteSpace(name))//
  303. sql += $" and Name like '%" + name.Trim() + "%'";
  304. // var modellist = new BLL.T_SMS_Template().GetModelList(sql);
  305. int recordCount = 0;
  306. dt = BLL.PagerBLL.GetListPager(
  307. "T_SMS_Template",
  308. "T_SMS_Template.ID",
  309. "*",
  310. sql,
  311. "ORDER BY T_SMS_Template.ID desc",
  312. pagesize,
  313. page,
  314. true,
  315. out recordCount);
  316. List<Model.T_SMS_Template> modlelist = new BLL.T_SMS_Template().DataTableToList(dt);
  317. var obj = new
  318. {
  319. state = "success",
  320. message = "成功",
  321. rows = modlelist,
  322. total = recordCount
  323. };
  324. return Content(obj.ToJson());
  325. }
  326. else
  327. return Error("无操作权限!");
  328. }
  329. /// <summary>
  330. /// 获取模板详情
  331. /// </summary>
  332. /// <param name="id"></param>
  333. /// <returns></returns>
  334. public ActionResult GetContentTemp(string name)
  335. {
  336. int userId = CurrentUser.UserData.F_UserId;
  337. if (userId != 0)
  338. {
  339. Model.T_SMS_Template dModel = new Model.T_SMS_Template();
  340. if (string.IsNullOrEmpty(name.Trim()))
  341. return Error("短信类型不能为空!");
  342. var model = new BLL.T_SMS_Template().GetModelList($"Name like '%" + name.Trim() + "%'").FirstOrDefault();
  343. if (model == null)
  344. return Error("查询不到此模板!");
  345. return Success("获取成功", model);
  346. }
  347. else
  348. return Error("无操作权限!");
  349. }
  350. /// <summary>
  351. /// 获取模板详情
  352. /// </summary>
  353. /// <param name="id"></param>
  354. /// <returns></returns>
  355. public ActionResult GetDetailsTemp(int id)
  356. {
  357. int userId = CurrentUser.UserData.F_UserId;
  358. if (userId != 0)
  359. {
  360. Model.T_SMS_Template dModel = new Model.T_SMS_Template();
  361. if (id <= 0)
  362. return Error("参数错误!");
  363. var model = new BLL.T_SMS_Template().GetModel(id);
  364. if (model == null)
  365. return Error("查询不到此模板!");
  366. return Success("获取成功", model);
  367. }
  368. else
  369. return Error("无操作权限!");
  370. }
  371. /// <summary>
  372. /// 导入excel
  373. /// </summary>
  374. public ActionResult ImportExcel()
  375. {
  376. int userId = CurrentUser.UserData.F_UserId;
  377. if (userId != 0)
  378. {
  379. string usercode = CurrentUser.UserData.F_UserCode;
  380. string ip = DTRequest.GetIP();
  381. if (!string.IsNullOrWhiteSpace(usercode))
  382. {
  383. HttpPostedFile _upFile = RequestString.GetFile("upFile");
  384. if (_upFile != null)
  385. {
  386. int headrow = 0;
  387. #region 上传文件
  388. string filepath = "";
  389. string datepath = DateTime.Now.ToString("yyyyMMddHHMMss");
  390. string aLastName = Path.GetExtension(_upFile.FileName);
  391. string oriname = Path.GetFileNameWithoutExtension(_upFile.FileName);
  392. if (aLastName != ".xls" && aLastName != ".xlsx")
  393. {
  394. return Error("文件类型错误,请选择Excel文件");
  395. }
  396. string newpath = datepath + "_" + _upFile.FileName;
  397. if (!Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData")))
  398. {
  399. Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData"));
  400. }
  401. filepath = this.Request.ApplicationPath + "/ExcelData/" + newpath;
  402. string PhysicalPath = Server.MapPath(filepath);
  403. _upFile.SaveAs(PhysicalPath);
  404. #endregion
  405. #region 添加附件日志
  406. Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  407. model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
  408. model_T_Sys_Accessories.F_FileName = newpath;//附件名称
  409. model_T_Sys_Accessories.F_FileType = aLastName;//附件类型
  410. model_T_Sys_Accessories.F_FileUrl = filepath;//附件地址
  411. model_T_Sys_Accessories.F_UserCode = usercode;//上传人
  412. int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  413. #endregion
  414. NPOIHelper np = new NPOIHelper();
  415. DataTable dt = np.ExcelToTable(_upFile, headrow);
  416. string msg = string.Empty;
  417. if (dt == null || dt.Rows.Count == 0)
  418. return Error("文件没有数据");
  419. else
  420. {
  421. Model.T_SMS_Template dModel = new Model.T_SMS_Template();
  422. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  423. string MID = ""; string MName = "";
  424. if (ua != null)
  425. {
  426. MID = ua.F_UserCode;
  427. MName = ua.F_UserName;
  428. }
  429. dModel.MID = MID.Trim();
  430. dModel.MName = MName.Trim();
  431. dModel.CreateDate = DateTime.Now;
  432. dModel.IsEnable = 0;
  433. foreach (DataRow dr in dt.Rows)
  434. {
  435. #region 数据入库
  436. headrow = headrow + 1;
  437. if (dr["短信类型"].ToString() != "")
  438. {
  439. if (!getunique( dr["短信类型"].ToString()))
  440. {
  441. dModel.Name = dr["短信类型"].ToString();
  442. dModel.Detail = dr["短信内容"].ToString();
  443. var res = new BLL.T_SMS_Template().Add(dModel);
  444. if (res < 0)
  445. {
  446. msg = msg + "第" + headrow + "行,导入失败<br>";
  447. }
  448. }
  449. else
  450. {
  451. msg = msg + "第" + headrow + "行,短信类型重复,未导入<br>";
  452. }
  453. }
  454. else
  455. msg = msg + "第" + headrow + "行,短信类型为空或格式不正确,未导入<br>";
  456. #endregion
  457. }
  458. if (string.IsNullOrEmpty(msg))
  459. return Success("导入成功 ");
  460. else
  461. return Error(msg);
  462. }
  463. }
  464. return Error("数据源上传失败");
  465. }
  466. }
  467. return Error("用户登录失败,请重新登录");
  468. }
  469. /// <summary>
  470. /// 验证短信类型是否唯一
  471. /// </summary>
  472. private bool getunique( string Name)
  473. {
  474. var sql = " IsEnable=0 ";
  475. sql += "and (Name='" + Name + "')";
  476. var count = new BLL.T_SMS_Template().GetModelList(sql).Count();
  477. return count > 0;
  478. }
  479. /// <summary>
  480. /// 新增短信记录
  481. /// </summary>
  482. /// <returns></returns>
  483. public bool AddSMSList(int SendWay, DateTime DSSendTime, DateTime SendTime, int IsSend,
  484. string Telephone, string Detail, int MBID)
  485. {
  486. int userId = CurrentUser.UserData.F_UserId;
  487. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  488. string MID = ""; string MName = "";
  489. if (ua != null)
  490. {
  491. MID = ua.F_UserCode;
  492. MName = ua.F_UserName;
  493. }
  494. Model.T_SMS_List dModel = new Model.T_SMS_List();
  495. dModel.SendWay = SendWay;
  496. dModel.DSSendTime = DSSendTime;
  497. dModel.SendTime = SendTime;
  498. dModel.IsSend = IsSend;
  499. dModel.Telephone = Telephone;
  500. dModel.Detail = Detail;
  501. dModel.MBID = MBID;
  502. dModel.MID = MID;
  503. dModel.MName = MName;
  504. dModel.F_IsDelete = 0;
  505. dModel.CreateDate = DateTime.Now;
  506. int b = new BLL.T_SMS_List().Add(dModel);
  507. if (b > 0)
  508. {
  509. return true;
  510. }
  511. else
  512. {
  513. return false;
  514. }
  515. }
  516. /// <summary>
  517. /// 导出短信记录
  518. /// </summary>
  519. /// <param name="stime"></param>
  520. /// <param name="endtime"></param>
  521. /// <returns></returns>
  522. public ActionResult ExitTypelist(string name, string phone, string creatname, int SendWay=-1, int IsSend=-1)
  523. {
  524. DataTable dt = new DataTable();
  525. string sql = $" F_IsDelete=0";
  526. if (!string.IsNullOrEmpty(name))
  527. {
  528. var model = new BLL.T_SMS_Template().GetModelList($"Name like '%" + name.Trim() + "%'").FirstOrDefault();
  529. if (model!=null )
  530. {
  531. sql += " and MBID=" + model.ID ;
  532. }
  533. }
  534. if (!string.IsNullOrEmpty(phone))
  535. sql += " and Telephone=" + phone;
  536. if (SendWay>=0)
  537. sql += " and SendWay=" + SendWay;
  538. if (IsSend >= 0)
  539. sql += " and IsSend=" + IsSend;
  540. if (!string.IsNullOrEmpty(creatname))
  541. sql += $" and ( MID like '%" + creatname.Trim() + "%'or MName like '%" + creatname.Trim() + "%') ";
  542. dt.Columns.Add("编号");
  543. dt.Columns.Add("接收号码");
  544. dt.Columns.Add("发送内容");
  545. dt.Columns.Add("发送方式");
  546. dt.Columns.Add("发送状态");
  547. dt.Columns.Add("发送时间");
  548. dt.Columns.Add("短信类型");
  549. dt.Columns.Add("发送人");
  550. var itemlist = new BLL.T_SMS_List().GetModelList(sql);
  551. foreach (var it in itemlist)
  552. {
  553. DataRow drNew = dt.NewRow();
  554. drNew["编号"] =it .ID ;
  555. drNew["接收号码"] = it.Telephone ;
  556. drNew["发送内容"] = it.Detail ;
  557. if (it .SendWay==0 )
  558. drNew["发送方式"] = "立即发送";
  559. else
  560. drNew["发送方式"] = "定时发送";
  561. drNew["发送时间"] = it.SendTime ;
  562. if (it.IsSend==1)
  563. drNew["发送状态"] = "已发送";
  564. else
  565. drNew["发送状态"] = "未发送";
  566. if (it.MBID>0)
  567. {
  568. var model = new BLL.T_SMS_Template().GetModel(int.Parse(it.MBID.ToString()));
  569. if (model != null)
  570. {
  571. drNew["短信类型"]= model.Name ;
  572. }
  573. }
  574. drNew["发送人"] =it .MID +"("+it.MName +")";
  575. dt.Rows.Add(drNew);
  576. }
  577. NPOIHelper npoi = new NPOIHelper();
  578. if (npoi.ExportToExcel("短信记录", dt) == "")
  579. {
  580. return Success("导出成功");
  581. }
  582. else
  583. {
  584. return Error("导出失败");
  585. }
  586. }
  587. /// <summary>
  588. /// 修改短信记录列表
  589. /// </summary>
  590. /// <returns></returns>
  591. public ActionResult UpdateSMSList(int id, int SendWay, DateTime DSSendTime, DateTime SendTime, int IsSend,
  592. string Telephone, string Detail, int MBID, DateTime CreateDate)
  593. {
  594. int userId = CurrentUser.UserData.F_UserId;
  595. if (userId != 0)
  596. {
  597. if (id <= 0)
  598. return Error("参数错误!");
  599. var model = new BLL.T_SMS_List().GetModel(id);
  600. if (model == null)
  601. return Error("查询不到此模板!");
  602. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  603. string MID = ""; string MName = "";
  604. if (ua != null)
  605. {
  606. MID = ua.F_UserCode;
  607. MName = ua.F_UserName;
  608. }
  609. model.SendWay = SendWay;
  610. model.DSSendTime = DSSendTime;
  611. model.SendTime = SendTime;
  612. model.IsSend = IsSend;
  613. model.Telephone = Telephone;
  614. model.Detail = Detail;
  615. model.MBID = MBID;
  616. model.MID = MID;
  617. model.MName = MName;
  618. model.CreateDate = DateTime.Now;
  619. bool b = new BLL.T_SMS_List().Update(model);
  620. if (b)
  621. {
  622. return Success("修改成功");
  623. }
  624. else
  625. {
  626. return Error("修改失败");
  627. }
  628. }
  629. else
  630. return Error("无操作权限");
  631. }
  632. /// <summary>
  633. /// 获取短信记录列表
  634. /// </summary>
  635. /// <returns></returns>
  636. public ActionResult GetSMSList(string name, string phone, string creatname ,int SendWay=-1, int IsSend=-1, int page = 1, int pagesize = 10)
  637. {
  638. DataTable dt = new DataTable();
  639. int userId = CurrentUser.UserData.F_UserId;
  640. if (userId != 0)
  641. {
  642. string sql = $"and F_IsDelete=0";
  643. if (!string.IsNullOrEmpty(name))
  644. {
  645. var model = new BLL.T_SMS_Template().GetModelList($"Name like '%" + name.Trim() + "%'").FirstOrDefault();
  646. if (model != null)
  647. {
  648. sql += " and MBID=" + model.ID;
  649. }
  650. }
  651. if (!string.IsNullOrEmpty(phone))
  652. sql += " and Telephone like'%" + phone+"%'";
  653. if (SendWay >= 0)
  654. sql += " and SendWay=" + SendWay;
  655. if (IsSend >= 0)
  656. sql += " and IsSend=" + IsSend;
  657. if (!string.IsNullOrEmpty(creatname))
  658. sql += $" and ( MID like '%" + creatname.Trim() + "%'or MName like '%" + creatname.Trim() + "%') ";
  659. int recordCount = 0;
  660. if (!string.IsNullOrWhiteSpace(sql))
  661. {
  662. dt = BLL.PagerBLL.GetListPager(
  663. "T_SMS_List",
  664. "T_SMS_List.ID",
  665. "*",
  666. sql,
  667. "ORDER BY T_SMS_List.ID desc",
  668. pagesize,
  669. page,
  670. true,
  671. out recordCount);
  672. }
  673. var modlelist = new BLL.T_SMS_List().DataTableToList(dt);
  674. //var modellist = new BLL.T_SMS_List().GetModelList(sql);
  675. var obj = new
  676. {
  677. state = "success",
  678. message = "成功",
  679. rows = ModeltoSMSList( modlelist),
  680. total= recordCount
  681. };
  682. return Content(obj.ToJson());
  683. }
  684. else
  685. return Error("无操作权限");
  686. }
  687. public List<SMSList> ModeltoSMSList(List <Model .T_SMS_List> list)
  688. {
  689. List<SMSList> modellist = new List<SMSList>();
  690. foreach (var it in list)
  691. {
  692. SMSList model = new SMSList();
  693. model.ID = it.ID;
  694. if (it.SendWay == 0)
  695. model.SendWay = "立即发送";
  696. else
  697. model.SendWay = "定时发送";
  698. model.DSSendTime = it.DSSendTime.ToString ();
  699. model.SendTime = it.SendTime.ToString();
  700. if (it.IsSend == 0)
  701. model.IsSend = "未发送";
  702. else
  703. model.IsSend = "已发送";
  704. model.Telephone = it.Telephone;
  705. model.Detail = it.Detail;
  706. if (it.MBID>0)
  707. {
  708. var MID = new BLL.T_SMS_Template().GetModel(int.Parse(it.MBID.ToString()));
  709. if (MID != null)
  710. model.MBDetail = MID.Name;
  711. }
  712. model.MID = it.MID;
  713. model.MName = it.MName;
  714. model.CreateDate = it.CreateDate.ToString ();
  715. modellist.Add(model);
  716. }
  717. return modellist;
  718. }
  719. /// <summary>
  720. /// 导入号码
  721. /// </summary>
  722. /// <returns></returns>
  723. public ActionResult ImportSend()
  724. {
  725. int userId = CurrentUser.UserData.F_UserId;
  726. if (userId != 0)
  727. {
  728. string usercode = CurrentUser.UserData.F_UserCode;
  729. string ip = DTRequest.GetIP();
  730. if (!string.IsNullOrWhiteSpace(usercode))
  731. {
  732. HttpPostedFile _upFile = RequestString.GetFile("upFile");
  733. if (_upFile != null)
  734. {
  735. int headrow = 0;
  736. #region 上传文件
  737. string filepath = "";
  738. string datepath = DateTime.Now.ToString("yyyyMMddHHMMss");
  739. string aLastName = Path.GetExtension(_upFile.FileName);
  740. string oriname = Path.GetFileNameWithoutExtension(_upFile.FileName);
  741. if (aLastName != ".xls" && aLastName != ".xlsx")
  742. {
  743. return Error("文件类型错误,请选择Excel文件");
  744. }
  745. string newpath = datepath + "_" + _upFile.FileName;
  746. if (!Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData")))
  747. {
  748. Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData"));
  749. }
  750. filepath = this.Request.ApplicationPath + "/ExcelData/" + newpath;
  751. string PhysicalPath = Server.MapPath(filepath);
  752. _upFile.SaveAs(PhysicalPath);
  753. #endregion
  754. #region 添加附件日志
  755. Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  756. model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
  757. model_T_Sys_Accessories.F_FileName = newpath;//附件名称
  758. model_T_Sys_Accessories.F_FileType = aLastName;//附件类型
  759. model_T_Sys_Accessories.F_FileUrl = filepath;//附件地址
  760. model_T_Sys_Accessories.F_UserCode = usercode;//上传人
  761. int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  762. #endregion
  763. NPOIHelper np = new NPOIHelper();
  764. DataTable dt = np.ExcelToTable(_upFile, headrow);
  765. string msg = string.Empty;
  766. string tels= string.Empty;
  767. if (dt == null || dt.Rows.Count == 0)
  768. return Error("文件没有数据");
  769. else
  770. {
  771. foreach (DataRow dr in dt.Rows)
  772. {
  773. #region 数据入库
  774. headrow = headrow + 1;
  775. if (dr["号码"].ToString() != "")
  776. {
  777. if (string.IsNullOrEmpty(tels))
  778. {
  779. tels = dr["号码"].ToString();
  780. }
  781. else
  782. {
  783. tels = tels + "," + dr["号码"].ToString();
  784. }
  785. }
  786. else
  787. msg = msg + "第" + headrow + "行,号码为空或格式不正确,未导入<br>";
  788. #endregion
  789. }
  790. if (string.IsNullOrEmpty(msg))
  791. return Success("获取成功 ", tels);
  792. else
  793. return Error(msg);
  794. }
  795. }
  796. return Error("数据源上传失败");
  797. }
  798. }
  799. return Error("用户登录失败,请重新登录");
  800. }
  801. #endregion
  802. public class SMSList
  803. {
  804. public int ID;
  805. public string SendWay;
  806. public string DSSendTime;
  807. public string SendTime;
  808. public string IsSend;
  809. public string Telephone;
  810. public string Detail;
  811. public string MBDetail;
  812. public string MID;
  813. public string MName;
  814. public string CreateDate;
  815. }
  816. }
  817. }