ComplianceServer/oldcode/WEB/Controllers/Csvr/CustomerRelationController.cs

524 lines
25 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 CRM.Core.DTO;
using CRM.Core.DTO.Res;
using Newtonsoft.Json;
using Ninject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using WX.CRM.BLL.Util;
using WX.CRM.Common;
using WX.CRM.IBLL.Csvr;
using WX.CRM.IBLL.Res;
using WX.CRM.IBLL.Util;
using WX.CRM.Model.DTO;
using WX.CRM.Model.Entity;
using WX.CRM.Model.Enum;
using WX.CRM.WEB.ViewModel.Sale;
using WX.CRM.WebHelper;
using CSVR_UNITECUSTOMERAPPLY = WX.CRM.Model.Entity.CSVR_UNITECUSTOMERAPPLY;
using CSVR_UNITECUSTOMERAPPLYDETAIL = WX.CRM.Model.Entity.CSVR_UNITECUSTOMERAPPLYDETAIL;
namespace WX.CRM.WEB.Controllers.Csvr
{
public class CustomerRelationController : BaseController
{
[Inject]
public ISecurityHelper sHelper { get; set; }
[Inject]
public IRES_RESOURCEMOBILE_Q res_ResourceMobile_BL { get; set; }
IRES_CUSTOMER_Q _customerBll_Q;
ICSVR_UNITECUSTOMERAPPLY _uniteApply;
ICSVR_UNITECUSTOMERAPPLY_Q _uniteApply_Q;
ICSVR_UNITECUSTOMERAPPLYDETAIL _uniteApplyDetail;
ICSVR_UNITECUSTOMERAPPLYDETAIL_Q _uniteApplyDetail_Q;
private ICACHE_Q _cacheQ;
public CustomerRelationController(IRES_CUSTOMER_Q customerBll_Q, ICSVR_UNITECUSTOMERAPPLY uniteApply,
ICSVR_UNITECUSTOMERAPPLYDETAIL uniteApplyDetail, ICSVR_UNITECUSTOMERAPPLY_Q uniteApply_Q, ICSVR_UNITECUSTOMERAPPLYDETAIL_Q uniteApplyDetail_Q, ICACHE_Q cacheQ)
{
this._customerBll_Q = customerBll_Q;
this._uniteApply = uniteApply;
this._uniteApplyDetail = uniteApplyDetail;
this._uniteApply_Q = uniteApply_Q;
this._uniteApplyDetail_Q = uniteApplyDetail_Q;
this._cacheQ = cacheQ;
}
ValidationErrors errors = new ValidationErrors();
#region
[AuthorizeRedirect(Roles = InitRights.CONST_客户关系变更申请)]
public ActionResult Apply()
{
Table tab = new Table("tablist");
tab.AddHeadCol("resID", "", "客户ID");
tab.AddHeadCol("cID", "", "原主客户ID");
tab.AddHeadCol("cName", "", "姓名");
tab.AddHeadCol("cMobile", "", "联系方式");
tab.AddHeadCol("newCID", "", "新主客户ID");
tab.AddHeadRow();
ViewBag.ListOne = tab.GetTable();
return View();
}
#endregion
#region
[AuthorizeRedirect(Roles = InitRights.CONST_客户关系变更申请)]
public JsonResult GetAllResIdInfo(string columns)
{
string res1 = Request.Form["Res1"];
string res2 = Request.Form["Res2"];
string customerid = string.Empty;
if (!string.IsNullOrEmpty(res1))
customerid += res1.Trim() + ",";
if (!string.IsNullOrEmpty(res2))
customerid += res2.Trim() + ",";
if (customerid.Length > 0)
customerid = customerid.Substring(0, customerid.Length - 1);
List<RES_CUSTOMER> list = _customerBll_Q.GetList_Customer(customerid);
if (list.Count == 0)
{
return JsonHandler.ManageMessage("查找的客户ID有误", false);
}
else
{
Table tb = new Table(columns, true);
string customerTemp = string.Empty;
string[] colors = { "red", "blue", "green", "peru" };
int colorIndex = -1;
foreach (RES_CUSTOMER model in list)
{
tb.AddCol(model.RESID);
if (customerTemp != model.CUSTOMERID)
{
colorIndex++;
}
tb.AddCol("color:" + colors[colorIndex] + "", "", model.CUSTOMERID);
customerTemp = model.CUSTOMERID;
tb.AddCol(model.RES_CUSTOMERDETAIL.CNAME);
//tb.AddCol(ResUtil.Reve_ms(model.RESID));
tb.AddCol(model.LASTNUM3);
tb.AddCol(DropDownList(list, model.RESID));
tb.AddRow();
}
var json = new
{
totalPages = 1,
totalRows = list.Count(),
rowsList = tb.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
}
#endregion
#region
[HttpPost]
public ActionResult CheckData(string data)
{
List<CustomerRelation> lists = JsonHelper.JsonDivertToObj<List<CustomerRelation>>(data);
List<string> resId = lists.Select(p => p.resId).ToList();
List<string> newCustomerid = lists.Select(p => p.newCustomerid).ToList();
for (int h = 0; h < resId.Count; h++)
{
if (resId[h] == newCustomerid[h])
continue;
else
{
int index = resId.IndexOf(newCustomerid[h]);
if (newCustomerid[index] == resId[index])
continue;
return JsonHandler.ManageMessage("不能选择被合并的客户ID作为新的主客户ID", false);
}
}
#region
Table tab2 = new Table("tablist2");
tab2.AddHeadCol("resID", "", "客户ID");
tab2.AddHeadCol("cID", "", "原主客户ID");
tab2.AddHeadCol("newCID", "", "新主客户ID");
tab2.AddHeadRow();
lists = lists.OrderByDescending(m => m.newCustomerid).ToList();
string customerTemp = string.Empty;
string[] colors = { "red", "blue", "palegoldenrod", "peru", "antique violet", "blueviolet", "cornsilk", "olive ", "shocking pink", "aquamarine" };
int colorIndex = -1;
foreach (CustomerRelation model in lists)
{
tab2.AddCol(model.resId);
tab2.AddCol(model.oldCustomerid);
if (customerTemp != model.newCustomerid)
{
colorIndex++;
}
tab2.AddCol("color:" + colors[colorIndex] + "", "", model.newCustomerid);
customerTemp = model.newCustomerid;
tab2.AddRow();
}
var json = new
{
rowsList = tab2.GetTable(),
};
#endregion
return Json(json, JsonRequestBehavior.AllowGet);
}
#endregion
#region
[HttpPost]
public JsonResult Submit(string Res1, string Res2, string Reason, string detail)
{
List<CustomerRelation> lists = JsonHelper.JsonDivertToObj<List<CustomerRelation>>(detail);
CSVR_UNITECUSTOMERAPPLY applyModel = new CSVR_UNITECUSTOMERAPPLY
{
APPLYTIME = DateTime.Now,
APPREMARK = Reason,
APPLYID = UserId,
RESID1 = Res1 == null ? "" : Res1.Trim(),
RESID2 = Res2 == null ? "" : Res2.Trim(),
STATE = 0
};
decimal uniteID = _uniteApply.Create_UniteCustomerApply(ref errors, applyModel);
return JsonHandler.InsertMessage(errors, _uniteApplyDetail.Creata_UnitCustomerApplyDetail(ref errors, lists, uniteID));
}
#endregion
#region
private MvcHtmlString DropDownList(List<RES_CUSTOMER> list, string customerid)
{
StringBuilder ddl = new StringBuilder();
ddl.AppendFormat("<div id='divCustomerid'><select id='ddlCustomerid_{0}' name='ddlCustomerid'>", customerid.Trim());
foreach (RES_CUSTOMER model in list)
{
ddl.AppendFormat("<option value='{0}'", model.RESID.Trim());
if (model.RESID == customerid)
ddl.Append("selected");
ddl.AppendFormat(">{0}</option>", model.RESID.Trim());
}
ddl.AppendFormat("</select>");
ddl.Append("<div>");
return new MvcHtmlString(ddl.ToString());
}
#endregion
#region
[HttpGet]
[AuthorizeRedirect(Roles = InitRights.CONST_客户关系变更审核)]
public ActionResult Check()
{
ToolBar tool = new ToolBar();
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
tool.AllowButton(toolbtn);
// tool.AllowButton("Details", "Other1", "Other2");
tool.AddOtherButton("Other1", "审核通过", "icon-yes", "Pass_click", true);
tool.AddOtherButton("Other2", "审核不通过", "icon-no", "NotPass_click", true);
ViewBag.ToolBar = tool;
Pager gp = new Pager() { page = 1, rows = 10, order = "desc", sort = "applyTime" };
Table tab = new Table("tablist");
tab.AddHiddenHeadCol("uniteId", "申请ID");
tab.AddHeadCol("resID1", "", "客户ID1");
tab.AddHeadCol("resID2", "", "客户ID2");
tab.AddHeadCol("applyName", "", "申请人");
tab.AddHeadCol("applyTime", "", "申请时间");
tab.AddHeadCol("applyReason", "", "申请理由");
tab.AddHeadCol("checkName", "", "审核人");
tab.AddHeadCol("checkTime", "", "审核时间");
tab.AddHeadCol("checkReason", "", "审核原因");
tab.AddHeadCol("checkStatus", "", "审核状态");
tab.AddHeadCol("checkResponse", "", "合并结果反馈");
tab.AddHeadRow();
ViewBag.GroupList = tab.GetTable() + Pagination.GetPage(gp, "tablist", "5,8,10,15");
return View();
}
#endregion
#region
[AuthorizeRedirect(Roles = InitRights.CONST_客户关系变更审核)]
public ActionResult GetList(Pager pg, string columns)
{
string stime = Request.Form["stime"];
string etime = Request.Form["etime"];
string resid = Request.Form["Resid"];
string status = Request.Form["checkStatus"];
List<CSVR_UNITECUSTOMERAPPLY> list = _uniteApply_Q.GetList_UniteCustomerApply(ref pg, resid, Convert.ToDecimal(status), stime, etime);
Table tb = new Table(columns, true);
foreach (CSVR_UNITECUSTOMERAPPLY model in list)
{
tb.AddHiddenCol(model.UNITEID);
tb.AddCol(model.RESID1);
tb.AddCol(model.RESID2);
tb.AddCol(InnerUserHelper.Instance.EidAndName(model.APPLYID));
tb.AddCol(model.APPLYTIME);
tb.AddCol(model.APPREMARK);
tb.AddCol(InnerUserHelper.Instance.EidAndName(model.AUDITID));
tb.AddCol(model.AUDITTIME);
tb.AddCol(model.AUDITREMARK);
if (model.STATE == 0)
tb.AddCol("未审核");
else if (model.STATE == 1)
tb.AddCol("已审核");
else
tb.AddCol("未通过");
tb.AddCol(model.AUDITRESPONSE);
tb.AddRow();
}
var json = new
{
totalPages = 1,
totalRows = list.Count(),
rowsList = tb.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
#endregion
#region
[HttpPost]
[AuthorizeToolBar(InitRights.CONST_客户关系变更审核, InitToolBar.CONST_Other1)]
public ActionResult Check(string result, string id, string reason)
{
if (result == "Pass")
{
decimal uniteid = Convert.ToDecimal(id);
bool issuccess = _uniteApply.Check_UniteCustomerApply(ref errors, uniteid, UserId);//审核数据
if (issuccess)
{
//#region 发送事件
//try
//{
// var deptCode = Utility.GetSettingByKey("DataClientCode");
// var list = _uniteApplyDetail_Q.GetList_UniteCustomerApplyDetail(Convert.ToDecimal(id));
// var newCustomerId = list.FirstOrDefault().NEWCUSTOMERID;
// var oldCustomerId = string.Join(",", list.Select(p => p.RESID));
// var data = new { newCustomerId, oldCustomerId };
// //LogHelper.Info(data.ToJson());
//var host = Utility.GetSettingOrNullByKey("DataSyncApiUrl");
// var url = host + "/api/DataSync";
// var para = new SYNC_PUSH_DTO()
// {
// bidatatype = "Server_UniteCustomer",
// deptcode = deptCode,
// jsontext = data.ToJson()
// };
// var rep = Utility.PostAjaxData(url, para.ToJson(), Encoding.UTF8);
// var ret = Utility.JSONToObject<retMsg>(rep);
// if (!ret.result)
// {
// LogHelper.Info("合并客户ID写入事件异常" + para.ToJson());
// }
//}
//catch (Exception ex)
//{
// LogHelper.Error("合并客户ID" + ex.ToString());
//}
//#endregion
//先调用明辉的合并接口
#region CMS合并接口
try
{
string unbindUrl = _cacheQ.GetValue_Parameter("ISVR_UnBindUrl_Post");//根据号码获取信息
string bindUrl = _cacheQ.GetValue_Parameter("ISVR_BindUrl_Post");//根据号码获取信息
var list = _uniteApplyDetail_Q.GetList_UniteCustomerApplyDetail(uniteid);//合并或者解绑明细
foreach (var item in list)
{
if (item.NEWCUSTOMERID != item.OLDCUSTOMERID)//customerID发生更改才需要进行操作
{
if (item.RESID != item.OLDCUSTOMERID)
{
if (!string.IsNullOrEmpty(unbindUrl))
{
UserCenterConcatUnConcat uninfo = new UserCenterConcatUnConcat()
{
appid = "com.web",
appuserid = item.RESID,
unappid = "com.web",
unappuserid = item.OLDCUSTOMERID// 和旧的数据解绑
};
//这里调用解绑接口
LogHelper.Info("调用CMS解绑接口:" + uninfo.ToJson());
var time = (long)Utility.ConvertDateTimeInt(DateTime.Now);
var message = JsonConvert.SerializeObject(new { account = "dn.crm", time });
var para = new SecurityHelper().createSignEncodingStr(message);
var rsp = Utility.PostAjaxData(unbindUrl + "?" + para, uninfo.ToJson(), Encoding.UTF8);
LogHelper.Info("结果:" + rsp);
}
}
if (item.NEWCUSTOMERID != item.RESID)
{
if (!string.IsNullOrEmpty(bindUrl))//如果数据不为空可以进行操作
{
UserCenterConcatConcat info = new UserCenterConcatConcat()
{
appid = "com.web",
appuserid = item.RESID,
toappid = "com.web",
toappuserid = item.NEWCUSTOMERID
};
//这里调用合并接口
LogHelper.Info("调用CMS合并接口:" + info.ToJson());
var time = (long)Utility.ConvertDateTimeInt(DateTime.Now);
var message = JsonConvert.SerializeObject(new { account = "dn.crm", time });
var para = new SecurityHelper().createSignEncodingStr(message);
var rsp = Utility.PostAjaxData(bindUrl + "?" + para, info.ToJson(), Encoding.UTF8);
LogHelper.Info("结果:" + rsp);
}
}
}
}
}
catch (Exception e)
{
LogHelper.Error(e.ToString());
}
#endregion
List<CSVR_UNITECUSTOMERAPPLYDETAIL> nlist = _uniteApplyDetail_Q.GetList_UniteCustomerApplyDetail(uniteid);//获取合并详细
var newList = nlist.Where(m => m.OLDCUSTOMERID != m.NEWCUSTOMERID).ToList();//获取发生了变化的数据
string hburl = _cacheQ.GetValue_Parameter(Parameter.Core_ZxdService_MergeToUserCenter);//合并 或者解绑的地址
string saleclus = _cacheQ.GetValue_Parameter("ISVR_Saleclus_Get");//根据号码获取信息
//string url = _cacheQ.GetValue_Parameter(Parameter.Core_ZxdService_CreateOrder);//解绑的
foreach (CSVR_UNITECUSTOMERAPPLYDETAIL item in newList)
{
item.CSVR_UNITECUSTOMERAPPLY = _uniteApply_Q.GetModel_UniteCustomerApply(item.UNITEID);
if (item.NEWCUSTOMERID == item.RESID)
{
var mobile = res_ResourceMobile_BL.GetNumberByResId(item.NEWCUSTOMERID);
var newcsmobile = res_ResourceMobile_BL.GetNumberByResId(item.OLDCUSTOMERID);
var objecb = new { mobiles = new List<string> { mobile, newcsmobile } };
string retmss = Utility.PostAjaxData(saleclus, JsonHelper.ObjDivertToJson(objecb), Encoding.UTF8);
var nrresult = JsonHelper.JsonDivertToObj<SaleClusResult>(retmss);
foreach (var wa in nrresult.list.Where(m => m.mobile == mobile))
{
var entry = nrresult.list.FirstOrDefault(m => m.mobile == newcsmobile && m.appid == wa.appid);
if (entry != null)//相同的APPID有数据就进行解绑
{
List<MergeAppUserId> mergelist = new List<MergeAppUserId>()
{
new MergeAppUserId(){ mobile=newcsmobile, appid=wa.appid, appuserid=wa.appuserid },
new MergeAppUserId(){ mobile=mobile, appid=entry.appid, appuserid=entry.appuserid }
};
MergeOrUnBind bingd = new MergeOrUnBind() { type = "unbind", mergeappuserlist = mergelist, resid = item.RESID, newcustomerid = item.NEWCUSTOMERID };
string json = Utility.ConvertToJSON<MergeOrUnBind>(bingd);
json = sHelper.createSignEncodingStr(json, SecurityHelper.OrderClientIdKey);//数据参数加密
string retmsg = Utility.PostData(hburl + "?" + json, Encoding.UTF8);//实现中心点先入库
retmsg = sHelper.decyptData(SecurityHelper.OrderClientIdKey, retmsg);
retMsg retmessage = JsonHelper.JsonDivertToObj<retMsg>(retmsg);//返回信息
//更新绑定情况
if (!string.IsNullOrEmpty(item.CSVR_UNITECUSTOMERAPPLY.AUDITRESPONSE))
{
item.CSVR_UNITECUSTOMERAPPLY.AUDITRESPONSE = retmessage.retmsg == null ? "" : "," + retmessage.retmsg;
}
else
{
item.CSVR_UNITECUSTOMERAPPLY.AUDITRESPONSE = retmessage.retmsg ?? "";
}
if (retmessage.result == false)
{
LogHelper.Error($"解绑客户出现错误uniteid:{item.UNITEID},id:{item.PKID}");
}
}
}
}
else
{
try
{
var mobile = res_ResourceMobile_BL.GetNumberByResId(item.RESID);
var newcsmobile = res_ResourceMobile_BL.GetNumberByResId(item.NEWCUSTOMERID);
List<MergeAppUserId> mergelist = new List<MergeAppUserId>()
{
new MergeAppUserId (){ mobile=newcsmobile },
new MergeAppUserId(){ mobile=mobile }
};
MergeOrUnBind bingd = new MergeOrUnBind() { type = "bind", mergeappuserlist = mergelist, resid = item.RESID, newcustomerid = item.NEWCUSTOMERID };
string json = Utility.ConvertToJSON<MergeOrUnBind>(bingd);
json = sHelper.createSignEncodingStr(json, SecurityHelper.OrderClientIdKey);//数据参数加密
string retmsg = Utility.PostData(hburl + "?" + json, Encoding.UTF8);//实现中心点先入库
retmsg = sHelper.decyptData(SecurityHelper.OrderClientIdKey, retmsg);
retMsg retmessage = JsonHelper.JsonDivertToObj<retMsg>(retmsg);//返回信息
//更新绑定情况
if (!string.IsNullOrEmpty(item.CSVR_UNITECUSTOMERAPPLY.AUDITRESPONSE))
{
item.CSVR_UNITECUSTOMERAPPLY.AUDITRESPONSE = retmessage.retmsg == null ? "" : "," + retmessage.retmsg;
}
else
{
item.CSVR_UNITECUSTOMERAPPLY.AUDITRESPONSE = retmessage.retmsg ?? "";
}
if (retmessage.result == false)
{
LogHelper.Error($"合并客户出现错误uniteid:{item.UNITEID},id:{item.PKID}");
}
}
catch (Exception e)
{
LogHelper.Error(e.ToString());
}
}
//没有记录到错误日志时
if (string.IsNullOrEmpty(item.CSVR_UNITECUSTOMERAPPLY.AUDITRESPONSE))
{
item.CSVR_UNITECUSTOMERAPPLY.AUDITRESPONSE = "绑定成功!";
}
_uniteApply.Update_UniteCustomerApply(ref errors, item.CSVR_UNITECUSTOMERAPPLY);
}
return JsonHandler.ManageMessage("审核通过!", issuccess);
}
else
return JsonHandler.ManageMessage(errors, issuccess);
}
else
{
CSVR_UNITECUSTOMERAPPLY model = _uniteApply_Q.GetModel_UniteCustomerApply(Convert.ToDecimal(id));
model.STATE = 2;
model.AUDITREMARK = reason;
model.AUDITID = UserId;
model.AUDITTIME = DateTime.Now;
bool issuccess = _uniteApply.Update_UniteCustomerApply(ref errors, model);
if (issuccess == true)
return JsonHandler.ManageMessage("已修改为审核不通过!", issuccess);
else
return JsonHandler.ManageMessage(errors, issuccess);
}
}
#endregion
#region
public ActionResult Details(string id)
{
List<CSVR_UNITECUSTOMERAPPLYDETAIL> list = _uniteApplyDetail_Q.GetList_UniteCustomerApplyDetail(Convert.ToDecimal(id));
return View(list);
}
#endregion
}
}