ComplianceServer/oldcode/Core.Web/Controllers/BlackNumberController.cs

440 lines
20 KiB
C#
Raw 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 Core.Web.App_Start;
using Core.Web.WebHelper;
using CRM.Core.BLL.BlackNumber;
using CRM.Core.BLL.Res;
using CRM.Core.BLL.Soft;
using CRM.Core.BLL.Util;
using CRM.Core.BLL.Wx;
using CRM.Core.Common;
using CRM.Core.Common.Layui;
using CRM.Core.Common.WebHelper;
using CRM.Core.DTO.Ord;
using CRM.Core.Model.Entity;
using CRM.Core.Model.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
namespace Core.Web.Controllers
{
public class BlackNumberController : BaseController
{
private CACHE_BL _cache = new CACHE_BL();
private BlackNumber_BL blackNumber_BL = new BlackNumber_BL();
private RES_CUSTOMER_BL res_Customer_BL = new RES_CUSTOMER_BL();
private RES_RESOURCEMOBILE_BL mobile_BL = new RES_RESOURCEMOBILE_BL();
private SOFT_USER_BL _softUserQ = new SOFT_USER_BL();
private RES_RESOURCEMOBILE_BL my = new RES_RESOURCEMOBILE_BL();
private SecurityHelper sHelper = new SecurityHelper();
// GET: Bill
[HttpGet]
[AuthorizeRedirect(RightsConfig.CONST_黑名单管理, ToolBarConfig.CONST_NotButton, true)]
public ActionResult Index()
{
ViewBag.rightCode = RightsConfig.CONST_黑名单管理;
//ViewBag.companyList = _cache.GetCompanyVirtual();
ViewBag.hgServiceHost = _cache.GetValue_Parameter("HgCrm_ServiceHost");
return View();
}
[HttpPost]
[AuthorizeRedirect(RightsConfig.CONST_黑名单管理, ToolBarConfig.CONST_NotButton, false)]
public JsonResult Index(Laypage pager, OrderQueryDto dto)
{
var list = blackNumber_BL.GetList(ref pager,dto);
var data = new LayuiData<CSVR_BLACKNUMBER_View>()
{
msg = "数据加载成功!",
count = pager.count,
code = 0,
data = list
};
return Json(data, JsonRequestBehavior.AllowGet);
}
[HttpGet]
[AuthorizeRedirect(RightsConfig.CONST_黑名单管理, ToolBarConfig.CONST_Add,false)]
public ActionResult Add()
{
CSVR_BLACKNUMBER model = null;
var companyList = new CACHE_BL().GetCompanyVirtual();
var allChannel = new List<Dictionary<string, string>>();
var allchannel = new Dictionary<string, string>
{
{ "name", "全事业部" },
{ "value", "-1" }
};
allChannel.Add(allchannel);
foreach (var company in companyList)
{
var channel = new Dictionary<string, string>
{
{ "name", company.CompanyName },
{ "value", company.Channel.Replace(",", ";") }
};
allChannel.Add(channel);
}
ViewBag.AllChannel = JsonHelper.ToJson(allChannel);
return View(model);
}
[HttpPost]
[AuthorizeRedirect(RightsConfig.CONST_黑名单管理, ToolBarConfig.CONST_Add, false)]
public ActionResult Add(string Blacktype,string txt_channel, string BLACKNUMBER_resids, string Reson, string txt_inputType)
{
try
{
string message = "";
List<CSVR_BLACKNUMBER> numbers = new List<CSVR_BLACKNUMBER>();
var channelName = "全事业部";
if (!string.IsNullOrWhiteSpace(txt_channel) && txt_channel != "-1")
{
var companyList = new CACHE_BL().GetCompanyVirtual();
var channelFilter = txt_channel.Split(',').Select(n => n.Replace(";", ",")).ToList();
var deptList = companyList.Where(n => channelFilter.Contains(n.Channel)).ToList();
channelName = string.Join(",", deptList.Select(n => n.CompanyName));
//txt_channel = txt_channel.Replace(";", ",");
}
if (txt_inputType == "2")
{
List<string> trueResIds = new List<string>();
string[] numberList = BLACKNUMBER_resids.Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace("", ",").Split(',');
foreach (string number in numberList)
{
if (string.IsNullOrEmpty(number)) continue;
var resid = WX.CRM.Common.ResUtil.CreateResId(number);
CSVR_BLACKNUMBER model = new CSVR_BLACKNUMBER
{
RESID = resid,
BLACKTYPE = Blacktype,
REASON = Reson,
CTIME = DateTime.Now,
CREATEUSER = UserId,
CREATEUSERNAME = Eid + "-" + UserName,
DeptChannel = txt_channel,
ChannelName = channelName
};
numbers.Add(model);
trueResIds.Add(resid);
}
string[] existresIds = blackNumber_BL.GetByResIds(trueResIds.ToArray(), Blacktype).Select(m => m.RESID.Trim()).ToArray();
if (existresIds.Count() > 0)
{
message += "已存在黑名单的客户ID" + string.Join(",", existresIds);
}
}
else
{
Reson = string.IsNullOrEmpty(Reson) ? " " : Reson;
if (string.IsNullOrEmpty(BLACKNUMBER_resids.Trim()))
{
return Json(new { type = 0, message = "找不到对应的客户Id", value = "" }, JsonRequestBehavior.AllowGet);
}
if (string.IsNullOrEmpty(txt_channel.Trim()) || string.IsNullOrEmpty(Reson.Trim()))
{
return Json(new { type = 0, message = "事业部和备注不能为空", value = "" }, JsonRequestBehavior.AllowGet);
}
var resIds = BLACKNUMBER_resids.Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace("", ",").Split(',').ToList();
resIds = blackNumber_BL.ChangeToResids(resIds);
string[] trueResIds = res_Customer_BL.getResByResIds(resIds.ToArray()).Select(m => m.RESID.Trim()).ToArray();
string[] existresIds = blackNumber_BL.GetByResIds(trueResIds, Blacktype).Select(m => m.RESID.Trim()).ToArray();
var nottrue = resIds.Except(trueResIds);
if (nottrue.Count() > 0)
{
message = "不存在系统的客户ID" + string.Join(",", blackNumber_BL.ChangeToumids(nottrue.ToList()));
}
if (existresIds.Count() > 0)
{
message += "已存在黑名单的客户ID" + string.Join(",", blackNumber_BL.ChangeToumids(existresIds.ToList()));
}
/////////
var updateResIds = trueResIds.Except(existresIds);
foreach (string resid in updateResIds)
{
if (!string.IsNullOrEmpty(resid))
{
CSVR_BLACKNUMBER model = new CSVR_BLACKNUMBER();
model.RESID = resid;
model.BLACKTYPE = Blacktype;
model.REASON = Reson;
model.CTIME = DateTime.Now;
model.CREATEUSER = UserId;
model.CREATEUSERNAME = Eid + "-" + UserName;
model.DeptChannel = txt_channel;
model.ChannelName = channelName;
numbers.Add(model);
}
}
}
if (!string.IsNullOrEmpty(message))
{
return Json(new { type = false, message = message, value = message }, JsonRequestBehavior.AllowGet);
}
if (numbers.Count > 0)
{
bool result = blackNumber_BL.CreateEntities(numbers);
if (result)
{
foreach(var item in numbers)
{
OpenFreeOrderRoot(item.RESID);
}
}
string msg = result ? "添加成功" : "添加失败";
return Json(new { type = result, message = msg, value = message }, JsonRequestBehavior.AllowGet);
}
else
{
return Json(new { type = 0, message = "添加失败,资源不存在系统或已经在黑名单里", value = message }, JsonRequestBehavior.AllowGet);
}
}
catch (Exception ex)
{
//errors.Add(ex.Message);
LogHelper.Error("BlackNumberController_Add:" + ex.StackTrace + ";" + ex.Message);
return Json(new { type = 0, message = ex.Message, value = "" }, JsonRequestBehavior.AllowGet);
}
}
/// <summary>
/// 写入风险客户权限
/// </summary>
/// <param name="resid"></param>
/// <returns></returns>
private bool OpenFreeOrderRoot(string resid)
{
var customer = res_Customer_BL.getResCustomerByResId(resid);
if (customer == null)
{
return false;
}
var list = res_Customer_BL.GetListByCustomerId(customer.CUSTOMERID);
var softuser = _softUserQ.GetUserList_userName(list.Select(m => m.USERNAME).ToArray());
foreach (var item in softuser)
{
var theModel = new freeordermodel
{
mobile = my.GetNumberByResId(resid),
needpay = 0,
opendays = 1,
ordertype = 1,
productId = 1092,
remark = "风险客户",
saledeptid = companyId,
source = "1",
softusername = item.USERNAME,
productcode = "UPCFJC_20201209093318_MFTY",//小类代码
teamserve = 1,
userid = 600000207,
count = 365 * 3,//产品数 --免费产品始终一天,这里天数作为数量传递,达到天数效果
productType = 0,//产品分类
opuser = UserId,
ctime = WX.CRM.Common.DateTimeTool.ConvertDateTimeInt(DateTime.Now).ToString(),
companycode = WX.CRM.Common.Utility.GetSettingOrNullByKey("DataClientCode"),
days = 365 * 3
};
var url = _cache.GetValue_Parameter("Core_ZxdService_FreeOrder");//内部接口··开通免费订单接口
var json = WX.CRM.Common.Utility.ConvertToJSON<freeordermodel>(theModel);
json = sHelper.createSignEncodingStr(json, SecurityHelper.OrderClientIdKey);
//LogHelper.Info("投顾订单" + model.ORDERID + (string.IsNullOrEmpty(model.WEBORDERID) ? "" : string.Format("({0})", model.WEBORDERID)) + "审核:" + url + "?" + json);
string retmsg = WX.CRM.Common.Utility.PostData(url + "?" + json, Encoding.UTF8);
retmsg = sHelper.decyptData(SecurityHelper.OrderClientIdKey, retmsg);
CreateOrderRsp retmessage = JsonHelper.JsonDivertToObj<CreateOrderRsp>(retmsg);//返回信息
if (retmessage.retCode == (int)NodeJsOrderEnum.)//成功
{
LogHelper.Info("写入风险客户权限成功!" + resid + "---" + item.USERNAME);
}
else
{
LogHelper.Error("写入风险客户权限失败!" + resid + "---" + item.USERNAME);
}
}
return true;
}
/// <summary>
/// 删除风险客户权限
/// </summary>
/// <param name="resid"></param>
private void CloseFreeOrderRoot(string resid)
{
var customer = res_Customer_BL.getResCustomerByResId(resid);
if (customer == null)
{
return;
}
var list = res_Customer_BL.GetListByCustomerId(customer.CUSTOMERID);
var softuser = _softUserQ.GetUserList_userName(list.Select(m => m.USERNAME).ToArray());
foreach (var item in softuser)
{
var theModel = new freeOrderClose
{
orderId = "1092",//订单ID
userName = item.USERNAME
};
var url = _cache.GetValue_Parameter("Core_ZxdService_CloseFreeOrder");//内部接口··开通免费订单接口
var json = WX.CRM.Common.Utility.ConvertToJSON<freeOrderClose>(theModel);
json = sHelper.createSignEncodingStr(json, SecurityHelper.OrderClientIdKey);
//LogHelper.Info("投顾订单" + model.ORDERID + (string.IsNullOrEmpty(model.WEBORDERID) ? "" : string.Format("({0})", model.WEBORDERID)) + "关闭:" + url + "?" + json);
string retmsg = WX.CRM.Common.Utility.PostData(url + "?" + json, Encoding.UTF8);
retmsg = sHelper.decyptData(SecurityHelper.OrderClientIdKey, retmsg);
freeOrderCloseRes retmessage = JsonHelper.JsonDivertToObj<freeOrderCloseRes>(retmsg);//返回信息
if (retmessage.iRet == 0)
{
LogHelper.Info("删除风险客户权限成功!" + resid + "---" + item.USERNAME);
}
else
{
LogHelper.Error("删除风险客户权限失败!" + resid + "---" + item.USERNAME);
}
}
}
[HttpGet]
[AuthorizeRedirect(RightsConfig.CONST_黑名单管理, ToolBarConfig.CONST_Add, false)]
public ActionResult Edit(decimal? id)
{
CSVR_BLACKNUMBER model = blackNumber_BL.Get(n=>n.PKID == id);
var companyList = new CACHE_BL().GetCompanyVirtual();
var allChannel = new List<object>();
if (model.DeptChannel.Split(',').Contains("-1"))
{
var allchannel = new
{
name = "全事业部",
value = "-1",
selected = true
};
allChannel.Add(allchannel);
}
else
{
var allchannel = new Dictionary<string, string>
{
{ "name", "全事业部" },
{ "value", "-1" }
};
allChannel.Add(allchannel);
}
foreach (var company in companyList)
{
if(model.DeptChannel.Split(',').Contains(company.Channel.Replace(",", ";")))
{
var channel = new
{
name = company.CompanyName,
value = company.Channel.Replace(",", ";"),
selected = true
};
allChannel.Add(channel);
}
else
{
var channel = new Dictionary<string, string>
{
{ "name", company.CompanyName },
{ "value", company.Channel.Replace(",", ";") }
};
allChannel.Add(channel);
}
}
ViewBag.AllChannel = JsonHelper.ToJson(allChannel);
return View(model);
}
[HttpPost]
[AuthorizeRedirect(RightsConfig.CONST_黑名单管理, ToolBarConfig.CONST_Add, false)]
public ActionResult Edit(string Blacktype, string txt_channel, decimal PKID, string Reson)
{
var model = blackNumber_BL.Get(n => n.PKID == PKID);
if (model == null)
{
return Json(new { type = 0, message = "找不到对应的客户Id", value = "" }, JsonRequestBehavior.AllowGet);
}
if (string.IsNullOrEmpty(txt_channel.Trim()) || string.IsNullOrEmpty(Reson.Trim()))
{
return Json(new { type = 0, message = "事业部和备注不能为空", value = "" }, JsonRequestBehavior.AllowGet);
}
if (!ModelState.IsValid)
{
return JsonHandler.JsonResultSerialize(ModelState);
}
try
{
var channelName = "全事业部";
if (!string.IsNullOrWhiteSpace(txt_channel) && txt_channel != "-1")
{
var companyList = new CACHE_BL().GetCompanyVirtual();
var channelFilter = txt_channel.Split(',').Select(n => n.Replace(";", ",")).ToList();
var deptList = companyList.Where(n => channelFilter.Contains(n.Channel)).ToList();
channelName = string.Join(",", deptList.Select(n => n.CompanyName));
}
model.REASON = Reson;
model.CREATEUSER = UserId;
model.CREATEUSERNAME = Eid + "-" + UserName;
model.DeptChannel = txt_channel;
model.ChannelName = channelName;
var result = blackNumber_BL.Update(model);
string msg = result ? "添加成功" : "添加失败";
return Json(new { type = result, message = msg, value = msg }, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
LogHelper.Error("BlackNumberController_Add:" + ex.StackTrace + ";" + ex.Message);
return Json(new { type = 0, message = ex.Message, value = "" }, JsonRequestBehavior.AllowGet);
}
}
public JsonResult GetAllResId(string resId)
{
resId = resId.Trim();
List<RES_CUSTOMER> list = res_Customer_BL.GetList_CustomerByResid(resId);
list = list.Where(m => m.RESID == resId || m.CUSTOMERID == resId).ToList();
List<object> obj = new List<object>();
foreach (RES_CUSTOMER model in list)
{
obj.Add(new { RESID = model.RESID, LASTNUM3 = model.LASTNUM3, ISPRIMARYNUM = model.CUSTOMERID == model.RESID?1:0 });
}
return Json(new { result = list.Count > 0 ? 1 : 0, message = list.Count > 0 ? "" : "请输入正确的客户ID", ResIds = obj });
}
[AuthorizeRedirect(RightsConfig.CONST_黑名单管理, ToolBarConfig.CONST_Delete, false)]
public JsonResult Delete(string id)
{
if (string.IsNullOrWhiteSpace(id))
{
return JsonHandler.ManageMessage("参数不对!", false);
}
//_saleMemo.DeleteHmdMemo(entity.RESID);
var result = false;
var errors = "删除成功";
try
{
var model = blackNumber_BL.GetCSVR_BLACKNUMBER(Convert.ToDecimal(id));
result = blackNumber_BL.RemoveEntity(Convert.ToDecimal(id));
if (result)
{
CloseFreeOrderRoot(model.RESID);
}
}
catch(Exception ex)
{
result = false;
errors = ex.Message;
}
return JsonHandler.DeleteMessage(null, result);
}
}
}