Нет описания

CallInScreenController.cs 42KB

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