ComplianceServer/oldcode/WEB/Controllers/TS/WebChatAssistantController.cs

536 lines
20 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.Mvc;
using WX.CRM.Common;
using WX.CRM.IBLL.TS;
using WX.CRM.IBLL.Wx;
using WX.CRM.Model.Entity;
using WX.CRM.Model.MAP;
using WX.CRM.WebHelper;
namespace WX.CRM.WEB.Controllers.TS
{
/// <summary>
/// 微信助手
/// </summary>
public class WebChatAssistantController : BaseController
{
IWX_TSADDFRIEND wx_tsaddfriend;
IWX_WORKACCOUNT wx_workaccount;
string cookieName = string.Empty;
public WebChatAssistantController(IWX_TSADDFRIEND _wx_tsaddfriend, IWX_WORKACCOUNT _wx_workaccount)
{
this.wx_tsaddfriend = _wx_tsaddfriend;
this.wx_workaccount = _wx_workaccount;
cookieName = "WebChatAssistant_" + Eid;
}
//
// GET: /WebChatAssistant/
public ActionResult Index()
{
Table tab2 = new Table("tablis1");
tab2.isCheckbox = true;
tab2.AddHeadCol("resid", "", "客户ID");
tab2.AddHeadCol("phone", "", "手机号码");
tab2.AddHeadCol("cname", "", "客户名称");
tab2.AddHeadCol("snedcount", "", "助手申请次数");
tab2.AddHeadCol("addcount", "", "已加客服人数");
tab2.AddHeadRow();
//添加分割线
tab2.AddTHeadAndTbodySplit();
ViewBag.gridTable2 = tab2.GetTable();
ViewBag.Eid = Eid;
return View();
}
public JsonResult GetHtmlList(Pager pager, string columns)
{
string resids = string.Empty;
if (Request.Cookies[cookieName] != null)
{
resids = HttpUtility.UrlDecode(Request.Cookies[cookieName].Value);
}
DataTable resTable = wx_tsaddfriend.GetResByCookiResid(resids);
Table table = new Table(columns, true);
table.gridPager = pager;
table.isCheckbox = true;
foreach (DataRow model in resTable.Rows)
{
table.AddCol(model["resid"]);
table.AddCol(model["lastnum3"]);
table.AddCol(model["cname"]);
int count = Convert.ToInt32(model["snedcount"]);//添加人数
if (count <= 1)
{
table.AddCol(model["snedcount"]);
}
else if (count == 2)
{
table.AddCol("<font color='#e09325'>" + count + "</font>");
}
else
{
table.AddCol("<font color='red'>" + count + "</font>");
}
table.AddCol(model["addcount"]);
table.AddRow();
}
var json = new
{
totalPages = pager.totalPages,
totalRows = pager.totalRows,
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
public JsonResult AddRes(string addResTxt)
{
int type = 1;
string resids = string.Empty;
if (Request.Cookies[cookieName] != null)
{
resids = HttpUtility.UrlDecode(Request.Cookies[cookieName].Value);
}
Dictionary<string, string> resDic = new Dictionary<string, string>();
string mobileStr = string.Empty;
mobileStr = addResTxt.Replace("\r\n", ",");
mobileStr = mobileStr.Replace("\r", ",");
mobileStr = mobileStr.Replace("\n", ",");
DataTable resTable = wx_tsaddfriend.GetCheckErroRes(mobileStr);
string[] mobiles = mobileStr.Split(',');
foreach (string item in mobiles)
{
if (string.IsNullOrEmpty(item))
continue;
string nitem = item.Trim();
if (!resDic.ContainsKey(nitem) && resids.IndexOf(nitem) == -1)//不在Cookies中的
{
resDic.Add(nitem, nitem);
}
}
string erroResid = string.Empty;
if (resTable.Rows.Count > 0)
{
type = 0;
foreach (DataRow row in resTable.Rows)
{
string nresid = row["resid"].ToString();
erroResid += nresid + "\r\n";
if (resDic.ContainsKey(nresid))//移除 不正确资源
{
resDic.Remove(nresid);
}
}
}
string okResid = string.Empty;
foreach (var item in resDic)
{
if (string.IsNullOrEmpty(okResid))
okResid += item.Key;
else
okResid += "," + item.Key;
}
if (!string.IsNullOrEmpty(resids))
{
okResid += "," + resids;
}
var json = new
{
type = type,
erroResid = erroResid,
okResid = okResid
};
return Json(json, JsonRequestBehavior.AllowGet);
}
public ActionResult SendToPhone()
{
//List<WX_WORKACCOUNT> wock = wx_workaccount.GetMyWorkAccountList(UserId);
DataTable table = wx_tsaddfriend.GetCanSendWorkAlias(UserId);
List<SelectListItem> lit = new List<SelectListItem>();
//foreach (WX_WORKACCOUNT item in wock)
//{
// lit.Add(new SelectListItem() { Text = item.ALIAS + "--" + item.NICKNAME, Value = item.ALIAS });
//}
foreach (DataRow item in table.Rows)
{
lit.Add(new SelectListItem() { Text = item["alias"].ToString() + "--" + item["nickname"].ToString(), Value = item["alias"].ToString() });
}
ViewBag.MyAlias = lit;
return View();
}
public JsonResult SendToPhoneSave(WX_SendResToPhone model)
{
ValidationErrors errors = new ValidationErrors();
if (!ModelState.IsValid)
{
return JsonHandler.ValidateFailMessage();
}
if (string.IsNullOrEmpty(model.Alias))
{
return JsonHandler.ManageMessage("请选择工作微信号如果选择框没有数据请去机房安装最新版本APP", false);
}
string resids = string.Empty;
if (Request.Cookies[cookieName] != null)
{
resids = HttpUtility.UrlDecode(Request.Cookies[cookieName].Value);
}
string nresids = string.Empty;
int rescount = 0;
foreach (string item in resids.Split(','))
{
if (string.IsNullOrEmpty(item))
{
continue;
}
if (wx_tsaddfriend.IsCanSend(item))
{
rescount++;
if (string.IsNullOrEmpty(nresids))
nresids = item;
else
nresids += "," + item;
}
}
bool result = true;
if (string.IsNullOrEmpty(nresids))
{
errors.Add("资源数不能为零!");
result = false;
}
else if (rescount > 30)
{
errors.Add("资源数一次性不要超过30个");
result = false;
}
else
{
result = wx_tsaddfriend.CreatePici(nresids, model.Alias, model.HolloMsg, model.timeType, model.exe_date, model.exe_time, ref errors);
}
return JsonHandler.UpdateMessage(errors, result);
}
public ActionResult WhiteResApply()
{
DataTable table = wx_tsaddfriend.GetCanSendWorkAlias(UserId);
List<SelectListItem> lit = new List<SelectListItem>();
//foreach (WX_WORKACCOUNT item in wock)
//{
// lit.Add(new SelectListItem() { Text = item.ALIAS + "--" + item.NICKNAME, Value = item.ALIAS });
//}
foreach (DataRow item in table.Rows)
{
lit.Add(new SelectListItem() { Text = item["alias"].ToString() + "--" + item["nickname"].ToString(), Value = item["alias"].ToString() });
}
ViewBag.MyAlias = lit;
return View();
}
public ActionResult WhiteResApplySave(WX_WhiteResApply model)
{
ValidationErrors errors = new ValidationErrors();
if (!ModelState.IsValid)
{
return JsonHandler.ValidateFailMessage();
}
if (string.IsNullOrEmpty(model.Alias))
{
return JsonHandler.ManageMessage("请选择工作微信号如果选择框没有数据请去机房安装最新版本APP", false);
}
int dept = 1;
if (saleDeptCode == "ZJZX04")
{//如果是三部
dept = 3;
}
bool result = wx_tsaddfriend.WhiteResApply(model.Alias, model.HolloMsg, model.timeType, model.exe_date, model.exe_time, model.ResCount, Eid, dept, ref errors);
return JsonHandler.UpdateMessage(errors, result);
}
#region --
public ActionResult TsLog()
{
//IBAS_COMPANY_Q doa = WebHelper.Infrastructure.NinjectControllerFactory.ninjectKernel.Get<IBAS_COMPANY_Q>();
//ToolBar
//table
Pager pager = new Pager() { page = 1, rows = 10 };
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("pici", "8%", "批次");
tab.AddHeadCol("alias", "8%", "微信号");
tab.AddHeadCol("validatemsg", "", "打招呼信息");
tab.AddHeadCol("rescount", "8%", "资源数");
tab.AddHeadCol("ctime", "8%", "创建时间");
tab.AddHeadCol("executetime", "8%", "设定的执行时间");
tab.AddHeadCol("snedstuts", "8%", "推送状态");
tab.AddHeadCol("starttime", "8%", "实际开始执行时间");
tab.AddHeadCol("endtime", "8%", "实际结束时间");
tab.AddHeadCol("erromsg", "", "错误信息");
tab.AddHeadCol("type", "8%", "来源");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetHead() + Pagination.GetPage(pager, tableId, "10,20,30");
List<WX_WORKACCOUNT> wock = wx_workaccount.GetMyWorkAccountList(UserId);
ViewBag.workAccount = wock;
return View();
}
[HttpPost]
/// <summary>
/// 按照条件获取数据
/// </summary>
/// <param name="pager"></param>
/// <param name="queryStr"></param>
/// <returns></returns>
public JsonResult TsLogGetHtmlList(Pager pager, string alias, string columns)
{
DataTable datable = wx_tsaddfriend.ResLogReport(Eid, alias, ref pager);
Table table = new Table(columns, true);
table.gridPager = pager;
foreach (DataRow row in datable.Rows)
{
table.AddCol(row["pici"]);
table.AddCol(row["alias"]);
table.AddCol(string.Format("<font style='color:green;'>{0}</font>", row["validatemsg"]));
table.AddCol(row["rescount"]);
table.AddCol(row["ctime"]);
table.AddCol(row["executetime"]);
if (row["snedstuts"] != DBNull.Value)
{
table.AddCol(getSendStatus(Convert.ToInt32(row["snedstuts"])));
}
else
{
table.AddCol("其他");
}
table.AddCol(row["starttime"]);
table.AddCol(row["endtime"]);
string errMsg = string.Format("{0}", row["erromsg"]);
if (errMsg.IndexOf("\"ActionStatus\":\"OK\"") > -1)
table.AddCol("");
else
table.AddCol(string.Format("<font style='color:red;'>{0}</font>", row["erromsg"]));
if (row["whiteid"] != DBNull.Value && Convert.ToInt64(row["whiteid"]) > 0)
table.AddCol("【白板资源申请】");
else
table.AddCol("【自填资源】");
table.AddRow();
}
var json = new
{
totalPages = pager.totalPages,
totalRows = pager.totalRows,
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
private string getSendStatus(int sendstatus)
{
switch (sendstatus)
{
case 0: return "<font style=\"color:#AAAAAA\">未推送</font>"; break;
case 1: return "<font style=\"color:blue\">发送成功</font>"; break;
case 2: return "<font style=\"color:red\">发送失败</font>"; break;
default: return "其他";
}
}
#endregion
#region --
[AuthorizeRedirect(Roles = InitRights.CONST_微信助手日志)]
public ActionResult TsLog_Manager()
{
//IBAS_COMPANY_Q doa = WebHelper.Infrastructure.NinjectControllerFactory.ninjectKernel.Get<IBAS_COMPANY_Q>();
//ToolBar
ToolBar tool = new ToolBar();
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
tool.AddOtherButton("Other1", "测试推送加人", "icon-lookup", "Test_Click", true);
tool.AllowButton(toolbtn);
ViewBag.ToolBar = tool;
//table
Pager pager = new Pager() { page = 1, rows = 10 };
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("pici", "8%", "批次");
tab.AddHeadCol("eid", "5%", "客服");
tab.AddHeadCol("alias", "8%", "微信号");
tab.AddHeadCol("validatemsg", "", "打招呼信息");
tab.AddHeadCol("rescount", "4%", "资源数");
tab.AddHeadCol("ctime", "8%", "创建时间");
tab.AddHeadCol("executetime", "8%", "设定的执行时间");
tab.AddHeadCol("snedstuts", "8%", "推送状态");
tab.AddHeadCol("starttime", "8%", "实际开始执行时间");
tab.AddHeadCol("endtime", "8%", "实际结束时间");
tab.AddHeadCol("erromsg", "", "错误信息");
tab.AddHeadCol("type", "8%", "来源");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetHead() + Pagination.GetPage(pager, tableId, "10,20,30");
return View();
}
[HttpPost]
/// <summary>
/// 按照条件获取数据
/// </summary>
/// <param name="pager"></param>
/// <param name="queryStr"></param>
/// <returns></returns>
[AuthorizeRedirect(Roles = InitRights.CONST_微信助手日志)]
public JsonResult TsLog_ManagerGetHtmlList(Pager pager, string alias, string eid, string columns)
{
decimal veid = 0;
if (eid != null && !decimal.TryParse(eid.Trim(), out veid))
{
throw new Exception("请输入正确的工号!");
}
DataTable datable = wx_tsaddfriend.ResLogReport_Manager(veid, alias, ref pager);
Table table = new Table(columns, true);
table.gridPager = pager;
foreach (DataRow row in datable.Rows)
{
table.AddCol(row["pici"]);
decimal x_eid = Convert.ToDecimal(row["eid"]);
table.AddCol(InnerUserHelper.Instance.GetEidAndTrueName(InnerUserHelper.Instance.GetUserIdByEid(x_eid)));
table.AddCol(row["alias"]);
table.AddCol(string.Format("<font style='color:green;'>{0}</font>", row["validatemsg"]));
table.AddCol(row["rescount"]);
table.AddCol(row["ctime"]);
table.AddCol(row["executetime"]);
if (row["snedstuts"] != DBNull.Value)
{
table.AddCol(getSendStatus(Convert.ToInt32(row["snedstuts"])));
}
else
{
table.AddCol("其他");
}
table.AddCol(row["starttime"]);
table.AddCol(row["endtime"]);
string errMsg = string.Format("{0}", row["erromsg"]);
if (errMsg.IndexOf("\"ActionStatus\":\"OK\"") > -1)
table.AddCol("");
else
table.AddCol(string.Format("<font style='color:red;'>{0}</font>", row["erromsg"]));
if (row["whiteid"] != DBNull.Value && Convert.ToInt64(row["whiteid"]) > 0)
table.AddCol("【白板资源申请】");
else
table.AddCol("【自填资源】");
table.AddRow();
}
var json = new
{
totalPages = pager.totalPages,
totalRows = pager.totalRows,
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
[AuthorizeToolBar(InitRights.CONST_微信助手日志, InitToolBar.CONST_Details)]
public ActionResult TsLog_Detial()
{
//table
string tableId = "tablist";
Table tab = new Table(tableId);
tab.AddHeadCol("pici", "", "批次");
tab.AddHeadCol("resid", "", "客户ID");
tab.AddHeadCol("state", "", "状态");
tab.AddHeadCol("zdtime", "", "执行时间");
tab.AddHeadCol("username", "", "客户微信用户名");
tab.AddHeadCol("snedstuts", "", "同意时间");
tab.AddHeadRow();
ViewBag.gridTable = tab.GetHead();
return View();
}
[HttpPost]
/// <summary>
/// 按照条件获取数据
/// </summary>
/// <param name="pager"></param>
/// <param name="queryStr"></param>
/// <returns></returns>
[AuthorizeToolBar(InitRights.CONST_微信助手日志, InitToolBar.CONST_Details)]
public JsonResult TsLog_DetialGetHtmlList(Pager pager, decimal pici, string columns)
{
DataTable datable = wx_tsaddfriend.ResLogReport_Detial(pici);
Table table = new Table(columns, true);
table.gridPager = pager;
foreach (DataRow row in datable.Rows)
{
table.AddCol(row["pici"]);
table.AddCol(row["resid"]);
table.AddCol(row["state"]);
table.AddCol(row["zdtime"]);
table.AddCol(row["username"]);
table.AddCol(row["createtime"]);
table.AddRow();
}
var json = new
{
rowsList = table.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
#endregion
#region
[AuthorizeToolBar(InitRights.CONST_微信助手日志, InitToolBar.CONST_Other1)]
public ActionResult TestSendPhone()
{
return View();
}
[AuthorizeToolBar(InitRights.CONST_微信助手日志, InitToolBar.CONST_Other1)]
public JsonResult TestSendToPhoneSave(Wx_TestSendPhone model)
{
ValidationErrors errors = new ValidationErrors();
if (!ModelState.IsValid)
{
return JsonHandler.ValidateFailMessage();
}
if (string.IsNullOrEmpty(model.Alias))
{
return JsonHandler.ManageMessage("请选择工作微信号如果选择框没有数据请去机房安装最新版本APP", false);
}
string resids = ResUtil.CreateResId(model.Phone);
bool result = wx_tsaddfriend.CreatePici(resids, model.Alias, model.HolloMsg, model.timeType, model.exe_date, model.exe_time, ref errors);
return JsonHandler.UpdateMessage(errors, result);
}
#endregion
}
}