| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269 |
- using BizCom;
- using BizCom.Enum;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using SiteCore.Redis;
- using SQLData;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Web;
- using Utils;
- using Utils.ImageUtils;
- namespace SiteCore.Handler
- {
- public partial class app
- {
- #region define
- string xiu_Appid_run = "wx20432512482565e9";//"wxee687601b460ac2f";
- string xiu_Secret_run = "07492bc9cbbc5b303e5e135b4dccd6f0";
- public UserObj GetXiuEntity()
- {
- string session_id = con.Request.Headers["session-id"];
- if (string.IsNullOrEmpty(session_id))
- {
- conLoginError("未授权登录");
- return null;
- }
- try
- {
- UserObj uo = xiuRedis.RedisHelper.StringGet<UserObj>(session_id);
- if (uo == null) {
- conLoginError("请重新登录");
- return null;
- }
- return uo;
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "GetXiuEntity:" + ex.Message);
- conLoginError("请重新登录");
- return null;
- }
- }
- public static object xiuCorpObj = new object();
- public Dictionary<int, string> XiuCorp
- {
- get
- {
- Dictionary<int, string> xiuCorpDics = new Dictionary<int, string>();
- xiuCorpDics = xiuRedis.RedisHelper.StringGet<Dictionary<int, string>>("xiu_corp");
- if (xiuCorpDics == null || xiuCorpDics.Count<1)
- {
- lock (xiuCorpObj)
- {
- xiuCorpDics = new Dictionary<int, string>();
- string sql = "select id,name from s_xiucorp";
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
- foreach (DataRow dr in dt.Rows)
- {
- xiuCorpDics.Add(Convert.ToInt32(dr["id"]), dr["name"].ToString());
- }
- xiuRedis.RedisHelper.StringSet("xiu_corp", xiuCorpDics);
- xiuRedis.RedisHelper.StringSet("xiu_corp_dt",dt);
- }
- }
- return xiuCorpDics;
- }
- }
- public static FrequencyControler xiusaveFrequency = new FrequencyControler("xiusave", 10, 2);
- private string get_openidbycorpperson(int corpid)
- {
- string v = xiuRedis.RedisHelper.StringGet("corpperson_" + corpid);
- if (string.IsNullOrEmpty(v))
- {
- string sql = "select miniopenid from s_xiuuser where charindex('" + corpid + ",',corpids+',')>0";
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
- List<string> lst = new List<string>();
- foreach (DataRow dr in dt.Rows)
- {
- string openid = xiuRedis.RedisHelper.StringGet("gzh_" + dr["miniopenid"].ToString());
- if (!String.IsNullOrEmpty(openid))
- {
- lst.Add(openid);
- }
- }
- if (lst.Count > 0)
- {
- v = string.Join(",", lst.ToArray());
- xiuRedis.RedisHelper.StringSet("corpperson_" + corpid, v, TimeSpan.FromHours(3));
- return v;
- }
- }
- else
- {
- return v;
- }
- return "";
- }
- private string get_openidbycorp(int corpid)
- {
- string v = xiuRedis.RedisHelper.StringGet("corp_" + corpid);
- if (string.IsNullOrEmpty(v))
- {
- string sql = "select miniopenid from s_xiuuser where corpid=" + corpid;
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
- List<string> lst = new List<string>();
- foreach (DataRow dr in dt.Rows)
- {
- string openid = xiuRedis.RedisHelper.StringGet("gzh_" + dr["miniopenid"].ToString());
- if (!String.IsNullOrEmpty(openid))
- {
- lst.Add(openid);
- }
- }
- if (lst.Count > 0)
- {
- v = string.Join(",", lst.ToArray());
- xiuRedis.RedisHelper.StringSet("corp_" + corpid, v, TimeSpan.FromHours(3));
- return v;
- }
- }
- else
- {
- return v;
- }
- return "";
- }
- public void xiu_getpersonbycorp()
- {
- int corpid = GetPostInt("corpid");
- string sql = "select id,lgname as name from s_xiuuser where charindex('" + corpid + ",',corpids+',')>0";
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
- conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- }
- #endregion
- #region user
- public void xiuuser_login()
- {
- if (UrlPostParmsCheck("code"))
- {
- string code = GetPostString("code");
- string uname = GetPostString("uname");
- string pwd = GetPostString("pwd");
- int utype = GetPostInt("utype");
- if (utype <= 0)
- {
- conError("错误参数,无法登录");
- return;
- }
- string nickname = GetPostString("nickname");
- string avatarUrl = GetPostString("avatarUrl");
- int gender = GetPostInt("gender");
- //向微信服务端 使用登录凭证 code 获取 session_key 和 openid
- string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + xiu_Appid_run + "&secret=" + xiu_Secret_run + "&js_code=" + code + "&grant_type=" + grant_type;
- string type = "utf-8";
- string json = GetUrltoHtml(url, type);//获取微信服务器返回字符串
- //微信服务器验证成功
- JObject jo = (JObject)JsonConvert.DeserializeObject(json);
- try
- {
- string openid = jo["openid"].ToString();
- string session_key = jo["session_key"].ToString();
- if (openid == "" || session_key == "")
- {
- conError("无法登录1");
- return;
- }
- pwd = SecurityHelper.EncryptSymmetric(pwd);//加密
- SXiuUser entity = SXiuUser.GetByAcc(uname, pwd, utype);
- if (entity == null)
- {
- conError("账号或密码错误");
- return;
- }
- if (entity.State == 2)
- {
- conError("该账号已被禁用");
- return;
- }
- //if (entity.miniopenid != "" && entity.miniopenid != openid)
- //{
- // conError("该账号已绑定一个微信,如要使用请先解绑!");
- // return;
- //}
- entity.miniopenid = openid;
- //entity.openid = openid;
- entity.Sex = gender;
- entity.NickName = nickname;
- if (avatarUrl != "")
- {
- Thread oThread = new Thread(delegate ()
- {
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- KeepAlive = true,
- Accept = "image/webp,image/*,*/*;q=0.8",
- URL = avatarUrl,
- ResultType = ResultType.Byte
- };
- HttpResult hResult = http.GetHtml(item);
- using (MemoryStream ms = new MemoryStream(hResult.ResultByte))
- {
- Bitmap bm = new Bitmap(ms);
- //Graphics g = Graphics.FromImage(bm);//实例一个画板的对象,就用上面的图像的画板
- //g.DrawImage(bm, 0, 0);
- bm.Save(webConfig.xiuUserPicPath + "\\b\\" + entity.ID + ".jpg", ImageFormat.Jpeg);
- using (System.Drawing.Image imgThumb = System.Drawing.Image.FromStream(ms))
- {
- ImageMaker.ToThumbnailImages(imgThumb, webConfig.xiuUserPicPath + "\\" + entity.ID + ".jpg", 100, "", 9, 3);
- //result = ImageMaker.ToThumbnailImages(imgThumb, saveFile, 600, "", 9, 3);
- }
- //bm.Save(webConfig.userPicPath + "\\" + entity.ID + ".jpg", ImageFormat.Jpeg);
- }
- });
- oThread.Start();
- }
- entity.UserPic = entity.ID + ".jpg";
- entity.Update();
- //string session_id = "svr_" + sid + "_" + con.Session.SessionID;
- //封装成对象
- string session_id = "svr_" +con.Session.SessionID;
- UserObj uObj = new UserObj()
- {
- session_id = session_id,
- openid = openid,
- userid = entity.ID,
- corpid = entity.CorpID,
- realname=entity.RealName,
- username = entity.lgName,
- isleader=entity.isLeader,
- corpids = entity.CorpIDs
- };
- Dictionary<int, string> xiuCorpDics = new Dictionary<int, string>();
- xiuCorpDics = XiuCorp;
- if (xiuCorpDics.ContainsKey(entity.CorpID))
- {
- uObj.cname = xiuCorpDics[entity.CorpID];
- }
- xiuRedis.RedisHelper.StringSet(session_id, JsonConvert.SerializeObject(uObj));
- //存储openid
- //xiuRedis.RedisHelper.StringSet("user_" + ukey, "1");
- string gzh_openid = xiuRedis.RedisHelper.StringGet("gzh_" + uObj.openid);
- bool isgzh = false;
- if (gzh_openid != null && gzh_openid != "")
- {
- isgzh = true;
- }
- else
- {
- xiuRedis.RedisHelper.StringSet("gzh_" + session_id, uObj.openid);
- }
- //存入内存中
- //xiuRedis.RedisHelper.StringSet(session_id, JsonConvert.SerializeObject(uObj));
- //xiuRedis.RedisHelper.StringSet(entity.ID.ToString(), session_id);
- //返回数据给小程序
- StringBuilder userStr = new StringBuilder();
- userStr.Append("{");
- userStr.AppendFormat("\"session2\":\"{0}\"", session_id);
- //userStr.AppendFormat(",\"userpic\":\"{0}\"", entity.UserPic);
- userStr.AppendFormat(",\"username\":\"{0}\"", entity.lgName);
- userStr.AppendFormat(",\"realname\":\"{0}\"", entity.RealName);
- if (uObj.cname!="") userStr.AppendFormat(",\"corpname\":\"{0}\"", uObj.cname);
- else userStr.Append(",\"corpname\":\"\"");
- userStr.AppendFormat(",\"gzh\":\"{0}\"", isgzh ? "1" : "0");
- userStr.AppendFormat(",\"il\":\"{0}\"", entity.isLeader ? "1" : "0");
- userStr.Append("}");
- conSuccess("登录成功", userStr.ToString());
- return;
- }
- catch (Exception ex)
- {
- //微信服务器验证失败
- //string msg = jo["errcode"].ToString() + "," + jo["errmsg"].ToString();
- conError("暂时无法登录");
- }
- return;
- }
- conError("错误的参数");
- }
- public void xiuuser_loginout()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- xiuRedis.RedisHelper.KeyDelete(uo.session_id);
- //erpRedis.RedisHelper.KeyDelete("pms_" + uo.siteid + "_" + uo.pcode);
- conSuccess("注销成功!");
- //SXiuUser entity = SXiuUser.Get(uid);
- //if (entity != null)
- //{
- // entity.miniopenid = "";
- // //entity.UserName = "";
- // entity.Update();
- // xiuRedis.RedisHelper.KeyDelete(uo.session_id);
- //}
- //conSuccess("登出");
- }
- public void xiuuser_updpwd()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("opwd,npwd"))
- {
- string opwd = GetPostString("opwd");
- string npwd = GetPostString("npwd");
- if (opwd == npwd)
- {
- conError("密码相同不能修改!");
- return;
- }
- SXiuUser entity = SXiuUser.GetByID(uid, SecurityHelper.EncryptSymmetric(opwd));
- if (entity != null)
- {
- entity.lgPwd = SecurityHelper.EncryptSymmetric(npwd);
- entity.Update();
- conSuccess("修改成功!");
- return;
- }
- else
- {
- conError("原密码不正确!");
- return;
- }
- }
- conError("无法修改密码!");
- }
- #endregion
- public void get_xiurecord_detail()
- {
- //UserObj uo = GetXiuEntity();
- //if (uo == null) return;
- //int uid = uo.userid;
- //if (UrlPostParmsCheck("rid"))
- //{
- // int rid = GetPostInt("rid");
- // 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";
- // string sql = "select fields from s_xiurecord where id=" + rid;
- // DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
- //}
- }
-
- #region 企业操作
- /// <summary>
- /// 企业获取维护记录
- /// </summary>
- public void xiu_getcorprecord()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- //int uid = uo.userid;
- DataStruct dStruct = GetPostStruct();
- List<string> lw = new List<string>();
- //lw.Add("(corpuserid=" + uo.userid + " or sureuserid=" + uo.userid + ")");
- lw.Add("corpid=" + uo.corpid);
- int st = GetPostInt("st");
- if (st > 0)
- {
- switch (st)
- {
- case 1:
- {
- lw.Add("state= " + (int)XiuState.None);
- break;
- }
- case 2:
- {
- lw.Add("state= " + (int)XiuState.Sure);
- break;
- }
- case 3:
- {
- lw.Add("state> " + (int)XiuState.Sure + " and state<" + (int)XiuState.Finish);
- break;
- }
- case 4:
- {
- lw.Add("state= " + (int)XiuState.Finish);
- break;
- }
- case 5:
- {
- lw.Add("state= " + (int)XiuState.Apply);
- break;
- }
- }
- }
- 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";
- dStruct.Order = "UpdTime desc";
- dStruct.MainWhere = string.Join(" and ", lw.ToArray());
- DataTable dt = WebCache.GetData("view_xiurecord", dStruct);
- conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- }
- /// <summary>
- /// 企业删除维护单
- /// </summary>
- public void xiu_corp_delrecord()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("rid"))
- {
- int rid = GetPostInt("rid");
- SXiuRecord entity = SXiuRecord.GetByCorp(rid, uo.corpid, uid);
- if (entity.State < 1)
- {
- entity.Delete();
- //通知删除
- conSuccess("已删除!");
- }
- return;
- }
- conError("错误的参数");
- }
- /// <summary>
- /// 企业发布维护
- /// </summary>
- public void xiu_corp_insrecord()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- //aid,
- //ainfo,
- if (UrlPostParmsCheck("tid,con"))
- {
- int rid = GetPostInt("rid");
- SXiuRecord entity = null;
- if (rid > 0) entity = SXiuRecord.GetByCorp(rid,uo.corpid,uid);
- else entity = new SXiuRecord();
- //GenerateOutTradeNo
- //int aid = GetPostInt("aid");
- int tid = GetPostInt("tid");
- string title = GetPostString("title");
- string con = GetPostString("con");
- con = con.Replace("\r\n", "<br>").Replace("\n", "<br>");
- con = con.Replace(" ", " ");
- string images = GetPostString("images").TrimEnd(',');
- string loc = GetPostString("loc");
- //entity.AddressID = aid;
- entity.CorpID = uo.corpid;
- //entity.XiuTypeID = tid;
- entity.CorpUserID = uid;
- entity.Title = title;
- entity.Summary = con;
- entity.XiuLocation = loc;
- //entity.AddressInfo = GetPostString("ainfo");
- entity.Imgs = images;
- //entity.XiuTypeInfo = GetPostString("xtinfo");
- if (rid > 0) entity.Update();
- else
- {
- entity.AddTime = DateTime.Now;
- entity.UpdTime = DateTime.Now;
- entity.Code = GenerateOutTradeNo("");
- entity.Create();
- }
- conSuccess("操作成功!");
- return;
- }
- conError("无法提交");
- }
- /// <summary>
- /// 企业确认通知维护
- /// </summary>
- public void xiu_corp_surerecord()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("rid"))
- {
- int rid = GetPostInt("rid");
- SXiuRecord entity = SXiuRecord.GetByCorp(rid, uo.corpid, uid);
- if (entity != null)
- {
- entity.State = 1;
- entity.AddTime = DateTime.Now;
- entity.UpdTime = DateTime.Now;
- entity.Update();
- //这里需要加入通知
- WxPush.sendXiuPersonMsg(get_openidbycorpperson(uo.corpid), uo.cname, entity.Title, "发起人:"+uo.realname);
-
- conSuccess("操作成功!");
- return;
- }
- }
- conError("错误的参数");
- }
- /// <summary>
- /// 企业负责人确认签收维护完成
- /// </summary>
- public void xiu_applyrecord()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("rid"))
- {
- int rid = GetPostInt("rid");
- string scon = GetPostString("scon");
- if (scon.Length > 0)
- {
- scon = scon.Replace("\r\n", "<br>").Replace("\n", "<br>");
- scon = scon.Replace(" ", " ");
- }
- string simg = GetPostString("simg");
- SXiuRecord entity = SXiuRecord.GetCorp(rid, uo.corpid);
- if (entity != null)
- {
- entity.State = (int)XiuState.Apply;
- entity.SureImgs = simg;
- entity.SureCon = scon;
- entity.SureTime = DateTime.Now;
- entity.UpdTime = DateTime.Now;
- entity.SureUserID = uid;
- entity.Update();
- //加入通知维护人员
- conSuccess("操作成功!");
- return;
- }
- }
- conError("错误的参数或找不到记录");
- }
- #endregion
- #region 维护人员
-
- /// <summary>
- /// 维护人员发起维护
- /// </summary>
- public void xiu_insrecord()
- {
- //if (xiusaveFrequency.IsTooFrequently(true))
- //{
- // conError("访问太频繁!");
- // return;
- //}
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- //aid,
- //ainfo,
- if (UrlPostParmsCheck("cid,tid"))
- {
- int rid = GetPostInt("rid");
- int cid = GetPostInt("cid");
- SXiuRecord entity = null;
- if (rid > 0) entity = SXiuRecord.Get(rid, uid);
- else entity = new SXiuRecord();
- //GenerateOutTradeNo
- //int aid = GetPostInt("aid");
- int tid = GetPostInt("tid");
- //string title = GetPostString("title");
- string con = GetPostString("repaircon");
- con = con.Replace("\r\n", "<br>").Replace("\n", "<br>");
- con = con.Replace(" ", " ");
- string loc = GetPostString("loc");
- string images = GetPostString("images").TrimEnd(',');
- //entity.AddressID = aid;
- entity.XiuTypeID = tid;
- entity.UserID = uid;
- entity.XiuLocation = loc;
- entity.Question = GetPostString("question");
- entity.Solution = GetPostString("solution");
- entity.XiuResult = GetPostString("result");
- entity.RepairSummary = con;
- entity.RepairImgs = images;
- //entity.Title = title;
- //entity.Summary = con;
- //entity.AddressInfo = GetPostString("ainfo");
- //entity.Imgs = images;
- entity.State = (int)XiuState.Ing;
- //entity.XiuTypeInfo = GetPostString("xtinfo");
- if (rid > 0) entity.Update();
- else {
- entity.CorpID = cid;
- entity.AddTime = DateTime.Now;
- entity.StartTime = DateTime.Now;
- entity.ReceiveTime = DateTime.Now;
- entity.UpdTime = DateTime.Now;
- entity.Code = GenerateOutTradeNo("");
- entity.Create();
- }
- //通知
- conSuccess("操作成功!");
- return;
- }
- conError("无法提交");
- }
- /// <summary>
- /// 维护人员删除维护单
- /// </summary>
- public void xiu_delrecord()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("rid"))
- {
- int rid = GetPostInt("rid");
- SXiuRecord entity = SXiuRecord.Get(rid, uid);
- if (entity.State < 2)
- {
- entity.Delete();
- }
- conSuccess("已删除!");
- return;
- }
- conError("错误的参数");
- }
- /// <summary>
- /// 开始维护
- /// </summary>
- public void xiu_ingrecord()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("rid"))
- {
- int rid = GetPostInt("rid");
- SXiuRecord entity = SXiuRecord.Get(rid, uid);
- if (entity == null)
- {
- conError("找不到该记录");
- return;
- }
- entity.StartTime = DateTime.Now;
- entity.UpdTime = DateTime.Now;
- entity.State = (int)XiuState.Ing;
- entity.Update();
- conSuccess("开始维护...");
- return;
- }
- }
- /// <summary>
- /// 受理维护
- /// </summary>
- public void xiu_receiverecord()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("cid,rid"))
- {
- int cid = GetPostInt("cid");
- int rid = GetPostInt("rid");
- SXiuRecord entity = SXiuRecord.GetCorp(rid,cid);
- if (entity != null)
- {
- entity.State = (int)XiuState.Receive;
- entity.ReceiveTime = DateTime.Now;
- entity.UpdTime = DateTime.Now;
- entity.UserID = uid;
- entity.Update();
- WxPush.sendXiuCorpMsg(get_openidbycorp(uo.corpid), "售后维护", "已受理", "您的单据已被受理");
- //这里需要加入通知
- conSuccess("操作成功!");
- return;
- }
- }
- conError("错误的参数");
- }
- /// <summary>
- /// 负责人派发给指定维护人员
- /// </summary>
- public void xiu_pairecord()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("cid,rid,tuid"))
- {
- int cid = GetPostInt("cid");
- int rid = GetPostInt("rid");
- int tuid = GetPostInt("tuid");
- SXiuRecord entity = SXiuRecord.GetCorp(rid, cid);
- if (entity != null)
- {
- entity.State = (int)XiuState.Receive;
- entity.ReceiveTime = DateTime.Now;
- entity.UpdTime = DateTime.Now;
- entity.UserID = tuid;
- entity.Update();
- //这里需要加入通知
- conSuccess("操作成功!");
- return;
- }
- }
- conError("错误的参数");
- }
- /// <summary>
- /// 维护人员完成维护
- /// </summary>
- public void xiu_finishrecord()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("rid"))
- {
- int rid = GetPostInt("rid");
- //string con = GetPostString("con");
- //if (con.Length > 0)
- //{
- // con = con.Replace("\r\n", "<br>").Replace("\n", "<br>");
- // con = con.Replace(" ", " ");
- //}
- //string imgs = GetPostString("imgs");
- SXiuRecord entity = SXiuRecord.Get(rid, uid);
- if (entity != null)
- {
- entity.State = (int)XiuState.Finish;
- //entity.RepairImgs = imgs;
- //entity.RepairSummary = con;
- entity.RepairTime = DateTime.Now;
- entity.UpdTime = DateTime.Now;
- entity.OpUserID = uid;
- entity.Update();
- //加入通知企业
- conSuccess("操作成功!");
- return;
- }
- }
- conError("错误的参数或找不到记录");
- }
- /// <summary>
- /// 获取维护人员关联的企业
- /// </summary>
- public void xiu_getusercorp()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- DataTable udt= xiuRedis.RedisHelper.StringGet<DataTable>(uo.userid+"_crops");
- if (udt == null || udt.Rows.Count < 1)
- {
- string sql = "select id,name from s_xiucorp where id in(" + uo.corpids + ")";
- udt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
- if (udt != null && udt.Rows.Count > 0) xiuRedis.RedisHelper.StringSet(uo.userid + "_crops", udt);
- }
- conGridJson(udt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(udt));
- }
- /// <summary>
- /// 获取用户维护记录
- /// </summary>
- public void xiu_getuserrecord()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- DataStruct dStruct = GetPostStruct();
- List<string> lw = new List<string>();
- //lw.Add("sureuserid=" + uid);
- string cids = GetPostString("cid");
- if (cids.Length > 0) lw.Add(" CorpID in (" + cids + ")");
- int st = GetPostInt("st");
- if (uo.isleader)
- {
- if (st > 0)
- {
- switch (st)
- {
- case 1:
- {
- lw.Add("(corpid in (" + uo.corpids + ") and state= " + (int)XiuState.Sure + ")");
- break;
- }
- case 2:
- {
- lw.Add("((corpid in (" + uo.corpids + ") and state= " + (int)XiuState.Receive + ")");
- break;
- }
- case 3:
- {
- lw.Add("((corpid in (" + uo.corpids + ") and state>" + (int)XiuState.Receive + " and state<" + (int)XiuState.Finish + ")");
- break;
- }
- case 4:
- {
- lw.Add("((corpid in (" + uo.corpids + ") and state>= " + (int)XiuState.Finish + ")");
- break;
- }
- }
- }
- else
- {
- lw.Add("(corpid in (" + uo.corpids + ") and state>= " + (int)XiuState.Sure + ")");
- }
- }
- else
- {
- if (st > 0)
- {
- switch (st)
- {
- case 1:
- {
- lw.Add("(userid=" + uid + " and state= " + (int)XiuState.Sure + ")");
- break;
- }
- case 2:
- {
- lw.Add("(userid=" + uid + " and state= " + (int)XiuState.Receive + ")");
- break;
- }
- case 3:
- {
- lw.Add("(userid=" + uid + " and state>" + (int)XiuState.Receive + " and state<" + (int)XiuState.Finish + ")");
- break;
- }
- case 4:
- {
- lw.Add("(userid=" + uid + " and state>= " + (int)XiuState.Finish + ")");
- break;
- }
- }
- }
- else
- {
- lw.Add("(userid=" + uid + " or (userid=0 and state>= " + (int)XiuState.Sure + "))");
- }
- }
- 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";
- dStruct.Order = "UpdTime desc";
- dStruct.MainWhere = string.Join(" and ", lw.ToArray());
-
- //string sql = "select from s_xiurecord where userid=" + uid + " and corpid=" + uo.cid + " order by id desc";
- //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
- DataTable dt = WebCache.GetData("view_xiurecord", dStruct);
- conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- }
- #endregion
-
- #region private
- public void xiu_gettype()
- {
- string sql = "select id,parentid as pid,name,code from s_xiutype order by sort";
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
- conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- }
- public void upload_xiu_imgs()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- string tag = GetPostString("tag");
- HttpPostedFile postFile = null;
- List<string> lstFile = new List<string>();
- int c = con.Request.Files.Count;
- if (c > 0)
- {
- for (int i = 0; i < c; i++)
- {
- string errMsg = "";
- postFile = con.Request.Files[i];
- if (!ImageHandler.CheckImage(postFile, out errMsg))
- {
- conError(errMsg);
- return;
- }
- string fileName = uid + DateTime.Now.ToFileTimeUtc() + ".jpg";
- string sourceExt = Path.GetExtension(postFile.FileName);
- if (sourceExt == ".gif")
- {
- fileName = uid + DateTime.Now.ToFileTimeUtc() + ".gif";
- postFile.SaveAs(webConfig.xiuPath + "\\" + fileName);
- }
- else
- {
- string saveFile = Path.Combine(webConfig.xiuPath, fileName);
- string result = "";
- using (System.Drawing.Image imgThumb = System.Drawing.Image.FromStream(postFile.InputStream))
- {
- result = ImageMaker.ToThumbnailImages(imgThumb, saveFile, 800, "", 9, 3);
- }
- }
- lstFile.Add(fileName);
- }
- }
- string fs = "";
- if (lstFile.Count > 0) fs = string.Join(",", lstFile.ToArray());
- conSuccess("上传成功", "{\"fname\":\"" + fs + "\"}");
- }
- #endregion
- #region report
- public void xiu_getmaininfo()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- StringBuilder sql = new StringBuilder();
- if (uo.isleader)
- {
- sql.AppendFormat("select (select count(0) from s_xiurecord where corpuserid>0 and corpid in ({0}) and state=1) as dsl, ", uo.corpids);
- sql.AppendFormat("(select count(0) from s_xiurecord where corpid in ({0}) and state>1 and state<4) as whz,", uo.corpids);
- sql.AppendFormat("(select count(0) from s_xiurecord where corpid in ({0}) and state=4) as dys", uo.corpids);
- }
- else
- {
- sql.AppendFormat("select (select count(0) from s_xiurecord where corpuserid>0 and corpid in ({0}) and state=1) as dsl, ", uo.corpids);
- sql.AppendFormat("(select count(0) from s_xiurecord where userid={0} and state>1 and state<4) as whz,", uid);
- sql.AppendFormat("(select count(0) from s_xiurecord where userid={0} and state=4) as dys", uid);
- }
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
- conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- }
- public void xiu_corp_getmaininfo()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select (select count(0) from s_xiurecord where corpid={0} and corpuserid={1} and state<1) as dsl, ", uo.corpid, uo.userid);
- sql.AppendFormat("(select count(0) from s_xiurecord where corpid={0} and state>1 and state<4) as whz,", uo.corpid);
- sql.AppendFormat("(select count(0) from s_xiurecord where corpid={0} and state=4) as dys", uo.corpid);
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
- conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- }
- public void get_xiu_userreport()
- {
- if (UrlPostParmsCheck("stime,etime"))
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- //int cid = GetPostInt("cid");
- string stime = GetPostString("stime");
- string etime = GetPostString("etime");
- DateTime sTime = Convert.ToDateTime(stime);
- DateTime eTime = Convert.ToDateTime(etime);
- List<string> lw = new List<string>();
- lw.Add(" RepairTime>='" + stime + "' and RepairTime<='" + etime+"'");
- //if (cid > 0) lw.Add(" corpid=" + cid);
- //else
- lw.Add(" corpid in (" + uo.corpids + ")");
- if (!uo.isleader) lw.Add("userid=" + uid);
- string where = string.Join(" and ", lw.ToArray());
- // string dis_one_sql = "select id from ce_erpdispatchtask where datediff(d,createtime,'" + dtime + "')=0";
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select * from view_xiurecord where {0};", where);
- DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
- DataTable pDt = ds.Tables[0];
- if (pDt.Rows.Count < 1)
- {
- conGridJson(0, "[]");
- return;
- }
- DataView pDv = new DataView(pDt);
- DataTable dt = new DataTable();
- dt.Columns.Add(new DataColumn("ctime", typeof(string)));
- dt.Columns.Add(new DataColumn("ctime2", typeof(string)));
- dt.Columns.Add(new DataColumn("cid", typeof(string)));
- dt.Columns.Add(new DataColumn("cname", typeof(string)));
- dt.Columns.Add(new DataColumn("cc", typeof(int)));
- int c = (int)eTime.Subtract(sTime).TotalDays;
- DateTime cTime;
- if (c == 0) c = 1;
- string ct = "";
- List<cplObj> cplLst = new List<cplObj>();
- for (int i = 0; i < c; i++)
- {
- cTime = sTime.AddDays(i);
- DataRow dr = null;
- ct = cTime.ToString("M.d");
- pDv.RowFilter = "RepairTime>='" + cTime.ToString("yyyy-MM-dd") + " 00:00:00' and RepairTime<'" + cTime.AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00'";
- if (pDv.Count < 1) continue;
- cplLst = getCidCount(pDv.ToTable());
- if (cplLst == null || cplLst.Count < 1) continue;
- foreach (cplObj obj in cplLst)
- {
- dr = dt.NewRow();
- dr["ctime"] = ct;
- dr["ctime2"] = cTime.ToString("yyyy-MM-dd");
- dr["cid"] = obj.pid;
- dr["cname"] =obj.pname;
- dr["cc"] = obj.count;
- dt.Rows.Add(dr);
- }
- }
- DataView resultDv = new DataView(dt);
- resultDv.Sort = "ctime asc";
- //AppendScript("reportData=" + JsonString.DataView2MiniAjaxJson(resultDv) + ";");
- //StringBuilder str = new StringBuilder();
- //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);
- //DataSet ds = DbHelper.DbConn.ExecuteDataset(str.ToString());
- //DataTable dt = ds.Tables[0];
- conGridJson(resultDv.Count, Utils.Serialization.JsonString.DataView2MiniAjaxJson(resultDv));
- return;
- }
- conError("错误的参数");
- }
- public void get_xiu_corpreport()
- {
- if (UrlPostParmsCheck("stime,etime"))
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- //int cid = GetPostInt("cid");
- string stime = GetPostString("stime");
- string etime = GetPostString("etime");
- DateTime sTime = Convert.ToDateTime(stime);
- DateTime eTime = Convert.ToDateTime(etime);
- List<string> lw = new List<string>();
- lw.Add(" RepairTime>='" + stime + "' and RepairTime<='" + etime + "'");
- lw.Add(" corpid=" + uo.corpid);
- //else
- //lw.Add(" corpid in (" + uo.corpids + ")");
- //if (!uo.isleader) lw.Add("userid=" + uid);
- string where = string.Join(" and ", lw.ToArray());
- // string dis_one_sql = "select id from ce_erpdispatchtask where datediff(d,createtime,'" + dtime + "')=0";
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select * from view_xiurecord where {0};", where);
- DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
- DataTable pDt = ds.Tables[0];
- if (pDt.Rows.Count < 1)
- {
- conGridJson(0, "[]");
- return;
- }
- DataView pDv = new DataView(pDt);
- DataTable dt = new DataTable();
- dt.Columns.Add(new DataColumn("ctime", typeof(string)));
- dt.Columns.Add(new DataColumn("cname", typeof(string)));
- dt.Columns.Add(new DataColumn("ctime2", typeof(string)));
- dt.Columns.Add(new DataColumn("cid", typeof(string)));
- dt.Columns.Add(new DataColumn("cc", typeof(int)));
- int c = (int)eTime.Subtract(sTime).TotalDays;
- DateTime cTime;
- if (c == 0) c = 1;
- DataRowView drv = null;
- string ct = "";
- List<cplObj> cplLst = new List<cplObj>();
- for (int i = 0; i < c; i++)
- {
- cTime = sTime.AddDays(i);
- DataRow dr = null;
- ct = cTime.ToString("M.d");
- pDv.RowFilter = "RepairTime>='" + cTime.ToString("yyyy-MM-dd") + " 00:00:00' and RepairTime<'" + cTime.AddDays(1).ToString("yyyy-MM-dd") + " 00:00:00'";
- if (pDv.Count < 1) continue;
- cplLst = getCidCount(pDv.ToTable());
- if (cplLst == null || cplLst.Count < 1) continue;
- foreach (cplObj obj in cplLst)
- {
- dr = dt.NewRow();
- dr["ctime"] = ct;
- dr["ctime2"] = cTime.ToString("yyyy-MM-dd");
- dr["cid"] = obj.pid;
- dr["cname"] = obj.pname;
- dr["cc"] = obj.count;
- dt.Rows.Add(dr);
- }
- }
- DataView resultDv = new DataView(dt);
- resultDv.Sort = "ctime asc";
- //AppendScript("reportData=" + JsonString.DataView2MiniAjaxJson(resultDv) + ";");
- //StringBuilder str = new StringBuilder();
- //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);
- //DataSet ds = DbHelper.DbConn.ExecuteDataset(str.ToString());
- //DataTable dt = ds.Tables[0];
- conGridJson(resultDv.Count, Utils.Serialization.JsonString.DataView2MiniAjaxJson(resultDv));
- return;
- }
- conError("错误的参数");
- }
- public void get_reportdetail()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("ctime,cid"))
- {
- int cid = GetPostInt("cid");
- string ctime = GetPostString("ctime");
- List<string> lw = new List<string>();
- lw.Add(" RepairTime>='" + ctime + " 00:00:00' and RepairTime<='" + ctime + " 23:59:59'");
- //if (cid > 0) lw.Add(" corpid=" + cid);
- //else
- lw.Add(" corpid =" + cid);
- string where = string.Join(" and ", lw.ToArray());
- StringBuilder sql = new StringBuilder();
- 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);
- DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
- DataView resultDv = new DataView(ds.Tables[0]);
- resultDv.Sort = "RepairTime asc";
- conGridJson(resultDv.Count, Utils.Serialization.JsonString.DataView2MiniAjaxJson(resultDv));
- return;
- }
- conError("错误的参数");
- }
- private List<cplObj> getCidCount(DataTable disDt)
- {
- var pList = from t in disDt.AsEnumerable()
- group t by new { t1 = t.Field<int>("CorpID"), t2 = t.Field<string>("CorpName") } into v
- select new
- {
- pid=v.Key.t1,
- pname = v.Key.t2,
- count = v.Count()
- };
- List<cplObj> cLst = new List<cplObj>();
- foreach (var p in pList.ToList())
- {
- cplObj co = new cplObj();
- co.pid = p.pid;
- co.count = p.count;
- co.pname = p.pname;
- cLst.Add(co);
- }
- return cLst;
- //return pList.ToList();
- //if (pList.Count() > 0)
- //{
- //
- // count = pList.ToList()[0].count;
- // measure = (double)pList.ToList()[0].mes;
- //}
- }
- #endregion
- #region tiding
- //public void get_modelsms()
- //{
- // int uid = getDecodeInt("uid");
- // if (uid == 0)
- // {
- // conError("找不到会员");
- // return;
- // }
- // 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";
- // DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
- // conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- //}
- //public void get_msm()
- //{
- // int uid = getDecodeInt("uid");
- // if (uid == 0)
- // {
- // conError("找不到会员");
- // return;
- // }
- // string sql = "select count(0) from s_tiding where touserid=" + uid + " and isread=0";
- // object result = DbHelper.DbConn.ExecuteScalar(sql);
- // if (result == null) conSuccess("0");
- // else conSuccess(result.ToString());
- // //DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
- // //conGridJson(dt.Rows.Count, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- //}
- public void get_xiusms()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- string typecode = GetPostString("typecode");
- DataStruct dStruct = GetPostStruct();
- List<string> lw = new List<string>();
- if (typecode.Length > 0) lw.Add("typecode='" + typecode + "'");
- lw.Add("touserid=" + uid);
- dStruct.Fileds = "id,tid,mainid,typecode,title,con,atime as time,isread";
- dStruct.MainWhere = string.Join(" and ", lw.ToArray());
- dStruct.Order = "atime desc";
- DataTable dt = WebCache.GetData("s_xiutiding", dStruct);
- conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- }
- public void read_xiusms()
- {
- UserObj uo = GetXiuEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("smsids"))
- {
- string smsIds = GetPostString("smsids");
- string sql = "update s_xiutiding set isread=1 where touserid=" + uid + " and id in(" + smsIds + ")";
- SXiuTiding.ExecuteNonQuery(sql);
- conSuccess("消息己读");
- return;
- }
- conError("错误的参数");
- }
- #endregion
- }
- }
|