827 lines
35 KiB
C#
827 lines
35 KiB
C#
using Ninject;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Web;
|
||
using System.Web.Mvc;
|
||
using WX.CRM.BLL.Base;
|
||
using WX.CRM.BLL.Util;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.IBLL.Base;
|
||
using WX.CRM.IBLL.Res;
|
||
using WX.CRM.IBLL.Wx;
|
||
using WX.CRM.Model.Entity;
|
||
using WX.CRM.WebHelper;
|
||
|
||
namespace WX.CRM.WEB.Controllers.WeiXin
|
||
{
|
||
public class WorkAccountInitController : BaseController
|
||
{
|
||
|
||
private IWX_WORKACCOUNT_INIT wx_WorkAccount_Init_BL { get; set; }
|
||
|
||
private IRES_CUSTOMER res_Customer_BL { get; set; }
|
||
|
||
private IWX_WORKACCOUNT wx_WorkAccount_BL { get; set; }
|
||
|
||
private IRES_CUSTOMER_Q res_Customer_Q_BL;
|
||
|
||
[Inject]
|
||
public CACHE_BL cache_BL { get; set; }
|
||
|
||
[Inject]
|
||
public IBAS_INNERUSERROLE_Q _inneruserRole { get; set; }
|
||
|
||
|
||
ValidationErrors errors = new ValidationErrors();
|
||
|
||
public WorkAccountInitController(IWX_WORKACCOUNT_INIT wx_WorkAccount_Init_BL, IRES_CUSTOMER res_Customer_BL, IWX_WORKACCOUNT wx_WorkAccount_BL, IRES_CUSTOMER_Q res_Customer_Q_BL)
|
||
{
|
||
this.wx_WorkAccount_Init_BL = wx_WorkAccount_Init_BL;
|
||
this.res_Customer_BL = res_Customer_BL;
|
||
this.wx_WorkAccount_BL = wx_WorkAccount_BL;
|
||
this.res_Customer_Q_BL = res_Customer_Q_BL;
|
||
}
|
||
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_工作微信号录入)]
|
||
public ActionResult Index()
|
||
{
|
||
//ToolBar
|
||
ToolBar tool = new ToolBar();
|
||
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.工作微信号录入, userRightId);
|
||
tool.AllowButton(toolbtn);
|
||
//tool.AllowButton("Create", "Edit", "Details", "Delete");
|
||
ViewBag.ToolBar = tool;
|
||
|
||
//table
|
||
Pager pager = new Pager() { page = 1, rows = 20 };
|
||
string tableId = "tablist";
|
||
Table tab = new Table(tableId);
|
||
tab.AddHiddenHeadCol("PKID", "编号");
|
||
tab.AddHeadCol("ALIAS", "", "微信号");
|
||
tab.AddHeadCol("EID", "", "员工编号");
|
||
tab.AddHeadCol("MOBILE", "", "手机号");
|
||
tab.AddHeadCol("RESID", "", "客户ID");
|
||
tab.AddHeadCol("AUDITSTATUS", "", "审核状态");
|
||
tab.AddHeadCol("QRCODEURL", "", "二维码");
|
||
tab.AddHeadCol("QRCODESIZE", "", "二维码大小");
|
||
tab.AddHeadCol("CTIME", "", "创建时间");
|
||
tab.AddHeadCol("QUANTITY", "", "微信序号");
|
||
tab.AddHeadCol("AUDITMEMO", "", "审核备注");
|
||
tab.AddHeadRow();
|
||
ViewBag.gridTable = tab.GetHead() + Pagination.GetPage(pager, tableId, "5,10,15,20");
|
||
return View();
|
||
}
|
||
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_待审核工作微信)]
|
||
public ActionResult AuditIndex()
|
||
{
|
||
//ToolBar
|
||
ToolBar tool = new ToolBar();
|
||
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.待审核工作微信, userRightId);
|
||
tool.AllowButton(toolbtn);
|
||
//tool.AllowButton("Create", "Edit", "Details", "Delete");
|
||
tool.AddOtherButton("Other1", "审核", "icon-detail", "Audit_Click", true);
|
||
tool.AddOtherButton("Other2", "下线", "icon-detail", "Stop_Click", true);
|
||
tool.AddOtherButton("Other3", "暂停", "icon-detail", "Pause_Click", true);
|
||
tool.AddOtherButton("Other4", "启用", "icon-detail", "ReUse_Click", true);
|
||
tool.AddOtherButton("Other5", "修改二维码", "icon-detail", "QRCode_Click", true);
|
||
ViewBag.ToolBar = tool;
|
||
|
||
//table
|
||
//Pager pager = new Pager() { page = 1, rows = 20 };
|
||
string tableId = "tablist";
|
||
Table tab = new Table(tableId);
|
||
tab.AddHiddenHeadCol("PKID", "编号");
|
||
tab.AddHeadCol("ALIAS", "", "微信号");
|
||
tab.AddHeadCol("EID", "", "员工编号");
|
||
tab.AddHeadCol("Name", "", "员工姓名");
|
||
tab.AddHeadCol("MOBILE", "", "手机号");
|
||
tab.AddHeadCol("RESID", "", "客户ID");
|
||
tab.AddHeadCol("AUDITSTATUS", "", "审核状态");
|
||
tab.AddHeadCol("IsValid", "", "微信状态");
|
||
tab.AddHeadCol("CTIME", "", "创建时间");
|
||
tab.AddHeadCol("QRCODESIZE", "", "二维码大小");
|
||
tab.AddHeadCol("QUANTITY", "", "微信序号");
|
||
tab.AddHeadCol("AUDITMEMO", "", "审核备注");
|
||
tab.AddHeadRow();
|
||
ViewBag.gridTable = tab.GetHead();
|
||
return View();
|
||
}
|
||
|
||
[HttpPost]
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_工作微信号录入)]
|
||
public JsonResult GetWorkAccountInitHtmlList(Pager pager, string columns)
|
||
{
|
||
List<WX_WORKACCOUNT_INIT> list = wx_WorkAccount_Init_BL.GetList(ref pager, null, null, Eid, null, null, null, null);
|
||
|
||
Table table = new Table(columns, true);
|
||
table.gridPager = pager;
|
||
foreach (var model in list)
|
||
{
|
||
table.AddHiddenCol(model.PKID);
|
||
table.AddCol(model.ALIAS);
|
||
table.AddCol(model.EID);
|
||
|
||
table.AddCol(model.MOBILE);
|
||
table.AddCol(model.RESID);
|
||
table.AddCol(model.AUDITSTATAUS == -1 ? string.Format("<span style=\"color:red\">{0}</span>", getAuditStatusText(model.AUDITSTATAUS.Value)) : getAuditStatusText(model.AUDITSTATAUS.Value));
|
||
table.AddCol(string.Format("<img src=\"{0}\" height=\"140\" width=\"140\"/>", model.QRCODEURL));
|
||
table.AddCol(model.QRCODESIZE.HasValue ? string.Format("{0}K", Math.Round(model.QRCODESIZE.Value / (1024)).ToString()) : "");
|
||
table.AddCol(model.CTIME);
|
||
table.AddCol(model.QUANTITY);
|
||
table.AddCol(model.AUDITSTATAUS != 1 ? model.AUDITMEMO : "");
|
||
table.AddRow();
|
||
}
|
||
var json = new
|
||
{
|
||
totalPages = pager.totalPages,
|
||
totalRows = pager.totalRows,
|
||
rowsList = table.GetRows()
|
||
};
|
||
return Json(json, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
[HttpPost]
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_待审核工作微信)]
|
||
public JsonResult GetAuditWorkAccountHtmlList(Pager pager, string alias, decimal? auditStatus, string resID, string eid, string isValid, string stime, string etime, string columns)
|
||
{
|
||
decimal parseEid;
|
||
decimal.TryParse(eid, out parseEid);
|
||
decimal? valid = null;
|
||
if (!string.IsNullOrWhiteSpace(isValid))
|
||
{
|
||
valid = Convert.ToDecimal(isValid);
|
||
}
|
||
pager.page = 1;
|
||
pager.rows = int.MaxValue;
|
||
List<WX_WORKACCOUNT_INIT> list = wx_WorkAccount_Init_BL.GetList(ref pager, alias, auditStatus, parseEid, resID, valid, stime, etime);
|
||
|
||
Table table = new Table(columns, true);
|
||
table.gridPager = pager;
|
||
foreach (var model in list)
|
||
{
|
||
table.AddHiddenCol(model.PKID);
|
||
table.AddCol(model.ALIAS);
|
||
table.AddCol(model.EID);
|
||
table.AddCol(InnerUserHelper.Instance.GetUsername(model.INNERUSERID));
|
||
table.AddCol(model.MOBILE);
|
||
table.AddCol(model.RESID);
|
||
table.AddCol(getAuditStatusText(model.AUDITSTATAUS.Value));
|
||
table.AddCol(model.AUDITSTATAUS == 1 ? (getWeixinValidText(model.ISVALID)) : "待审");
|
||
table.AddCol(model.CTIME);
|
||
table.AddCol(model.QRCODESIZE.HasValue ? string.Format("{0}K", Math.Round(model.QRCODESIZE.Value / (1024)).ToString()) : "");
|
||
table.AddCol(model.QUANTITY);
|
||
table.AddCol(model.AUDITMEMO);
|
||
table.AddRow();
|
||
}
|
||
var json = new
|
||
{
|
||
totalPages = pager.totalPages,
|
||
totalRows = pager.totalRows,
|
||
rowsList = table.GetRows()
|
||
};
|
||
return Json(json, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
[HttpGet]
|
||
[AuthorizeToolBar(InitRights.CONST_工作微信号录入, InitToolBar.CONST_Edit)]
|
||
public ActionResult Edit(string id)
|
||
{
|
||
WX_WORKACCOUNT_INIT model = null;
|
||
if (id == null)
|
||
{
|
||
model = new WX_WORKACCOUNT_INIT();
|
||
// 数据初始化
|
||
}
|
||
else
|
||
{
|
||
var pkid = Convert.ToDecimal(id);
|
||
model = wx_WorkAccount_Init_BL.Get(m => m.PKID == pkid);
|
||
|
||
}
|
||
|
||
return View(model);
|
||
}
|
||
|
||
|
||
[HttpPost]
|
||
[AuthorizeToolBar(InitRights.CONST_工作微信号录入, InitToolBar.CONST_Edit)]
|
||
public JsonResult Edit(WX_WORKACCOUNT_INIT model)
|
||
{
|
||
if (!ModelState.IsValid)
|
||
{
|
||
return JsonHandler.ValidateFailMessage();
|
||
}
|
||
|
||
if (model.PKID == 0)
|
||
{
|
||
var alias = model.ALIAS.Trim();
|
||
var isHaveAlias = wx_WorkAccount_Init_BL.Get(m => m.ALIAS == alias) != null;
|
||
if (isHaveAlias)
|
||
{
|
||
errors.Add("该微信号已经存在,不能重复添加!");
|
||
return JsonHandler.InsertMessage(errors, false);
|
||
}
|
||
|
||
var weixinCount = 0;
|
||
var quantity = 1;
|
||
var myWeiXinList = wx_WorkAccount_Init_BL.GetList(m => m.EID == Eid); //客服的工作微信号列表
|
||
if (myWeiXinList != null)
|
||
{
|
||
weixinCount = myWeiXinList.Count();
|
||
var list = myWeiXinList.Where(m => m.AUDITSTATAUS == 1 && m.ISVALID == 0); //客服被封号的微信号列表
|
||
if (list != null)
|
||
{
|
||
weixinCount = weixinCount - list.Count(); //客服非封号的微信号数量
|
||
}
|
||
var notTerminalist = myWeiXinList.Where(m => m.ISVALID != 0);
|
||
for (int i = 1; i <= 100; i++)
|
||
{
|
||
if (notTerminalist.Any(m => m.QUANTITY == i))
|
||
{
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
quantity = i;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
string roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId);//获取员工角色
|
||
if (roleCodes.IndexOf("SJZL") < 0 && roleCodes.IndexOf("GLY") < 0)
|
||
{
|
||
//后台配置的客服添加工作微信号数量
|
||
var setCount = cache_BL.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.WeiXin_WorkAccountInitCount);
|
||
int i = 1;
|
||
int.TryParse(setCount, out i);
|
||
if (weixinCount > (i - 1))
|
||
{
|
||
errors.Add(string.Format("一个用户最多添加{0}个微信号", setCount));
|
||
return JsonHandler.InsertMessage(errors, false);
|
||
}
|
||
}
|
||
|
||
var resultFilePath = UploadFile();
|
||
if (resultFilePath == null || string.IsNullOrWhiteSpace(resultFilePath[0]))
|
||
{
|
||
errors.Add("请上传微信二维码图片");
|
||
return JsonHandler.InsertMessage(errors, false);
|
||
|
||
}
|
||
|
||
|
||
model.PKID = new SEQUENCES_BL().Seq_base_get();
|
||
|
||
model.QRCODEURL = resultFilePath[0];
|
||
model.QRCODESIZE = Convert.ToDecimal(resultFilePath[1]);
|
||
model.RESID = ResUtil.CreateResId(model.MOBILE.Trim());
|
||
if (res_Customer_Q_BL.getResCustomerByResId(model.RESID) == null)
|
||
{
|
||
res_Customer_BL.ResgisterCustomer(model.MOBILE.Trim(), model.RESID, "workaccountinit");
|
||
}
|
||
|
||
model.CTIME = DateTime.Now;
|
||
model.EID = Eid;
|
||
model.MOBILE = model.MOBILE.Trim();
|
||
model.ALIAS = alias;
|
||
model.INNERUSERID = UserId;// InnerUserHelper.Instance.GetUserIdByEid(Eid);
|
||
model.AUDITSTATAUS = 0;
|
||
model.QUANTITY = quantity;
|
||
|
||
bool result = wx_WorkAccount_Init_BL.Add(model) == 1;
|
||
return JsonHandler.InsertMessage(errors, result);
|
||
}
|
||
else
|
||
{
|
||
|
||
var resultFilePath = UploadFile();
|
||
model.RESID = ResUtil.CreateResId(model.MOBILE.Trim());
|
||
if (res_Customer_Q_BL.getResCustomerByResId(model.RESID) == null)
|
||
{
|
||
res_Customer_BL.ResgisterCustomer(model.MOBILE.Trim(), model.RESID, "workaccountinit");
|
||
}
|
||
bool result = wx_WorkAccount_Init_BL.Update(ref errors, model.PKID, model.ALIAS, model.MOBILE, resultFilePath[0], 0, Convert.ToDecimal(resultFilePath[1]));
|
||
return JsonHandler.UpdateMessage(errors, result);
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
[AuthorizeToolBar(InitRights.CONST_待审核工作微信, InitToolBar.CONST_Other5)]
|
||
public ActionResult QRCodeEdit(string id)
|
||
{
|
||
WX_WORKACCOUNT_INIT model = null;
|
||
if (id == null)
|
||
{
|
||
model = new WX_WORKACCOUNT_INIT();
|
||
// 数据初始化
|
||
}
|
||
else
|
||
{
|
||
var pkid = Convert.ToDecimal(id);
|
||
|
||
model = wx_WorkAccount_Init_BL.Get(m => m.PKID == pkid);
|
||
ViewBag.AuditText = getAuditStatusText(model.AUDITSTATAUS.Value);
|
||
}
|
||
|
||
return View(model);
|
||
}
|
||
|
||
[HttpPost]
|
||
[AuthorizeToolBar(InitRights.CONST_待审核工作微信, InitToolBar.CONST_Other5)]
|
||
public JsonResult QRCodeEdit(WX_WORKACCOUNT_INIT model)
|
||
{
|
||
if (!ModelState.IsValid)
|
||
{
|
||
return JsonHandler.ValidateFailMessage();
|
||
}
|
||
|
||
if (model.PKID == 0)
|
||
{
|
||
errors.Add("请选择操作记录");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
var workAccountInit = wx_WorkAccount_Init_BL.Get(m => m.PKID == model.PKID);
|
||
if (workAccountInit == null)
|
||
{
|
||
errors.Add("请选择操作记录");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
var resultFilePath = UploadFile();
|
||
if (resultFilePath == null || string.IsNullOrWhiteSpace(resultFilePath[0]))
|
||
{
|
||
errors.Add("请上传微信二维码图片");
|
||
return JsonHandler.InsertMessage(errors, false);
|
||
|
||
}
|
||
bool result = wx_WorkAccount_Init_BL.UpdateQRCode(ref errors, model.PKID, resultFilePath[0], Convert.ToDecimal(resultFilePath[1]));
|
||
//当微信号开启的状态时候,推送图片数据,到网站数据库
|
||
if (workAccountInit.ISVALID == 1)
|
||
{
|
||
wx_WorkAccount_Init_BL.PushWordAccountData(ref errors, workAccountInit.ALIAS, 1);
|
||
}
|
||
return JsonHandler.UpdateMessage(errors, result);
|
||
|
||
}
|
||
|
||
[HttpGet]
|
||
[AuthorizeToolBar(InitRights.CONST_待审核工作微信, InitToolBar.CONST_Other1)]
|
||
public ActionResult AuditEdit(string id)
|
||
{
|
||
WX_WORKACCOUNT_INIT model = null;
|
||
if (id == null)
|
||
{
|
||
model = new WX_WORKACCOUNT_INIT();
|
||
// 数据初始化
|
||
}
|
||
else
|
||
{
|
||
var pkid = Convert.ToDecimal(id);
|
||
model = wx_WorkAccount_Init_BL.Get(m => m.PKID == pkid);
|
||
|
||
}
|
||
List<SelectListItem> list = new List<SelectListItem>()
|
||
{
|
||
new SelectListItem() {Text="待审核",Value="0" },
|
||
new SelectListItem() {Text ="审核通过",Value="1"},
|
||
new SelectListItem() {Text ="审核未通过",Value="-1"}
|
||
};
|
||
ViewBag.AuditStatusList = list;
|
||
ViewBag.AuditText = getAuditStatusText(model.AUDITSTATAUS.Value);
|
||
return View(model);
|
||
}
|
||
|
||
|
||
[HttpPost]
|
||
[AuthorizeToolBar(InitRights.CONST_待审核工作微信, InitToolBar.CONST_Other1)]
|
||
public JsonResult AuditEdit(WX_WORKACCOUNT_INIT model)
|
||
{
|
||
if (!ModelState.IsValid)
|
||
{
|
||
return JsonHandler.ValidateFailMessage();
|
||
}
|
||
|
||
if (model.PKID == 0)
|
||
{
|
||
errors.Add("没有选择操作记录");
|
||
return JsonHandler.InsertMessage(errors, false);
|
||
}
|
||
else
|
||
{
|
||
var workAccountInit = wx_WorkAccount_Init_BL.Get(m => m.PKID == model.PKID);
|
||
if (workAccountInit == null)
|
||
{
|
||
errors.Add("没有选择操作记录");
|
||
return JsonHandler.InsertMessage(errors, false);
|
||
}
|
||
|
||
|
||
var auditStatus = model.AUDITSTATAUS.Value;
|
||
var auditUser = InnerUserHelper.Instance.GetUserIdByEid(Eid);
|
||
|
||
if (auditStatus == 1)
|
||
{
|
||
bool flag = canAddWeixin(workAccountInit.EID);
|
||
if (!flag)
|
||
{
|
||
errors.Add("该用户名下的微信数,已经达到上限!不能再增加!");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
}
|
||
|
||
bool result = wx_WorkAccount_Init_BL.Audit(ref errors, model.PKID, auditStatus, model.AUDITMEMO, auditUser.ToString());
|
||
//审核通过的,同时处理WorkAccount表的相应信息
|
||
if (result && auditStatus == 1)
|
||
{
|
||
if (workAccountInit != null)
|
||
{
|
||
//更新workaccount表
|
||
decimal workAccountPkId;
|
||
result = wx_WorkAccount_BL.Update(ref errors, workAccountInit.ALIAS, workAccountInit.RESID, workAccountInit.QRCODEURL, workAccountInit.INNERUSERID.Value, workAccountInit.QUANTITY, out workAccountPkId);
|
||
if (result)
|
||
{
|
||
//微信号分配给内部人员
|
||
var msg = "";
|
||
result = wx_WorkAccount_BL.WxUserBindToInnerUser(workAccountInit.INNERUSERID.Value, workAccountPkId, workAccountInit.ALIAS, string.Format("{0:yyyy-MM-dd}", DateTime.Now), DateTime.Now, out msg);
|
||
if (!result)
|
||
{
|
||
errors.Add(msg);
|
||
}
|
||
else
|
||
{
|
||
//审核通过后,新增加的微信号,暂时不推广
|
||
result = wx_WorkAccount_Init_BL.ModifyWorkAccountIsValid(ref errors, workAccountInit.ALIAS, 2, DateTime.Now.AddYears(10).ToShortDateString(), "新微信号,暂不推广", UserId, 0);
|
||
// result = wx_WorkAccount_Init_BL.PushWordAccountData(ref errors, workAccountInit.ALIAS, 1);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return JsonHandler.UpdateMessage(errors, result);
|
||
}
|
||
}
|
||
|
||
[HttpGet]
|
||
[AuthorizeToolBar(InitRights.CONST_待审核工作微信, InitToolBar.CONST_Other3)]
|
||
public ActionResult AuditPause(string id)
|
||
{
|
||
WX_WORKACCOUNT_INIT model = null;
|
||
if (id == null)
|
||
{
|
||
model = new WX_WORKACCOUNT_INIT();
|
||
// 数据初始化
|
||
}
|
||
else
|
||
{
|
||
var pkid = Convert.ToDecimal(id);
|
||
model = wx_WorkAccount_Init_BL.Get(m => m.PKID == pkid);
|
||
|
||
}
|
||
return View(model);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 暂停微信号操作
|
||
/// </summary>
|
||
/// <param name="model"></param>
|
||
/// <param name="etime"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[AuthorizeToolBar(InitRights.CONST_待审核工作微信, InitToolBar.CONST_Other3)]
|
||
public JsonResult AuditPause(WX_WORKACCOUNT_INIT model, string etime)
|
||
{
|
||
if (!ModelState.IsValid)
|
||
{
|
||
return JsonHandler.ValidateFailMessage();
|
||
}
|
||
|
||
if (model.PKID == 0)
|
||
{
|
||
errors.Add("没有选择操作记录");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
else
|
||
{
|
||
var workAccountInit = wx_WorkAccount_Init_BL.Get(m => m.PKID == model.PKID);
|
||
if (workAccountInit == null)
|
||
{
|
||
errors.Add("操作记录不存在");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
if (!workAccountInit.ISVALID.HasValue || workAccountInit.ISVALID == 0 || workAccountInit.ISVALID == 3)
|
||
{
|
||
errors.Add("只有正常和手工暂停的微信状态才能执行暂停操作!");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
if (string.IsNullOrWhiteSpace(etime))
|
||
{
|
||
errors.Add("暂停截止时间必须要大于等于当前日期!");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
if (Convert.ToDateTime(etime) < DateTime.Now.Date)
|
||
{
|
||
errors.Add("暂停截止时间必须要大于等于当前日期!");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
if (string.IsNullOrWhiteSpace(model.AUDITMEMO))
|
||
{
|
||
errors.Add("备注信息不能为空!");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
var flag = wx_WorkAccount_Init_BL.ModifyWorkAccountIsValid(ref errors, workAccountInit.ALIAS, 2, etime, model.AUDITMEMO, UserId, 1);
|
||
//推送数据操作已经集成在oracle存储过程中
|
||
//flag = wx_WorkAccount_Init_BL.PushWordAccountData(ref errors, workAccountInit.ALIAS, 0);
|
||
|
||
return JsonHandler.UpdateMessage(errors, flag);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 封号微信号操作
|
||
/// </summary>
|
||
/// <param name="alias"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[AuthorizeToolBar(InitRights.CONST_待审核工作微信, InitToolBar.CONST_Other2)]
|
||
public JsonResult ModifyWorkAccountIsValid(string alias)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(alias))
|
||
{
|
||
errors.Add("请选择操作记录");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
var model = wx_WorkAccount_Init_BL.Get(m => m.ALIAS == alias);
|
||
if (model == null)
|
||
{
|
||
errors.Add("请选择操作记录");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
else
|
||
{
|
||
if (model.ISVALID == 0)
|
||
{
|
||
errors.Add("该微信号已经下线,无需重复操作");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
if (model.AUDITSTATAUS != 1)
|
||
{
|
||
errors.Add("只有审核通过的微信,才能执行下线操作!");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
}
|
||
|
||
var flag = wx_WorkAccount_Init_BL.ModifyWorkAccountIsValid(ref errors, alias, 0, "", "", UserId, 1);
|
||
//推送数据操作已经集成在oracle存储过程中
|
||
//if (flag)
|
||
//{
|
||
// flag = wx_WorkAccount_Init_BL.PushWordAccountData(ref errors, alias, 0);//推送微信工作号数据
|
||
//}
|
||
return JsonHandler.UpdateMessage(errors, flag);
|
||
}
|
||
|
||
[HttpGet]
|
||
[AuthorizeToolBar(InitRights.CONST_待审核工作微信, InitToolBar.CONST_Other2)]
|
||
public ActionResult AuditStop(string id)
|
||
{
|
||
WX_WORKACCOUNT_INIT model = null;
|
||
if (id == null)
|
||
{
|
||
model = new WX_WORKACCOUNT_INIT();
|
||
// 数据初始化
|
||
}
|
||
else
|
||
{
|
||
var pkid = Convert.ToDecimal(id);
|
||
model = wx_WorkAccount_Init_BL.Get(m => m.PKID == pkid);
|
||
|
||
}
|
||
return View(model);
|
||
}
|
||
|
||
[HttpPost]
|
||
[AuthorizeToolBar(InitRights.CONST_待审核工作微信, InitToolBar.CONST_Other2)]
|
||
public JsonResult AuditStop(WX_WORKACCOUNT_INIT model)
|
||
{
|
||
if (!ModelState.IsValid)
|
||
{
|
||
return JsonHandler.ValidateFailMessage();
|
||
}
|
||
|
||
if (model.PKID == 0)
|
||
{
|
||
errors.Add("没有选择操作记录");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
else
|
||
{
|
||
var workAccountInit = wx_WorkAccount_Init_BL.Get(m => m.PKID == model.PKID);
|
||
if (workAccountInit == null)
|
||
{
|
||
errors.Add("操作记录不存在");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
if (workAccountInit.ISVALID == 0)
|
||
{
|
||
errors.Add("该微信号已经停用,无需重复操作");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
if (workAccountInit.AUDITSTATAUS != 1)
|
||
{
|
||
errors.Add("只有审核通过的微信,才能执行下线操作!");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
if (string.IsNullOrWhiteSpace(model.AUDITMEMO))
|
||
{
|
||
errors.Add("备注信息不能为空!");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
var flag = wx_WorkAccount_Init_BL.ModifyWorkAccountIsValid(ref errors, workAccountInit.ALIAS, 0, "", model.AUDITMEMO, UserId, 1);
|
||
//推送数据操作已经集成在oracle存储过程中
|
||
//flag = wx_WorkAccount_Init_BL.PushWordAccountData(ref errors, workAccountInit.ALIAS, 0);
|
||
|
||
return JsonHandler.UpdateMessage(errors, flag);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 重新启用暂停的微信号操作
|
||
/// </summary>
|
||
/// <param name="alias"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[AuthorizeToolBar(InitRights.CONST_待审核工作微信, InitToolBar.CONST_Other4)]
|
||
public JsonResult ReUseWorkAccount(string alias)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(alias))
|
||
{
|
||
errors.Add("请选择操作记录");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
var model = wx_WorkAccount_Init_BL.Get(m => m.ALIAS == alias);
|
||
if (model == null)
|
||
{
|
||
errors.Add("请选择操作记录");
|
||
return JsonHandler.UpdateMessage(errors, false);
|
||
}
|
||
else
|
||
{
|
||
//var useList = wx_WorkAccount_Init_BL.GetList(m => m.INNERUSERID == model.INNERUSERID && m.ISVALID > 0 && m.ISVALID != 2 && m.ALIAS != alias).ToList();
|
||
//if(useList!=null && useList.Count> 0)
|
||
//{
|
||
// errors.Add("该用户已有一个微信号在推广,不能再次开启第二个推广微信");
|
||
// return JsonHandler.UpdateMessage(errors, false);
|
||
//}
|
||
//if (model.ISVALID != 2 && model.ISVALID != 3)
|
||
//{
|
||
// errors.Add("只有暂停的微信号,才能执行此操作");
|
||
// return JsonHandler.UpdateMessage(errors, false);
|
||
//}
|
||
}
|
||
var flag = wx_WorkAccount_Init_BL.ModifyWorkAccountIsValid(ref errors, alias, 1, "", "", UserId, 1);
|
||
//推送数据操作已经集成在oracle存储过程中
|
||
//if (flag)
|
||
//{
|
||
// flag = wx_WorkAccount_Init_BL.PushWordAccountData(ref errors, alias, 1);//推送微信工作号数据
|
||
//}
|
||
return JsonHandler.UpdateMessage(errors, flag);
|
||
}
|
||
|
||
public string[] UploadFile()
|
||
{
|
||
var result = new string[] { "", "0" };
|
||
var resultFilePath = "";
|
||
try
|
||
{
|
||
string vPath = System.Configuration.ConfigurationManager.AppSettings["UploadWeixinQRCode"];
|
||
HttpFileCollectionBase files = Request.Files;
|
||
HttpPostedFileBase file = files["FileQRCodeUrl"];
|
||
|
||
if (file != null && file.ContentLength > 0)
|
||
{
|
||
result[1] = file.ContentLength.ToString();
|
||
string fileName = file.FileName;
|
||
string extName = fileName.Substring(fileName.LastIndexOf('.'), fileName.Length - fileName.LastIndexOf('.')).ToLower();
|
||
if (extName != ".jpg" && extName != ".png" && extName != ".gif" && extName != ".jpeg" && extName != ".bmp")
|
||
{
|
||
return result;
|
||
}
|
||
//判断文件名字是否包含路径名,如果有则提取文件名
|
||
//if (fileName.LastIndexOf("\\") > -1)
|
||
//{
|
||
// fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
|
||
//}
|
||
//vPath = string.Format("{0}/{1:yyyy}/{1:MM}", vPath, DateTime.Now);
|
||
fileName = string.Format("{0}{1}", Guid.NewGuid().ToString(), extName);
|
||
if (!System.IO.Directory.Exists(Server.MapPath(vPath)))
|
||
{
|
||
System.IO.Directory.CreateDirectory(Server.MapPath(vPath));
|
||
}
|
||
string path = Server.MapPath((vPath + "/") + fileName);
|
||
file.SaveAs(path);
|
||
resultFilePath = string.Format("{0}/{1}", vPath, fileName); //上传带路径的图片
|
||
System.Net.WebClient client = new System.Net.WebClient();
|
||
var buffer = System.IO.File.ReadAllBytes(Server.MapPath(resultFilePath));
|
||
//client.UploadDataCompleted += UploadWc_UploadDataCompleted;
|
||
|
||
var UploadQrCodeUrl = System.Configuration.ConfigurationManager.AppSettings["UploadQrCodeUrl"].ToString();
|
||
var url = string.Format("{0}?filePath={1}", UploadQrCodeUrl, resultFilePath);
|
||
byte[] byteArray = client.UploadData(new Uri(url), buffer);
|
||
string res = System.Text.Encoding.Default.GetString(byteArray); //返回结果是一个xml值
|
||
var flag = res.Replace("</boolean>", "").Replace("<boolean xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">", ""); //去掉xml标签
|
||
if (flag != "true")
|
||
{
|
||
resultFilePath = "";//如果接口上传二维码出错,返回空值
|
||
}
|
||
result[0] = resultFilePath;
|
||
}
|
||
return result;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("WorkAccountInitController:【UploadFile】:" + ex.Message + ex.StackTrace);
|
||
return result;
|
||
}
|
||
}
|
||
|
||
private string getAuditStatusText(decimal auditStatus)
|
||
{
|
||
if (auditStatus == 0)
|
||
return "待审核";
|
||
else if (auditStatus == -1)
|
||
return "审核未通过";
|
||
else
|
||
return "审核通过";
|
||
}
|
||
|
||
private string getWeixinValidText(decimal? valid)
|
||
{
|
||
if (!valid.HasValue)
|
||
return "待审";
|
||
if (valid == 0)
|
||
return string.Format("<span style=\"color:red\">{0}</span>", "下线");
|
||
else if (valid == 1)
|
||
return "正常";
|
||
else if (valid == 2)
|
||
return string.Format("<span style=\"color:red\">{0}</span>", "手工暂停");
|
||
else if (valid == 3)
|
||
return string.Format("<span style=\"color:red\">{0}</span>", "系统暂停");
|
||
else
|
||
return "待审";
|
||
}
|
||
|
||
private bool canAddWeixin(decimal? eid)
|
||
{
|
||
if (!eid.HasValue)
|
||
return false;
|
||
var roleList = _inneruserRole.GetInneruserRoleByUserId(InnerUserHelper.Instance.GetUserIdByEid(eid));
|
||
string roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(roleList.Select(m => m.ROLEID).ToArray<decimal>());//获取员工角色
|
||
if (roleCodes.IndexOf("SJZL") < 0 && roleCodes.IndexOf("GLY") < 0)
|
||
{
|
||
var weixinCount = 0;
|
||
var myWeiXinList = wx_WorkAccount_Init_BL.GetList(m => m.EID == eid && m.AUDITSTATAUS == 1); //客服审核通过的工作微信号列表
|
||
if (myWeiXinList != null)
|
||
{
|
||
weixinCount = myWeiXinList.Count();
|
||
var list = myWeiXinList.Where(m => m.AUDITSTATAUS == 1 && m.ISVALID == 0); //客服被封号的微信号列表
|
||
if (list != null)
|
||
{
|
||
weixinCount = weixinCount - list.Count(); //客服非封号的微信号数量
|
||
}
|
||
}
|
||
//后台配置的客服添加工作微信号数量
|
||
var setCount = cache_BL.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.WeiXin_WorkAccountInitCount);
|
||
int i = 1;
|
||
int.TryParse(setCount, out i);
|
||
if (weixinCount > (i - 1))
|
||
{
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
|
||
public JsonResult IintQRCodeSize()
|
||
{
|
||
var list = wx_WorkAccount_Init_BL.GetList();
|
||
string str = "";
|
||
foreach (var model in list)
|
||
{
|
||
System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(model.QRCODEURL));
|
||
|
||
if (file != null && file.Exists)
|
||
{
|
||
model.QRCODESIZE = file.Length;
|
||
wx_WorkAccount_Init_BL.Update(model);
|
||
str += string.Format("file:{0},length:{1},lengthK:{2}\r\n", model.QRCODEURL, file.Length, Math.Round((double)file.Length / 1024));
|
||
}
|
||
}
|
||
return JsonHandler.ManageMessage(str, true);
|
||
}
|
||
}
|
||
} |