ES_UsageMemberController.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using Common.Model;
  11. using CoreEntity.DAL;
  12. using CoreEntity.Entity;
  13. using CoreEntity.ESEntity;
  14. using JCSoft.WX.Framework.Api;
  15. using MemberWeb.Commonss;
  16. using Microsoft.AspNetCore.Mvc;
  17. using Microsoft.Extensions.Caching.Memory;
  18. using Newtonsoft.Json;
  19. using Newtonsoft.Json.Converters;
  20. using Newtonsoft.Json.Linq;
  21. using PublicLibrary.Model;
  22. using SupplierWeb.Commonss;
  23. using ZcPeng.PublicLibrary;
  24. namespace SupplierWeb.Controllers
  25. {
  26. [Route("web/ES_UsageMem")]
  27. public class ES_UsageMemberController : BaseController
  28. {
  29. public ES_UsageMemberController(IMemoryCache cache, IApiClient client) : base(cache, client)
  30. {
  31. }
  32. public IActionResult Index()
  33. {
  34. return View();
  35. }
  36. /// <summary>
  37. /// 用户用药列表
  38. /// </summary>
  39. /// <param name="data"></param>
  40. /// <param name="filters"></param>
  41. /// <returns></returns>
  42. [HttpPost]
  43. [Route("usedrug")]
  44. public ActionResult usedrug(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,string [] tagArr,
  45. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  46. {
  47. int OutDays = 5;
  48. if (data != null)
  49. {
  50. filters = data.filters.ToObject<QueryFilter[]>();
  51. pageIndex = data.pageIndex;
  52. pageSize = data.pageSize;
  53. sortField = data.sortField;
  54. sortDirection = data.sortDirection;
  55. sumFields = data.sumFields.ToObject<string[]>();
  56. }
  57. #region 获取列表
  58. DataTable dt = new DataTable();
  59. string result;
  60. List<SqlParameter> parameters = new List<SqlParameter>();
  61. string source = "";//平台
  62. string tagstr = "";//标签
  63. string commandText="";
  64. string chaheKey = "";//查询的缓存key
  65. long totalcount = 0;
  66. Random rand = new Random();
  67. if (filters != null && filters.Length > 0)
  68. {
  69. //if (filters != null && filters.Length > 0 && filters[0].field.Equals("tagKey")) {
  70. string keyTag = null;
  71. foreach (var filter in filters)
  72. {
  73. if (filter.field == "OutDays" && filter.value != null && filter.value != "")
  74. {
  75. OutDays = Convert.ToInt32(filter.value.ToString());
  76. }
  77. if (filter.field == "tagKey" && filter.value != null && filter.value != "")
  78. {
  79. keyTag = filter.value;
  80. }
  81. }
  82. if (keyTag!=null) {
  83. var keyArr = keyTag.Split("_");//0标签1平台2终端
  84. if (keyArr.Length > 0)
  85. {
  86. chaheKey = keyTag;
  87. var key0 = keyArr[0].Split(",");
  88. if (!key0[0].Equals("0")&& key0[0].Length>0)
  89. {
  90. //获取标签会员号码
  91. List<mem_MemberTag> _sourceTag = TagIDList(keyArr[0]);
  92. /*
  93. string result3;
  94. //创建临时表
  95. foreach (mem_MemberTag memtag in _sourceTag)
  96. {
  97. commandText = commandText + "'"+ ES_DataStaisController.getPhoneEncDesrypt(memtag.MemberPhone)+"',";
  98. }
  99. if (commandText != ""&& commandText.Length>0) {
  100. tagstr = " and s.AConsigneePhone2 IN("+ commandText.Substring(0,commandText.Length-1) + ") ";
  101. }*/
  102. foreach (string memtag in key0)
  103. {
  104. commandText = commandText + "'" + memtag + "',";
  105. }
  106. if (commandText != "" && commandText.Length > 0)
  107. {
  108. tagstr = " AND t.tagId IN(" + commandText.Substring(0, commandText.Length - 1) + ") ";
  109. }
  110. }
  111. if (keyArr.Length > 1 && keyArr[1] != null)
  112. {
  113. var key1 = keyArr[1].Split(",");
  114. if (!key1[0].Equals("0"))
  115. {
  116. source = source + " AND s.ConsigneeType IN("+ keyArr[1] + ") ";
  117. }
  118. }
  119. if (keyArr.Length > 2 && keyArr[2]!=null)
  120. {
  121. var key2 = keyArr[2].Split(",");
  122. if (!key2[0].Equals("0"))
  123. {
  124. source = source + " AND s.OriginType IN(" + keyArr[2]+ ") ";
  125. }
  126. }
  127. }
  128. }
  129. }
  130. string direct = " asc ";
  131. if (sortDirection != 1)
  132. {
  133. direct = " desc ";
  134. }
  135. string orderStr = " MinDates asc,DomeCount desc ";
  136. if (sortField.Equals("MemPhone")||sortField.Equals("UseCount")||sortField.Equals("DomeCount")||sortField.Equals("EndTime")) {
  137. orderStr = sortField + direct;
  138. }
  139. int start = (pageIndex - 1) * pageSize;
  140. int end = (start + 1 + pageSize);
  141. //有选择标签,ES查询标签会员
  142. if (tagArr!=null&& tagArr.Length>0) {
  143. }
  144. string staTime1 = DateTime.Now.AddDays(-60).ToString("yyyy-MM-dd HH:mm:ss");
  145. totalcount = rand.Next(9000, 10000);
  146. //获取会员订,有使用量,未被忽略商品
  147. IList<Mem_UserDrug> permss = new List<Mem_UserDrug>(0);
  148. IList<Mem_UserDrugv2> permssa = RedisUtil.getRedisUtils("0_"+start + "_" + end + chaheKey + orderStr);//获取缓存数据
  149. if (permssa != null && permssa.Count > 0)
  150. {
  151. foreach (Mem_UserDrugv2 mu in permssa)
  152. {
  153. Mem_UserDrug mug = new Mem_UserDrug();
  154. mug.MemPhone= mu.MemPhone;
  155. mug.DomeCount=Convert.ToString(mu.DomeCount);
  156. mug.EndTime = DateTime.ParseExact(mu.EndTime.Replace("T"," "), "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture); ;
  157. mug.UseCount = mu.UseCount;
  158. permss.Add(mug);
  159. }
  160. }
  161. else
  162. {//缓存中没有数据
  163. /*
  164. string commandText1s = "select (SELECT dbo.DesDecryptFixKey('123456','123456e10adc3949ba59abbe56e057f20f883e',A.AConsigneePhone2)) AS MemPhone,A.CreationDate, " +
  165. " sum(CASE WHEN((u.UsageDays*s.Amount) - DATEDIFF(day, s.CreationDate, CONVERT(varchar, GETDATE(), 23))) <= 5 THEN 1 ELSE 0 END) AS DomeCount " +
  166. " FROM mall..Orders A left join mall..OrderProducts s on s.OrdersCode = A.OrdersCode and s.CreationDate > '" + staTime1 + "' " +
  167. " and A.CreationDate > '" + staTime1 + "' LEFT JOIN mall..ProductUsage u ON u.ProductCode = s.ProductCode " +
  168. " and s.CreationDate > '" + staTime1 + "' AND u.UsageDays!='' " + tagstr +
  169. " LEFT JOIN MemberStopDrugMsg d ON d.MemPhone=A.AConsigneePhone2 AND d.ProductCode=u.ProductCode " +
  170. " where 1=1 " +
  171. " and A.AConsigneePhone2!='' and A.CreationDate>'" + staTime1 + "' and s.CreationDate>'" + staTime1 + "' and u.ID!='' and u.ID is not null " +
  172. source +
  173. " GROUP BY A.AConsigneePhone2 ,A.CreationDate,d.MemPhone ";
  174. commandText1s = commandText1s + " ORDER BY " + orderStr;
  175. string commandText2s = " OFFSET " + start + " ROWS FETCH NEXT 15 ROWS ONLY ";
  176. string commandText3s = commandText + commandText1s + commandText2s;
  177. bool success = DataAccess.GetValuesV2(commandText3s, ref dt, parameters.ToArray(), out result);
  178. */
  179. string sql = " sum(CASE WHEN(minus(multiply(toInt8(u.UsageDays),toInt8(s.Amount)),minus(today(),toDate(s.OrderTime)))) <= "+ OutDays + " THEN 1 ELSE 0 END) as DomeCount," +
  180. "sum(CASE WHEN(minus(multiply(toInt8(u.UsageDays),toInt8(s.Amount)),minus(today(),toDate(s.OrderTime)))) >0 THEN 1 ELSE 0 END) as UseCount, " +
  181. "min(minus(multiply(toInt8(u.UsageDays),toInt8(s.Amount)),minus(today(),toDate(s.OrderTime)))) as MinDates," +
  182. "min(toDateTime(plus(multiply(toInt8(u.UsageDays),toInt8(s.Amount))*24*3600,toUnixTimestamp(s.OrderTime)))) as EndTime," +
  183. "toDate(plus(toUnixTimestamp(now()),MinDates*24*3600)) as EndDay," +
  184. "" + OutDays + " as OutDays," +
  185. "s.AConsigneePhone2 AS MemPhone ";
  186. string commandText1 = "SELECT " + sql+
  187. " FROM `default`.OrdersAndOrderProducts s " +
  188. "global LEFT JOIN (select ProductCode,min(UsageDays)as UsageDays from ProductUsage group by ProductCode) u ON u.ProductCode = s.ProductCode " +
  189. "global LEFT JOIN (select MemberPhone,tagId,id,MAX(create_date) FROM memberTagV2 m " +
  190. "global LEFT JOIN (SELECT id,create_date FROM memberTagV2 WHERE tagId='0' GROUP BY id,MemberPhone,tagId,create_date)c ON c.id=m.MemberPhone " +
  191. "WHERE m.create_date>c.create_date GROUP BY m.id,m.MemberPhone,m.tagId) t ON t.MemberPhone=s.AConsigneePhone2 " +
  192. "where u.UsageDays != '' AND s.AConsigneePhone2 != '' " +
  193. " AND s.OrderTime > '"+ staTime1 + "' " + source+ tagstr;
  194. commandText1 = commandText1 + " GROUP BY MemPhone,s.OrderTime HAVING DomeCount>0 and MinDates>=1 " +
  195. " ORDER BY " + orderStr;
  196. string commandText2 = " LIMIT "+ start + ",20 ";
  197. string commandText3 = commandText1 + commandText2+ " FORMAT JSON ";
  198. var dugObj =ClickHouseUtil.HttpClickHouseGet(commandText3);
  199. var obj = (JObject)JsonConvert.DeserializeObject(dugObj);
  200. permss = JsonConvert.DeserializeObject<List<Mem_UserDrug>>(JsonConvert.SerializeObject(obj.GetValue("data")));
  201. #endregion
  202. if (dt != null)
  203. {
  204. // 把DataTable转换为IList<T>
  205. //permss = ModelConvertHelper<Mem_UserDrug>.ConvertToModel(dt);
  206. RedisUtil.addRedisUtils(permss, "0_" + start + "_" + end + chaheKey + orderStr);//保存
  207. commandText1 = "SELECT count(1) cn FROM ("+ commandText1 + ")";
  208. commandText1=ClickHouseUtil.HttpClickHouseGet(commandText1);
  209. totalcount = Convert.ToInt64(commandText1);
  210. }
  211. }
  212. string result1;
  213. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  214. {
  215. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  216. };
  217. staTime1 = DateTime.Now.AddDays(-61).ToString("yyyy-MM-dd HH:mm:ss");
  218. //计算会员用药数据
  219. foreach (Mem_UserDrug m in permss)
  220. {
  221. DataTable dt1 = new DataTable();
  222. if (m.MemPhone != null && m.MemPhone != "") {
  223. //m.MemPhone = "";
  224. IList<Mem_UserDrugGoods> permss1 = new List<Mem_UserDrugGoods>(0);
  225. string sqlcount = "SELECT o.OrderStatus," +
  226. "p1.ProductCode,p1.ProductName,p1.Dosage,(select dbo.DesDecryptFixKey('123456','123456e10adc3949ba59abbe56e057f20f883e',o.AConsigneePhone2)) as AConsigneePhone2,o.Consignee,CONVERT(varchar(100), p.CreationDate, 23) AS CrDate,B.CreationDate AS GoDate,p1.packing,(ISNULL(u.UsageDays*p.Amount,0)) AS EndCount FROM Orders o " +
  227. " LEFT JOIN OrderProducts p ON o.OrdersCode= p.OrdersCode " +
  228. " LEFT JOIN Product p1 ON p1.ProductCode=p.ProductCode " +
  229. " LEFT JOIN ProductUsageData u ON u.ProductCode=p1.ProductCode " +
  230. " LEFT JOIN MemberStopDrugMsg B ON B.MemPhone=o.AConsigneePhone2 " +
  231. " WHERE NOT (o.AConsigneePhone2 IN(SELECT B.MemPhone FROM MemberStopDrugMsg B ) AND p1.ProductCode IN(SELECT B.ProductCode FROM MemberStopDrugMsg B )) AND o.CreationDate > '"+ staTime1 + "' " +
  232. " AND p1.ProductCode!='' AND o.AConsigneePhone2='" + m.MemPhone + "' " +
  233. " GROUP BY " +
  234. "o.OrderStatus," + "p1.ProductCode,o.Consignee,CONVERT(varchar(100), p.CreationDate, 23),B.CreationDate,p1.ProductName,p1.Dosage,p.Amount,u.UsageFrequencyCount,u.UsageDays,u.UsagePerUseCount,p1.packing,o.AConsigneePhone2 ORDER BY B.CreationDate ";
  235. DataAccess.GetValuesV2(sqlcount, ref dt1, parameters.ToArray(), out result);
  236. if (dt1 != null && dt1.Rows.Count > 0)
  237. {
  238. // 把DataTable转换为IList<T>
  239. permss1 = ModelConvertHelper<Mem_UserDrugGoods>.ConvertToModel(dt1);
  240. m.UpTime = permss1[0].GoDate;
  241. m.MemName = permss1[0].Consignee;
  242. int totla1 = 0;
  243. int totla2 = 0;
  244. string MemPhone = "";
  245. foreach (Mem_UserDrugGoods u in permss1)
  246. {
  247. if (u.EndCount!=null) {
  248. DateTime startTime = Convert.ToDateTime(u.CrDate);//购买时间
  249. DateTime endTime = Convert.ToDateTime(DateTime.Now.ToLocalTime().ToString());//当前时间
  250. TimeSpan ts = endTime - startTime;//使用天数
  251. int? tocount = u.EndCount - ts.Days;
  252. if (tocount > 0)
  253. {//正在用药
  254. totla1 = totla1 + 1;
  255. if (tocount <= 5)
  256. {//快用完数
  257. totla2 = totla2 + 1;
  258. //m.EndTime = startTime.AddDays(Convert.ToDouble(u.EndCount));
  259. }
  260. //if (m.EndTime!=null && (Convert.ToDateTime(m.EndTime)- endTime).Days>0 && (Convert.ToDateTime(m.EndTime) - endTime).Days <= 5) { } else
  261. //{
  262. // m.EndTime = startTime.AddDays(Convert.ToDouble(u.EndCount));
  263. //}
  264. }
  265. else
  266. {
  267. totla2 = totla2 + 1;
  268. //m.EndTime = u.CrDate;
  269. }
  270. if (tocount<0) {
  271. tocount = 0;
  272. }
  273. u.EndCount = tocount;
  274. }
  275. if (MemPhone=="" || MemPhone.Length<=0) {
  276. MemPhone = m.MemPhone;
  277. }
  278. m.MemPhone = u.AConsigneePhone2.Substring(0, 3) + "****" + u.AConsigneePhone2.Substring(u.AConsigneePhone2.Length - 4, 4);
  279. u.AConsigneePhone2 = MemPhone;
  280. }
  281. //m.UseCount = totla1;
  282. m.Mem_Goods = permss1;
  283. }
  284. }
  285. }
  286. var jsonData = JsonConvert.SerializeObject(permss, timejson);
  287. return Json(new
  288. {
  289. items = JsonConvert.DeserializeObject(jsonData),
  290. sum = new { },
  291. totalCount = totalcount
  292. });
  293. }
  294. /// <summary>
  295. /// 获取终端平台列表
  296. /// </summary>
  297. /// <param name="filters"></param>
  298. /// <param name="data"></param>
  299. /// <returns></returns>
  300. [HttpPost]
  301. [Route("getTermain")]
  302. public ActionResult getTermain([FromBody]dynamic data, QueryFilter[] filters)
  303. {
  304. #region 获取列表
  305. DataTable dt = new DataTable();
  306. DataTable dt1 = new DataTable();
  307. string result;
  308. IList<Mem_Terminaldoc> permss = new List<Mem_Terminaldoc>(0);
  309. IList<Mem_Terminaldoc> permss1 = new List<Mem_Terminaldoc>(0);
  310. List<SqlParameter> parameters = new List<SqlParameter>();
  311. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Mem_Terminaldoc(), "A.");
  312. //终端
  313. string commandText3 = " SELECT d.Text AS TerminalDesc, d.Value AS ParentTerminalKey FROM Mall..DataDictory d WHERE d.ParentId IN (785,786) AND d.IsHide=0 ";
  314. bool success = DataAccess.GetValues(commandText3, ref dt, parameters.ToArray(), out result);
  315. #endregion
  316. if (dt != null && dt.Rows.Count > 0)
  317. {
  318. // 把DataTable转换为IList<T>
  319. permss = ModelConvertHelper<Mem_Terminaldoc>.ConvertToModel(dt);
  320. }
  321. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  322. {
  323. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  324. };
  325. var jsonData = JsonConvert.SerializeObject(permss, timejson);
  326. //平台
  327. commandText3 = " SELECT d.Text AS TerminalDesc, d.Value AS ParentTerminalKey FROM Mall..DataDictory d WHERE d.ParentId IN (783) AND d.IsHide=0 ";
  328. success = DataAccess.GetValues(commandText3, ref dt1, parameters.ToArray(), out result);
  329. if (dt1 != null && dt1.Rows.Count > 0)
  330. {
  331. // 把DataTable转换为IList<T>
  332. permss1 = ModelConvertHelper<Mem_Terminaldoc>.ConvertToModel(dt1);
  333. }
  334. var jsonData1 = JsonConvert.SerializeObject(permss1, timejson);
  335. return Json(new
  336. {
  337. items = JsonConvert.DeserializeObject(jsonData),
  338. items1 = JsonConvert.DeserializeObject(jsonData1),
  339. sum = new { }
  340. });
  341. }
  342. [HttpPost]
  343. [Route("upDurGood")]
  344. public JsonResult upDurGood(String ProductCode, String MemPhone, [FromBody]dynamic data)
  345. {
  346. if (data != null)
  347. {
  348. ProductCode = data.ProductCode;
  349. MemPhone = data.MemPhone;
  350. }
  351. string date=DateTime.Now.ToString();
  352. #region 添加
  353. string commandText = "INSERT INTO MemberStopDrugMsg(ProductCode,MemPhone,CreationDate)VALUES (@ProductCode,@MemPhone,@CreationDate)";
  354. string result;
  355. //准备参数
  356. List<List<Object>> parameters = new List<List<Object>>();
  357. parameters.Add(new List<Object>() { "ProductCode", ProductCode });
  358. parameters.Add(new List<Object>() { "MemPhone", MemPhone });
  359. parameters.Add(new List<Object>() { "CreationDate", date });
  360. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  361. int success = DataAccess.ExecuteCommandv2(commandText, parameters1, out result);
  362. #endregion
  363. return Json(new
  364. {
  365. success = success
  366. });
  367. }
  368. public static List<mem_MemberTag> TagIDList(string tagId)
  369. {
  370. Object query = null;
  371. string MemPhone = "";
  372. List<mem_MemberTag> _sourceTag = new List<mem_MemberTag>();
  373. if (tagId != null && tagId.Length>0)
  374. {
  375. #region 会员tag
  376. query = new { query = "select MemberPhone from mem_membertag where TagId in(" + tagId + ")" };
  377. //将参数转换成JSON数据
  378. var jsonTag = JsonConvert.SerializeObject(query);
  379. //通过传来的SQL语句,转换成DSL语句
  380. string sqlTag = Util.ElasticQuery("_xpack/sql/translate?format=json", "POST", jsonTag);
  381. //通过转换的DSL语句,获取数据
  382. var strTag = Util.ElasticQuery("mem_membertag/_search?format=json", "POST", sqlTag);
  383. //JSON转Root对象
  384. Root<mem_MemberTag> stobjTag = EsCommon.FromJSON<Root<mem_MemberTag>>(strTag);
  385. //给_source额外的属性赋值
  386. stobjTag.hits.hits.ForEach(x =>
  387. {
  388. x._source._id = x._id;
  389. });
  390. //将Root对象中的子对象取出来
  391. _sourceTag = stobjTag.hits.hits.Select(x => x.entity()).ToList();
  392. #endregion
  393. }
  394. return _sourceTag;
  395. }
  396. //获取用户分机号
  397. [HttpGet, Route("getUsreTel")]
  398. public JsonResult getUsreTel(string accountId, string staffId)
  399. {
  400. string userid = getStaff(staffId, "userid");
  401. //判断参数是否合法
  402. if (string.IsNullOrEmpty(userid))
  403. {
  404. return Json(new
  405. {
  406. timeout = 1,
  407. msg = "没有登陆"
  408. });
  409. }
  410. var dt = new DataTable();
  411. if (accountId != null)
  412. {
  413. var param = new List<SqlParameter>();
  414. string sql = "SELECT top 1 UserTel FROM mem_Account_Tel WHERE IsDelete='1' AND UserId='" + accountId + "' ";
  415. DataAccess.GetValues(sql, ref dt, param.ToArray(), out var msg);
  416. }
  417. return Json(new
  418. {
  419. tel = dt
  420. });
  421. }
  422. //保存用户分机号
  423. [HttpPost, Route("addUsreTel")]
  424. public JsonResult addUsreTel(string content, string UserTel, string UserId, string staffId, string code, [FromBody]dynamic data)
  425. {
  426. string accountId = getStaff(staffId, "userid");
  427. //判断参数是否合法
  428. if (string.IsNullOrEmpty(accountId))
  429. {
  430. return Json(new
  431. {
  432. timeout = false,
  433. msg = "没有登陆"
  434. });
  435. }
  436. if (data != null)
  437. {
  438. UserTel = data.userTel;
  439. UserId = data.userId;
  440. code = data.code;
  441. content = data.content;
  442. }
  443. int success = 0;
  444. string msg = "";
  445. if (code == "1")
  446. {
  447. //添加
  448. var sql = "INSERT INTO mem_Account_Tel (AccountId,Content,UserTel,UserId,CreateDate)VALUES(@AccountId,@Content,@UserTel,@UserId,@CreateDate)";
  449. var param = new List<SqlParameter>();
  450. param.Add(new SqlParameter("AccountId", accountId));
  451. param.Add(new SqlParameter("Content", content));
  452. param.Add(new SqlParameter("UserTel", UserTel));
  453. param.Add(new SqlParameter("UserId", UserId));
  454. param.Add(new SqlParameter("CreateDate", DateTime.Now));
  455. success = DataAccess.ExecuteCommand(sql, param, out msg);
  456. }
  457. else
  458. {
  459. string sql = "UPDATE mem_Account_Tel SET UserTel=@UserTel,Content=@Content WHERE UserId = @UserId";
  460. //准备参数
  461. List<List<Object>> parametersC = new List<List<Object>>();
  462. parametersC.Add(new List<Object>() { "UserTel", UserTel });
  463. parametersC.Add(new List<Object>() { "Content", content });
  464. parametersC.Add(new List<Object>() { "UserId", UserId });
  465. List<SqlParameter> parametersC1 = DataAccess.ToParameters(parametersC);
  466. success = DataAccess.ExecuteCommand(sql, parametersC1, out msg);
  467. }
  468. return Json(new
  469. {
  470. success = success,
  471. msg = msg
  472. });
  473. }
  474. [HttpPost, Route("usreTel")]
  475. public JsonResult usreTel(string userPhone, string staffId, string accountTel, [FromBody]dynamic data)
  476. {
  477. string userid = getStaff(staffId, "userid");
  478. string success = "";
  479. //判断参数是否合法
  480. if (string.IsNullOrEmpty(userid))
  481. {
  482. return Json(new
  483. {
  484. msg = "没有登陆"
  485. });
  486. }
  487. if (data != null)
  488. {
  489. string url = "http://119.130.113.244:8001/admin/?m=interface&c=api&a=dial&extension=ACCOUNTTEL&extensionDst=USERPHONE";
  490. userPhone = data.userPhone;
  491. accountTel = data.accountTel;
  492. if (userPhone != null && accountTel != null)
  493. {
  494. //获取用户手机号
  495. userPhone = ES_DataStaisController.getPhoneDesEncrypt(userPhone);
  496. if (userPhone != "" && userPhone.Length > 0)
  497. {
  498. string getUrl = "http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel=" + userPhone;//号码归属地,加拨0
  499. string phoneStr = userTelDialPhone(getUrl);
  500. if (!phoneStr.Contains("广州"))
  501. {
  502. userPhone = "0" + userPhone;
  503. }
  504. url = url.Replace("ACCOUNTTEL", accountTel).Replace("USERPHONE", userPhone);
  505. //拨号
  506. success = userTelDialPhone(url);
  507. }
  508. }
  509. }
  510. return Json(new
  511. {
  512. success = success
  513. });
  514. }
  515. public string userTelDialPhone(string url)
  516. {
  517. WebRequest myWebRequest = WebRequest.Create(url);
  518. WebResponse myWebResponse = myWebRequest.GetResponse();
  519. myWebRequest.Timeout = 60000;
  520. Stream ReceiveStream = myWebResponse.GetResponseStream();
  521. string responseStr = "";
  522. if (ReceiveStream != null)
  523. {
  524. StreamReader reader = new StreamReader(ReceiveStream, Encoding.UTF8);
  525. responseStr = reader.ReadToEnd();
  526. reader.Close();
  527. }
  528. myWebResponse.Close();
  529. return responseStr;
  530. }
  531. }
  532. }