323 lines
12 KiB
C#
323 lines
12 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.IO;
|
||
using System.Web;
|
||
using System.Web.Mvc;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.IBLL.Res;
|
||
using WX.CRM.IBLL.Sms;
|
||
using WX.CRM.Model.Entity;
|
||
using WX.CRM.Model.QueryMap;
|
||
using WX.CRM.WebHelper;
|
||
|
||
namespace WX.CRM.WEB.Controllers.Sms
|
||
{
|
||
public class BatchModelMsgController : BaseController
|
||
{
|
||
private readonly ISMS_BATCHMSG BatchMsgBiz;
|
||
private readonly ISMS_BATCHMSG_Q BatchMsgBiz_Q;
|
||
private readonly ISMS_MSGSUBTYPE_Q MsgSubTypeBiz_Q;
|
||
private readonly ISMS_ACCOUNT_Q SmsAccountBiz_Q;
|
||
private readonly IRES_CUSTOMER _customer;
|
||
private readonly IRES_CUSTOMER_Q _customer_Q;
|
||
private readonly ISMS_BATCHMSGTEMPLATE_Q sms_BatchModelTemplate_Q;
|
||
public BatchModelMsgController(ISMS_BATCHMSG _BatchMsgBiz, ISMS_BATCHMSG_Q _BatchMsgBiz_Q, ISMS_MSGSUBTYPE_Q _MsgSubTypeBiz_Q, ISMS_ACCOUNT_Q _SmsAccountBiz_Q, IRES_CUSTOMER customer, IRES_CUSTOMER_Q customer_Q, ISMS_BATCHMSGTEMPLATE_Q _sms_BatchModelTemplate_Q)
|
||
{
|
||
BatchMsgBiz = _BatchMsgBiz;
|
||
BatchMsgBiz_Q = _BatchMsgBiz_Q;
|
||
MsgSubTypeBiz_Q = _MsgSubTypeBiz_Q;
|
||
SmsAccountBiz_Q = _SmsAccountBiz_Q;
|
||
_customer = customer;
|
||
_customer_Q = customer_Q;
|
||
sms_BatchModelTemplate_Q = _sms_BatchModelTemplate_Q;
|
||
}
|
||
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_批量模版短信)]
|
||
public ActionResult Index()
|
||
{
|
||
Pager pager = new Pager() { order = "BATCHID", page = 1, rows = 10 };
|
||
string tableId = "tablist";
|
||
Table tab = new Table(tableId);
|
||
tab.AddHeadCol("map_BATCHID", "100", "批次ID");
|
||
tab.AddHeadCol("map_MESSAGE", "", "短信内容");
|
||
tab.AddHeadCol("map_TYPECODENAME", "120", "短信类型");
|
||
tab.AddHeadCol("map_CLIENTENAME", "120", "短信平台");
|
||
tab.AddHeadCol("map_CTIME", "120", "提交时间");
|
||
tab.AddHeadCol("map_CREATEUSERNAME", "120", "提交人");
|
||
tab.AddHeadRow();
|
||
ViewBag.gridTable = tab.GetTable() + Pagination.GetPage(pager, tableId, "15,30,50,100");
|
||
|
||
return View();
|
||
}
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_批量模版短信)]
|
||
public JsonResult GetHtmlList(Pager pager, string columns)
|
||
{
|
||
int c = 0;
|
||
List<WX.CRM.Model.Entity.SMS_BATCHMSG> lis = BatchMsgBiz_Q.GetList(pager.page, pager.rows, ref c);
|
||
pager.totalRows = c;
|
||
Table table = new Table(columns, true);
|
||
table.gridPager = pager;
|
||
foreach (WX.CRM.Model.Entity.SMS_BATCHMSG model in lis)
|
||
{
|
||
table.AddCol(model.map_BATCHID);
|
||
table.AddCol(model.map_MESSAGE);
|
||
table.AddCol(model.map_TYPECODENAME);
|
||
table.AddCol(model.map_CLIENTENAME);
|
||
table.AddCol(model.map_CTIME);
|
||
table.AddCol(model.map_CREATEUSERNAME);
|
||
table.AddRow();
|
||
}
|
||
var json = new
|
||
{
|
||
totalPages = pager.totalPages,
|
||
totalRows = pager.totalRows,
|
||
rowsList = table.GetRows()
|
||
};
|
||
return Json(json, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
|
||
|
||
|
||
public string RecFile(string id)
|
||
{
|
||
string result = "ok";
|
||
string tn = string.Format("{0}", id);
|
||
List<string> lis = new List<string>();
|
||
try
|
||
{
|
||
|
||
int pkid = int.Parse(Request.Form["hidtemplateId"]);
|
||
SMS_BATCHMSGTEMPLATE smstemplate = sms_BatchModelTemplate_Q.getTempLateBypkid(pkid);
|
||
|
||
string param = Request.Form["hidParamMsg"];
|
||
WX.CRM.Model.Entity.SMS_BATCHMSG info = new WX.CRM.Model.Entity.SMS_BATCHMSG();
|
||
info.SUBTYPEID = decimal.Parse(string.Format("{0}", Request.Form["hidSubTypeID"]));
|
||
info.CLIENTCODE = smstemplate.CILENTCODE;
|
||
info.CREATEUSER = UserId;
|
||
info.CTIME = DateTime.Now;
|
||
info.MESSAGE = smstemplate.SENDSTR;
|
||
string[] paramArr = param.Split('|');
|
||
for (int i = 0; i < paramArr.Length; i++)
|
||
{
|
||
info.MESSAGE = info.MESSAGE.Replace("{" + i.ToString() + "}", paramArr[i]).TrimEnd('\r').TrimEnd('\n');
|
||
}
|
||
|
||
switch (tn)
|
||
{
|
||
case "客户ID批量提交":
|
||
lis = ReciveFile1();
|
||
|
||
info.TYPECODE = "BATMBSMS0001"; //未定义
|
||
break;
|
||
case "客户ID文件批量提交":
|
||
lis = ReciveFile2();
|
||
info.TYPECODE = "BATMBSMS0001"; //未定义
|
||
break;
|
||
|
||
default:
|
||
result = string.Format("【{0}】当前标签不正确!", tn);
|
||
break;
|
||
}
|
||
//提交短信
|
||
if (lis == null || lis.Count == 0)
|
||
throw new Exception("请提交正确的客户ID!");
|
||
if (string.IsNullOrEmpty(info.MESSAGE))
|
||
throw new Exception("短信内容能为空!");
|
||
if (info.MESSAGE.Length > smstemplate.TEMPLATELEN)
|
||
throw new Exception("短信内容最多可输入" + smstemplate.TEMPLATELEN.Value.ToString() + "个字符!");
|
||
|
||
BatchMsgBiz.ImpotDt(info, lis, 300);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
result = ex.Message;
|
||
}
|
||
return result;
|
||
}
|
||
|
||
|
||
|
||
#region 处理提交上来的数据文件
|
||
public List<string> ReciveFile1()
|
||
{
|
||
List<string> lis = new List<string>();
|
||
string mobileStr = string.Format("{0}", Request.Form["txtResIdFromSql"]);
|
||
|
||
string[] mbs = mobileStr.Trim().Split(',');
|
||
|
||
for (int i = 0; i < mbs.Length; i++)
|
||
{
|
||
if (!string.IsNullOrEmpty(mbs[i]))
|
||
lis.Add(mbs[i].Trim());
|
||
}
|
||
return lis;
|
||
}
|
||
public List<string> ReciveFile2()
|
||
{
|
||
string vPath = System.Configuration.ConfigurationManager.AppSettings["UploadTemFileDic"];
|
||
List<string> lis = new List<string>();
|
||
HttpFileCollectionBase files = Request.Files;
|
||
HttpPostedFileBase file = files["FileMobile"];
|
||
if (file != null && file.ContentLength > 0)
|
||
{
|
||
string fileName = file.FileName;
|
||
//判断文件名字是否包含路径名,如果有则提取文件名
|
||
if (fileName.LastIndexOf("\\") > -1)
|
||
{
|
||
fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
|
||
}
|
||
if (fileName.ToLower().IndexOf(".txt") > -1)
|
||
{
|
||
if (!System.IO.Directory.Exists(Server.MapPath(vPath)))
|
||
{
|
||
System.IO.Directory.CreateDirectory(Server.MapPath(vPath));
|
||
}
|
||
string path = Server.MapPath((vPath + "/") + fileName);
|
||
|
||
file.SaveAs(path);
|
||
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||
StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default);
|
||
while (!sr.EndOfStream)
|
||
{
|
||
string number = sr.ReadLine();
|
||
if (!string.IsNullOrEmpty(number))
|
||
lis.Add(number.Trim());
|
||
}
|
||
sr.Close();
|
||
fs.Close();
|
||
System.IO.File.Delete(path);
|
||
}
|
||
else
|
||
{
|
||
throw new Exception("文件格式不正确!");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
throw new Exception("请选择正确的文件!");
|
||
}
|
||
return lis;
|
||
}
|
||
#endregion
|
||
|
||
#region 获取客户ID
|
||
public JsonResult GetAllResId(string resIds)
|
||
{
|
||
resIds = resIds.Trim().Replace("\r\n", ",");
|
||
resIds = resIds.Replace("\r\n", ",");
|
||
resIds = resIds.Replace("\r", ",");
|
||
resIds = resIds.Replace("\n", ",");
|
||
|
||
DataTable tab = _customer_Q.GetList_CustomerByResIds(resIds);
|
||
List<object> obj = new List<object>();
|
||
string residLastChar = string.Empty;
|
||
foreach (DataRow row in tab.Rows)
|
||
{
|
||
residLastChar = string.Format("{0}", row["RESID"]);
|
||
residLastChar = residLastChar.Substring(residLastChar.Length - 1, 1);
|
||
obj.Add(new { RESID = row["RESID"], LASTNUM3 = row["LASTNUM3"], ISPRIMARYNUM = row["ISPRIMARYNUM"], isCallPhone = (Convert.ToInt32(residLastChar) % 2 == 0) });
|
||
}
|
||
return Json(new { result = tab.Rows.Count > 0 ? 1 : 0, message = tab.Rows.Count > 0 ? "" : "请输入正确的客户ID!", ResIds = obj });
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region combox数据列表,未加载实际数据
|
||
public JsonResult SmsSubTypeList(string id)
|
||
{
|
||
List<WX.CRM.Model.Entity.SMS_MSGSUBTYPE> lis = new List<WX.CRM.Model.Entity.SMS_MSGSUBTYPE>();
|
||
List<WX.CRM.Model.Entity.SMS_MSGSUBTYPE> tem = new List<WX.CRM.Model.Entity.SMS_MSGSUBTYPE>();
|
||
switch (id)
|
||
{
|
||
case "客户ID批量提交":
|
||
tem = MsgSubTypeBiz_Q.GetList("BATMBSMS0001");
|
||
break;
|
||
case "客户ID文件批量提交":
|
||
tem = MsgSubTypeBiz_Q.GetList("BATMBSMS0001");
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
lis.Clear();
|
||
lis.Add(new WX.CRM.Model.Entity.SMS_MSGSUBTYPE() { SUBTYPEID = 0, SUBTYPENAME = "-请选择-" });
|
||
foreach (var obj in tem)
|
||
{
|
||
|
||
lis.Add(new WX.CRM.Model.Entity.SMS_MSGSUBTYPE() { SUBTYPEID = obj.SUBTYPEID, SUBTYPENAME = obj.SUBTYPENAME });
|
||
}
|
||
return Json(lis, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
|
||
public JsonResult SmsModelList(string id)
|
||
{
|
||
List<WX.CRM.Model.Entity.SMS_BATCHMSGTEMPLATE> lis = new List<WX.CRM.Model.Entity.SMS_BATCHMSGTEMPLATE>();
|
||
List<WX.CRM.Model.Entity.SMS_BATCHMSGTEMPLATE> tem = new List<WX.CRM.Model.Entity.SMS_BATCHMSGTEMPLATE>();
|
||
int typeid = int.Parse(id);
|
||
tem = sms_BatchModelTemplate_Q.getTempLateBySubtypeid(typeid);
|
||
lis.Clear();
|
||
lis.Add(new WX.CRM.Model.Entity.SMS_BATCHMSGTEMPLATE() { PKID = 0, TEMPLATENAME = "-请选择-" });
|
||
foreach (var obj in tem)
|
||
{
|
||
lis.Add(new WX.CRM.Model.Entity.SMS_BATCHMSGTEMPLATE() { PKID = obj.PKID, TEMPLATENAME = obj.TEMPLATENAME });
|
||
}
|
||
return Json(lis, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
|
||
public JsonResult GetTempLateInfo(string id)
|
||
{
|
||
|
||
SMS_BATCHMSGTEMPLATE tem = new SMS_BATCHMSGTEMPLATE();
|
||
SMS_BATCHMSGTEMPLATE_Model lis = new SMS_BATCHMSGTEMPLATE_Model();
|
||
if (string.IsNullOrEmpty(id) || id.ToLower() == "null")
|
||
{
|
||
return Json(tem, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
|
||
int typeid = int.Parse(id);
|
||
tem = sms_BatchModelTemplate_Q.getTempLateBypkid(typeid);
|
||
lis.CILENTCODE = tem.CILENTCODE;
|
||
lis.CTIME = tem.CTIME;
|
||
lis.PARMNUM = tem.PARMNUM;
|
||
lis.PKID = tem.PKID;
|
||
lis.SENDSTR = tem.SENDSTR;
|
||
lis.SUBTYPEID = tem.SUBTYPEID;
|
||
lis.TEMPLATELEN = tem.TEMPLATELEN;//模版总长度;
|
||
lis.TEMPLATENAME = tem.TEMPLATENAME;
|
||
lis.TEMPLATEVALUE = tem.TEMPLATEVALUE;
|
||
|
||
lis.ParamCount = Convert.ToInt32(tem.TEMPLATELEN) - getParamLen(tem.TEMPLATEVALUE);
|
||
|
||
return Json(lis, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
|
||
public int getParamLen(string tempvalue)
|
||
{
|
||
try
|
||
{
|
||
string str = tempvalue;
|
||
|
||
string[] tr = str.Split('}');
|
||
int strlen = 0;
|
||
foreach (string item in tr)
|
||
{
|
||
string[] arr = item.Split('$');
|
||
strlen += arr[0].Length;
|
||
}
|
||
return strlen;
|
||
}
|
||
catch
|
||
{
|
||
|
||
return 0;
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
}
|