PingAnYeXianSZCG_API 接口代码

WxLoginController.cs 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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 model = new BLL.T_Sys_Users().GetModel(wld.OpenId);
  69. if (model == null)
  70. {
  71. model = new Model.T_Sys_Users();
  72. model.F_OpenId = wld.OpenId;
  73. model.F_Type = 1;
  74. model.F_CreateTime = DateTime.Now;
  75. new BLL.T_Sys_Users().Add(model);
  76. }
  77. return Success("成功", wld.OpenId);
  78. }
  79. #region 工单相关
  80. /// <summary>
  81. /// 获取工单列表
  82. /// </summary>
  83. /// <returns></returns>
  84. [WechatActionFilter]
  85. public ActionResult GetList()
  86. {
  87. DataTable dt = new DataTable();
  88. //string sql = " and F_IsDelete=0 ";
  89. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  90. string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));//状态
  91. string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));//联系人
  92. string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));//联系电话
  93. string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));//关键字
  94. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  95. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  96. string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));//工单编号
  97. string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));//创建人工号
  98. string source = HttpUtility.UrlDecode(RequestString.GetQueryString("source"));//工单来源
  99. string infotype = HttpUtility.UrlDecode(RequestString.GetQueryString("infotype"));//信息分类
  100. string strpageindex = RequestString.GetQueryString("page");
  101. int pageindex = 1;
  102. string strpagesize = RequestString.GetQueryString("pagesize");
  103. int pagesize = 10;
  104. #region sql 语句相关处理
  105. //根据openid获取所有工单号
  106. var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  107. string sql = " and id in (select distinct F_WorkOrderID from T_WO_UserWorkOrder where F_UserId='" + wxuser.F_Id + "') ";
  108. if (strstate.Trim() != "" && strstate != "undefined")
  109. {
  110. sql += " and State = '" + strstate.Trim() + "' ";
  111. }
  112. if (strworkid.Trim() != "" && strworkid != "undefined")
  113. {
  114. sql += " and WorkOrderID like '%" + strworkid + "%' ";
  115. }
  116. if (strname.Trim() != "" && strname != "undefined")
  117. {
  118. sql += " and Customer like '%" + strname + "%' ";
  119. }
  120. if (strtel.Trim() != "" && strtel != "undefined")
  121. {
  122. sql += " and (CustomerTel like '%" + strtel + "%' ) ";
  123. }
  124. if (strkey.Trim() != "" && strkey != "undefined")
  125. {
  126. sql += " and (Title like '%" + strkey + "%' or Detail like '%" + strkey + "%') ";
  127. }
  128. if (strusercode.Trim() != "" && strusercode != "undefined")
  129. {
  130. sql += " and CreateUser = '" + strusercode + "' ";
  131. }
  132. if (infotype.Trim() != "" && infotype != "undefined")
  133. {
  134. sql += " and InfoTypeID = " + infotype + " ";
  135. }
  136. if (source.Trim() != "" && source != "undefined")
  137. {
  138. sql += " and Source = '" + source + "' ";
  139. }
  140. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  141. {
  142. sql += " and datediff(day,CreateTime,'" + strstarttime + "')<=0 ";
  143. }
  144. if (strendtime.Trim() != "" && strendtime != "undefined")
  145. {
  146. sql += " and datediff(day,CreateTime,'" + strendtime + "')>=0 ";
  147. }
  148. #endregion
  149. if (strpageindex.Trim() != "")
  150. {
  151. pageindex = Convert.ToInt32(strpageindex);
  152. }
  153. if (strpagesize.Trim() != "")
  154. {
  155. pagesize = Convert.ToInt32(strpagesize);
  156. }
  157. string cols = "*,dbo.GetUserName(CreateUser) as UserName";
  158. int recordCount = 0;
  159. dt = BLL.PagerBLL.GetListPager(
  160. "T_Wo_WorkOrder",
  161. "WorkOrderID",
  162. cols,
  163. sql,
  164. "ORDER BY CreateTime DESC",
  165. pagesize,
  166. pageindex,
  167. true,
  168. out recordCount);
  169. var obj = new
  170. {
  171. state = "success",
  172. message = "成功",
  173. rows = dt,
  174. total = recordCount
  175. };
  176. return Content(obj.ToJson());
  177. }
  178. /// <summary>
  179. /// 新增工单
  180. /// </summary>
  181. /// <returns></returns>
  182. [WechatActionFilter]
  183. public ActionResult AddWorkOrder()
  184. {
  185. DataTable dt = new DataTable();
  186. string cusname = RequestString.GetFormString("cusname");
  187. string cusphone = RequestString.GetFormString("cusphone");//GetFormString
  188. string content = RequestString.GetFormString("content");
  189. string files = RequestString.GetFormString("files");
  190. int type = RequestString.GetInt("type", 3);//默认为3投诉建议
  191. string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  192. var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  193. workorder.WorkOrderController wo = new workorder.WorkOrderController();
  194. string workorderid = wo.AddWorkOrders(type, cusname, cusphone, content, files);
  195. if (string.IsNullOrEmpty(workorderid))
  196. {
  197. return Error("新增失败");
  198. }
  199. else
  200. {
  201. Model.T_WO_UserWorkOrder tbu = new Model.T_WO_UserWorkOrder();
  202. tbu.F_UserId = wxuser.F_Id;
  203. tbu.F_WorkOrderId = workorderid;
  204. new BLL.T_WO_UserWorkOrder().Add(tbu);
  205. return Success("新增成功", workorderid);
  206. }
  207. }
  208. /// <summary>
  209. /// 处理工单
  210. /// </summary>
  211. /// <returns></returns>
  212. [WechatActionFilter]
  213. public ActionResult DealWorkOrder()
  214. {
  215. DataTable dt = new DataTable();
  216. string orderid = RequestString.GetFormString("orderid");
  217. string clcont = HttpUtility.UrlDecode(RequestString.GetFormString("clcont"));
  218. int isaudit = RequestString.GetFormInt("isaudit", 0);
  219. int infotypeid = RequestString.GetFormInt("infotypeid", 0);
  220. int unitid = RequestString.GetFormInt("unitid", 0);
  221. string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  222. workorder.WorkOrderController wo = new workorder.WorkOrderController();
  223. bool res = wo.DealWorkOrders(orderid, clcont, stropenid, isaudit, infotypeid, unitid);
  224. if (res)
  225. {
  226. return Error("操作失败");
  227. }
  228. else
  229. {
  230. return Success("操作成功");
  231. }
  232. }
  233. /// <summary>
  234. /// 获取工单详情
  235. /// </summary>
  236. /// <returns></returns>
  237. [WechatActionFilter]
  238. public ActionResult GetWorkOrder()
  239. {
  240. string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
  241. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  242. var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "' and F_Type=1 ").FirstOrDefault();
  243. var tbu = new BLL.T_WO_UserWorkOrder().GetList(" F_UserId='" + wxuser.F_Id + "' and F_WorkOrderId=" + strworkorderid + " ").Tables[0];
  244. if (tbu.Rows.Count > 0)
  245. {
  246. string sql = "select *,dbo.GetUserName(CreateUser) as CreateUserName "
  247. + " from T_Wo_WorkOrder where id =" + strworkorderid + " ";
  248. var dt = DbHelperSQL.Query(sql).Tables[0];
  249. if (dt.Rows.Count > 0)
  250. {
  251. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  252. var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  253. if (configfj != null)
  254. {
  255. dt = BindFileData(dt, configfj.F_ParamValue);
  256. }
  257. string gcsql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
  258. + "from T_Wo_Operation where F_IsDelete=0 and F_WorkOrderId ='" + dt.Rows[0]["WorkOrderId"] + "'";
  259. var gcdt = DbHelperSQL.Query(gcsql).Tables[0];
  260. dt.Columns.Add("FilePath", typeof(string));
  261. if (configfj != null || config != null)
  262. {
  263. foreach (DataRow bldr in dt.Rows)
  264. {
  265. if (bldr["CallID"] != null && config != null)
  266. {
  267. bldr["FilePath"] = GetCallPath(bldr["CallID"].ToString(), config.F_ParamValue);
  268. }
  269. }
  270. }
  271. var obj = new
  272. {
  273. data = dt,
  274. item = gcdt
  275. };
  276. return Success("查询成功", obj);
  277. }
  278. else
  279. {
  280. return Error("查询失败");
  281. }
  282. }
  283. else
  284. {
  285. return Error("查询失败");
  286. }
  287. }
  288. #endregion
  289. #region 获取下拉框
  290. /// <summary>
  291. /// 获取信息分类列表
  292. /// </summary>
  293. /// <returns></returns>
  294. [WechatActionFilter]
  295. public ActionResult GetTypeList()
  296. {
  297. string sql = "select * from T_Sys_DictionaryValue where F_DictionaryFlag='XXFL' and F_State=1 ";
  298. var dt = DbHelperSQL.Query(sql).Tables[0];
  299. return Success("列表加载成功", dt);
  300. }
  301. /// <summary>
  302. /// 获取交办单位列表
  303. /// </summary>
  304. /// <returns></returns>
  305. [WechatActionFilter]
  306. public ActionResult GetAreaList()
  307. {
  308. string sql = "select * from T_Sys_DictionaryValue where F_DictionaryFlag='JBDW' and F_State=1 ";
  309. var dt = DbHelperSQL.Query(sql).Tables[0];
  310. return Success("列表加载成功", dt);
  311. }
  312. #endregion
  313. #region 附件和语音文件
  314. /// <summary>
  315. /// 获取留言路径
  316. /// </summary>
  317. /// <param name="lid">留言id</param>
  318. /// <param name="prefix">前缀</param>
  319. /// <returns></returns>
  320. public string GetLeavePath(string lid, string prefix)
  321. {
  322. string path = string.Empty;
  323. var liuyan = new BLL.T_Call_LeaveRecord().GetModelList(" F_Id='" + lid + "' ").FirstOrDefault();
  324. if (liuyan != null)
  325. {
  326. if (!string.IsNullOrEmpty(liuyan.F_RecFileUrl))
  327. {
  328. path = prefix + liuyan.F_RecFileUrl;
  329. }
  330. }
  331. return path;
  332. }
  333. /// <summary>
  334. /// 获取通话录音路径
  335. /// </summary>
  336. /// <param name="cid">通话id</param>
  337. /// <param name="prefix">前缀</param>
  338. /// <returns></returns>
  339. public string GetCallPath(string cid, string prefix)
  340. {
  341. string path = string.Empty;
  342. var luyin = new BLL.T_Call_CallRecords().GetModelList(" callid='" + cid + "' ").FirstOrDefault();
  343. if (luyin != null)
  344. {
  345. if (!string.IsNullOrEmpty(luyin.FilePath))
  346. {
  347. var ym = prefix;
  348. ym = ym.Substring(0, ym.Length - 1);
  349. path = ym + luyin.FilePath.Substring(luyin.FilePath.IndexOf(':') + 1).Replace('\\', '/');
  350. }
  351. }
  352. return path;
  353. }
  354. /// <summary>
  355. /// 获取附件数据
  356. /// </summary>
  357. /// <param name="ids">附件id,多个用英文逗号,隔开</param>
  358. /// <param name="prefix">前缀</param>
  359. /// <returns></returns>
  360. public DataTable GetFileData(string ids, string prefix)
  361. {
  362. DataTable dt = DbHelperSQL.Query("select * from T_Sys_Accessories where F_FileId in (" + ids + ")").Tables[0];
  363. foreach (DataRow dr in dt.Rows)
  364. {
  365. dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
  366. }
  367. return dt;
  368. }
  369. /// <summary>
  370. /// 绑定附件信息
  371. /// </summary>
  372. /// <param name="dt"></param>
  373. /// <param name="prefix"></param>
  374. /// <returns></returns>
  375. public DataTable BindFileData(DataTable dt, string prefix)
  376. {
  377. dt.Columns.Add("File", typeof(object));
  378. foreach (DataRow dr in dt.Rows)
  379. {
  380. if (dr["Files"] != null && dr["Files"].ToString() != "")
  381. {
  382. dr["File"] = GetFileData(dr["Files"].ToString(), prefix);
  383. }
  384. }
  385. return dt;
  386. }
  387. /// <summary>
  388. /// 上传附件
  389. /// </summary>
  390. /// <returns></returns>
  391. public ActionResult UpdateFile()
  392. {
  393. //string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  394. //byte[] filesss = HttpUtility.UrlDecodeToBytes(RequestString.GetFormString("filesss"));
  395. string filess = HttpUtility.UrlDecode(RequestString.GetFormString("filesss"));
  396. Error(filess);
  397. byte[] filesss = Convert.FromBase64String(filess.Split(',')[1]);
  398. //string fileurl = HttpUtility.UrlDecode(RequestString.GetFormString("fileurl"));
  399. string filename = HttpUtility.UrlDecode(RequestString.GetFormString("filename"));
  400. string filesize = HttpUtility.UrlDecode(RequestString.GetFormString("filesize"));
  401. string filetype = HttpUtility.UrlDecode(RequestString.GetFormString("filetype"));
  402. FileUp fu = new FileUp();
  403. string path = "/Upload/Files/" + DateTime.Now.ToString("yyyy/MM/dd") + "/";
  404. #region
  405. if (filesss.Length > 0)
  406. {
  407. //byte[] by = fu.GetBinaryFile(fileurl);
  408. string newfilename = DateTime.Now.ToString("yyyyMMddHHmmssmsfff") + "_" + filename;
  409. fu.SaveFile(filesss, path, newfilename, filetype);
  410. Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  411. model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
  412. model_T_Sys_Accessories.F_FileName = newfilename;//附件名称
  413. model_T_Sys_Accessories.F_FileType = filetype;//附件类型
  414. model_T_Sys_Accessories.F_FileUrl = path + newfilename;//附件地址
  415. model_T_Sys_Accessories.F_Size = long.Parse(filesize);
  416. //model_T_Sys_Accessories.F_UserCode = stropenid;//上传人
  417. int id = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  418. if (id > 0)
  419. {
  420. return Success("文件日志都成功", id);
  421. }
  422. else
  423. return Success("文件成功");
  424. }
  425. else
  426. {
  427. return Error("请选择要上传的文件");
  428. }
  429. #endregion
  430. #region 多个上传
  431. //HttpFileCollection files = RequestString.GetFiles();
  432. //if (files.Count > 0)
  433. //{
  434. // List<Model.T_Sys_Accessories> acs = new List<Model.T_Sys_Accessories>();
  435. // for (int i = 0; i < files.Count; i++)
  436. // {
  437. // HttpPostedFile file = files[i];
  438. // string name = fu.Upload(file, path);
  439. // Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
  440. // model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
  441. // model_T_Sys_Accessories.F_FileName = name;//附件名称
  442. // model_T_Sys_Accessories.F_FileType = System.IO.Path.GetExtension(file.FileName);//附件类型
  443. // model_T_Sys_Accessories.F_FileUrl = path + name;//附件地址
  444. // model_T_Sys_Accessories.F_Size = file.ContentLength;
  445. // //model_T_Sys_Accessories.F_UserCode = stropenid;//上传人
  446. // int id = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
  447. // model_T_Sys_Accessories.F_FileId = id;
  448. // acs.Add(model_T_Sys_Accessories);
  449. // }
  450. // return Success("成功", acs);
  451. //}
  452. //else
  453. //{
  454. // return Error("请选择要上传的文件");
  455. //}
  456. #endregion
  457. }
  458. #endregion
  459. #region
  460. public ActionResult UpLoadProcess(string id, HttpPostedFileBase file)
  461. {
  462. try
  463. {
  464. string filePathName = string.Empty;
  465. string path = "/Upload/Files/" + DateTime.Now.ToString("yyyy/MM/dd") + "/";
  466. string localPath = Path.Combine(HttpRuntime.AppDomainAppPath, path);
  467. if (Request.Files.Count == 0)
  468. {
  469. return Json(new { jsonrpc = 2.0, error = new { code = 102, message = "保存失败" }, id = "id" });
  470. }
  471. string ex = Path.GetExtension(file.FileName);
  472. filePathName = DateTime.Now.ToString("yyyyMMddHHmmssmsfff") + "_" + Guid.NewGuid().ToString("N") + ex;
  473. if (!System.IO.Directory.Exists(localPath))
  474. {
  475. System.IO.Directory.CreateDirectory(localPath);
  476. }
  477. file.SaveAs(Path.Combine(localPath, filePathName));
  478. return Success("上传成功", path + filePathName);
  479. }
  480. catch (Exception ex)
  481. {
  482. return Error(ex.Message);
  483. }
  484. }
  485. #endregion
  486. }
  487. }