using dccdc.Models; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; using System.Web; using System.Web.Mvc; namespace dccdc.Controllers { public class OAController : Controller { // GET: OA public ActionResult Index() { return View(); } public ActionResult selectDepts() { return View(); } [HttpPost] public string getKSList(string selected, string ksmc) { DAL.OA oa = new DAL.OA(); var list = oa.getKSlist(selected, ksmc); return Newtonsoft.Json.JsonConvert.SerializeObject(list); } //getSelKSList [HttpPost] public string getSelKSList(string selected) { DAL.OA oa = new DAL.OA(); var list = oa.getSelKSlist(selected); return Newtonsoft.Json.JsonConvert.SerializeObject(list); } public ActionResult selectRY() { return View(); } [HttpPost] public string getRYList(string ksOneself, string selected, string key) { string where = "1=1"; int ksid = 49; if (!string.IsNullOrEmpty(ksOneself)) //当前科室 { var user = Session["loginUser"] as Models.ERPUser; ksid = user.ksid; } where += " and b.id in " + getChildrenKsid(ksid); if (!string.IsNullOrEmpty(selected)) where += " and a.id not in (" + selected + ")"; if (!string.IsNullOrEmpty(key)) where += " and a.truename like '%" + key + "%'"; DAL.ERPUserDal dal = new DAL.ERPUserDal(); var list = dal.GetUserDepart(where); return Newtonsoft.Json.JsonConvert.SerializeObject(list); } [HttpPost] public string getSelRYList(string selected) { string where = ""; if (!string.IsNullOrEmpty(selected)) where = "a.id in (" + selected + ")"; DAL.ERPUserDal dal = new DAL.ERPUserDal(); var list = dal.GetUserDepart(where); return Newtonsoft.Json.JsonConvert.SerializeObject(list); } //得到所有子科室id private string getChildrenKsid(int ksid) { var bll = new BLL.ERPBuMenBll(); List result = bll.GetAllChildren(ksid.ToString()); string result2 = string.Join(",", result); return " (" + result2 + ")"; } //网盘接口 获取用户与部门 [AllowAnonymous] public string getWpUser(string key) { string where = ""; if (!string.IsNullOrEmpty(key)) where = "a.truename like '%" + key + "%' or a.department like '%" + key + "%'"; DAL.ERPUserDal dal = new DAL.ERPUserDal(); var list = dal.GetUserDepart(where); return Newtonsoft.Json.JsonConvert.SerializeObject(list); } [AllowAnonymous] public string getWpUserone(string id) { string where = "1=2"; if (!string.IsNullOrEmpty(id)) where = "a.id =" + id; DAL.ERPUserDal dal = new DAL.ERPUserDal(); var list = dal.GetUserDepart(where); return Newtonsoft.Json.JsonConvert.SerializeObject(list); } //新分享 新邮件 通知接口 [AllowAnonymous] public string sentMessage(string message, string ids) { var bll = new ERPUserBll(); string sql = "select * from ERPUser where id in (" + ids + ")"; List models = bll.getOpenids(sql); try { int success = 0; foreach (ERPUser model in models) { if (!string.IsNullOrEmpty(model.Openid)) { string template_id = "Pa3LFO_jV4z4mbFyMtGVbI6warV7CFbCatGtLVgAqDY"; string token = dccdc.Common.Global.getAccessTokenYM.access_token; var data = new { touser = model.Openid, template_id = template_id, url = "http://dc.51csharp.com/default.aspx?tjlogout=ok&yhid=" + model.ID.ToString(), data = new { first = new { value = "新消息", color = "#173177" }, keyword1 = new { value = "", color = "#173177" }, keyword2 = new { value = "", color = "#173177" }, keyword3 = new { value = "", color = "#173177" }, remark = new { value = "", color = "#173177" }, } }; WebClient wc = new WebClient(); byte[] responseBytes = wc.UploadData("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(data))); string responseText = System.Text.Encoding.UTF8.GetString(responseBytes); success++; } } return success.ToString(); } catch (Exception ex) { return "error:" + ex.Message; } } } }