Нет описания

WxLoginController.cs 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. using CallCenter.Utility;
  2. using CallCenterApi.DB;
  3. using CallCenterApi.Interface.Controllers.Base;
  4. using CallCenterApi.Interface.App_Start;
  5. using CallCenterAPI.WechatSDK;
  6. using CallCenterAPI.WechatSDK.Models;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Linq;
  11. using System.Web;
  12. using System.Web.Mvc;
  13. using System.Transactions;
  14. using System.IO;
  15. namespace CallCenterApi.Interface.Controllers.weixin
  16. {
  17. public class WxLoginController : BaseController
  18. {
  19. private readonly BLL.T_Sys_UserAccount userAccountBLL = new BLL.T_Sys_UserAccount();
  20. /// <summary>
  21. /// 绑定微信号
  22. /// </summary>
  23. /// <param name="login"></param>
  24. /// <returns></returns>
  25. [WechatActionFilter]
  26. public ActionResult Login(WxLoginDto login)
  27. {
  28. Dictionary<string, string> paras = new Dictionary<string, string>();
  29. string sql = " select * from T_Sys_UserAccount where F_UserCode=@F_UserCode and F_PassWord=@F_PassWord ";
  30. paras.Add("@F_UserCode", login.UserCode);
  31. paras.Add("@F_PassWord", login.Password);
  32. var dt = DbHelperSQL.Query(sql, paras).Tables[0];
  33. if (dt != null)
  34. {
  35. var user = userAccountBLL.GetModel(login.UserCode);
  36. user.F_WxOpenId = login.OpenId;
  37. if (userAccountBLL.Update(user))
  38. {
  39. return Success("绑定成功");
  40. }
  41. else
  42. {
  43. return Error("绑定失败");
  44. }
  45. }
  46. else
  47. {
  48. return Error("账号或密码错误,请重新登录");
  49. }
  50. }
  51. /// <summary>
  52. /// 获取微信openid
  53. /// </summary>
  54. /// <param name="login"></param>
  55. /// <returns></returns>
  56. public ActionResult GetOpenId(WxLoginDto wld)
  57. {
  58. wld.RedirectUrl = RequestString.GetUrlReferrer();
  59. if (string.IsNullOrEmpty(wld.OpenId))
  60. {
  61. var temp = WxHelper.GetOpenId(wld);
  62. if (string.IsNullOrWhiteSpace(temp.OpenId))
  63. {
  64. return Redirect("请求", temp.RedirectUrl);
  65. }
  66. wld.OpenId = temp.OpenId;
  67. //获取是否绑定用户表
  68. var usertemp = new BLL.T_Sys_UserAccount().GetModelByOpenid(wld.OpenId);
  69. if (usertemp != null)
  70. {
  71. wld.UserCode = usertemp.F_UserCode;
  72. }
  73. else
  74. {
  75. wld.UserCode = "";
  76. }
  77. }
  78. var model = new BLL.T_Sys_Users().GetModel(wld.OpenId);
  79. if (model == null)
  80. {
  81. model = new Model.T_Sys_Users();
  82. model.F_OpenId = wld.OpenId;
  83. model.F_Type = 1;
  84. model.F_CreateTime = DateTime.Now;
  85. new BLL.T_Sys_Users().Add(model);
  86. }
  87. var newobj = new
  88. {
  89. openid = wld.OpenId,
  90. usercode = wld.UserCode,
  91. };
  92. return Success("成功", newobj);
  93. }
  94. #region 工单相关
  95. /// <summary>
  96. /// 获取工单列表
  97. /// </summary>
  98. /// <returns></returns>
  99. [WechatActionFilter]
  100. public ActionResult GetList()
  101. {
  102. DataTable dt = new DataTable();
  103. //string sql = " and IsDel=0 ";
  104. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  105. string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));//状态 0待处理 1已处理
  106. string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));//联系人
  107. string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));//联系电话
  108. string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));//关键字
  109. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  110. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  111. string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));//工单编号
  112. string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));//创建人工号
  113. string source = HttpUtility.UrlDecode(RequestString.GetQueryString("source"));//工单来源
  114. string infotype = HttpUtility.UrlDecode(RequestString.GetQueryString("infotype"));//信息分类
  115. string strpageindex = RequestString.GetQueryString("page");
  116. int pageindex = 1;
  117. string strpagesize = RequestString.GetQueryString("pagesize");
  118. int pagesize = 10;
  119. #region sql 语句相关处理
  120. //根据openid获取所有工单号
  121. var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  122. string sql = " and IsDel=0 and id in (select distinct F_WorkOrderID from T_WO_UserWorkOrder where F_UserId='" + wxuser.F_Id + "') ";
  123. if (strstate.Trim() != "" && strstate != "undefined")
  124. {
  125. if (strstate.Trim() == "0")
  126. {
  127. sql += " and State in(0,1) ";
  128. }
  129. else
  130. {
  131. sql += " and State =2 ";
  132. }
  133. //sql += " and State = '" + strstate.Trim() + "' ";
  134. }
  135. if (strworkid.Trim() != "" && strworkid != "undefined")
  136. {
  137. sql += " and WorkOrderID like '%" + strworkid + "%' ";
  138. }
  139. if (strname.Trim() != "" && strname != "undefined")
  140. {
  141. sql += " and Customer like '%" + strname + "%' ";
  142. }
  143. if (strtel.Trim() != "" && strtel != "undefined")
  144. {
  145. sql += " and (CustomerTel like '%" + strtel + "%' ) ";
  146. }
  147. if (strkey.Trim() != "" && strkey != "undefined")
  148. {
  149. sql += " and (Title like '%" + strkey + "%' or Detail like '%" + strkey + "%') ";
  150. }
  151. if (strusercode.Trim() != "" && strusercode != "undefined")
  152. {
  153. sql += " and CreateUser = '" + strusercode + "' ";
  154. }
  155. if (infotype.Trim() != "" && infotype != "undefined")
  156. {
  157. sql += " and InfoTypeID = " + infotype + " ";
  158. }
  159. if (source.Trim() != "" && source != "undefined")
  160. {
  161. sql += " and Source = '" + source + "' ";
  162. }
  163. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  164. {
  165. sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
  166. }
  167. if (strendtime.Trim() != "" && strendtime != "undefined")
  168. {
  169. sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
  170. }
  171. #endregion
  172. if (strpageindex.Trim() != "")
  173. {
  174. pageindex = Convert.ToInt32(strpageindex);
  175. }
  176. if (strpagesize.Trim() != "")
  177. {
  178. pagesize = Convert.ToInt32(strpagesize);
  179. }
  180. string cols = "*,dbo.GetUserName(CreateUser) as UserName";
  181. int recordCount = 0;
  182. dt = BLL.PagerBLL.GetListPager(
  183. "T_Wo_WorkOrder",
  184. "WorkOrderID",
  185. cols,
  186. sql,
  187. "ORDER BY CreateTime DESC",
  188. pagesize,
  189. pageindex,
  190. true,
  191. out recordCount);
  192. var obj = new
  193. {
  194. state = "success",
  195. message = "成功",
  196. rows = dt,
  197. total = recordCount
  198. };
  199. return Content(obj.ToJson());
  200. }
  201. /// <summary>
  202. /// 新增工单
  203. /// </summary>
  204. /// <returns></returns>
  205. [WechatActionFilter]
  206. public ActionResult AddWorkOrder()
  207. {
  208. DataTable dt = new DataTable();
  209. string cusname = RequestString.GetFormString("cusname");
  210. string cusphone = RequestString.GetFormString("cusphone");//GetFormString
  211. string country = RequestString.GetFormString("country");
  212. string address = RequestString.GetFormString("address");
  213. string content = RequestString.GetFormString("content");
  214. string files = RequestString.GetFormString("files");
  215. int type = RequestString.GetInt("type", 3);//默认为3投诉建议
  216. string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  217. var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  218. workorder.WorkOrderController wo = new workorder.WorkOrderController();
  219. string workorderid = wo.AddWorkOrders(type, cusname, cusphone,country,address, content, files);
  220. if (string.IsNullOrEmpty(workorderid))
  221. {
  222. return Error("新增失败");
  223. }
  224. else
  225. {
  226. Model.T_WO_UserWorkOrder tbu = new Model.T_WO_UserWorkOrder();
  227. tbu.F_UserId = wxuser.F_Id;
  228. tbu.F_WorkOrderId = workorderid;
  229. new BLL.T_WO_UserWorkOrder().Add(tbu);
  230. return Success("新增成功", workorderid);
  231. }
  232. }
  233. /// <summary>
  234. /// 处理工单
  235. /// </summary>
  236. /// <returns></returns>
  237. [WechatActionFilter]
  238. public ActionResult DealWorkOrder()
  239. {
  240. DataTable dt = new DataTable();
  241. string orderid = RequestString.GetFormString("orderid");//GetFormString
  242. string customer= HttpUtility.UrlDecode(RequestString.GetFormString("customer"));
  243. string inqtime = HttpUtility.UrlDecode(RequestString.GetFormString("inqtime"));
  244. string inquser = HttpUtility.UrlDecode(RequestString.GetFormString("inquser"));
  245. string country = HttpUtility.UrlDecode(RequestString.GetFormString("country"));
  246. string address = HttpUtility.UrlDecode(RequestString.GetFormString("address"));
  247. string detail = HttpUtility.UrlDecode(RequestString.GetFormString("detail"));
  248. string cont = HttpUtility.UrlDecode(RequestString.GetFormString("cont"));
  249. string answer = HttpUtility.UrlDecode(RequestString.GetFormString("answer"));
  250. string remark = HttpUtility.UrlDecode(RequestString.GetFormString("remark"));
  251. int infotypeid = RequestString.GetFormInt("infotypeid", 0);
  252. int unitid = RequestString.GetFormInt("unitid", 0);
  253. string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  254. workorder.WorkOrderController wo = new workorder.WorkOrderController();
  255. bool res = wo.DealWorkOrders(orderid, customer,inqtime,inquser,country,address,detail,detail,answer,remark, infotypeid, unitid, stropenid);
  256. if (res)
  257. {
  258. return Error("操作成功");
  259. }
  260. else
  261. {
  262. return Success("操作失败");
  263. }
  264. }
  265. /// <summary>
  266. /// 获取工单详情
  267. /// </summary>
  268. /// <returns></returns>
  269. [WechatActionFilter]
  270. public ActionResult GetWorkOrder()
  271. {
  272. string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
  273. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  274. var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  275. var tbu = new BLL.T_WO_UserWorkOrder().GetList(" F_UserId='" + wxuser.F_Id + "' and F_WorkOrderId=" + strworkorderid + " ").Tables[0];
  276. if (tbu.Rows.Count > 0)
  277. {
  278. string sql = "select *,dbo.GetUserName(CreateUser) as CreateUserName "
  279. + " from T_Wo_WorkOrder where id =" + strworkorderid + " ";
  280. var dt = DbHelperSQL.Query(sql).Tables[0];
  281. if (dt.Rows.Count > 0)
  282. {
  283. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  284. var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  285. if (configfj != null)
  286. {
  287. dt = BindFileData(dt, configfj.F_ParamValue);
  288. }
  289. string gcsql = "select *,dbo.GetUserName(CreateUser) as UserName "
  290. + "from T_Wo_WorkOrderItem where IsDel=0 and WorkOrderID ='" + dt.Rows[0]["WorkOrderId"] + "'";
  291. var gcdt = DbHelperSQL.Query(gcsql).Tables[0];
  292. dt.Columns.Add("FilePath", typeof(string));
  293. if (configfj != null || config != null)
  294. {
  295. foreach (DataRow bldr in dt.Rows)
  296. {
  297. if (bldr["CallID"] != null && config != null)
  298. {
  299. bldr["FilePath"] = GetCallPath(bldr["CallID"].ToString(), config.F_ParamValue);
  300. }
  301. }
  302. }
  303. var obj = new
  304. {
  305. data = dt,
  306. item = gcdt
  307. };
  308. return Success("查询成功", obj);
  309. }
  310. else
  311. {
  312. return Error("查询失败");
  313. }
  314. }
  315. else
  316. {
  317. return Error("查询失败");
  318. }
  319. }
  320. #endregion
  321. #region 获取下拉框
  322. /// <summary>
  323. /// 获取信息分类列表
  324. /// </summary>
  325. /// <returns></returns>
  326. [WechatActionFilter]
  327. public ActionResult GetTypeList()
  328. {
  329. string sql = "select * from T_Sys_DictionaryValue where F_DictionaryFlag='XXFL' and F_State=1 ";
  330. var dt = DbHelperSQL.Query(sql).Tables[0];
  331. return Success("列表加载成功", dt);
  332. }
  333. /// <summary>
  334. /// 获取交办单位列表
  335. /// </summary>
  336. /// <returns></returns>
  337. [WechatActionFilter]
  338. public ActionResult GetAreaList()
  339. {
  340. string sql = "select * from T_Sys_DictionaryValue where F_DictionaryFlag='JBDW' and F_State=1 ";
  341. var dt = DbHelperSQL.Query(sql).Tables[0];
  342. return Success("列表加载成功", dt);
  343. }
  344. #endregion
  345. #region 附件和语音文件
  346. /// <summary>
  347. /// 获取留言路径
  348. /// </summary>
  349. /// <param name="lid">留言id</param>
  350. /// <param name="prefix">前缀</param>
  351. /// <returns></returns>
  352. public string GetLeavePath(string lid, string prefix)
  353. {
  354. string path = string.Empty;
  355. var liuyan = new BLL.T_Call_LeaveRecord().GetModelList(" F_Id='" + lid + "' ").FirstOrDefault();
  356. if (liuyan != null)
  357. {
  358. if (!string.IsNullOrEmpty(liuyan.F_RecFileUrl))
  359. {
  360. path = prefix + liuyan.F_RecFileUrl;
  361. }
  362. }
  363. return path;
  364. }
  365. /// <summary>
  366. /// 获取通话录音路径
  367. /// </summary>
  368. /// <param name="cid">通话id</param>
  369. /// <param name="prefix">前缀</param>
  370. /// <returns></returns>
  371. public string GetCallPath(string cid, string prefix)
  372. {
  373. string path = string.Empty;
  374. var luyin = new BLL.T_Call_CallRecords().GetModelList(" callid='" + cid + "' ").FirstOrDefault();
  375. if (luyin != null)
  376. {
  377. if (!string.IsNullOrEmpty(luyin.FilePath))
  378. {
  379. var ym = prefix;
  380. ym = ym.Substring(0, ym.Length - 1);
  381. path = ym + luyin.FilePath.Substring(luyin.FilePath.IndexOf(':') + 1).Replace('\\', '/');
  382. }
  383. }
  384. return path;
  385. }
  386. /// <summary>
  387. /// 获取附件数据
  388. /// </summary>
  389. /// <param name="ids">附件id,多个用英文逗号,隔开</param>
  390. /// <param name="prefix">前缀</param>
  391. /// <returns></returns>
  392. public DataTable GetFileData(string ids, string prefix)
  393. {
  394. DataTable dt = DbHelperSQL.Query("select * from T_Sys_Accessories where F_FileId in (" + ids + ")").Tables[0];
  395. foreach (DataRow dr in dt.Rows)
  396. {
  397. dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
  398. }
  399. return dt;
  400. }
  401. /// <summary>
  402. /// 绑定附件信息
  403. /// </summary>
  404. /// <param name="dt"></param>
  405. /// <param name="prefix"></param>
  406. /// <returns></returns>
  407. public DataTable BindFileData(DataTable dt, string prefix)
  408. {
  409. dt.Columns.Add("File", typeof(object));
  410. foreach (DataRow dr in dt.Rows)
  411. {
  412. if (dr["Files"] != null && dr["Files"].ToString() != "")
  413. {
  414. dr["File"] = GetFileData(dr["Files"].ToString(), prefix);
  415. }
  416. }
  417. return dt;
  418. }
  419. #endregion
  420. #region
  421. /// <summary>
  422. /// 上传附件
  423. /// </summary>
  424. /// <returns></returns>
  425. public ActionResult UpLoadProcess(string id, string name, string type, string lastModifiedDate, int size, HttpPostedFileBase file)
  426. {
  427. try
  428. {
  429. string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  430. string filePathName = string.Empty;
  431. string path = "/Upload/Files/" + DateTime.Now.ToString("yyyy/MM/dd") + "/";
  432. string localPath = Server.MapPath(Path.Combine(HttpRuntime.AppDomainAppPath, path));
  433. if (Request.Files.Count == 0)
  434. {
  435. return Error("保存失败");
  436. }
  437. string ex = Path.GetExtension(file.FileName);
  438. filePathName = DateTime.Now.ToString("yyyyMMddHHmmssmsfff") + "_" + Guid.NewGuid().ToString("N") + ex;
  439. if (!System.IO.Directory.Exists(localPath))
  440. {
  441. System.IO.Directory.CreateDirectory(localPath);
  442. }
  443. file.SaveAs(Path.Combine(localPath, filePathName));
  444. #region 添加日志
  445. Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  446. model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
  447. model_T_Sys_Accessories.F_FileName = filePathName;//附件名称
  448. model_T_Sys_Accessories.F_FileType = type;//附件类型
  449. model_T_Sys_Accessories.F_FileUrl = path + filePathName;//附件地址
  450. model_T_Sys_Accessories.F_Size = size;
  451. model_T_Sys_Accessories.F_UserCode = stropenid;//上传人
  452. int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  453. #endregion
  454. if (fid > 0)
  455. {//返回附件的ID
  456. return Success("文件日志都成功", fid);
  457. }
  458. else
  459. return Success("文件成功");
  460. }
  461. catch (Exception ex)
  462. {
  463. return Error(ex.Message);
  464. }
  465. }
  466. #endregion
  467. }
  468. }