Нет описания

WxLoginController.cs 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.DB;
  4. using CallCenterApi.Interface.App_Start;
  5. using CallCenterApi.Interface.Controllers.Base;
  6. using CallCenterApi.Interface.Controllers.Sms;
  7. using CallCenterApi.Model;
  8. using CallCenterAPI.WechatSDK;
  9. using CallCenterAPI.WechatSDK.Models;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Linq;
  14. using System.Web;
  15. using System.Web.Mvc;
  16. namespace CallCenterApi.Interface.Controllers.weixin
  17. {
  18. public class WxLoginController : BaseController
  19. {
  20. private readonly BLL.T_Sys_UserAccount userAccountBLL = new BLL.T_Sys_UserAccount();
  21. private readonly BLL.T_Sys_RoleInfo roleBLL = new BLL.T_Sys_RoleInfo();
  22. /// <summary>
  23. /// 绑定微信号
  24. /// </summary>
  25. /// <param name="login"></param>
  26. /// <returns></returns>
  27. [WechatActionFilter]
  28. public ActionResult Login(WxLoginDto login)
  29. {
  30. string rolecode = "";
  31. Dictionary<string, string> paras = new Dictionary<string, string>();
  32. string sql = " select * from T_Sys_UserAccount where F_UserCode=@F_UserCode and F_PassWord=@F_PassWord ";
  33. paras.Add("@F_UserCode", login.UserCode);
  34. paras.Add("@F_PassWord", login.Password);
  35. var dt = DbHelperSQL.Query(sql, paras).Tables[0];
  36. if (dt != null)
  37. {
  38. var user = userAccountBLL.GetModel(login.UserCode);
  39. user.F_WxOpenId = login.OpenId;
  40. if (userAccountBLL.Update(user))
  41. {
  42. var rolemodel = roleBLL.GetModel(user.F_RoleId);
  43. if (rolemodel != null)
  44. rolecode = rolemodel.F_RoleCode;
  45. var obj = new
  46. {
  47. openid = login.OpenId,
  48. usercode = login.UserCode,
  49. rolecode = rolecode
  50. };
  51. return Success("绑定成功", obj);
  52. }
  53. else
  54. {
  55. return Error("绑定失败");
  56. }
  57. }
  58. else
  59. {
  60. return Error("账号或密码错误,请重新登录");
  61. }
  62. }
  63. /// <summary>
  64. /// 获取微信openid
  65. /// </summary>
  66. /// <param name="login"></param>
  67. /// <returns></returns>
  68. public ActionResult GetOpenId(WxLoginDto wld)
  69. {
  70. wld.RedirectUrl = RequestString.GetUrlReferrer();
  71. if (string.IsNullOrEmpty(wld.OpenId))
  72. {
  73. var temp = WxHelper.GetOpenId(wld);
  74. if (string.IsNullOrWhiteSpace(temp.OpenId))
  75. {
  76. return Redirect("请求", temp.RedirectUrl);
  77. }
  78. wld.OpenId = temp.OpenId;
  79. }
  80. var model = new BLL.T_Sys_Users().GetModel(wld.OpenId);
  81. if (model == null)
  82. {
  83. model = new Model.T_Sys_Users();
  84. model.F_OpenId = wld.OpenId;
  85. model.F_Type = (int)EnumUserType.wechat;//1;
  86. model.F_CreateTime = DateTime.Now;
  87. new BLL.T_Sys_Users().Add(model);
  88. }
  89. return Success("成功", wld.OpenId);
  90. }
  91. /// <summary>
  92. /// 获取微信用户信息
  93. /// </summary>
  94. /// <param name="login"></param>
  95. /// <returns></returns>
  96. public ActionResult GetUserInfo(WxLoginDto wld)
  97. {
  98. wld.RedirectUrl = RequestString.GetUrlReferrer();
  99. if (string.IsNullOrEmpty(wld.OpenId))
  100. {
  101. var temp = WxHelper.GetUserInfo(wld);
  102. if (string.IsNullOrWhiteSpace(temp.OpenId))
  103. {
  104. return Redirect("请求", temp.RedirectUrl);
  105. }
  106. wld.OpenId = temp.OpenId;
  107. wld.UserInfo = temp.UserInfo;
  108. }
  109. var model = new BLL.T_Sys_Users().GetModel(wld.OpenId);
  110. if (model == null)
  111. {
  112. model = new Model.T_Sys_Users();
  113. model.F_OpenId = wld.OpenId;
  114. model.F_Name = wld.UserInfo.nickname;
  115. model.F_ImgUrl = wld.UserInfo.headimgurl;
  116. model.F_Province = wld.UserInfo.province;
  117. model.F_City = wld.UserInfo.city;
  118. model.F_County = wld.UserInfo.country;
  119. model.F_Type = (int)EnumUserType.wechat;//1;
  120. model.F_CreateTime = DateTime.Now;
  121. new BLL.T_Sys_Users().Add(model);
  122. }
  123. return Success("成功", model);
  124. }
  125. /// <summary>
  126. /// 发送短信验证码
  127. /// </summary>
  128. /// <param name="mobile"></param>
  129. /// <returns></returns>
  130. [WechatActionFilter]
  131. public ActionResult SendCode(string mobile)
  132. {
  133. int codes = new Random().Next(100000, 999999);
  134. string mag = "[\"" + codes.ToString() + "\"]";
  135. string v = SmsNewController.AddSmS(0, "您本次登录的验证码是" + codes.ToString() + ",10分钟内有效。", mobile, "1053396176871632896", mag,
  136. "");
  137. if (v == "")
  138. {
  139. return Error("发送成功");
  140. }
  141. else
  142. {
  143. return Error("发送失败");
  144. }
  145. }
  146. /// <summary>
  147. /// 修改微信用户信息
  148. /// </summary>
  149. /// <param name="login"></param>
  150. /// <returns></returns>
  151. [WechatActionFilter]
  152. public ActionResult EditUserInfo(WxLoginDto wld,string code,string mobile)
  153. {
  154. wld.RedirectUrl = RequestString.GetUrlReferrer();
  155. if (string.IsNullOrEmpty(wld.OpenId))
  156. {
  157. var temp = WxHelper.GetUserInfo(wld);
  158. if (string.IsNullOrWhiteSpace(temp.OpenId))
  159. {
  160. return Redirect("请求", temp.RedirectUrl);
  161. }
  162. wld.OpenId = temp.OpenId;
  163. wld.UserInfo = temp.UserInfo;
  164. }
  165. if (string.IsNullOrEmpty(mobile))
  166. return Error("请输入手机号码");
  167. string msgcount = "您的验证码是" + code + ",10分钟内有效。";
  168. if (string.IsNullOrEmpty(code))
  169. return Error("请输入验证码");
  170. var sms = new BLL.T_SMS_RecvSMS().GetModelList("Content='" + msgcount + "' and CallerNum='" + mobile + "'order by RecvTime desc");
  171. if (sms != null && sms.Count > 0)
  172. {
  173. var modelSms = sms.First();
  174. if ((DateTime.Now - modelSms.RecvTime).Minutes > 10)
  175. {
  176. return Error("验证码已失效");
  177. }
  178. }
  179. else
  180. return Error("请输入正确验证码");
  181. var model = new BLL.T_Sys_Users().GetModel(wld.OpenId);
  182. if (model == null)
  183. {
  184. model = new Model.T_Sys_Users();
  185. model.F_OpenId = wld.OpenId;
  186. model.F_Name = wld.UserInfo.nickname;
  187. model.F_ImgUrl = wld.UserInfo.headimgurl;
  188. model.F_Province = wld.UserInfo.province;
  189. model.F_City = wld.UserInfo.city;
  190. model.F_Telphone = mobile;
  191. model.F_County = wld.UserInfo.country;
  192. model.F_Type = (int)EnumUserType.wechat;//1;
  193. model.F_CreateTime = DateTime.Now;
  194. new BLL.T_Sys_Users().Add(model);
  195. }
  196. else
  197. {
  198. model.F_Telphone = mobile;
  199. new BLL.T_Sys_Users().Update (model);
  200. }
  201. return Success("成功", wld.UserInfo);
  202. }
  203. /// <summary>
  204. /// 解除微信用户信息
  205. /// </summary>
  206. /// <param name="login"></param>
  207. /// <returns></returns>
  208. [WechatActionFilter]
  209. public ActionResult RelieveUserInfo(WxLoginDto wld, string code, string mobile)
  210. {
  211. wld.RedirectUrl = RequestString.GetUrlReferrer();
  212. if (string.IsNullOrEmpty(mobile))
  213. return Error("请输入手机号码");
  214. string msgcount = "您的验证码是" + code + ",10分钟内有效。";
  215. if (string.IsNullOrEmpty(code))
  216. return Error("请输入验证码");
  217. var sms = new BLL.T_SMS_RecvSMS().GetModelList("Content='" + msgcount + "' and CallerNum='" + mobile + "'order by RecvTime desc");
  218. if (sms != null && sms.Count > 0)
  219. {
  220. var modelSms = sms.First();
  221. if ((DateTime.Now - modelSms.RecvTime).Minutes > 10)
  222. {
  223. return Error("验证码已失效");
  224. }
  225. }
  226. else
  227. return Error("请输入正确验证码");
  228. if (string.IsNullOrEmpty(wld.OpenId))
  229. {
  230. var temp = WxHelper.GetUserInfo(wld);
  231. if (string.IsNullOrWhiteSpace(temp.OpenId))
  232. {
  233. return Redirect("请求", temp.RedirectUrl);
  234. }
  235. wld.OpenId = temp.OpenId;
  236. wld.UserInfo = temp.UserInfo;
  237. }
  238. var model = new BLL.T_Sys_Users().GetModel(wld.OpenId);
  239. if (model != null)
  240. {
  241. model.F_Telphone = "";
  242. new BLL.T_Sys_Users().Update(model);
  243. }
  244. else
  245. {
  246. return Error("该用户不存在");
  247. }
  248. return Success("解除成功", wld.UserInfo);
  249. }
  250. /// <summary>
  251. /// 获取政务网用户
  252. /// </summary>
  253. /// <returns></returns>
  254. [WechatActionFilter]
  255. public ActionResult GetZWWUser(string usercode, string signcode)
  256. {
  257. if (string.IsNullOrEmpty(usercode) || string.IsNullOrEmpty(signcode))
  258. {
  259. return Error("非法访问");
  260. }
  261. string zwwcode = Configs.GetValue("ZWWCode");
  262. string appsigncode = Configs.GetValue("APPSignCode");
  263. string jssigncode = EncryptHelper.MD5Encrypt(usercode + "|" + EncryptHelper.SHA1Encrypt(appsigncode + "|" + DateTime.Now.ToString("yyyyMMdd")));
  264. if (signcode != jssigncode)
  265. {
  266. return Error("非法访问");
  267. }
  268. Model.T_Sys_Users dModel = new Model.T_Sys_Users();
  269. usercode = zwwcode + usercode;
  270. var list = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + usercode + "' ");
  271. if (list.Count == 0)
  272. {
  273. dModel.F_OpenId = usercode;
  274. dModel.F_Type = (int)EnumUserType.zwwreg; //4;
  275. dModel.F_CreateTime = DateTime.Now;
  276. long n = new BLL.T_Sys_Users().Add(dModel);
  277. return Success("成功", usercode);
  278. }
  279. else
  280. {
  281. return Success("成功", usercode);
  282. }
  283. }
  284. #region 工单相关
  285. /// <summary>
  286. /// 获取工单列表
  287. /// </summary>
  288. /// <returns></returns>
  289. [WechatActionFilter]
  290. public ActionResult GetList()
  291. {
  292. DataTable dt = new DataTable();
  293. //string sql = " and F_IsDelete=0 ";
  294. string sql = " and (F_IsEnabled=0 or F_IsDelete=0) ";
  295. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  296. string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
  297. string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
  298. string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  299. string strkey = HttpUtility.UrlDecode(RequestString.GetQueryString("key"));
  300. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  301. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  302. string strworkid = HttpUtility.UrlDecode(RequestString.GetQueryString("workid"));
  303. string strusercode = HttpUtility.UrlDecode(RequestString.GetQueryString("usercode"));
  304. int source = RequestString.GetInt("source", 0);
  305. int keyid = RequestString.GetInt("keyid", 0);
  306. int type = RequestString.GetInt("type", 0);
  307. int bigtype = RequestString.GetInt("bigtype", 0);
  308. int smalltype = RequestString.GetInt("smalltype", 0);
  309. int sourcearea = RequestString.GetInt("sourcearea", 0);
  310. int isdeal = RequestString.GetInt("isdeal", -1);
  311. string strpageindex = RequestString.GetQueryString("page");
  312. int pageindex = 1;
  313. string strpagesize = RequestString.GetQueryString("pagesize");
  314. int pagesize = 10;
  315. #region sql 语句相关处理
  316. //根据openid获取所有工单号
  317. var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  318. sql += " and F_WorkOrderId in (select distinct F_WorkOrderId from T_Bus_UserWorkOrder where F_UserId='" + wxuser.F_Id + "') ";
  319. if (strstate.Trim() != "" && strstate != "undefined")
  320. {
  321. sql += " and F_WorkState = '" + strstate.Trim() + "' ";
  322. }
  323. if (strworkid.Trim() != "" && strworkid != "undefined")
  324. {
  325. sql += " and F_WorkOrderId like '%" + strworkid + "%' ";
  326. }
  327. if (strname.Trim() != "" && strname != "undefined")
  328. {
  329. sql += " and F_CusName like '%" + strname + "%' ";
  330. }
  331. if (strtel.Trim() != "" && strtel != "undefined")
  332. {
  333. sql += " and (F_CusPhone like '%" + strtel + "%' or F_ConPhone like '%" + strtel + "%') ";
  334. }
  335. if (strkey.Trim() != "" && strkey != "undefined")
  336. {
  337. sql += " and (F_ComTitle like '%" + strkey + "%' or F_ComContent like '%" + strkey + "%') ";
  338. }
  339. if (strusercode.Trim() != "" && strusercode != "undefined")
  340. {
  341. sql += " and F_CreateUser = '" + strusercode + "' ";
  342. }
  343. if (source != 0)
  344. {
  345. sql += " and F_InfoSource = '" + source + "' ";
  346. }
  347. if (keyid != 0)
  348. {
  349. sql += " and ','+F_Key+',' like '%," + keyid + ",%' ";
  350. }
  351. if (type != 0)
  352. {
  353. sql += " and F_InfoType = '" + type + "' ";
  354. }
  355. if (bigtype != 0)
  356. {
  357. sql += " and F_InfoConBigType = '" + bigtype + "' ";
  358. }
  359. if (smalltype != 0)
  360. {
  361. sql += " and F_InfoConSmallType = '" + smalltype + "' ";
  362. }
  363. if (sourcearea != 0)
  364. {
  365. sql += " and F_SourceArea = '" + sourcearea + "' ";
  366. }
  367. if (isdeal != -1)
  368. {
  369. if (isdeal == 1)
  370. {
  371. sql += " and F_WorkState = '9' ";
  372. }
  373. else
  374. {
  375. sql += " and F_WorkState != '9' ";
  376. }
  377. }
  378. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  379. {
  380. sql += " and datediff(day,F_CreateTime,'" + strstarttime + "')<=0 ";
  381. }
  382. if (strendtime.Trim() != "" && strendtime != "undefined")
  383. {
  384. sql += " and datediff(day,F_CreateTime,'" + strendtime + "')>=0 ";
  385. }
  386. #endregion
  387. if (strpageindex.Trim() != "")
  388. {
  389. pageindex = Convert.ToInt32(strpageindex);
  390. }
  391. if (strpagesize.Trim() != "")
  392. {
  393. pagesize = Convert.ToInt32(strpagesize);
  394. }
  395. string cols = "*,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName,"
  396. + "dbo.GetDictionaryName(F_InfoSource) as SourceName,dbo.GetWorkOrderAssign(F_WorkOrderId) as DeptName ";
  397. int recordCount = 0;
  398. dt = BLL.PagerBLL.GetListPager(
  399. "T_Bus_WorkOrder",
  400. "F_WorkOrderId",
  401. cols,
  402. sql,
  403. "ORDER BY F_CreateTime DESC",
  404. pagesize,
  405. pageindex,
  406. true,
  407. out recordCount);
  408. var obj = new
  409. {
  410. state = "success",
  411. message = "成功",
  412. rows = dt,
  413. total = recordCount
  414. };
  415. return Content(obj.ToJson());
  416. }
  417. /// <summary>
  418. /// 新增工单
  419. /// </summary>
  420. /// <returns></returns>
  421. [WechatActionFilter]
  422. public ActionResult AddWorkOrder()
  423. {
  424. DataTable dt = new DataTable();
  425. string cusname = RequestString.GetFormString("cusname");
  426. string cussex = RequestString.GetFormString("cussex");
  427. string cusphone = RequestString.GetFormString("cusphone");
  428. string cusaddress = RequestString.GetFormString("cusaddress");
  429. string email = RequestString.GetFormString("email");
  430. string zipcode = RequestString.GetFormString("zipcode");
  431. string conname = RequestString.GetFormString("conname");
  432. string conphone = RequestString.GetFormString("conphone");
  433. string title = RequestString.GetFormString("title");
  434. string content = RequestString.GetFormString("content");
  435. string files = RequestString.GetFormString("files");
  436. int sourcearea = RequestString.GetInt("sourcearea", 0);
  437. string sourceaddress = RequestString.GetFormString("sourceaddress");
  438. int isresult = RequestString.GetInt("isresult", 0);
  439. string result = RequestString.GetFormString("result");
  440. string keys = RequestString.GetFormString("keys");
  441. string splituser = RequestString.GetFormString("splituser");
  442. int type = RequestString.GetInt("type", 0);
  443. int bigtype = RequestString.GetInt("bigtype", 0);
  444. int smalltype = RequestString.GetInt("smalltype", 0);
  445. int isprotect = RequestString.GetInt("isprotect", 0);
  446. int level = RequestString.GetInt("level", 0);
  447. int soursetype = 5;
  448. string stropenid = HttpUtility.UrlDecode(RequestString.GetFormString("openid"));
  449. var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  450. if (wxuser.F_Type == (int)EnumUserType.zwwreg) { soursetype = 6; }
  451. //if (wxuser.F_Type == 4) { soursetype = 6; }
  452. workorder.WorkOrderController wo = new workorder.WorkOrderController();
  453. string workorderid = wo.AddWorkOrderBySource(soursetype, cusname, cussex, cusphone, cusaddress, email, zipcode, conname, conphone, title,
  454. content, sourcearea, sourceaddress, keys, splituser, type, bigtype, smalltype, isprotect, level, files);
  455. if (string.IsNullOrEmpty(workorderid))
  456. {
  457. return Error("新增失败");
  458. }
  459. else
  460. {
  461. Model.T_Bus_UserWorkOrder tbu = new Model.T_Bus_UserWorkOrder();
  462. tbu.F_UserId = wxuser.F_Id;
  463. tbu.F_WorkOrderId = workorderid;
  464. new BLL.T_Bus_UserWorkOrder().Add(tbu);
  465. return Success("新增成功", workorderid);
  466. }
  467. }
  468. /// <summary>
  469. /// 获取工单详情
  470. /// </summary>
  471. /// <returns></returns>
  472. [WechatActionFilter]
  473. public ActionResult GetWorkOrder()
  474. {
  475. string strworkorderid = HttpUtility.UrlDecode(RequestString.GetQueryString("workorderid"));
  476. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  477. var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  478. var tbu = new BLL.T_Bus_UserWorkOrder().GetList(" F_UserId='" + wxuser.F_Id + "' and F_WorkOrderId='" + strworkorderid + "' ").Tables[0];
  479. if (tbu.Rows.Count > 0)
  480. {
  481. string sql = "select *,dbo.GetUserName(F_CreateUser) as UserName,dbo.GetDictionaryName(F_InfoType) as TypeName1,"
  482. //+ "dbo.GetDictionaryName(F_InfoConBigType) as TypeName2,dbo.GetDictionaryName(F_InfoConSmallType) as TypeName3,"
  483. + "dbo.GetWorkOrderAssign(F_WorkOrderId) as DeptName,dbo.GetDictionaryName(F_InfoSource) as SourceName ,"
  484. + "dbo.GetAreaName(F_SourceArea) as AreaName "
  485. + " from T_Bus_WorkOrder where F_WorkOrderId ='" + strworkorderid + "' and (F_IsEnabled=0 or F_IsDelete=0)";
  486. var dt = DbHelperSQL.Query(sql).Tables[0];
  487. if (dt.Rows.Count > 0)
  488. {
  489. var configly = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayLeaveVoice' ").FirstOrDefault();
  490. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  491. var configfj = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='FileUrlPath' ").FirstOrDefault();
  492. dt.Columns.Add("FilePath", typeof(string));
  493. if (dt.Rows[0]["F_LeaveRecordId"] != null)
  494. {
  495. dt.Rows[0]["FilePath"] = GetLeavePath(dt.Rows[0]["F_LeaveRecordId"].ToString(), config.F_ParamValue);
  496. }
  497. else if (dt.Rows[0]["F_CallRecordId"] != null)
  498. {
  499. dt.Rows[0]["FilePath"] = GetCallPath(dt.Rows[0]["F_CallRecordId"].ToString(), config.F_ParamValue);
  500. }
  501. if (configfj != null)
  502. {
  503. dt = BindFileData(dt, configfj.F_ParamValue);
  504. }
  505. string gcsql = "select *,dbo.GetUserName(F_CreateUser) as UserName "
  506. + "from T_Bus_Operation where F_IsDelete=0 and F_WorkOrderId ='" + strworkorderid + "'";
  507. var gcdt = DbHelperSQL.Query(gcsql).Tables[0];
  508. gcdt.Columns.Add("File", typeof(object));
  509. gcdt.Columns.Add("FilePath", typeof(string));
  510. if (configfj != null || configly != null || config != null)
  511. {
  512. foreach (DataRow bldr in gcdt.Rows)
  513. {
  514. if (bldr["F_File"] != null && bldr["F_File"].ToString() != "" && configfj != null)
  515. {
  516. bldr["File"] = GetFileData(bldr["F_File"].ToString(), configfj.F_ParamValue);
  517. }
  518. if (bldr["F_LeaveRecordId"] != null && configly != null)
  519. {
  520. bldr["FilePath"] = GetLeavePath(bldr["F_LeaveRecordId"].ToString(), configly.F_ParamValue);
  521. }
  522. else if (bldr["F_CallRecordId"] != null && config != null)
  523. {
  524. bldr["FilePath"] = GetCallPath(bldr["F_CallRecordId"].ToString(), config.F_ParamValue);
  525. }
  526. }
  527. }
  528. var obj = new
  529. {
  530. data = dt,
  531. item = gcdt
  532. };
  533. return Success("查询成功", obj);
  534. }
  535. else
  536. {
  537. return Error("查询失败");
  538. }
  539. }
  540. else
  541. {
  542. return Error("查询失败");
  543. }
  544. }
  545. /// <summary>
  546. /// 获取工单数量
  547. /// </summary>
  548. /// <returns></returns>
  549. [WechatActionFilter]
  550. public ActionResult GetWorkOrderCount()
  551. {
  552. string stropenid = HttpUtility.UrlDecode(RequestString.GetQueryString("openid"));
  553. int type = RequestString.GetInt("type", 0);
  554. var wxuser = new BLL.T_Sys_Users().GetModelList(" F_OpenId='" + stropenid.Trim() + "'").FirstOrDefault();
  555. string where= " F_WorkOrderId in (select F_WorkOrderId from T_Bus_UserWorkOrder where F_UserId='" + wxuser.F_Id + "') and (F_IsEnabled=0 or F_IsDelete=0) ";
  556. string sql = " select count(1) from T_Bus_WorkOrder where " + where ;
  557. string sqlblz = " select count(1) from T_Bus_WorkOrder where " + where + " and F_WorkState!=9 ";
  558. string sqlybl = " select count(1) from T_Bus_WorkOrder where " + where + " and F_WorkState =9 ";
  559. string sqltype = " select F_ValueId,F_Value,(select COUNT(1) from T_Bus_WorkOrder where (F_IsEnabled=0 or F_IsDelete=0) ";
  560. if (type == 1)
  561. {
  562. sqltype += " and F_WorkState!=9";
  563. }
  564. else if (type == 2)
  565. {
  566. sqltype += " and F_WorkState=9";
  567. }
  568. sqltype += " and F_InfoType=F_ValueId and " + where + ") Count from dbo.T_Sys_DictionaryValue where (F_PrentId=37 or F_ItemId=2) and F_State=0 ";
  569. DataTable dt = DbHelperSQL.Query(sqltype).Tables[0];
  570. var obj = new
  571. {
  572. total = DbHelperSQL.GetSingle(sql).ToString(),
  573. blzcount = DbHelperSQL.GetSingle(sqlblz).ToString(),
  574. yblcount = DbHelperSQL.GetSingle(sqlybl).ToString(),
  575. typedata = dt
  576. };
  577. return Success("成功", obj);
  578. }
  579. #endregion
  580. #region 获取下拉框
  581. /// <summary>
  582. /// 获取工单类型列表
  583. /// </summary>
  584. /// <returns></returns>
  585. [WechatActionFilter]
  586. public ActionResult GetTypeList()
  587. {
  588. string sql = "select * from T_Sys_DictionaryValue where (F_PrentId=37 or F_ItemId=2) and F_State=0 ";
  589. var dt = DbHelperSQL.Query(sql).Tables[0];
  590. return Success("列表加载成功", dt);
  591. }
  592. /// <summary>
  593. /// 获取事发地域列表
  594. /// </summary>
  595. /// <returns></returns>
  596. [WechatActionFilter]
  597. public ActionResult GetAreaList()
  598. {
  599. string sql = "select * from T_Sys_Area where isnull(F_PrentId,0)=0 and F_State=0 ";
  600. var dt = DbHelperSQL.Query(sql).Tables[0];
  601. return Success("列表加载成功", dt);
  602. }
  603. /// <summary>
  604. /// 获取工单类型列表
  605. /// </summary>
  606. /// <returns></returns>
  607. [WechatActionFilter]
  608. public ActionResult GetKeyList()
  609. {
  610. string sql = "select * from T_Sys_DictionaryValue where (F_PrentId=38 or F_ItemId=3) and F_State=0 ";
  611. var dt = DbHelperSQL.Query(sql).Tables[0];
  612. return Success("列表加载成功", dt);
  613. }
  614. #endregion
  615. #region 附件和语音文件
  616. /// <summary>
  617. /// 获取留言路径
  618. /// </summary>
  619. /// <param name="lid">留言id</param>
  620. /// <param name="prefix">前缀</param>
  621. /// <returns></returns>
  622. public string GetLeavePath(string lid, string prefix)
  623. {
  624. string path = string.Empty;
  625. var liuyan = new BLL.T_Call_LeaveRecord().GetModelList(" F_Id='" + lid + "' ").FirstOrDefault();
  626. if (liuyan != null)
  627. {
  628. if (!string.IsNullOrEmpty(liuyan.F_RecFileUrl))
  629. {
  630. path = prefix + liuyan.F_RecFileUrl;
  631. }
  632. }
  633. return path;
  634. }
  635. /// <summary>
  636. /// 获取通话录音路径
  637. /// </summary>
  638. /// <param name="cid">通话id</param>
  639. /// <param name="prefix">前缀</param>
  640. /// <returns></returns>
  641. public string GetCallPath(string cid, string prefix)
  642. {
  643. string path = string.Empty;
  644. var luyin = new BLL.T_Call_CallRecords().GetModelList(" CallRecordsId='" + cid + "' ").FirstOrDefault();
  645. if (luyin != null)
  646. {
  647. if (!string.IsNullOrEmpty(luyin.FilePath))
  648. {
  649. var ym = prefix;
  650. ym = ym.Substring(0, ym.Length - 1);
  651. string lujing = luyin.FilePath.Substring(luyin.FilePath.IndexOf(':') + 1).Replace('\\', '/');
  652. path = ym + lujing;
  653. //if (!CommonHelper.FileIsExist(path))
  654. //{
  655. // path = lujing;
  656. //}
  657. }
  658. }
  659. return path;
  660. }
  661. /// <summary>
  662. /// 获取附件数据
  663. /// </summary>
  664. /// <param name="ids">附件id,多个用英文逗号,隔开</param>
  665. /// <param name="prefix">前缀</param>
  666. /// <returns></returns>
  667. public DataTable GetFileData(string ids, string prefix)
  668. {
  669. DataTable dt = DbHelperSQL.Query("select * from T_Sys_Accessories where F_FileId in (" + ids + ")").Tables[0];
  670. foreach (DataRow dr in dt.Rows)
  671. {
  672. dr["F_FileUrl"] = prefix + dr["F_FileUrl"].ToString();
  673. }
  674. return dt;
  675. }
  676. /// <summary>
  677. /// 绑定附件信息
  678. /// </summary>
  679. /// <param name="dt"></param>
  680. /// <param name="prefix"></param>
  681. /// <returns></returns>
  682. public DataTable BindFileData(DataTable dt, string prefix)
  683. {
  684. dt.Columns.Add("File", typeof(object));
  685. foreach (DataRow dr in dt.Rows)
  686. {
  687. if (dr["F_File"] != null && dr["F_File"].ToString() != "")
  688. {
  689. dr["File"] = GetFileData(dr["F_File"].ToString(), prefix);
  690. }
  691. }
  692. return dt;
  693. }
  694. #endregion
  695. }
  696. }