Нет описания

CallInScreenController.cs 43KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. using CallCenter.Utility;
  2. using CallCenterApi.Interface.Controllers.Base;
  3. using CallCenterApi.Interface.Controllers.workorder;
  4. using CallCenterApi.Interface.Models.Enum;
  5. using CallCenterAPI.WechatSDK;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Linq;
  10. using System.Web;
  11. using System.Web.Mvc;
  12. namespace CallCenterApi.Interface.Controllers.tel
  13. {
  14. public class CallInScreenController : BaseController
  15. {
  16. private BLL.T_Sys_UserAccount sysUserAccountBll = new BLL.T_Sys_UserAccount();
  17. private BLL.T_Sys_Department sysDeptBll = new BLL.T_Sys_Department();
  18. private BLL.T_Sys_DictionaryValue dicvalueBll = new BLL.T_Sys_DictionaryValue();
  19. /// <summary>
  20. /// 添加黑名单
  21. /// </summary>
  22. /// <returns></returns>
  23. public ActionResult AddBlack()
  24. {
  25. ActionResult res = NoToken("未知错误,请重新登录");
  26. if (Request.IsAuthenticated)
  27. {
  28. int userId = CurrentUser.UserData.F_UserId;
  29. if (userId != 0)
  30. {
  31. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  32. if (ua != null)
  33. {
  34. string tel = HttpUtility.UrlDecode(RequestString.GetFormString("tel"));
  35. string callid = HttpUtility.UrlDecode(RequestString.GetFormString("callid"));
  36. int n = RequestString.GetInt("num", 0);
  37. int type = RequestString.GetInt("type", 0);
  38. Model.T_Call_Blacklist dModel = new BLL.T_Call_Blacklist().GetModelList(" F_TelPhone='" + tel + "' ").FirstOrDefault();
  39. var date = DateTime.Now;
  40. var enddate = date;
  41. switch (type)
  42. {
  43. case 1: enddate = enddate.AddDays(n); break;
  44. case 2: enddate = enddate.AddHours(n); break;
  45. case 3: enddate = enddate.AddMinutes(n); break;
  46. case 4: enddate = DateTime.MaxValue; break;
  47. }
  48. if (dModel == null)
  49. {
  50. dModel = new Model.T_Call_Blacklist();
  51. dModel.F_CallId = callid;
  52. dModel.F_TelPhone = tel.Trim();
  53. dModel.F_SetTime = date;
  54. dModel.F_RemoveTime = enddate;
  55. dModel.F_InterceptNum = 1;
  56. dModel.F_UserId = ua.F_UserId;
  57. int b = new BLL.T_Call_Blacklist().Add(dModel);
  58. if (b > 0)
  59. {
  60. res = Success("添加成功", enddate.ToString("yyyy-MM-dd HH:mm:ss"));
  61. }
  62. else
  63. {
  64. res = Error("添加失败");
  65. }
  66. }
  67. else
  68. {
  69. dModel.F_RemoveTime = enddate;
  70. if (new BLL.T_Call_Blacklist().Update(dModel))
  71. {
  72. res = Success("修改成功", enddate.ToString("yyyy-MM-dd HH:mm:ss"));
  73. }
  74. else
  75. {
  76. res = Error("修改失败");
  77. }
  78. }
  79. }
  80. }
  81. }
  82. return res;
  83. }
  84. /// <summary>
  85. /// 取消黑名单
  86. /// </summary>
  87. /// <returns></returns>
  88. public ActionResult DelBlack()
  89. {
  90. ActionResult res = NoToken("未知错误,请重新登录");
  91. if (Request.IsAuthenticated)
  92. {
  93. string tel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  94. Model.T_Call_Blacklist dModel = new BLL.T_Call_Blacklist().GetModelList(" F_TelPhone='" + tel + "' ").FirstOrDefault();
  95. if (dModel != null)
  96. {
  97. bool bl = new BLL.T_Call_Blacklist().Delete(dModel.F_BlackId);
  98. if (bl)
  99. {
  100. res = Success("取消成功");
  101. }
  102. }
  103. }
  104. return res;
  105. }
  106. /// <summary>
  107. /// 根据来电号码获取客户信息
  108. /// </summary>
  109. /// <returns></returns>
  110. public ActionResult GetCustomerByTel()
  111. {
  112. ActionResult res = NoToken("未知错误,请重新登录");
  113. if (Request.IsAuthenticated)
  114. {
  115. string tel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  116. //var sql = $" and (F_LegalTel like '%" + tel.Trim() + "%') or F_CustomerId in (select F_CustomerId from T_Cus_ContactPersonNew where F_Telephone like '%" + tel.Trim() + "%')";
  117. var sql = $" ( F_CompanyName like '%" + tel.Trim() + "%' or F_CustomerCode like '%" + tel.Trim() + "%' ) ";
  118. var userModel = new BLL.T_Cus_CustomerBaseNew().GetModelList(" F_DeleteFlag = 0 " + sql);
  119. if (userModel.Count() > 0)
  120. {
  121. var model = userModel.Last();
  122. int cusid = model.F_CustomerId;
  123. //var conlist = new BLL.T_Cus_ContactPersonNew().GetModelList(" F_DeleteFlag=0 and F_CustomerId=" + cusid);
  124. #region 绑定部门
  125. //var deptname = "";
  126. //var deptmodel = new BLL.T_Sys_Department().GetModel(model.F_BeDept.Value);
  127. //if (deptmodel != null)
  128. // deptname = deptmodel.F_DeptName;
  129. #endregion
  130. var obj = new
  131. {
  132. CustomerBase = model,
  133. //BeDeptName = deptname,
  134. //ContactList = conlist,
  135. };
  136. return Success("获取成功", obj);
  137. }
  138. }
  139. return res;
  140. }
  141. /// <summary>
  142. /// 根据来电号码获取最近的callid
  143. /// </summary>
  144. /// <returns></returns>
  145. public ActionResult GetCallIdByPhone()
  146. {
  147. ActionResult res = NoToken("未知错误,请重新登录");
  148. if (Request.IsAuthenticated)
  149. {
  150. DataTable dt = new DataTable();
  151. string tel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  152. Model.T_Call_CallRecords model = new BLL.T_Call_CallRecords().GetModelByTelphone(tel);
  153. res = Success("加载成功", model);
  154. }
  155. return res;
  156. }
  157. /// <summary>
  158. /// 根据callid获取最近的通话记录
  159. /// </summary>
  160. /// <returns></returns>
  161. public ActionResult GetTelRecordByCallid()
  162. {
  163. ActionResult res = NoToken("未知错误,请重新登录");
  164. if (Request.IsAuthenticated)
  165. {
  166. DataTable dt = new DataTable();
  167. string callid = HttpUtility.UrlDecode(RequestString.GetQueryString("callid"));
  168. Model.T_Call_CallRecords model = new BLL.T_Call_CallRecords().GetModelByCallId(callid);
  169. res = Success("通话记录加载成功", model);
  170. }
  171. return res;
  172. }
  173. /// <summary>
  174. /// 来电归属地查询
  175. /// </summary>
  176. /// <returns></returns>
  177. public ActionResult GetPhoneLocation()
  178. {
  179. ActionResult res = NoToken("未知错误,请重新登录");
  180. if (Request.IsAuthenticated)
  181. {
  182. string location = "未知";
  183. string tel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  184. if (tel.Trim().Length == 11 && tel.Substring(0, 1) != "0")
  185. {
  186. BLL.T_Sys_MobileData mobile_Bll = new BLL.T_Sys_MobileData();
  187. Model.T_Sys_MobileData mobileModel = mobile_Bll.GetModelList(" F_MobileNum='" + tel.Substring(0, 7) + "' ").FirstOrDefault();
  188. if (mobileModel != null)
  189. {
  190. location = mobileModel.F_CityDes + mobileModel.F_CardDes;
  191. }
  192. }
  193. else
  194. {
  195. BLL.T_Sys_TelTitleData numbBll = new BLL.T_Sys_TelTitleData();
  196. List<Model.T_Sys_TelTitleData> mobileModel = numbBll.GetModelList(" 1=1 and F_KeyPhoneNum='" + tel.Substring(0, 4) + "'");
  197. if (mobileModel == null || mobileModel.Count <= 0)
  198. {
  199. mobileModel = numbBll.GetModelList(" 1=1 and F_KeyPhoneNum='" + tel.Substring(0, 3) + "'");
  200. }
  201. if (mobileModel.Count > 0)
  202. {
  203. location = mobileModel[0].F_TitleName;
  204. }
  205. }
  206. res = Success("归属地加载成功", location);
  207. }
  208. return res;
  209. }
  210. /// <summary>
  211. /// 历史记录列表
  212. /// </summary>
  213. /// <returns></returns>
  214. public ActionResult GetOldList()
  215. {
  216. ActionResult res = NoToken("未知错误,请重新登录");
  217. if (Request.IsAuthenticated)
  218. {
  219. int userId = CurrentUser.UserData.F_UserId;
  220. if (userId != 0)
  221. {
  222. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  223. if (ua != null)
  224. {
  225. string sql = "";
  226. string sqlcount = "";
  227. DataTable dt = new DataTable();
  228. //来电号码
  229. string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  230. string strcalltype = HttpUtility.UrlDecode(RequestString.GetQueryString("calltype"));
  231. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  232. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  233. string strpageindex = RequestString.GetQueryString("page");
  234. int pageindex = 1;
  235. string strpagesize = RequestString.GetQueryString("pagesize");
  236. int pagesize = 10;
  237. //除管理员外,各坐席只能看到自己的
  238. //20180507 每个人都能看到该来电的所有历史记录 machenyang
  239. //if (ua.F_RoleId != 17)
  240. // sql += " and UserId = '" + userId + "'";
  241. ////20180514 坐席能看到同组的
  242. //var usergroup = ua.F_SeartGroup;
  243. //var usercodes = new BLL.T_Sys_UserAccount().GetModelList("F_SeartGroup='" + usergroup + "'") == null ? null : new BLL.T_Sys_UserAccount().GetModelList("F_SeartGroup='" + usergroup + "'").Select(p => p.F_UserCode);
  244. //var str = "";
  245. //if (usercodes != null)
  246. //{
  247. // foreach (var item in usercodes)
  248. // {
  249. // str += item.ToString() + ',';
  250. // }
  251. // str = str.TrimEnd(',');
  252. // sql += " and UserCode in ("+str+") ";
  253. //}
  254. //else
  255. // sql += " and UserCode='"+ua.F_UserCode+"' ";
  256. if (strcalltype.Trim() != "" && strcalltype != "undefined")
  257. {
  258. sql += " and CallType=" + strcalltype + " ";
  259. }
  260. if (strtel.Trim() != "" && strtel != "undefined")
  261. {
  262. sql += " and CallNumber= '" + strtel.Trim() + "' ";
  263. sqlcount += " and CallNumber= '" + strtel.Trim() + "' ";
  264. }
  265. //else
  266. //{
  267. // sql += " and 1=0 ";
  268. //}
  269. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  270. {
  271. sql += " and datediff(day,BeginTime,'" + strstarttime + "')<=0 ";
  272. sqlcount += " and datediff(day,BeginTime,'" + strstarttime + "')<=0 ";
  273. }
  274. if (strendtime.Trim() != "" && strendtime != "undefined")
  275. {
  276. sql += " and datediff(day,BeginTime,'" + strendtime + "')>=0 ";
  277. sqlcount += " and datediff(day,BeginTime,'" + strendtime + "')>=0 ";
  278. }
  279. if (strpageindex.Trim() != "")
  280. {
  281. pageindex = Convert.ToInt32(strpageindex);
  282. }
  283. if (strpagesize.Trim() != "")
  284. {
  285. pagesize = Convert.ToInt32(strpagesize);
  286. }
  287. int recordCount = 0;
  288. dt = BLL.PagerBLL.GetListPager(
  289. "T_Call_CallRecords",
  290. "CallRecordsId",
  291. "*",
  292. sql,
  293. "ORDER BY CallRecordsId desc",
  294. pagesize,
  295. pageindex,
  296. true,
  297. out recordCount);
  298. var config = new BLL.T_Sys_SystemConfig().GetModelList(" F_ParamCode='PlayPath' ").FirstOrDefault();
  299. foreach (DataRow dr in dt.Rows)
  300. {
  301. string path = dr["FilePath"] != null ? dr["FilePath"].ToString() : "";
  302. if (path != "" && config != null && !string.IsNullOrEmpty(config.F_ParamValue))
  303. {
  304. var ym = config.F_ParamValue;
  305. if (ym.Substring(ym.Length - 1) == "/")
  306. {
  307. ym = ym.Substring(0, ym.Length - 1);
  308. }
  309. dr["FilePath"] = ym + path.Substring(path.IndexOf(':') + 1).Replace('\\', '/');
  310. }
  311. }
  312. int hrcount = new BLL.T_Call_CallRecords().GetRecordCount(" calltype=0 " + sqlcount);
  313. int hccount = new BLL.T_Call_CallRecords().GetRecordCount(" calltype=1 " + sqlcount);
  314. var obj = new
  315. {
  316. state = "success",
  317. message = "成功",
  318. rows = dt,
  319. total = recordCount,
  320. hrcount = hrcount,
  321. hccount = hccount,
  322. };
  323. res = Content(obj.ToJson());
  324. }
  325. }
  326. }
  327. return res;
  328. }
  329. /// <summary>
  330. /// 获取最新知识库
  331. /// </summary>
  332. /// <returns></returns>
  333. public ActionResult GetZSKList()
  334. {
  335. ActionResult res = NoToken("未知错误,请重新登录");
  336. if (Request.IsAuthenticated)
  337. {
  338. DataTable dt = new DataTable();
  339. string pid = HttpUtility.UrlDecode(RequestString.GetQueryString("pid"));
  340. string keywords = HttpUtility.UrlDecode(RequestString.GetQueryString("keywords"));
  341. string sql = " F_DeleteFlag=0";
  342. if (pid.Trim() != "")
  343. {
  344. sql += " and F_CategoryId=" + pid.Trim();
  345. }
  346. if (keywords.Trim() != "")
  347. {
  348. sql += " and (F_Content like '%" + keywords.Trim() + "%' or F_Title like '%"
  349. + keywords.Trim() + "%' or F_KeyWords like '%" + keywords.Trim() + "%')";
  350. }
  351. dt = new BLL.T_RepositoryInformation().GetList(8, sql, " F_RepositoryId desc").Tables[0];
  352. res = Success("加载成功", dt);
  353. }
  354. return res;
  355. }
  356. /// <summary>
  357. /// 振铃事件
  358. /// </summary>
  359. /// <returns></returns>
  360. public ActionResult UpdateZL()
  361. {
  362. ActionResult res = NoToken("未知错误,请重新登录");
  363. if (Request.IsAuthenticated)
  364. {
  365. int userId = CurrentUser.UserData.F_UserId;
  366. if (userId != 0)
  367. {
  368. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  369. if (ua != null)
  370. {
  371. Model.T_Call_CallRecords model = new Model.T_Call_CallRecords();
  372. model.CallId = RequestString.GetFormString("callid");
  373. //model.UserId = ua.F_UserId;
  374. //model.UserCode = ua.F_UserCode;
  375. //model.UserName = ua.F_UserName;
  376. ////model.ExtNumber = ua.F_WorkNumber;
  377. //model.ExtNumber = CurrentUser.UserData.F_ExtensionNumber;
  378. model.DealType = 5;
  379. bool bl = new BLL.T_Call_CallRecords().UpdateCallInRingTelRecord(model);
  380. if (bl)
  381. {
  382. res = Success("更新振铃状态成功");
  383. }
  384. else
  385. {
  386. // res = Error("更新振铃状态失败");
  387. res = Success("更新振铃状态失败");
  388. }
  389. }
  390. }
  391. }
  392. return res;
  393. }
  394. /// <summary>
  395. /// 摘机事件
  396. /// </summary>
  397. /// <returns></returns>
  398. public ActionResult UpdateZJ()
  399. {
  400. ActionResult res = NoToken("未知错误,请重新登录");
  401. if (Request.IsAuthenticated)
  402. {
  403. Model.T_Call_CallRecords model = new Model.T_Call_CallRecords();
  404. model.CallId = RequestString.GetFormString("callid");
  405. model.CallState = 1;
  406. model.DealType = 6;
  407. bool bl = new BLL.T_Call_CallRecords().UpdateCallInAnswerTelRecord(model);
  408. if (bl)
  409. {
  410. Model.T_Call_CallRecords vmodel = new BLL.T_Call_CallRecords().GetModelByCallId(model.CallId);
  411. string type = vmodel.OperateType.ToString();
  412. if (type == "7")
  413. {
  414. new BLL.T_Call_TaskTelNum().UpdateYJ(Convert.ToInt32(vmodel.OperateObject.ToString()), 1);
  415. }
  416. res = Success("更新摘机状态成功");
  417. }
  418. else
  419. {
  420. //res = Error("更新摘机状态失败");
  421. res = Success("更新摘机状态失败");
  422. }
  423. }
  424. return res;
  425. }
  426. /// <summary>
  427. /// 挂机事件
  428. /// </summary>
  429. /// <returns></returns>
  430. public ActionResult UpdateGJ()
  431. {
  432. ActionResult res = NoToken("未知错误,请重新登录");
  433. if (Request.IsAuthenticated)
  434. {
  435. string strid = RequestString.GetFormString("callid");
  436. bool bl = new BLL.T_Call_CallRecords().UpdateCallInHookTelRecord(strid);
  437. if (bl)
  438. {
  439. res = Success("更新挂机状态成功");
  440. }
  441. else
  442. {
  443. res = Success("更新挂机状态失败");
  444. }
  445. }
  446. return res;
  447. }
  448. /// <summary>
  449. /// 录音事件
  450. /// </summary>
  451. /// <returns></returns>
  452. public ActionResult UpdateLY()
  453. {
  454. ActionResult res = NoToken("未知错误,请重新登录");
  455. if (Request.IsAuthenticated)
  456. {
  457. Model.T_Call_CallRecords model = new Model.T_Call_CallRecords();
  458. model.CallId = RequestString.GetFormString("callid");
  459. model.CallState = 1;
  460. model.DealType = 6;
  461. //model.FilePath = RequestString.GetFormString("path");
  462. bool bl = new BLL.T_Call_CallRecords().UpdateCallInPathTelRecord(model);
  463. if (bl)
  464. {
  465. Model.T_Call_CallRecords vmodel = new BLL.T_Call_CallRecords().GetModelByCallId(model.CallId);
  466. string type = vmodel.OperateType.ToString();
  467. if (type == "7")
  468. {
  469. new BLL.T_Call_TaskTelNum().UpdateYJ(Convert.ToInt32(vmodel.OperateObject.ToString()), 1);
  470. }
  471. res = Success("更新挂机状态成功");
  472. }
  473. else
  474. {
  475. res = Success("更新挂机状态失败");
  476. }
  477. }
  478. return res;
  479. }
  480. /// <summary>
  481. /// 创建工单
  482. /// </summary>
  483. /// <returns></returns>
  484. public ActionResult AddWorkOrder()
  485. {
  486. ActionResult res = NoToken("未知错误,请重新登录");
  487. if (Request.IsAuthenticated)
  488. {
  489. string usercode = CurrentUser.UserData.F_UserCode;
  490. int userId = CurrentUser.UserData.F_UserId;
  491. if (userId != 0)
  492. {
  493. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  494. if (ua != null)
  495. {
  496. //工单来源
  497. string source = RequestString.GetFormString("source");
  498. //工单类型
  499. int gdlx = RequestString.GetFormInt("gdlx", 0);
  500. //业务类型
  501. int ywlx = RequestString.GetFormInt("ywlx", 0);
  502. //客户id
  503. int customerid = RequestString.GetFormInt("customerid", 0);
  504. //客户姓名
  505. string callCustomer = RequestString.GetFormString("callCustomer");
  506. //公司名称
  507. string company = RequestString.GetFormString("company");
  508. //联系电话
  509. string tel = RequestString.GetFormString("tel");
  510. //受理人 - 审核人工号
  511. string auditusercode = RequestString.GetFormString("auditusercode");
  512. //接待描述 - 反馈内容
  513. string fkcont = RequestString.GetFormString("fkcont");
  514. string callid = HttpUtility.UrlDecode(RequestString.GetFormString("callid"));
  515. //是否有效工单项(0有效,1无效)
  516. int iseffective = RequestString.GetFormInt("iseffective", 0);
  517. //咨询类工单指派部门
  518. int clbm = RequestString.GetFormInt("clbm", 0);
  519. //咨询类工单指派接收人
  520. int clid = RequestString.GetFormInt("clid", 0);
  521. //备注
  522. string note = RequestString.GetFormString("note");
  523. //是否结束
  524. int isover = RequestString.GetFormInt("isover", 0);
  525. #region 添加验证判断
  526. if (string.IsNullOrEmpty(callCustomer))
  527. return Error("姓名不能为空!");
  528. if (string.IsNullOrEmpty(tel))
  529. return Error("电话不能为空!");
  530. if (clbm != 0 && clid == 0)
  531. return Error("请选择接收人");
  532. #endregion
  533. Model.T_Wo_WorkOrder model = new Model.T_Wo_WorkOrder();
  534. model.WorkOrderID = DateTime.Now.ToString("yyyyMMddHHmmssfff"); //工单编号
  535. model.Type = gdlx; //工单类型
  536. model.TypeClass = ywlx; //业务办理-数据字典读取
  537. model.Customer = callCustomer; //客户姓名
  538. model.CustomerTel = tel; //联系电话
  539. model.CustomerID = customerid; //用户档案Id
  540. model.County = company;//公司名称
  541. model.IsAudit = 1; //是否需要审核(0未审核,1已审核)pc端默认审核,微信端默认为审核
  542. model.IsEffective = iseffective;
  543. if (iseffective == 1)
  544. model.Province = System.Web.HttpUtility.UrlDecode(note, System.Text.Encoding.UTF8); //备注
  545. model.Source = source; //工单来源
  546. model.AuditUser = auditusercode; //受理人 - 审核人工号
  547. model.State = (int)EnumWorkOrderState.neworder;//0; //工单状态
  548. model.ResponDept = clbm;//指派部门
  549. #region 获取接收人
  550. string touser = ""; string tousername = "";
  551. if (clid != 0)
  552. {
  553. Model.T_Sys_UserAccount clus = new BLL.T_Sys_UserAccount().GetModel(clid);
  554. if (clus != null)
  555. {
  556. touser = clus.F_UserCode;
  557. tousername = clus.F_UserName + "(" + touser + ")";
  558. }
  559. }
  560. else
  561. {
  562. string users = string.Empty;
  563. var list = new BLL.T_Sys_UserAccount().GetModelList(" F_DeptId='" + clbm + "'");
  564. foreach (var l in list)
  565. {
  566. if (string.IsNullOrEmpty(users))
  567. {
  568. users = l.F_UserCode;
  569. tousername = l.F_UserName + "(" + l.F_UserCode + ")";
  570. }
  571. else
  572. {
  573. users = users + "," + l.F_UserCode;
  574. tousername = tousername + "," + l.F_UserName + "(" + l.F_UserCode + ")";
  575. }
  576. }
  577. touser = users;
  578. }
  579. #endregion
  580. model.F_IsOver = isover;
  581. if (isover == 1)
  582. {
  583. model.LastDealUser = usercode;
  584. model.LastDealTime = DateTime.Now;
  585. model.State = (int)EnumWorkOrderState.finish;//2;
  586. }
  587. else
  588. {
  589. //无接收人时,状态修改成 0待指派
  590. if (clid == 0)
  591. {
  592. model.State = (int)EnumWorkOrderState.neworder; //工单状态 待指派
  593. }
  594. else
  595. {
  596. model.AuditUser = touser;
  597. model.State = (int)EnumWorkOrderState.assign; //待处理
  598. }
  599. }
  600. //接待描述 - 反馈内容
  601. var detailutf8 = System.Web.HttpUtility.UrlDecode(fkcont, System.Text.Encoding.UTF8);
  602. model.Detail = detailutf8;
  603. model.CallID = callid; //存入callid
  604. model.CreateTime = DateTime.Now;
  605. model.IsDel = 0;
  606. model.IsReturn = 0;
  607. model.IsReturnBak = 0;
  608. model.Answer = "";
  609. model.CreateUser = usercode;
  610. long orderid = new BLL.T_Wo_WorkOrder().Add(model);
  611. if (orderid > 0)
  612. {
  613. #region 创建工单 处理记录
  614. var opt = "创建工单"; int optbut = (int)EnumItemOpt.create;
  615. string deptname = "";
  616. if (!string.IsNullOrWhiteSpace(touser))
  617. {
  618. #region 读取当前登录人部门
  619. var deptmodel = sysDeptBll.GetModel(ua.F_DeptId);
  620. if (deptmodel != null)
  621. {
  622. deptname = deptmodel.F_DeptName + "-";
  623. }
  624. #endregion
  625. opt = "创建并指派工单给"+ tousername;
  626. optbut = (int)EnumItemOpt.assign;
  627. }
  628. if (isover == 1)
  629. opt = "创建并处理完结工单"; optbut = (int)EnumItemOpt.end;
  630. var content = deptname + ua.F_UserName + "(" + ua.F_UserCode + ")" + opt;
  631. var itemid=new WorkOrderController().AddLog((int)orderid, model.State.Value, content, (int)EnumItemType.deal, optbut, touser, clbm, "", 0, "", "", ua);
  632. if (itemid > 0)
  633. {
  634. if (!string.IsNullOrWhiteSpace(touser))
  635. {
  636. model.ID = orderid;
  637. new WorkOrderController().sendsysmsg(model, ua, touser, (int)orderid, opt);//推送系统消息
  638. var modelUser2 = sysUserAccountBll.GetModel(touser); //被指派人
  639. if (modelUser2 != null)
  640. {
  641. if (!string.IsNullOrEmpty(modelUser2.F_WxOpenId))
  642. {
  643. new WorkOrderController().sendwxmsg(model, modelUser2.F_WxOpenId, ua, "指派");
  644. }
  645. }
  646. }
  647. }
  648. #region
  649. //if (isover == 0) {
  650. // if (clbm != 0 || clid != 0)
  651. // {
  652. // #region 工单记录
  653. // Model.T_Wo_WorkOrderItem item = new Model.T_Wo_WorkOrderItem();
  654. // item.ToUser = users;
  655. // item.WorkOrderID = model.WorkOrderID;
  656. // item.Type = (int)EnumItemType.deal;//1; //处理
  657. // item.ToDept = clbm; //部门
  658. // //item.ToUser = clus != null ? clus.F_UserCode : ""; //接收人
  659. // item.Detail = detailutf8;
  660. // item.IsDel = 0;
  661. // //转派
  662. // item.State = (int)EnumItemState.assign;//0
  663. // item.IsLast = 0;
  664. // item.IsStart = 0;
  665. // item.IsTimeOut = 0;
  666. // item.IsUsed = 0;
  667. // item.CreateUser = ua.F_UserCode;
  668. // item.CreateTime = DateTime.Now;
  669. // long itemid = new BLL.T_Wo_WorkOrderItem().Add(item);
  670. // #endregion
  671. // if (itemid > 0)
  672. // {
  673. // string strmsg = string.Empty;
  674. // strmsg = ua.F_UserName + "创建转派了工单,单号:" + model.WorkOrderID;
  675. // #region 消息表
  676. // Model.T_Msg_List msg = new Model.T_Msg_List();
  677. // msg.Type = (int)Model.MSGType.workorder;//处理
  678. // msg.ToUser = ua.F_UserCode;
  679. // msg.ToID = Int32.Parse(itemid.ToString());
  680. // msg.Detail = strmsg;
  681. // msg.State = 0;
  682. // msg.IsDel = 0;
  683. // msg.CreateUser = ua.F_UserCode;
  684. // msg.CreateDate = DateTime.Now;
  685. // new BLL.T_Msg_List().Add(msg);
  686. // #endregion
  687. // #region 派单后发送微信推送
  688. // if (model.State == (int)EnumWorkOrderState.assign)
  689. // {//已派单状态
  690. // var modelUser2 = sysUserAccountBll.GetModel(clid); //被指派人
  691. // if (modelUser2 != null)
  692. // {
  693. // if (!string.IsNullOrEmpty(modelUser2.F_WxOpenId))
  694. // {
  695. // var dicv = dicvalueBll.GetModel(model.TypeClass.Value);
  696. // string content = string.Empty;
  697. // var wotype = "";
  698. // if (dicv != null)
  699. // {
  700. // wotype = dicv.F_Name;
  701. // }
  702. // content = "客户" + model.Customer + "提出的工单已派单,请及时处理";
  703. // WxHelper.SendWechatMsg1(model.WorkOrderID, "你有新的工单需要处理", wotype,model.State.ToString(), content, orderid.ToString(), modelUser2.F_WxOpenId);
  704. // }
  705. // }
  706. // }
  707. // #endregion
  708. // res = Success("处理成功");
  709. // }
  710. // }
  711. //}
  712. #endregion
  713. #endregion
  714. #region 通话记录绑定工单
  715. if (!string.IsNullOrEmpty(callid))
  716. {
  717. var rec = new BLL.T_Call_CallRecords().GetModelByCallId(callid);
  718. if (rec != null)
  719. {
  720. rec.IsExitWorkOrder = true;
  721. new BLL.T_Call_CallRecords().Update(rec);
  722. }
  723. }
  724. #endregion
  725. res = Success("新增成功!");
  726. }
  727. else
  728. {
  729. res = Error("新增失败!");
  730. }
  731. }
  732. }
  733. }
  734. return res;
  735. }
  736. /// <summary>
  737. /// 获取受理人下拉 by 部门,区域,项目、期,案场经理
  738. /// </summary>
  739. /// <param name="depid">部门id</param>
  740. /// <param name="arearid">区域id</param>
  741. /// <param name="proid">项目id</param>
  742. /// <returns></returns>
  743. public ActionResult GetUserListByBuildingidDrop(int depid = 0, int arearid = 0, int proid = 0)
  744. {
  745. //查询条件是根据:受理人(销售类直接根据项目名称、房间号关联下拉点选各案场经理;物业类直接根据项目名称、房间号关联下拉框点选各物业负责人;客服类直接根据项目名称、房间号关联下拉框点选各区域客服)
  746. string sql = " F_DeleteFlag = 0 ";
  747. bool isExists = false;
  748. //SELECT TOP 1 F_DeptId FROM dbo.T_Sys_Department 这个地方排序有要求,部门排序要求
  749. int depRegion = 0;
  750. if (depid == 0)
  751. return Error("请选择接收部门");
  752. if (depid > 0)
  753. {
  754. ////部门信息
  755. //var modelDep = new BLL.T_Sys_Department().GetModel(depid);
  756. //if (modelDep != null)
  757. //{
  758. // depType = modelDep.F_Type ?? 0; //部门操作权限:1接待部,2办理人员,3区域客服,4监管
  759. // depRegion = modelDep.F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
  760. //}
  761. //通过一级栏目查到一级栏目中的第一条部门信息
  762. var list = new BLL.T_Sys_Department().DataTableToList(new BLL.T_Sys_Department().GetList($" F_ParentId = {depid} ").Tables[0]);
  763. var modelDep = list.FirstOrDefault();
  764. //部门信息
  765. //modelDep = new BLL.T_Sys_Department().GetModel(deptid);
  766. if (modelDep != null)
  767. {
  768. depRegion = modelDep.F_Header ?? 0; //部门权限范围:9全部,1区域,2项目,3期
  769. //deptids = modelDep.F_DeptId;
  770. }
  771. sql += $" and F_DeptId = (SELECT TOP 1 F_DeptId FROM dbo.T_Sys_Department WHERE F_ParentId = {depid} ORDER BY F_Sort ASC) ";
  772. //sql += $" and (F_DeptId = (SELECT TOP 1 F_DeptId FROM dbo.T_Sys_Department WHERE F_ParentId = {depid} ORDER BY F_Sort ASC) or F_DeptId = {depid}) ";
  773. }
  774. if (depRegion == 1)
  775. {
  776. //if (arearid == 0)
  777. // return Error("请选择区域下拉");
  778. if (arearid > 0)
  779. {
  780. isExists = true;
  781. sql += $" AND RegionId = {arearid} ";
  782. }
  783. }
  784. else
  785. {
  786. //if (proid == 0)
  787. // return Error("请选择项目下拉");
  788. if (proid > 0)
  789. {
  790. isExists = true;
  791. sql += $" AND RegionId = {proid} ";
  792. }
  793. }
  794. if (isExists)
  795. {
  796. var listUser = sysUserAccountBll.GetModelList(sql + " order by f_userid desc ");
  797. var rows = listUser.Select(x => new
  798. {
  799. F_UserId = x.F_UserId,
  800. F_UserCode = x.F_UserCode,
  801. F_ExtensionNumber = x.F_ExtensionNumber,
  802. F_UserName = x.F_UserName,
  803. F_DeptId = x.F_DeptId,
  804. F_RoleId = x.F_RoleId,
  805. F_SeatFlag = x.F_SeatFlag
  806. });
  807. return Success("列表加载成功", listUser);
  808. }
  809. else
  810. {
  811. return Success("列表加载成功", null);
  812. }
  813. }
  814. /// <summary>
  815. /// 获取当前坐席所在部门及坐席组
  816. /// </summary>
  817. /// <returns></returns>
  818. public ActionResult GetCurrUserDep()
  819. {
  820. ActionResult res = NoToken("未知错误,请重新登录");
  821. if (Request.IsAuthenticated)
  822. {
  823. int? groid = CurrentUser.UserData.F_SeartGroupID;
  824. //string groname = CurrentUser.UserData.F_SeartGroup;
  825. string groname = "", grocode = "";
  826. string depname = "";
  827. int depid = CurrentUser.UserData.F_DeptId;
  828. if (depid != 0)
  829. {
  830. Model.T_Sys_Department depModel = new BLL.T_Sys_Department().GetModel(depid);
  831. if (depModel != null)
  832. {
  833. depname = depModel.F_DeptName;
  834. Model.T_Sys_SeatGroup groModel = new BLL.T_Sys_SeatGroup().GetModel(groid == null ? 0 : int.Parse(groid.ToString()));
  835. if (groModel != null)
  836. {
  837. groname = groModel.F_ZXZName;
  838. grocode = groModel.F_ZXZCode;
  839. }
  840. }
  841. }
  842. var obj = new
  843. {
  844. depid = depid,
  845. depname = depname,
  846. groid = groid,
  847. groname = groname,
  848. grocode = grocode
  849. };
  850. res = Success("获取坐席部门成功!", obj);
  851. }
  852. return res;
  853. }
  854. /// <summary>
  855. /// 获取所有坐席
  856. /// </summary>
  857. /// <returns></returns>
  858. public ActionResult GetUsers()
  859. {
  860. ActionResult res = NoToken("未知错误,请重新登录");
  861. if (Request.IsAuthenticated)
  862. {
  863. List<Model.T_Sys_UserAccount> userModel = new BLL.T_Sys_UserAccount().GetModelList("F_DeleteFlag=0");
  864. var list = userModel.Select(p => new { p.F_UserId, p.F_UserCode, p.F_UserName });
  865. var obj = new
  866. {
  867. user = list
  868. };
  869. res = Success("获取坐席成功!", obj);
  870. }
  871. return res;
  872. }
  873. }
  874. }