app.xiu.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. using BizCom;
  2. using BizCom.Enum;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using SiteCore.Redis;
  6. using SQLData;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Drawing;
  11. using System.Drawing.Imaging;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading;
  16. using System.Threading.Tasks;
  17. using System.Web;
  18. using Utils;
  19. using Utils.ImageUtils;
  20. namespace SiteCore.Handler
  21. {
  22. public partial class app
  23. {
  24. #region define
  25. string xiu_Appid_run = "wx20432512482565e9";//"wxee687601b460ac2f";
  26. string xiu_Secret_run = "07492bc9cbbc5b303e5e135b4dccd6f0";
  27. public UserObj GetXiuEntity()
  28. {
  29. string session_id = con.Request.Headers["session-id"];
  30. if (string.IsNullOrEmpty(session_id))
  31. {
  32. conLoginError("未授权登录");
  33. return null;
  34. }
  35. try
  36. {
  37. UserObj uo = xiuRedis.RedisHelper.StringGet<UserObj>(session_id);
  38. if (uo == null) {
  39. conLoginError("请重新登录");
  40. return null;
  41. }
  42. return uo;
  43. }
  44. catch (Exception ex)
  45. {
  46. XLog.SaveLog(0, "GetXiuEntity:" + ex.Message);
  47. conLoginError("请重新登录");
  48. return null;
  49. }
  50. }
  51. public static object xiuCorpObj = new object();
  52. public Dictionary<int, string> XiuCorp
  53. {
  54. get
  55. {
  56. Dictionary<int, string> xiuCorpDics = new Dictionary<int, string>();
  57. xiuCorpDics = xiuRedis.RedisHelper.StringGet<Dictionary<int, string>>("xiu_corp");
  58. if (xiuCorpDics == null || xiuCorpDics.Count<1)
  59. {
  60. lock (xiuCorpObj)
  61. {
  62. xiuCorpDics = new Dictionary<int, string>();
  63. string sql = "select id,name from s_xiucorp";
  64. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  65. foreach (DataRow dr in dt.Rows)
  66. {
  67. xiuCorpDics.Add(Convert.ToInt32(dr["id"]), dr["name"].ToString());
  68. }
  69. xiuRedis.RedisHelper.StringSet("xiu_corp", xiuCorpDics);
  70. xiuRedis.RedisHelper.StringSet("xiu_corp_dt",dt);
  71. }
  72. }
  73. return xiuCorpDics;
  74. }
  75. }
  76. public static FrequencyControler xiusaveFrequency = new FrequencyControler("xiusave", 10, 2);
  77. private string get_openidbycorpperson(int corpid)
  78. {
  79. string v = xiuRedis.RedisHelper.StringGet("corpperson_" + corpid);
  80. if (string.IsNullOrEmpty(v))
  81. {
  82. string sql = "select miniopenid from s_xiuuser where charindex('" + corpid + ",',corpids+',')>0";
  83. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  84. List<string> lst = new List<string>();
  85. foreach (DataRow dr in dt.Rows)
  86. {
  87. string openid = xiuRedis.RedisHelper.StringGet("gzh_" + dr["miniopenid"].ToString());
  88. if (!String.IsNullOrEmpty(openid))
  89. {
  90. lst.Add(openid);
  91. }
  92. }
  93. if (lst.Count > 0)
  94. {
  95. v = string.Join(",", lst.ToArray());
  96. xiuRedis.RedisHelper.StringSet("corpperson_" + corpid, v, TimeSpan.FromHours(3));
  97. return v;
  98. }
  99. }
  100. else
  101. {
  102. return v;
  103. }
  104. return "";
  105. }
  106. private string get_openidbycorp(int corpid)
  107. {
  108. string v = xiuRedis.RedisHelper.StringGet("corp_" + corpid);
  109. if (string.IsNullOrEmpty(v))
  110. {
  111. string sql = "select miniopenid from s_xiuuser where corpid=" + corpid;
  112. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  113. List<string> lst = new List<string>();
  114. foreach (DataRow dr in dt.Rows)
  115. {
  116. string openid = xiuRedis.RedisHelper.StringGet("gzh_" + dr["miniopenid"].ToString());
  117. if (!String.IsNullOrEmpty(openid))
  118. {
  119. lst.Add(openid);
  120. }
  121. }
  122. if (lst.Count > 0)
  123. {
  124. v = string.Join(",", lst.ToArray());
  125. xiuRedis.RedisHelper.StringSet("corp_" + corpid, v, TimeSpan.FromHours(3));
  126. return v;
  127. }
  128. }
  129. else
  130. {
  131. return v;
  132. }
  133. return "";
  134. }
  135. public void xiu_getpersonbycorp()
  136. {
  137. int corpid = GetPostInt("corpid");
  138. string sql = "select id,lgname as name from s_xiuuser where charindex('" + corpid + ",',corpids+',')>0";
  139. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  140. conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  141. }
  142. #endregion
  143. #region user
  144. public void xiuuser_login()
  145. {
  146. if (UrlPostParmsCheck("code"))
  147. {
  148. string code = GetPostString("code");
  149. string uname = GetPostString("uname");
  150. string pwd = GetPostString("pwd");
  151. int utype = GetPostInt("utype");
  152. if (utype <= 0)
  153. {
  154. conError("错误参数,无法登录");
  155. return;
  156. }
  157. string nickname = GetPostString("nickname");
  158. string avatarUrl = GetPostString("avatarUrl");
  159. int gender = GetPostInt("gender");
  160. //向微信服务端 使用登录凭证 code 获取 session_key 和 openid
  161. string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + xiu_Appid_run + "&secret=" + xiu_Secret_run + "&js_code=" + code + "&grant_type=" + grant_type;
  162. string type = "utf-8";
  163. string json = GetUrltoHtml(url, type);//获取微信服务器返回字符串
  164. //微信服务器验证成功
  165. JObject jo = (JObject)JsonConvert.DeserializeObject(json);
  166. try
  167. {
  168. string openid = jo["openid"].ToString();
  169. string session_key = jo["session_key"].ToString();
  170. if (openid == "" || session_key == "")
  171. {
  172. conError("无法登录1");
  173. return;
  174. }
  175. pwd = SecurityHelper.EncryptSymmetric(pwd);//加密
  176. SXiuUser entity = SXiuUser.GetByAcc(uname, pwd, utype);
  177. if (entity == null)
  178. {
  179. conError("账号或密码错误");
  180. return;
  181. }
  182. if (entity.State == 2)
  183. {
  184. conError("该账号已被禁用");
  185. return;
  186. }
  187. //if (entity.miniopenid != "" && entity.miniopenid != openid)
  188. //{
  189. // conError("该账号已绑定一个微信,如要使用请先解绑!");
  190. // return;
  191. //}
  192. entity.miniopenid = openid;
  193. //entity.openid = openid;
  194. entity.Sex = gender;
  195. entity.NickName = nickname;
  196. if (avatarUrl != "")
  197. {
  198. Thread oThread = new Thread(delegate ()
  199. {
  200. HttpHelper http = new HttpHelper();
  201. HttpItem item = new HttpItem()
  202. {
  203. KeepAlive = true,
  204. Accept = "image/webp,image/*,*/*;q=0.8",
  205. URL = avatarUrl,
  206. ResultType = ResultType.Byte
  207. };
  208. HttpResult hResult = http.GetHtml(item);
  209. using (MemoryStream ms = new MemoryStream(hResult.ResultByte))
  210. {
  211. Bitmap bm = new Bitmap(ms);
  212. //Graphics g = Graphics.FromImage(bm);//实例一个画板的对象,就用上面的图像的画板
  213. //g.DrawImage(bm, 0, 0);
  214. bm.Save(webConfig.xiuUserPicPath + "\\b\\" + entity.ID + ".jpg", ImageFormat.Jpeg);
  215. using (System.Drawing.Image imgThumb = System.Drawing.Image.FromStream(ms))
  216. {
  217. ImageMaker.ToThumbnailImages(imgThumb, webConfig.xiuUserPicPath + "\\" + entity.ID + ".jpg", 100, "", 9, 3);
  218. //result = ImageMaker.ToThumbnailImages(imgThumb, saveFile, 600, "", 9, 3);
  219. }
  220. //bm.Save(webConfig.userPicPath + "\\" + entity.ID + ".jpg", ImageFormat.Jpeg);
  221. }
  222. });
  223. oThread.Start();
  224. }
  225. entity.UserPic = entity.ID + ".jpg";
  226. entity.Update();
  227. //string session_id = "svr_" + sid + "_" + con.Session.SessionID;
  228. //封装成对象
  229. string session_id = "svr_" +con.Session.SessionID;
  230. UserObj uObj = new UserObj()
  231. {
  232. session_id = session_id,
  233. openid = openid,
  234. userid = entity.ID,
  235. corpid = entity.CorpID,
  236. realname=entity.RealName,
  237. username = entity.lgName,
  238. isleader=entity.isLeader,
  239. corpids = entity.CorpIDs
  240. };
  241. Dictionary<int, string> xiuCorpDics = new Dictionary<int, string>();
  242. xiuCorpDics = XiuCorp;
  243. if (xiuCorpDics.ContainsKey(entity.CorpID))
  244. {
  245. uObj.cname = xiuCorpDics[entity.CorpID];
  246. }
  247. xiuRedis.RedisHelper.StringSet(session_id, JsonConvert.SerializeObject(uObj));
  248. //存储openid
  249. //xiuRedis.RedisHelper.StringSet("user_" + ukey, "1");
  250. string gzh_openid = xiuRedis.RedisHelper.StringGet("gzh_" + uObj.openid);
  251. bool isgzh = false;
  252. if (gzh_openid != null && gzh_openid != "")
  253. {
  254. isgzh = true;
  255. }
  256. else
  257. {
  258. xiuRedis.RedisHelper.StringSet("gzh_" + session_id, uObj.openid);
  259. }
  260. //存入内存中
  261. //xiuRedis.RedisHelper.StringSet(session_id, JsonConvert.SerializeObject(uObj));
  262. //xiuRedis.RedisHelper.StringSet(entity.ID.ToString(), session_id);
  263. //返回数据给小程序
  264. StringBuilder userStr = new StringBuilder();
  265. userStr.Append("{");
  266. userStr.AppendFormat("\"session2\":\"{0}\"", session_id);
  267. //userStr.AppendFormat(",\"userpic\":\"{0}\"", entity.UserPic);
  268. userStr.AppendFormat(",\"username\":\"{0}\"", entity.lgName);
  269. userStr.AppendFormat(",\"realname\":\"{0}\"", entity.RealName);
  270. if (uObj.cname!="") userStr.AppendFormat(",\"corpname\":\"{0}\"", uObj.cname);
  271. else userStr.Append(",\"corpname\":\"\"");
  272. userStr.AppendFormat(",\"gzh\":\"{0}\"", isgzh ? "1" : "0");
  273. userStr.AppendFormat(",\"il\":\"{0}\"", entity.isLeader ? "1" : "0");
  274. userStr.Append("}");
  275. conSuccess("登录成功", userStr.ToString());
  276. return;
  277. }
  278. catch (Exception ex)
  279. {
  280. //微信服务器验证失败
  281. //string msg = jo["errcode"].ToString() + "," + jo["errmsg"].ToString();
  282. conError("暂时无法登录");
  283. }
  284. return;
  285. }
  286. conError("错误的参数");
  287. }
  288. public void xiuuser_loginout()
  289. {
  290. UserObj uo = GetXiuEntity();
  291. if (uo == null) return;
  292. int uid = uo.userid;
  293. xiuRedis.RedisHelper.KeyDelete(uo.session_id);
  294. //erpRedis.RedisHelper.KeyDelete("pms_" + uo.siteid + "_" + uo.pcode);
  295. conSuccess("注销成功!");
  296. //SXiuUser entity = SXiuUser.Get(uid);
  297. //if (entity != null)
  298. //{
  299. // entity.miniopenid = "";
  300. // //entity.UserName = "";
  301. // entity.Update();
  302. // xiuRedis.RedisHelper.KeyDelete(uo.session_id);
  303. //}
  304. //conSuccess("登出");
  305. }
  306. public void xiuuser_updpwd()
  307. {
  308. UserObj uo = GetXiuEntity();
  309. if (uo == null) return;
  310. int uid = uo.userid;
  311. if (UrlPostParmsCheck("opwd,npwd"))
  312. {
  313. string opwd = GetPostString("opwd");
  314. string npwd = GetPostString("npwd");
  315. if (opwd == npwd)
  316. {
  317. conError("密码相同不能修改!");
  318. return;
  319. }
  320. SXiuUser entity = SXiuUser.GetByID(uid, SecurityHelper.EncryptSymmetric(opwd));
  321. if (entity != null)
  322. {
  323. entity.lgPwd = SecurityHelper.EncryptSymmetric(npwd);
  324. entity.Update();
  325. conSuccess("修改成功!");
  326. return;
  327. }
  328. else
  329. {
  330. conError("原密码不正确!");
  331. return;
  332. }
  333. }
  334. conError("无法修改密码!");
  335. }
  336. #endregion
  337. public void get_xiurecord_detail()
  338. {
  339. //UserObj uo = GetXiuEntity();
  340. //if (uo == null) return;
  341. //int uid = uo.userid;
  342. //if (UrlPostParmsCheck("rid"))
  343. //{
  344. // int rid = GetPostInt("rid");
  345. // string fields = "corpusermobile,corpusername,username,usermobile,surename,suremobile,id,corpid,corpname,corpuserid,summary as con,imgs,XiuTypeName as typename,addtime,xiutypeid,state,code,title,receivetime,starttime,repairtime,repairsummary as repaircon,repairimgs,suretime,surecon,sureimgs,question,solution,xiuresult,xiulocation as loc";
  346. // string sql = "select fields from s_xiurecord where id=" + rid;
  347. // DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  348. //}
  349. }
  350. #region 企业操作
  351. /// <summary>
  352. /// 企业获取维护记录
  353. /// </summary>
  354. public void xiu_getcorprecord()
  355. {
  356. UserObj uo = GetXiuEntity();
  357. if (uo == null) return;
  358. //int uid = uo.userid;
  359. DataStruct dStruct = GetPostStruct();
  360. List<string> lw = new List<string>();
  361. //lw.Add("(corpuserid=" + uo.userid + " or sureuserid=" + uo.userid + ")");
  362. lw.Add("corpid=" + uo.corpid);
  363. int st = GetPostInt("st");
  364. if (st > 0)
  365. {
  366. switch (st)
  367. {
  368. case 1:
  369. {
  370. lw.Add("state= " + (int)XiuState.None);
  371. break;
  372. }
  373. case 2:
  374. {
  375. lw.Add("state= " + (int)XiuState.Sure);
  376. break;
  377. }
  378. case 3:
  379. {
  380. lw.Add("state> " + (int)XiuState.Sure + " and state<" + (int)XiuState.Finish);
  381. break;
  382. }
  383. case 4:
  384. {
  385. lw.Add("state= " + (int)XiuState.Finish);
  386. break;
  387. }
  388. case 5:
  389. {
  390. lw.Add("state= " + (int)XiuState.Apply);
  391. break;
  392. }
  393. }
  394. }
  395. dStruct.Fileds = "corpusermobile,corpusername,corpuserid,username,usermobile,surename,suremobile,id,corpid,corpname,summary as con,imgs,XiuTypeName as typename,addtime,xiutypeid,state,code,title,receivetime,starttime,repairtime,repairsummary as repaircon,repairimgs,suretime,surecon,sureimgs,question,solution,xiuresult,xiulocation as loc,updtime";
  396. dStruct.Order = "UpdTime desc";
  397. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  398. DataTable dt = WebCache.GetData("view_xiurecord", dStruct);
  399. conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  400. }
  401. /// <summary>
  402. /// 企业删除维护单
  403. /// </summary>
  404. public void xiu_corp_delrecord()
  405. {
  406. UserObj uo = GetXiuEntity();
  407. if (uo == null) return;
  408. int uid = uo.userid;
  409. if (UrlPostParmsCheck("rid"))
  410. {
  411. int rid = GetPostInt("rid");
  412. SXiuRecord entity = SXiuRecord.GetByCorp(rid, uo.corpid, uid);
  413. if (entity.State < 1)
  414. {
  415. entity.Delete();
  416. //通知删除
  417. conSuccess("已删除!");
  418. }
  419. return;
  420. }
  421. conError("错误的参数");
  422. }
  423. /// <summary>
  424. /// 企业发布维护
  425. /// </summary>
  426. public void xiu_corp_insrecord()
  427. {
  428. UserObj uo = GetXiuEntity();
  429. if (uo == null) return;
  430. int uid = uo.userid;
  431. //aid,
  432. //ainfo,
  433. if (UrlPostParmsCheck("tid,con"))
  434. {
  435. int rid = GetPostInt("rid");
  436. SXiuRecord entity = null;
  437. if (rid > 0) entity = SXiuRecord.GetByCorp(rid,uo.corpid,uid);
  438. else entity = new SXiuRecord();
  439. //GenerateOutTradeNo
  440. //int aid = GetPostInt("aid");
  441. int tid = GetPostInt("tid");
  442. string title = GetPostString("title");
  443. string con = GetPostString("con");
  444. con = con.Replace("\r\n", "<br>").Replace("\n", "<br>");
  445. con = con.Replace(" ", "&nbsp;");
  446. string images = GetPostString("images").TrimEnd(',');
  447. string loc = GetPostString("loc");
  448. //entity.AddressID = aid;
  449. entity.CorpID = uo.corpid;
  450. //entity.XiuTypeID = tid;
  451. entity.CorpUserID = uid;
  452. entity.Title = title;
  453. entity.Summary = con;
  454. entity.XiuLocation = loc;
  455. //entity.AddressInfo = GetPostString("ainfo");
  456. entity.Imgs = images;
  457. //entity.XiuTypeInfo = GetPostString("xtinfo");
  458. if (rid > 0) entity.Update();
  459. else
  460. {
  461. entity.AddTime = DateTime.Now;
  462. entity.UpdTime = DateTime.Now;
  463. entity.Code = GenerateOutTradeNo("");
  464. entity.Create();
  465. }
  466. conSuccess("操作成功!");
  467. return;
  468. }
  469. conError("无法提交");
  470. }
  471. /// <summary>
  472. /// 企业确认通知维护
  473. /// </summary>
  474. public void xiu_corp_surerecord()
  475. {
  476. UserObj uo = GetXiuEntity();
  477. if (uo == null) return;
  478. int uid = uo.userid;
  479. if (UrlPostParmsCheck("rid"))
  480. {
  481. int rid = GetPostInt("rid");
  482. SXiuRecord entity = SXiuRecord.GetByCorp(rid, uo.corpid, uid);
  483. if (entity != null)
  484. {
  485. entity.State = 1;
  486. entity.AddTime = DateTime.Now;
  487. entity.UpdTime = DateTime.Now;
  488. entity.Update();
  489. //这里需要加入通知
  490. WxPush.sendXiuPersonMsg(get_openidbycorpperson(uo.corpid), uo.cname, entity.Title, "发起人:"+uo.realname);
  491. conSuccess("操作成功!");
  492. return;
  493. }
  494. }
  495. conError("错误的参数");
  496. }
  497. /// <summary>
  498. /// 企业负责人确认签收维护完成
  499. /// </summary>
  500. public void xiu_applyrecord()
  501. {
  502. UserObj uo = GetXiuEntity();
  503. if (uo == null) return;
  504. int uid = uo.userid;
  505. if (UrlPostParmsCheck("rid"))
  506. {
  507. int rid = GetPostInt("rid");
  508. string scon = GetPostString("scon");
  509. if (scon.Length > 0)
  510. {
  511. scon = scon.Replace("\r\n", "<br>").Replace("\n", "<br>");
  512. scon = scon.Replace(" ", "&nbsp;");
  513. }
  514. string simg = GetPostString("simg");
  515. SXiuRecord entity = SXiuRecord.GetCorp(rid, uo.corpid);
  516. if (entity != null)
  517. {
  518. entity.State = (int)XiuState.Apply;
  519. entity.SureImgs = simg;
  520. entity.SureCon = scon;
  521. entity.SureTime = DateTime.Now;
  522. entity.UpdTime = DateTime.Now;
  523. entity.SureUserID = uid;
  524. entity.Update();
  525. //加入通知维护人员
  526. conSuccess("操作成功!");
  527. return;
  528. }
  529. }
  530. conError("错误的参数或找不到记录");
  531. }
  532. #endregion
  533. #region 维护人员
  534. /// <summary>
  535. /// 维护人员发起维护
  536. /// </summary>
  537. public void xiu_insrecord()
  538. {
  539. //if (xiusaveFrequency.IsTooFrequently(true))
  540. //{
  541. // conError("访问太频繁!");
  542. // return;
  543. //}
  544. UserObj uo = GetXiuEntity();
  545. if (uo == null) return;
  546. int uid = uo.userid;
  547. //aid,
  548. //ainfo,
  549. if (UrlPostParmsCheck("cid,tid"))
  550. {
  551. int rid = GetPostInt("rid");
  552. int cid = GetPostInt("cid");
  553. SXiuRecord entity = null;
  554. if (rid > 0) entity = SXiuRecord.Get(rid, uid);
  555. else entity = new SXiuRecord();
  556. //GenerateOutTradeNo
  557. //int aid = GetPostInt("aid");
  558. int tid = GetPostInt("tid");
  559. //string title = GetPostString("title");
  560. string con = GetPostString("repaircon");
  561. con = con.Replace("\r\n", "<br>").Replace("\n", "<br>");
  562. con = con.Replace(" ", "&nbsp;");
  563. string loc = GetPostString("loc");
  564. string images = GetPostString("images").TrimEnd(',');
  565. //entity.AddressID = aid;
  566. entity.XiuTypeID = tid;
  567. entity.UserID = uid;
  568. entity.XiuLocation = loc;
  569. entity.Question = GetPostString("question");
  570. entity.Solution = GetPostString("solution");
  571. entity.XiuResult = GetPostString("result");
  572. entity.RepairSummary = con;
  573. entity.RepairImgs = images;
  574. //entity.Title = title;
  575. //entity.Summary = con;
  576. //entity.AddressInfo = GetPostString("ainfo");
  577. //entity.Imgs = images;
  578. entity.State = (int)XiuState.Ing;
  579. //entity.XiuTypeInfo = GetPostString("xtinfo");
  580. if (rid > 0) entity.Update();
  581. else {
  582. entity.CorpID = cid;
  583. entity.AddTime = DateTime.Now;
  584. entity.StartTime = DateTime.Now;
  585. entity.ReceiveTime = DateTime.Now;
  586. entity.UpdTime = DateTime.Now;
  587. entity.Code = GenerateOutTradeNo("");
  588. entity.Create();
  589. }
  590. //通知
  591. conSuccess("操作成功!");
  592. return;
  593. }
  594. conError("无法提交");
  595. }
  596. /// <summary>
  597. /// 维护人员删除维护单
  598. /// </summary>
  599. public void xiu_delrecord()
  600. {
  601. UserObj uo = GetXiuEntity();
  602. if (uo == null) return;
  603. int uid = uo.userid;
  604. if (UrlPostParmsCheck("rid"))
  605. {
  606. int rid = GetPostInt("rid");
  607. SXiuRecord entity = SXiuRecord.Get(rid, uid);
  608. if (entity.State < 2)
  609. {
  610. entity.Delete();
  611. }
  612. conSuccess("已删除!");
  613. return;
  614. }
  615. conError("错误的参数");
  616. }
  617. /// <summary>
  618. /// 开始维护
  619. /// </summary>
  620. public void xiu_ingrecord()
  621. {
  622. UserObj uo = GetXiuEntity();
  623. if (uo == null) return;
  624. int uid = uo.userid;
  625. if (UrlPostParmsCheck("rid"))
  626. {
  627. int rid = GetPostInt("rid");
  628. SXiuRecord entity = SXiuRecord.Get(rid, uid);
  629. if (entity == null)
  630. {
  631. conError("找不到该记录");
  632. return;
  633. }
  634. entity.StartTime = DateTime.Now;
  635. entity.UpdTime = DateTime.Now;
  636. entity.State = (int)XiuState.Ing;
  637. entity.Update();
  638. conSuccess("开始维护...");
  639. return;
  640. }
  641. }
  642. /// <summary>
  643. /// 受理维护
  644. /// </summary>
  645. public void xiu_receiverecord()
  646. {
  647. UserObj uo = GetXiuEntity();
  648. if (uo == null) return;
  649. int uid = uo.userid;
  650. if (UrlPostParmsCheck("cid,rid"))
  651. {
  652. int cid = GetPostInt("cid");
  653. int rid = GetPostInt("rid");
  654. SXiuRecord entity = SXiuRecord.GetCorp(rid,cid);
  655. if (entity != null)
  656. {
  657. entity.State = (int)XiuState.Receive;
  658. entity.ReceiveTime = DateTime.Now;
  659. entity.UpdTime = DateTime.Now;
  660. entity.UserID = uid;
  661. entity.Update();
  662. WxPush.sendXiuCorpMsg(get_openidbycorp(uo.corpid), "售后维护", "已受理", "您的单据已被受理");
  663. //这里需要加入通知
  664. conSuccess("操作成功!");
  665. return;
  666. }
  667. }
  668. conError("错误的参数");
  669. }
  670. /// <summary>
  671. /// 负责人派发给指定维护人员
  672. /// </summary>
  673. public void xiu_pairecord()
  674. {
  675. UserObj uo = GetXiuEntity();
  676. if (uo == null) return;
  677. int uid = uo.userid;
  678. if (UrlPostParmsCheck("cid,rid,tuid"))
  679. {
  680. int cid = GetPostInt("cid");
  681. int rid = GetPostInt("rid");
  682. int tuid = GetPostInt("tuid");
  683. SXiuRecord entity = SXiuRecord.GetCorp(rid, cid);
  684. if (entity != null)
  685. {
  686. entity.State = (int)XiuState.Receive;
  687. entity.ReceiveTime = DateTime.Now;
  688. entity.UpdTime = DateTime.Now;
  689. entity.UserID = tuid;
  690. entity.Update();
  691. //这里需要加入通知
  692. conSuccess("操作成功!");
  693. return;
  694. }
  695. }
  696. conError("错误的参数");
  697. }
  698. /// <summary>
  699. /// 维护人员完成维护
  700. /// </summary>
  701. public void xiu_finishrecord()
  702. {
  703. UserObj uo = GetXiuEntity();
  704. if (uo == null) return;
  705. int uid = uo.userid;
  706. if (UrlPostParmsCheck("rid"))
  707. {
  708. int rid = GetPostInt("rid");
  709. //string con = GetPostString("con");
  710. //if (con.Length > 0)
  711. //{
  712. // con = con.Replace("\r\n", "<br>").Replace("\n", "<br>");
  713. // con = con.Replace(" ", "&nbsp;");
  714. //}
  715. //string imgs = GetPostString("imgs");
  716. SXiuRecord entity = SXiuRecord.Get(rid, uid);
  717. if (entity != null)
  718. {
  719. entity.State = (int)XiuState.Finish;
  720. //entity.RepairImgs = imgs;
  721. //entity.RepairSummary = con;
  722. entity.RepairTime = DateTime.Now;
  723. entity.UpdTime = DateTime.Now;
  724. entity.OpUserID = uid;
  725. entity.Update();
  726. //加入通知企业
  727. conSuccess("操作成功!");
  728. return;
  729. }
  730. }
  731. conError("错误的参数或找不到记录");
  732. }
  733. /// <summary>
  734. /// 获取维护人员关联的企业
  735. /// </summary>
  736. public void xiu_getusercorp()
  737. {
  738. UserObj uo = GetXiuEntity();
  739. if (uo == null) return;
  740. DataTable udt= xiuRedis.RedisHelper.StringGet<DataTable>(uo.userid+"_crops");
  741. if (udt == null || udt.Rows.Count < 1)
  742. {
  743. string sql = "select id,name from s_xiucorp where id in(" + uo.corpids + ")";
  744. udt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  745. if (udt != null && udt.Rows.Count > 0) xiuRedis.RedisHelper.StringSet(uo.userid + "_crops", udt);
  746. }
  747. conGridJson(udt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(udt));
  748. }
  749. /// <summary>
  750. /// 获取用户维护记录
  751. /// </summary>
  752. public void xiu_getuserrecord()
  753. {
  754. UserObj uo = GetXiuEntity();
  755. if (uo == null) return;
  756. int uid = uo.userid;
  757. DataStruct dStruct = GetPostStruct();
  758. List<string> lw = new List<string>();
  759. //lw.Add("sureuserid=" + uid);
  760. string cids = GetPostString("cid");
  761. if (cids.Length > 0) lw.Add(" CorpID in (" + cids + ")");
  762. int st = GetPostInt("st");
  763. if (uo.isleader)
  764. {
  765. if (st > 0)
  766. {
  767. switch (st)
  768. {
  769. case 1:
  770. {
  771. lw.Add("(corpid in (" + uo.corpids + ") and state= " + (int)XiuState.Sure + ")");
  772. break;
  773. }
  774. case 2:
  775. {
  776. lw.Add("((corpid in (" + uo.corpids + ") and state= " + (int)XiuState.Receive + ")");
  777. break;
  778. }
  779. case 3:
  780. {
  781. lw.Add("((corpid in (" + uo.corpids + ") and state>" + (int)XiuState.Receive + " and state<" + (int)XiuState.Finish + ")");
  782. break;
  783. }
  784. case 4:
  785. {
  786. lw.Add("((corpid in (" + uo.corpids + ") and state>= " + (int)XiuState.Finish + ")");
  787. break;
  788. }
  789. }
  790. }
  791. else
  792. {
  793. lw.Add("(corpid in (" + uo.corpids + ") and state>= " + (int)XiuState.Sure + ")");
  794. }
  795. }
  796. else
  797. {
  798. if (st > 0)
  799. {
  800. switch (st)
  801. {
  802. case 1:
  803. {
  804. lw.Add("(userid=" + uid + " and state= " + (int)XiuState.Sure + ")");
  805. break;
  806. }
  807. case 2:
  808. {
  809. lw.Add("(userid=" + uid + " and state= " + (int)XiuState.Receive + ")");
  810. break;
  811. }
  812. case 3:
  813. {
  814. lw.Add("(userid=" + uid + " and state>" + (int)XiuState.Receive + " and state<" + (int)XiuState.Finish + ")");
  815. break;
  816. }
  817. case 4:
  818. {
  819. lw.Add("(userid=" + uid + " and state>= " + (int)XiuState.Finish + ")");
  820. break;
  821. }
  822. }
  823. }
  824. else
  825. {
  826. lw.Add("(userid=" + uid + " or (userid=0 and state>= " + (int)XiuState.Sure + "))");
  827. }
  828. }
  829. dStruct.Fileds = "corpusermobile,corpusername,username,usermobile,surename,suremobile,id,corpid,corpname,corpuserid,summary as con,imgs,XiuTypeName as typename,addtime,xiutypeid,state,code,title,receivetime,starttime,repairtime,repairsummary as repaircon,repairimgs,suretime,surecon,sureimgs,question,solution,xiuresult,xiulocation as loc,updtime";
  830. dStruct.Order = "UpdTime desc";
  831. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  832. //string sql = "select from s_xiurecord where userid=" + uid + " and corpid=" + uo.cid + " order by id desc";
  833. //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  834. DataTable dt = WebCache.GetData("view_xiurecord", dStruct);
  835. conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  836. }
  837. #endregion
  838. #region private
  839. public void xiu_gettype()
  840. {
  841. string sql = "select id,parentid as pid,name,code from s_xiutype order by sort";
  842. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  843. conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  844. }
  845. public void upload_xiu_imgs()
  846. {
  847. UserObj uo = GetXiuEntity();
  848. if (uo == null) return;
  849. int uid = uo.userid;
  850. string tag = GetPostString("tag");
  851. HttpPostedFile postFile = null;
  852. List<string> lstFile = new List<string>();
  853. int c = con.Request.Files.Count;
  854. if (c > 0)
  855. {
  856. for (int i = 0; i < c; i++)
  857. {
  858. string errMsg = "";
  859. postFile = con.Request.Files[i];
  860. if (!ImageHandler.CheckImage(postFile, out errMsg))
  861. {
  862. conError(errMsg);
  863. return;
  864. }
  865. string fileName = uid + DateTime.Now.ToFileTimeUtc() + ".jpg";
  866. string sourceExt = Path.GetExtension(postFile.FileName);
  867. if (sourceExt == ".gif")
  868. {
  869. fileName = uid + DateTime.Now.ToFileTimeUtc() + ".gif";
  870. postFile.SaveAs(webConfig.xiuPath + "\\" + fileName);
  871. }
  872. else
  873. {
  874. string saveFile = Path.Combine(webConfig.xiuPath, fileName);
  875. string result = "";
  876. using (System.Drawing.Image imgThumb = System.Drawing.Image.FromStream(postFile.InputStream))
  877. {
  878. result = ImageMaker.ToThumbnailImages(imgThumb, saveFile, 800, "", 9, 3);
  879. }
  880. }
  881. lstFile.Add(fileName);
  882. }
  883. }
  884. string fs = "";
  885. if (lstFile.Count > 0) fs = string.Join(",", lstFile.ToArray());
  886. conSuccess("上传成功", "{\"fname\":\"" + fs + "\"}");
  887. }
  888. #endregion
  889. #region report
  890. public void xiu_getmaininfo()
  891. {
  892. UserObj uo = GetXiuEntity();
  893. if (uo == null) return;
  894. int uid = uo.userid;
  895. StringBuilder sql = new StringBuilder();
  896. if (uo.isleader)
  897. {
  898. sql.AppendFormat("select (select count(0) from s_xiurecord where corpuserid>0 and corpid in ({0}) and state=1) as dsl, ", uo.corpids);
  899. sql.AppendFormat("(select count(0) from s_xiurecord where corpid in ({0}) and state>1 and state<4) as whz,", uo.corpids);
  900. sql.AppendFormat("(select count(0) from s_xiurecord where corpid in ({0}) and state=4) as dys", uo.corpids);
  901. }
  902. else
  903. {
  904. sql.AppendFormat("select (select count(0) from s_xiurecord where corpuserid>0 and corpid in ({0}) and state=1) as dsl, ", uo.corpids);
  905. sql.AppendFormat("(select count(0) from s_xiurecord where userid={0} and state>1 and state<4) as whz,", uid);
  906. sql.AppendFormat("(select count(0) from s_xiurecord where userid={0} and state=4) as dys", uid);
  907. }
  908. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  909. conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  910. }
  911. public void xiu_corp_getmaininfo()
  912. {
  913. UserObj uo = GetXiuEntity();
  914. if (uo == null) return;
  915. int uid = uo.userid;
  916. StringBuilder sql = new StringBuilder();
  917. sql.AppendFormat("select (select count(0) from s_xiurecord where corpid={0} and corpuserid={1} and state<1) as dsl, ", uo.corpid, uo.userid);
  918. sql.AppendFormat("(select count(0) from s_xiurecord where corpid={0} and state>1 and state<4) as whz,", uo.corpid);
  919. sql.AppendFormat("(select count(0) from s_xiurecord where corpid={0} and state=4) as dys", uo.corpid);
  920. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  921. conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  922. }
  923. public void get_xiu_userreport()
  924. {
  925. if (UrlPostParmsCheck("stime,etime"))
  926. {
  927. UserObj uo = GetXiuEntity();
  928. if (uo == null) return;
  929. int uid = uo.userid;
  930. //int cid = GetPostInt("cid");
  931. string stime = GetPostString("stime");
  932. string etime = GetPostString("etime");
  933. DateTime sTime = Convert.ToDateTime(stime);
  934. DateTime eTime = Convert.ToDateTime(etime);
  935. List<string> lw = new List<string>();
  936. lw.Add(" RepairTime>='" + stime + "' and RepairTime<='" + etime+"'");
  937. //if (cid > 0) lw.Add(" corpid=" + cid);
  938. //else
  939. lw.Add(" corpid in (" + uo.corpids + ")");
  940. if (!uo.isleader) lw.Add("userid=" + uid);
  941. string where = string.Join(" and ", lw.ToArray());
  942. // string dis_one_sql = "select id from ce_erpdispatchtask where datediff(d,createtime,'" + dtime + "')=0";
  943. StringBuilder sql = new StringBuilder();
  944. sql.AppendFormat("select * from view_xiurecord where {0};", where);
  945. DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  946. DataTable pDt = ds.Tables[0];
  947. if (pDt.Rows.Count < 1)
  948. {
  949. conGridJson(0, "[]");
  950. return;
  951. }
  952. DataView pDv = new DataView(pDt);
  953. DataTable dt = new DataTable();
  954. dt.Columns.Add(new DataColumn("ctime", typeof(string)));
  955. dt.Columns.Add(new DataColumn("ctime2", typeof(string)));
  956. dt.Columns.Add(new DataColumn("cid", typeof(string)));
  957. dt.Columns.Add(new DataColumn("cname", typeof(string)));
  958. dt.Columns.Add(new DataColumn("cc", typeof(int)));
  959. int c = (int)eTime.Subtract(sTime).TotalDays;
  960. DateTime cTime;
  961. if (c == 0) c = 1;
  962. string ct = "";
  963. List<cplObj> cplLst = new List<cplObj>();
  964. for (int i = 0; i < c; i++)
  965. {
  966. cTime = sTime.AddDays(i);
  967. DataRow dr = null;
  968. ct = cTime.ToString("M.d");
  969. pDv.RowFilter = "RepairTime>='" + cTime.ToString("yyyy-MM-dd") + " 00:00:00' and RepairTime<'" + cTime.AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00'";
  970. if (pDv.Count < 1) continue;
  971. cplLst = getCidCount(pDv.ToTable());
  972. if (cplLst == null || cplLst.Count < 1) continue;
  973. foreach (cplObj obj in cplLst)
  974. {
  975. dr = dt.NewRow();
  976. dr["ctime"] = ct;
  977. dr["ctime2"] = cTime.ToString("yyyy-MM-dd");
  978. dr["cid"] = obj.pid;
  979. dr["cname"] =obj.pname;
  980. dr["cc"] = obj.count;
  981. dt.Rows.Add(dr);
  982. }
  983. }
  984. DataView resultDv = new DataView(dt);
  985. resultDv.Sort = "ctime asc";
  986. //AppendScript("reportData=" + JsonString.DataView2MiniAjaxJson(resultDv) + ";");
  987. //StringBuilder str = new StringBuilder();
  988. //str.AppendFormat("select EngineeringBody as eb,count(0) as pCount, sum(PlanVolume) as pv, sum(CarCount) as cCount, (sum(MeasureCount) + sum(MortarCount)) as mcount,sum(MortarCarCount) as mcCount, sum(MortarCount) as mortarCount, sum(WaterCarCount) as wcCount,0.0 as smcount from ce_erpproductiontask where {0} group by EngineeringBody; ", where);
  989. //DataSet ds = DbHelper.DbConn.ExecuteDataset(str.ToString());
  990. //DataTable dt = ds.Tables[0];
  991. conGridJson(resultDv.Count, Utils.Serialization.JsonString.DataView2MiniAjaxJson(resultDv));
  992. return;
  993. }
  994. conError("错误的参数");
  995. }
  996. public void get_xiu_corpreport()
  997. {
  998. if (UrlPostParmsCheck("stime,etime"))
  999. {
  1000. UserObj uo = GetXiuEntity();
  1001. if (uo == null) return;
  1002. int uid = uo.userid;
  1003. //int cid = GetPostInt("cid");
  1004. string stime = GetPostString("stime");
  1005. string etime = GetPostString("etime");
  1006. DateTime sTime = Convert.ToDateTime(stime);
  1007. DateTime eTime = Convert.ToDateTime(etime);
  1008. List<string> lw = new List<string>();
  1009. lw.Add(" RepairTime>='" + stime + "' and RepairTime<='" + etime + "'");
  1010. lw.Add(" corpid=" + uo.corpid);
  1011. //else
  1012. //lw.Add(" corpid in (" + uo.corpids + ")");
  1013. //if (!uo.isleader) lw.Add("userid=" + uid);
  1014. string where = string.Join(" and ", lw.ToArray());
  1015. // string dis_one_sql = "select id from ce_erpdispatchtask where datediff(d,createtime,'" + dtime + "')=0";
  1016. StringBuilder sql = new StringBuilder();
  1017. sql.AppendFormat("select * from view_xiurecord where {0};", where);
  1018. DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  1019. DataTable pDt = ds.Tables[0];
  1020. if (pDt.Rows.Count < 1)
  1021. {
  1022. conGridJson(0, "[]");
  1023. return;
  1024. }
  1025. DataView pDv = new DataView(pDt);
  1026. DataTable dt = new DataTable();
  1027. dt.Columns.Add(new DataColumn("ctime", typeof(string)));
  1028. dt.Columns.Add(new DataColumn("cname", typeof(string)));
  1029. dt.Columns.Add(new DataColumn("ctime2", typeof(string)));
  1030. dt.Columns.Add(new DataColumn("cid", typeof(string)));
  1031. dt.Columns.Add(new DataColumn("cc", typeof(int)));
  1032. int c = (int)eTime.Subtract(sTime).TotalDays;
  1033. DateTime cTime;
  1034. if (c == 0) c = 1;
  1035. DataRowView drv = null;
  1036. string ct = "";
  1037. List<cplObj> cplLst = new List<cplObj>();
  1038. for (int i = 0; i < c; i++)
  1039. {
  1040. cTime = sTime.AddDays(i);
  1041. DataRow dr = null;
  1042. ct = cTime.ToString("M.d");
  1043. pDv.RowFilter = "RepairTime>='" + cTime.ToString("yyyy-MM-dd") + " 00:00:00' and RepairTime<'" + cTime.AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00'";
  1044. if (pDv.Count < 1) continue;
  1045. cplLst = getCidCount(pDv.ToTable());
  1046. if (cplLst == null || cplLst.Count < 1) continue;
  1047. foreach (cplObj obj in cplLst)
  1048. {
  1049. dr = dt.NewRow();
  1050. dr["ctime"] = ct;
  1051. dr["ctime2"] = cTime.ToString("yyyy-MM-dd");
  1052. dr["cid"] = obj.pid;
  1053. dr["cname"] = obj.pname;
  1054. dr["cc"] = obj.count;
  1055. dt.Rows.Add(dr);
  1056. }
  1057. }
  1058. DataView resultDv = new DataView(dt);
  1059. resultDv.Sort = "ctime asc";
  1060. //AppendScript("reportData=" + JsonString.DataView2MiniAjaxJson(resultDv) + ";");
  1061. //StringBuilder str = new StringBuilder();
  1062. //str.AppendFormat("select EngineeringBody as eb,count(0) as pCount, sum(PlanVolume) as pv, sum(CarCount) as cCount, (sum(MeasureCount) + sum(MortarCount)) as mcount,sum(MortarCarCount) as mcCount, sum(MortarCount) as mortarCount, sum(WaterCarCount) as wcCount,0.0 as smcount from ce_erpproductiontask where {0} group by EngineeringBody; ", where);
  1063. //DataSet ds = DbHelper.DbConn.ExecuteDataset(str.ToString());
  1064. //DataTable dt = ds.Tables[0];
  1065. conGridJson(resultDv.Count, Utils.Serialization.JsonString.DataView2MiniAjaxJson(resultDv));
  1066. return;
  1067. }
  1068. conError("错误的参数");
  1069. }
  1070. public void get_reportdetail()
  1071. {
  1072. UserObj uo = GetXiuEntity();
  1073. if (uo == null) return;
  1074. int uid = uo.userid;
  1075. if (UrlPostParmsCheck("ctime,cid"))
  1076. {
  1077. int cid = GetPostInt("cid");
  1078. string ctime = GetPostString("ctime");
  1079. List<string> lw = new List<string>();
  1080. lw.Add(" RepairTime>='" + ctime + " 00:00:00' and RepairTime<='" + ctime + " 23:59:59'");
  1081. //if (cid > 0) lw.Add(" corpid=" + cid);
  1082. //else
  1083. lw.Add(" corpid =" + cid);
  1084. string where = string.Join(" and ", lw.ToArray());
  1085. StringBuilder sql = new StringBuilder();
  1086. sql.AppendFormat("select id,corpid,corpname,corpuserid,summary as con,imgs,XiuTypeName as typename,addtime,xiutypeid,state,code,title,receivetime,starttime,repairtime,repairsummary as repaircon,repairimgs,suretime,surecon,sureimgs,question,solution,xiuresult,xiulocation as loc from view_xiurecord where {0};", where);
  1087. DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  1088. DataView resultDv = new DataView(ds.Tables[0]);
  1089. resultDv.Sort = "RepairTime asc";
  1090. conGridJson(resultDv.Count, Utils.Serialization.JsonString.DataView2MiniAjaxJson(resultDv));
  1091. return;
  1092. }
  1093. conError("错误的参数");
  1094. }
  1095. private List<cplObj> getCidCount(DataTable disDt)
  1096. {
  1097. var pList = from t in disDt.AsEnumerable()
  1098. group t by new { t1 = t.Field<int>("CorpID"), t2 = t.Field<string>("CorpName") } into v
  1099. select new
  1100. {
  1101. pid=v.Key.t1,
  1102. pname = v.Key.t2,
  1103. count = v.Count()
  1104. };
  1105. List<cplObj> cLst = new List<cplObj>();
  1106. foreach (var p in pList.ToList())
  1107. {
  1108. cplObj co = new cplObj();
  1109. co.pid = p.pid;
  1110. co.count = p.count;
  1111. co.pname = p.pname;
  1112. cLst.Add(co);
  1113. }
  1114. return cLst;
  1115. //return pList.ToList();
  1116. //if (pList.Count() > 0)
  1117. //{
  1118. //
  1119. // count = pList.ToList()[0].count;
  1120. // measure = (double)pList.ToList()[0].mes;
  1121. //}
  1122. }
  1123. #endregion
  1124. #region tiding
  1125. //public void get_modelsms()
  1126. //{
  1127. // int uid = getDecodeInt("uid");
  1128. // if (uid == 0)
  1129. // {
  1130. // conError("找不到会员");
  1131. // return;
  1132. // }
  1133. // string sql = "select typecode,(select count(0) from s_tiding where typecode=b.typecode and touserid=b.touserid and isread=0) as c,(select top 1 con from view_tiding where typecode=b.typecode and touserid=b.touserid order by atime desc) as lcon from view_tiding as b where touserid=" + uid + " group by typecode,touserid";
  1134. // DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1135. // conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  1136. //}
  1137. //public void get_msm()
  1138. //{
  1139. // int uid = getDecodeInt("uid");
  1140. // if (uid == 0)
  1141. // {
  1142. // conError("找不到会员");
  1143. // return;
  1144. // }
  1145. // string sql = "select count(0) from s_tiding where touserid=" + uid + " and isread=0";
  1146. // object result = DbHelper.DbConn.ExecuteScalar(sql);
  1147. // if (result == null) conSuccess("0");
  1148. // else conSuccess(result.ToString());
  1149. // //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1150. // //conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  1151. //}
  1152. public void get_xiusms()
  1153. {
  1154. UserObj uo = GetXiuEntity();
  1155. if (uo == null) return;
  1156. int uid = uo.userid;
  1157. string typecode = GetPostString("typecode");
  1158. DataStruct dStruct = GetPostStruct();
  1159. List<string> lw = new List<string>();
  1160. if (typecode.Length > 0) lw.Add("typecode='" + typecode + "'");
  1161. lw.Add("touserid=" + uid);
  1162. dStruct.Fileds = "id,tid,mainid,typecode,title,con,atime as time,isread";
  1163. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  1164. dStruct.Order = "atime desc";
  1165. DataTable dt = WebCache.GetData("s_xiutiding", dStruct);
  1166. conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  1167. }
  1168. public void read_xiusms()
  1169. {
  1170. UserObj uo = GetXiuEntity();
  1171. if (uo == null) return;
  1172. int uid = uo.userid;
  1173. if (UrlPostParmsCheck("smsids"))
  1174. {
  1175. string smsIds = GetPostString("smsids");
  1176. string sql = "update s_xiutiding set isread=1 where touserid=" + uid + " and id in(" + smsIds + ")";
  1177. SXiuTiding.ExecuteNonQuery(sql);
  1178. conSuccess("消息己读");
  1179. return;
  1180. }
  1181. conError("错误的参数");
  1182. }
  1183. #endregion
  1184. }
  1185. }