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;
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, "S", out remark))
{
erroMessage = "此号码为黑名单!" + remark;
}
//_blacknumberq.GetById();
ViewBag.erroMessage = erroMessage;
return View();
}
private bool IsBlackNumber(string resid, string type, out string remark)
{
bool result = false;
remark = "";
var list = _blacknumberq.GetBlackNumberByRESID(resid, 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