sync.xiu.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. using BizCom;
  2. using BizCom.Enum;
  3. using SiteCore.Redis;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using Utils;
  14. namespace SiteCore.Handler
  15. {
  16. public partial class sync
  17. {
  18. public void distribute_xiumaster()
  19. {
  20. if(UrlPostParmsCheck("fid,uname,upwd"))
  21. {
  22. int fid = GetPostInt("fid");
  23. string uname = GetPostString("uname");
  24. string upwd = GetPostString("upwd");
  25. SXiuMaster entity = SXiuMaster.Get(fid);
  26. if(entity!=null)
  27. {
  28. if (entity.UserID>0)
  29. {
  30. }
  31. else
  32. {
  33. SXiuUser userEntity = new SXiuUser();
  34. userEntity.lgName = uname;
  35. userEntity.lgPwd = SecurityHelper.EncryptSymmetric(upwd);
  36. userEntity.State = 2;
  37. userEntity.Create();
  38. entity.UserID = userEntity.ID;
  39. entity.Update();
  40. }
  41. }
  42. returnSuccessMsg("操作成功");
  43. }
  44. }
  45. public void resetpwd_xiumaster()
  46. {
  47. if (UrlPostParmsCheck("fid,uid,upwd"))
  48. {
  49. int fid = GetPostInt("fid");
  50. int uid = GetPostInt("uid");
  51. string upwd = GetPostString("upwd");
  52. SXiuMaster entity = SXiuMaster.Get(fid);
  53. if (entity != null)
  54. {
  55. SXiuUser userEntity = SXiuUser.Get(uid);
  56. userEntity.lgPwd = SecurityHelper.EncryptSymmetric(upwd);
  57. userEntity.Update();
  58. }
  59. returnSuccessMsg("操作成功");
  60. }
  61. }
  62. public void get_xiurecord()
  63. {
  64. DataStruct dStruct = GetPostStruct();
  65. List<string> lw = new List<string>();
  66. string key = GetPostString("key");
  67. if (key.Length > 0) lw.Add(string.Format("summary like '%{0}%'", key));
  68. dStruct.Order = "addtime desc";
  69. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  70. DataTable dt = WebCache.GetData("view_XiuRecord", dStruct);
  71. writeGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  72. }
  73. public void del_xiurecord()
  74. {
  75. if(UrlPostParmsCheck("rid"))
  76. {
  77. int rid = GetPostInt("rid");
  78. SXiuRecord.Del(rid);
  79. returnSuccessMsg("删除成功");
  80. }
  81. }
  82. public void receive_xiurecord()
  83. {
  84. if(UrlPostParmsCheck("rid,openid"))
  85. {
  86. int rid = GetPostInt("rid");
  87. string openid = GetPostString("openid");
  88. SXiuRecord entity = SXiuRecord.Get(rid);
  89. if (entity != null)
  90. {
  91. entity.State = (int)XiuState.Receive;//
  92. entity.ReceiveTime = DateTime.Now;
  93. entity.Update();
  94. string form_key = "form_" + entity.UserID;
  95. string fid= xiuRedis.RedisHelper.ListLeftPop<string>(form_key);
  96. if (fid != "") {
  97. XiuNotifyHelper.sendReceiveMsg(openid, fid, entity);
  98. }
  99. SXiuTiding.addTiding(rid, "wx", entity.UserID, "订单己受理", "工程师会尽快与你取得联系");
  100. returnSuccessMsg("已接受");
  101. }
  102. }
  103. }
  104. public void finish_xiurecord()
  105. {
  106. if (UrlPostParmsCheck("rid"))
  107. {
  108. int rid = GetPostInt("rid");
  109. SXiuRecord entity = SXiuRecord.Get(rid);
  110. if (entity != null)
  111. {
  112. entity.State = (int)XiuState.Finish;//
  113. entity.Update();
  114. returnSuccessMsg("已接受");
  115. }
  116. }
  117. }
  118. public void get_xiumaster()
  119. {
  120. DataStruct dStruct = GetPostStruct();
  121. List<string> lw = new List<string>();
  122. string key = GetPostString("key");
  123. if (key.Length > 0) lw.Add(string.Format("name like '%{0}%'", key));
  124. dStruct.Order = "addtime desc";
  125. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  126. DataTable dt = WebCache.GetData("view_XiuMaster", dStruct);
  127. foreach(DataRow dr in dt.Rows)
  128. {
  129. dr["lgPwd"] = SecurityHelper.DecryptSymmetric(dr["lgPwd"].ToString());
  130. }
  131. writeGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  132. }
  133. public void save_xiumaster()
  134. {
  135. if (UrlPostParmsCheck("name"))
  136. {
  137. //,address,phone,contex
  138. int mid = GetPostInt("mid");
  139. string name = GetPostString("name");
  140. string phone = GetPostString("phone");
  141. string duties = GetPostString("Duties");
  142. string tids = GetPostString("tids");
  143. string tags = GetPostString("Tags");
  144. string intro = GetPostString("intro");
  145. double star = GetPostDouble("star");
  146. int sort = GetPostInt("sort");
  147. //string lnglat = GetPostString("lnglat");
  148. //string blnglat = GetPostString("blnglat");
  149. SXiuMaster entity = null;
  150. if (mid > 0) entity = SXiuMaster.Get(mid);
  151. else entity = new SXiuMaster();
  152. entity.Name = name;
  153. entity.Phone = phone;
  154. entity.Duties = duties;
  155. entity.Tids = tids;
  156. entity.Tags = tags;
  157. entity.Star = star;
  158. entity.Sort = sort;
  159. entity.Intro = getFormartBr(intro);
  160. //if (lnglat != "")
  161. //{
  162. // string[] lArr = lnglat.Split(',');
  163. // entity.lng = lArr[0];
  164. // entity.lat = lArr[1];
  165. //}
  166. //if (blnglat != "")
  167. //{
  168. // string[] lArr = blnglat.Split(',');
  169. // entity.blng = lArr[0];
  170. // entity.blat = lArr[1];
  171. //}
  172. //entity.Con = intro;
  173. if (mid > 0) entity.Update();
  174. else {
  175. entity.AddTime = DateTime.Now;
  176. entity.Create();
  177. }
  178. returnSuccessMsg("保存成功!");
  179. }
  180. }
  181. public void del_xiumaster()
  182. {
  183. if (UrlPostParmsCheck("mid"))
  184. {
  185. int mid = GetPostInt("mid");
  186. SXiuMaster.Del(mid);
  187. returnSuccessMsg("删除成功");
  188. }
  189. }
  190. #region indexdev
  191. public void get_xiunav()
  192. {
  193. DataStruct dStruct = GetStruct();
  194. IList<string> lw = new List<string>();
  195. string key = GetPostString("key");
  196. if (key.Length > 0) lw.Add(string.Format(" (title like '%{0}%' or tag like '%{0}%')", key));
  197. if (lw.Count > 0) dStruct.SecondWhere = string.Join(" and ", lw.ToArray());
  198. dStruct.Order = "sort asc";
  199. DataTable dt = WebCache.GetData("s_xiunav", dStruct);
  200. writeGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  201. }
  202. public void del_xiunav()
  203. {
  204. if (UrlParmsCheck("id"))
  205. {
  206. int id = GetInt("id");
  207. SXiuNav.Del(id);
  208. returnSuccessMsg("删除成功!");
  209. }
  210. }
  211. #endregion
  212. public void get_xiu_corp()
  213. {
  214. DataStruct dStruct = GetStruct();
  215. List<string> lw = new List<string>();
  216. dStruct.Order = "id desc";
  217. dStruct.Fileds="*,(select count(0) from s_xiuuser where corpid=s_xiucorp.id) as uc";
  218. DataTable dt = WebCache.GetData("S_XiuCorp", dStruct);
  219. writeGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  220. }
  221. public void save_xiu_corp()
  222. {
  223. if (UrlPostParmsCheck("name"))
  224. {
  225. int sid = GetPostInt("sid");
  226. string name = GetPostString("name");
  227. string address = GetPostString("address");
  228. string phone = GetPostString("phone");
  229. string stime = GetPostString("stime");
  230. string etime = GetPostString("etime");
  231. string summary = GetPostString("summary");
  232. string acc = GetPostString("acc");
  233. string pwd = GetPostString("pwd");
  234. bool isnew = false;
  235. SXiuCorp entity = null;
  236. if (sid > 0) entity = SXiuCorp.Get(sid);
  237. else
  238. {
  239. entity = new SXiuCorp();
  240. isnew = true;
  241. }
  242. entity.Name = name;
  243. entity.Address = address;
  244. entity.Phone = phone;
  245. if (stime.Length > 0) entity.StartTime = Convert.ToDateTime(stime);
  246. if (etime.Length > 0) entity.EndTime = Convert.ToDateTime(etime);
  247. entity.Summary = summary;
  248. if (isnew)
  249. {
  250. entity.Create();
  251. if (acc.Length > 0 && pwd.Length > 0)
  252. {
  253. SXiuUser uentity = new SXiuUser();
  254. uentity.AddTime = DateTime.Now;
  255. isnew = true;
  256. uentity.lgName = acc;
  257. uentity.lgPwd = SecurityHelper.EncryptSymmetric(pwd);
  258. uentity.UserType = 2;
  259. uentity.CorpID = entity.ID;
  260. uentity.Create();
  261. }
  262. }
  263. else entity.Update();
  264. xiuRedis.RedisHelper.KeyDelete("xiu_corp");
  265. returnSuccessMsg("保存成功");
  266. }
  267. }
  268. public void del_xiu_corp()
  269. {
  270. if (UrlPostParmsCheck("cid"))
  271. {
  272. int cid = GetPostInt("cid");
  273. SXiuCorp.Del(cid);
  274. xiuRedis.RedisHelper.KeyDelete("xiu_corp");
  275. returnSuccessMsg("删除成功");
  276. }
  277. }
  278. public void get_xiu_acc()
  279. {
  280. DataStruct dStruct = GetStruct();
  281. //List<string> lw = new List<string>();
  282. dStruct.Order = "id desc";
  283. dStruct.Fileds = "*,STUFF((select ','+name from s_xiucorp where charindex(convert(varchar,id)+',',corpids+',')>0 for xml path('')),1,1,'') as cnames";
  284. dStruct.MainWhere = "corpid=0 and usertype=1";
  285. DataTable dt = WebCache.GetData("S_XiuUser", dStruct);
  286. foreach (DataRow dr in dt.Rows)
  287. {
  288. dr["lgPwd"] = SecurityHelper.DecryptSymmetric(dr["lgPwd"].ToString());
  289. }
  290. writeGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  291. }
  292. public void save_xiu_acc()
  293. {
  294. if (UrlPostParmsCheck("acc"))
  295. {
  296. int aid = GetPostInt("aid");
  297. string acc = GetPostString("acc");
  298. string pwd = GetPostString("pwd");
  299. string name = GetPostString("name");
  300. string mobile = GetPostString("mobile");
  301. int st = GetPostInt("st");
  302. int leader = GetPostInt("leader");
  303. string cids = GetPostString("cids");
  304. bool isnew = false;
  305. SXiuUser entity = null;
  306. if (aid > 0) entity = SXiuUser.Get(aid);
  307. else
  308. {
  309. entity = new SXiuUser();
  310. entity.AddTime = DateTime.Now;
  311. isnew = true;
  312. }
  313. entity.lgName = acc;
  314. entity.lgPwd = SecurityHelper.EncryptSymmetric(pwd);
  315. entity.RealName = name ==""? acc : name;
  316. entity.Mobile = mobile;
  317. entity.State = st;
  318. entity.UserType = 1;
  319. entity.isLeader = leader == 1 ? true : false;
  320. entity.CorpIDs = cids;
  321. if (isnew) entity.Create();
  322. else entity.Update();
  323. returnSuccessMsg("保存成功");
  324. }
  325. }
  326. public void del_xiu_acc()
  327. {
  328. if (UrlPostParmsCheck("aid"))
  329. {
  330. int aid = GetPostInt("aid");
  331. SXiuUser.Del(aid);
  332. returnSuccessMsg("删除成功");
  333. }
  334. }
  335. public void get_xiu_corpacc()
  336. {
  337. DataStruct dStruct = GetStruct();
  338. //List<string> lw = new List<string>();
  339. dStruct.Order = "id desc";
  340. string cid = GetPostString("cid");
  341. if (cid == "")
  342. {
  343. writeGridJson(0, "[]");
  344. return;
  345. }
  346. dStruct.MainWhere = "corpid=" + cid;
  347. DataTable dt = WebCache.GetData("S_XiuUser", dStruct);
  348. foreach (DataRow dr in dt.Rows)
  349. {
  350. dr["lgPwd"] = SecurityHelper.DecryptSymmetric(dr["lgPwd"].ToString());
  351. }
  352. writeGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt));
  353. }
  354. public void save_xiu_corpacc()
  355. {
  356. if (UrlPostParmsCheck("acc"))
  357. {
  358. int aid = GetPostInt("aid");
  359. int cid = GetPostInt("cid");
  360. string acc = GetPostString("acc");
  361. string name = GetPostString("name");
  362. string pwd = GetPostString("pwd");
  363. string mobile = GetPostString("mobile");
  364. int st = GetPostInt("st");
  365. bool isnew = false;
  366. SXiuUser entity = null;
  367. if (aid > 0) entity = SXiuUser.GetByCorp(aid,cid);
  368. else
  369. {
  370. entity = new SXiuUser();
  371. entity.AddTime = DateTime.Now;
  372. isnew = true;
  373. }
  374. entity.RealName = name;
  375. entity.lgName = acc;
  376. entity.lgPwd = SecurityHelper.EncryptSymmetric(pwd);
  377. entity.Mobile = mobile;
  378. entity.UserType = 2;
  379. entity.CorpID = cid;
  380. entity.State = st;
  381. if (isnew) entity.Create();
  382. else entity.Update();
  383. returnSuccessMsg("保存成功");
  384. }
  385. }
  386. public void del_xiu_corpacc()
  387. {
  388. if (UrlPostParmsCheck("aid,cid"))
  389. {
  390. int aid = GetPostInt("aid");
  391. int cid = GetPostInt("cid");
  392. SXiuUser.DelCorpUser(aid, cid);
  393. returnSuccessMsg("删除成功");
  394. }
  395. }
  396. //public void trades_sold_get()
  397. //{
  398. // string sg = GetSign();
  399. // string _url = "http://api.taoesoft.com/Api.aspx?action=executeTopApi&methodName=taobao.trades.sold.get&requestObjectJson=" + System.Text.Encoding.UTF8.GetBytes("{\"fields\":\"tid, type, status, payment, orders, rx_audit_status\"}")+"&SessionKey=2201404768885&format=1&sign=" + sg;
  400. // string xxx = Http(_url);
  401. // returnSuccessMsg(xxx);
  402. //}
  403. ///// <summary>
  404. ///// 不做catch处理,需要在外部做
  405. ///// </summary>
  406. ///// <param name="url"></param>
  407. ///// <param name="method">默认GET,空则补充为GET</param>
  408. ///// <param name="contenttype">默认json,空则补充为json</param>
  409. ///// <param name="header">请求头部</param>
  410. ///// <param name="data">请求body内容</param>
  411. ///// <returns></returns>
  412. //public static string Http(string url, string method = "POST", string contenttype = "application/json;charset=utf-8", Hashtable header = null, string data = null)
  413. //{
  414. // HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  415. // request.Method = string.IsNullOrEmpty(method) ? "GET" : method;
  416. // request.ContentType = string.IsNullOrEmpty(contenttype) ? "application/json;charset=utf-8" : contenttype;
  417. // if (header != null)
  418. // {
  419. // foreach (var i in header.Keys)
  420. // {
  421. // request.Headers.Add(i.ToString(), header[i].ToString());
  422. // }
  423. // }
  424. // if (!string.IsNullOrEmpty(data))
  425. // {
  426. // Stream RequestStream = request.GetRequestStream();
  427. // byte[] bytes = Encoding.UTF8.GetBytes(data);
  428. // RequestStream.Write(bytes, 0, bytes.Length);
  429. // RequestStream.Close();
  430. // }
  431. // HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  432. // Stream ResponseStream = response.GetResponseStream();
  433. // StreamReader StreamReader = new StreamReader(ResponseStream, Encoding.GetEncoding("utf-8"));
  434. // string re = StreamReader.ReadToEnd();
  435. // StreamReader.Close();
  436. // ResponseStream.Close();
  437. // return re;
  438. //}
  439. }
  440. }