using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.Mvc; using WX.CRM.Common; using WX.CRM.IBLL.Csvr; using WX.CRM.IBLL.Sms; using WX.CRM.IBLL.Util; using WX.CRM.Model.Entity; using WX.CRM.Model.Enum; using WX.CRM.Model.QueryMap; using WX.CRM.WEB.Controllers; using WX.CRM.WebHelper; namespace WX.CRM.WEB.Areas.SMS.Controllers { public class MsgTemplateController : BaseController { private readonly ISMS_MSGTEMPLATE _smsMsgtemplate; private readonly ISMS_MSGTEMPLATE_Q _smsMsgtemplateQ; private readonly ISMS_MSGSUBTYPE_Q _smsMsgsubtypeQ; private ICSVR_BLACKNUMBER_Q _blacknumberq; private readonly ISecurityHelper sHelper; private readonly ICACHE_Q cacheQ; private ValidationErrors errors = new ValidationErrors(); public MsgTemplateController(ISMS_MSGTEMPLATE smsMsgtemplate, ISMS_MSGTEMPLATE_Q smsMsgtemplateQ, ISMS_MSGSUBTYPE_Q smsMsgsubtypeQ, ICSVR_BLACKNUMBER_Q blacknumberq, ISecurityHelper _sHelper, ICACHE_Q _cacheQ) { this._smsMsgtemplate = smsMsgtemplate; this._smsMsgtemplateQ = smsMsgtemplateQ; this._smsMsgsubtypeQ = smsMsgsubtypeQ; this._blacknumberq = blacknumberq; this.sHelper = _sHelper; this.cacheQ = _cacheQ; } [AuthorizeRedirect(Roles = InitRights.CONST_短信模板)] public ActionResult Index() { ToolBar tool = new ToolBar(); string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.短信模板, userRightId); tool.AllowButton(toolbtn); // tool.AllowButton("Create", "Edit", "Delete", "Other1"); tool.AddOtherButton("Other1", "审核", "icon-flag", "Audited_Click", true); ViewBag.ToolBar = tool; //table var pager = new Pager() { page = 1, rows = 10 }; var tableId = "tablist"; var tab = new Table(tableId); tab.AddHeadCol("PKID", "", "ID"); tab.AddHeadCol("SUBTYPEID", "", "短信类型"); tab.AddHeadCol("TITLE", "", "标题"); tab.AddHeadCol("TEMPLATE", "30%", "模版"); tab.AddHeadCol("TPARAM", "", "参数"); tab.AddHeadCol("ISSHOW", "", "是否显示"); tab.AddHeadCol("ISAUDITED", "", "是否审核"); tab.AddHeadCol("AUDITORID", "", "审核人"); tab.AddHeadCol("CTIME", "", "添加时间"); tab.AddHeadRow(); ViewBag.gridTable = tab.GetTable() + Pagination.GetPage(pager, tableId, "5,8,10,15"); return View(); } #region 列表 /// /// /// /// /// /// [HttpPost] [AuthorizeRedirect(Roles = InitRights.CONST_短信模板)] public JsonResult GetHtmlList(Pager pager, string columns) { decimal subtypeId = Request["SubType"].GetDecimal(-1); decimal isShow = Request["IsShow"].GetDecimal(-1); decimal isCheck = Request["IsCheck"].GetDecimal(-1); string param = Request["Param"]; string title = Request["Title"]; string stime = Request["Stime"]; string etime = Request["Etime"]; var list = _smsMsgtemplateQ.GetList(ref pager, subtypeId, isShow, isCheck, param, title, stime, etime); var table = new Table(columns, true); table.gridPager = pager; foreach (var model in list) { table.AddCol(model.PKID); table.AddCol(_smsMsgsubtypeQ.GetModel(model.SUBTYPEID).SUBTYPENAME); table.AddCol(model.TITLE); table.AddCol(table.tdLeftPadding5, "", model.TEMPLATE); table.AddCol(model.TPARAM); table.AddCol(model.ISSHOW == 1 ? "是" : "否"); table.AddCol(model.ISAUDITED == 1 ? "是" : "否"); table.AddCol(InnerUserHelper.Instance.EidAndName(model.AUDITORID)); table.AddCol(model.CTIME); table.AddRow(); } var json = new { totalPages = pager.totalPages, totalRows = pager.totalRows, rowsList = table.GetRows() }; return Json(json, JsonRequestBehavior.AllowGet); } #endregion 列表 #region 编辑 [HttpGet] [AuthorizeToolBar(InitRights.CONST_短信模板, InitToolBar.CONST_Edit)] public ActionResult Edit(string id) { WX.CRM.Model.Entity.SMS_MSGTEMPLATE model = null; model = id == null ? new SMS_MSGTEMPLATE() : _smsMsgtemplateQ.GetModel(Convert.ToDecimal(id)); ViewBag.MsgSubType = _smsMsgsubtypeQ.GetList().Select(p => new SelectListItem() { Text = p.SUBTYPENAME, Value = p.SUBTYPEID.ToString() }); return View(model); } [HttpPost] [AuthorizeToolBar(InitRights.CONST_短信模板, InitToolBar.CONST_Edit)] public JsonResult Edit(WX.CRM.Model.Entity.SMS_MSGTEMPLATE model) { if (!ModelState.IsValid) return JsonHandler.ValidateFailMessage(); if (model.PKID == 0) { model.TEMPLATE = model.TEMPLATE.Trim(); if (model.TPARAM == null) model.TPARAM = ""; model.TPARAM = model.TPARAM.Replace(",", ",").Trim(); model.CREATEUSER = UserId; model.CTIME = DateTime.Now; model.ISSHOW = 1; model.ISAUDITED = 0; return JsonHandler.InsertMessage(errors, _smsMsgtemplate.Create(ref errors, model)); } else { model.TEMPLATE = model.TEMPLATE.Trim(); if (model.TPARAM == null) model.TPARAM = ""; model.TPARAM = model.TPARAM.Replace(",", ",").Trim(); model.UTIME = DateTime.Now; model.UPDATEUSER = UserId; model.ISAUDITED = 0; return JsonHandler.UpdateMessage(errors, _smsMsgtemplate.Update(ref errors, model)); } } #endregion 编辑 #region 删除 [AuthorizeToolBar(InitRights.CONST_短信模板, InitToolBar.CONST_Delete)] public JsonResult Delete(string id) { var model = _smsMsgtemplateQ.GetModel(Convert.ToDecimal(id)); if (model != null) return JsonHandler.DeleteMessage(errors, _smsMsgtemplate.Delete(ref errors, Convert.ToDecimal(id))); else return JsonHandler.DeleteMessage(errors, false); } #endregion 删除 #region 详细 [AuthorizeToolBar(InitRights.CONST_短信模板, InitToolBar.CONST_Other1)] public ActionResult Details(string id) { var model = _smsMsgtemplateQ.GetModel(Convert.ToDecimal(id)); if (model != null) return View(model); return View(); } #endregion 详细 #region 审核 [AuthorizeToolBar(InitRights.CONST_短信模板, InitToolBar.CONST_Other1)] public JsonResult Audited(string pkid) { var model = _smsMsgtemplateQ.GetModel(Convert.ToDecimal(pkid)); if (model != null) { model.ISAUDITED = 1; model.AUDITORID = UserId; return JsonHandler.UpdateMessage(errors, _smsMsgtemplate.Update(ref errors, model)); } return JsonHandler.ManageMessage("参数错误", false); } #endregion 审核 public ActionResult SendTemplateMessage(string customerId, string resId) { string erroMessage = string.Empty; if (string.IsNullOrWhiteSpace(customerId) || string.IsNullOrWhiteSpace(resId)) { erroMessage = "参数错误!"; } string remark = string.Empty; if (IsBlackNumber(resId, UserId, "S", out remark)) { erroMessage = "此号码为黑名单!" + remark; } //_blacknumberq.GetById(); ViewBag.erroMessage = erroMessage; return View(); } private bool IsBlackNumber(string resid, decimal userId, string type, out string remark) { bool result = false; remark = ""; var list = _blacknumberq.GetBlackNumberByRESID(resid, userId, out remark); if (list != null && list.Count() > 0 && list.Count(p => p.BLACKTYPE == type) > 0) { remark = list.Select(p => p.REASON).FirstOrDefault(); result = true; } return result; } public JsonResult GetTemplate(string subTypeId) { if (string.IsNullOrWhiteSpace(subTypeId)) return Json(new { result = false, message = "参数不对!" }, JsonRequestBehavior.AllowGet); decimal type = Convert.ToDecimal(subTypeId); List obj = new List(); List list = _smsMsgtemplateQ.GetList(type); foreach (SMS_MSGTEMPLATE model in list) { obj.Add(new { PKID = model.PKID, TITLE = model.TITLE, TEMPLATE = model.TEMPLATE, TPARAM = model.TPARAM == null ? "" : model.TPARAM }); } return Json(new { result = true, template = obj }, JsonRequestBehavior.AllowGet); } [HttpPost] public JsonResult SendMsg() { SmsServiceModel smsmodel = new SmsServiceModel(); smsmodel.SubTypeCode = Request.Form["msgSubTypeCode"]; smsmodel.typeCode = Request.Form["msgTypeCode"]; //smsmodel.message = Request.Form["txtNewMessage"]; smsmodel.resid = Request.Form["resId"]; smsmodel.createteuser = UserId;//赋员工ID var msg = new { smsmodel.typeCode, smsmodel.SubTypeCode, smsmodel.resid, para = Request.Form["para"] }; smsmodel.message = msg.ToJson(); string json = Utility.ConvertToJSON(smsmodel); json = sHelper.createSignEncodingStr(json); string url = cacheQ.GetValue_Parameter(Parameter.ISVR_IAD_localhostSmsMsg);//内部接口··调用RiaSerivice string retmsg = Utility.PostData(url + "?" + json, Encoding.UTF8); var sysenv = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_Environment_DeptCode); sysenv = sysenv ?? ""; //retmsg = JsonHelper.JsonDivertToObj(retmsg); retmsg = sHelper.decyptData("UPWEBSITE", retmsg); SmsSendMsgModel retmessage = JsonHelper.JsonDivertToObj(retmsg); return Json(new { result = retmessage.result, retcode = retmessage.retcode, retMessage = retmessage.retMessage }, JsonRequestBehavior.AllowGet); //string ddddd = serize.Serialize(smsmodel); //string message = ddddd; //string clientid = "UPWEBSITE"; //string key = "content={0}&clientId=UPWEBSITE&sign={1}"; //string jiami = .encyptData(clientid, message); //string jiami1 = HttpUtility.UrlEncode(jiami, Encoding.UTF8); //string jiasuo = SecurityHelper.signData(clientid, jiami); //string jiasuo1 = HttpUtility.UrlEncode(jiasuo, Encoding.UTF8); //key = string.Format(key, jiami1, jiasuo1); //key = Utility.PostData("http://localhost:18739/SmsService.svc/ConfirmCode?" + key, Encoding.UTF8); //key = Utility.JsonDrivertObj(key); //解密操作 //key = SecurityHelper.decyptData("UPWEBSITE", key); //解密操作 //key = HttpUtility.UrlDecode(key, System.Text.Encoding.UTF8); //context.Response.Write(key); } } }