TG.WXCRM.V4/WEB/Controllers/Csvr/CustomerInfoController.cs

1691 lines
72 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.Ord;
using Jayrock.Json.Conversion;
using Ninject;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
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.Csvr;
using WX.CRM.IBLL.QH;
using WX.CRM.IBLL.RedisBL;
using WX.CRM.IBLL.Res;
using WX.CRM.IBLL.Util;
using WX.CRM.IBLL.WeWork;
using WX.CRM.IBLL.Ww;
using WX.CRM.IBLL.Wx;
using WX.CRM.Model.Entity;
using WX.CRM.Model.Enum;
using WX.CRM.Model.QueryMap;
using WX.CRM.Model.Ww;
using WX.CRM.WebHelper;
using WX.CRM.WebHelper.DoItems;
using WX.CRM.WebHelper.RedisFactory;
namespace WX.CRM.WEB.Controllers.Csvr
{
public class CustomerInfoController : BaseController
{
[Inject]
public CACHE_BL cache_BL { get; set; }
[Inject]
public ICUSTOMER_REDIS customerRedisBL { get; set; }
[Inject]
public BAS_BUSSINESSLINE_BL line_BL { get; set; }
//
// GET: /Customer/
private IRES_CUSTOMERDETAIL_Q customerdetailBiz_Q;
private IRES_CUSTOMERUSER_Q _customerUserQ;
private IRES_CUSTOMER _customer;
private IRES_CUSTOMER_Q _customerQ;
private IBAS_BUSINESS_Q businessBiz_Q;
private ICSVR_IDMAP_Q csvr_idmap;
private ICACHE_Q cacheQ;
private IBAS_MOBILEAREA_Q mobileareaQ;
private readonly IWX_RCONTACT _wxRcontact;
private readonly IRES_CUSTOMERDETAIL _resCustomerdetail;
private IQH_CUSTOMER_RESID _iqh_Customer_Resid;
private ValidationErrors errors = new ValidationErrors();
[Inject]
private IWw_huser _wwhuserbll { get; set; }
[Inject]
public IWW_EXTUSER_RESID _wwExtUserResId { get; set; }
[Inject]
public IBAS_INNERGROUP_Q Bas_InnerGroup_BL { get; set; }
[Inject]
public ISecurityHelper sHelper { get; set; }
[Inject]
public IWW_EXTUSER ww_extuser { get; set; }
public RedisFactory redisFactory = new RedisFactory();
[Inject]
public IRES_CUSTOMER_LABEL _label { get; set; }
public CustomerInfoController(IRES_CUSTOMERDETAIL_Q _customerdetailBiz_Q
, IRES_CUSTOMERUSER_Q customerUserQ,
IRES_CUSTOMER customer,
IRES_CUSTOMER_Q customerQ,
IBAS_BUSINESS_Q _businessBiz_Q,
ICSVR_IDMAP_Q _csvr_idmap,
ICACHE_Q _cacheQ,
IBAS_MOBILEAREA_Q _mobileareaQ,
IWX_RCONTACT wxRcontact,
IRES_CUSTOMERDETAIL resCustomerdetail,
IQH_CUSTOMER_RESID iQH_CUSTOMER_RESID,
IWw_huser wwhuserbll
)
{
this.customerdetailBiz_Q = _customerdetailBiz_Q;
this._customerUserQ = customerUserQ;
this._customerQ = customerQ;
this._customer = customer;
this.businessBiz_Q = _businessBiz_Q;
this.csvr_idmap = _csvr_idmap;
this.cacheQ = _cacheQ;
this.mobileareaQ = _mobileareaQ;
_wxRcontact = wxRcontact;
_resCustomerdetail = resCustomerdetail;
this._iqh_Customer_Resid = iQH_CUSTOMER_RESID;
this._wwhuserbll = wwhuserbll;
}
#region ID
/// <summary>
/// 筛选未外呼客户ID
/// </summary>
/// <returns></returns>
public ActionResult ResIDNoOutboundFilter()
{
var groupList = Bas_InnerGroup_BL.GetList();
if (groupList != null)
{
groupList = groupList.Where(m => m.ISHIDE == 0).ToList();
}
if (groupList == null)
{
groupList = new List<BAS_INNERGROUP>();
}
ViewBag.DeptCode = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_Environment_DeptCode);
ViewBag.MemoSubTypeList = cacheQ.GetList_MemoSubType(1);
ViewBag.GroupList = groupList;
return View();
}
[AuthorizeRedirect(Roles = InitRights.CONST_筛选未外呼客户ID)]
public JsonResult ResIDUpload(DateTime? stime, DateTime? etime, decimal? t_type, string slt_Open, string slt_NotOpen)
{
string dname = "这批ID在这个时间段已经全部有外呼";
if (t_type != null && t_type == 1)
dname = "这批ID在这个时间段没有无效外呼";
else if (t_type != null && t_type == 2)
dname = "筛选后无数据!";
else if (t_type != null && t_type == 8)
dname = "根据条件去除后无数据!";
string importId = DateTime.Now.ToString("yyyyMMddHHmmss");
HttpPostedFileBase file = Request.Files["uploadFile"];
DataTable tab = new DataTable();
DataColumn column = new DataColumn("IMPORTID");
column.Caption = "导入批次ID";
column.DataType = typeof(System.Decimal);
tab.Columns.Add(column);
DataColumn column2 = new DataColumn("IMPORTDATA");
column2.Caption = "客户ID";
column2.DataType = typeof(System.String);
tab.Columns.Add(column2);
using (StreamReader read = new StreamReader(file.InputStream, Encoding.GetEncoding("gb2312")))
{
while (!read.EndOfStream)
{
DataRow row = tab.NewRow();
row["IMPORTID"] = importId;
row["IMPORTDATA"] = read.ReadLine().Trim();
tab.Rows.Add(row);
}
}
List<string> list = _customerQ.ResIDNoOutboundFilter(ref errors, tab, importId, stime.Value, etime.Value, t_type.Value, slt_Open, slt_NotOpen);
Stream stream = ExcelHelper.ExportListObjectToExcel(list, "客户ID", "客户ID", null);
if (errors.Count > 0)
{
JsonResult rs = Json(new { result = false, message = "错误提示:" + errors.Error });
rs.ContentType = "text/html";
return rs;
}
else if (list.Count == 0)
{
JsonResult rs = Json(new { result = false, message = "温馨提示:" + dname }, JsonRequestBehavior.AllowGet);
rs.ContentType = "text/html";
return rs;
}
string fileName = DateTime.Now.ToString("yyyyMMddHHmmffff") + ".xls";
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length); //将流的内容读到缓冲区
FileStream fs = new FileStream(Server.MapPath("~/UploadFile/" + fileName), FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
fs.Close();
JsonResult rb = Json(new { result = true, src = fileName });
rb.ContentType = "text/html";
return rb;
}
[AuthorizeRedirect(Roles = InitRights.CONST_筛选未外呼客户ID)]
public JsonResult ResIDUploadNew(DateTime? stime, DateTime? etime, string checkType_hid, string subType_hid)
{
string dname = "赛选客户ID";
if (Request.Files["uploadFile"] == null)
{
JsonResult rs = null;
rs = Json(new { result = false, message = "错误提示:请选择文件!" });
rs.ContentType = "text/html";
return rs;
}
if (string.IsNullOrEmpty(checkType_hid) && string.IsNullOrEmpty(subType_hid))
{
JsonResult rs = null;
rs = Json(new { result = false, message = "错误提示:请至少选择一项过滤条件!" });
rs.ContentType = "text/html";
return rs;
}
if (!string.IsNullOrEmpty(subType_hid) && (!stime.HasValue || !etime.HasValue))
{
JsonResult rs = null;
rs = Json(new { result = false, message = "错误提示:工单过滤,请选择时间!" });
rs.ContentType = "text/html";
return rs;
}
string importId = DateTime.Now.ToString("yyyyMMddHHmmss");
HttpPostedFileBase file = Request.Files["uploadFile"];
DataTable tab = new DataTable();
DataColumn column = new DataColumn("IMPORTID");
column.Caption = "导入批次ID";
column.DataType = typeof(System.Decimal);
tab.Columns.Add(column);
DataColumn column2 = new DataColumn("IMPORTDATA");
column2.Caption = "客户ID";
column2.DataType = typeof(System.String);
tab.Columns.Add(column2);
using (StreamReader read = new StreamReader(file.InputStream, Encoding.GetEncoding("gb2312")))
{
while (!read.EndOfStream)
{
DataRow row = tab.NewRow();
row["IMPORTID"] = importId;
row["IMPORTDATA"] = read.ReadLine().Trim();
tab.Rows.Add(row);
}
}
List<string> list = _customerQ.res_GetFilterImportRes(ref errors, tab, importId, stime.Value, etime.Value, checkType_hid, subType_hid);
Stream stream = ExcelHelper.ExportListObjectToExcel(list, "客户ID", "客户ID", null);
if (errors.Count > 0)
{
JsonResult rs = Json(new { result = false, message = "错误提示:" + errors.Error });
rs.ContentType = "text/html";
return rs;
}
else if (list.Count == 0)
{
JsonResult rs = Json(new { result = false, message = "温馨提示:过滤后没有数据!" }, JsonRequestBehavior.AllowGet);
rs.ContentType = "text/html";
return rs;
}
string fileName = DateTime.Now.ToString("yyyyMMddHHmmffff") + ".xls";
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length); //将流的内容读到缓冲区
FileStream fs = new FileStream(Server.MapPath("~/UploadFile/" + fileName), FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
fs.Close();
JsonResult rb = Json(new { result = true, src = fileName });
rb.ContentType = "text/html";
return rb;
}
[AuthorizeRedirect(Roles = InitRights.CONST_筛选未外呼客户ID)]
public JsonResult ResIDChoice(DateTime? resStime, DateTime? resEtime, bool checkWeixin, bool checkOrder, string memoSubType, DateTime? memoStime, DateTime? memoEtime)
{
JsonResult rs = null;
var dname = "资源筛选导出";
if (!resStime.HasValue)
{
rs = Json(new { result = false, message = "错误提示:资源开始时间不能为空" });
rs.ContentType = "text/html";
return rs;
}
if (!resEtime.HasValue)
{
rs = Json(new { result = false, message = "错误提示:资源结束时间不能为空" });
rs.ContentType = "text/html";
return rs;
}
if (resEtime > DateTime.Now.AddDays(-9))
{
//rs = Json(new { result = false, message = "错误提示:资源结束时间不能大于"+ DateTime.Now.AddDays(-9).ToString() });
rs = Json(new { result = false, message = "新资源不能倒出请筛选导出10天前的资源。" });
rs.ContentType = "text/html";
return rs;
}
if (resStime < resEtime.Value.AddDays(-30))
{
rs = Json(new { result = false, message = "错误提示由于资源太多资源时间跨度不能超过1个月如若需要可以分多次导出" });
rs.ContentType = "text/html";
return rs;
}
if (!memoStime.HasValue)
{
rs = Json(new { result = false, message = "错误提示:工单开始时间不能为空" });
rs.ContentType = "text/html";
return rs;
}
if (!memoEtime.HasValue)
{
rs = Json(new { result = false, message = "错误提示:工单结束时间不能为空" });
rs.ContentType = "text/html";
return rs;
}
List<string> list = _customerQ.GetResChoiceExpor(ref errors, resStime.ToString(), resEtime.ToString(), checkWeixin ? 1 : 0, checkOrder ? 1 : 0, memoSubType, memoStime.ToString(), memoEtime.ToString());
Stream stream = ExcelHelper.ExportListObjectToExcel(list, "客户ID", "客户ID", null);
if (errors.Count > 0)
{
rs = Json(new { result = false, message = "错误提示:" + errors.Error });
rs.ContentType = "text/html";
return rs;
}
else if (list.Count == 0)
{
rs = Json(new { result = false, message = "温馨提示:" + dname }, JsonRequestBehavior.AllowGet);
rs.ContentType = "text/html";
return rs;
}
string fileName = DateTime.Now.ToString("yyyyMMddHHmmffff") + ".xls";
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length); //将流的内容读到缓冲区
FileStream fs = new FileStream(Server.MapPath("~/UploadFile/" + fileName), FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
fs.Close();
JsonResult rb = Json(new { result = true, src = fileName });
rb.ContentType = "text/html";
return rb;
}
[AuthorizeRedirect(Roles = InitRights.CONST_筛选未外呼客户ID)]
public JsonResult ResIdByMemoChoice(DateTime? memoStime2, DateTime? memoEtime2, decimal? memoType1, decimal? memoType2, decimal? group1, decimal? group2)
{
JsonResult rs = null;
var dname = "没查询到符合条件的工单资源";
if (!memoStime2.HasValue)
{
rs = Json(new { result = false, message = "错误提示:工单开始时间不能为空" });
rs.ContentType = "text/html";
return rs;
}
if (!memoEtime2.HasValue)
{
rs = Json(new { result = false, message = "错误提示:工单结束时间不能为空" });
rs.ContentType = "text/html";
return rs;
}
List<string> list = _customerQ.GetResIdByMemoChoiceExport(ref errors, memoStime2, memoEtime2, memoType1, memoType2, group1, group2);
Stream stream = ExcelHelper.ExportListObjectToExcel(list, "客户ID", "客户ID", null);
if (errors.Count > 0)
{
rs = Json(new { result = false, message = "错误提示:" + errors.Error });
rs.ContentType = "text/html";
return rs;
}
else if (list.Count == 0)
{
rs = Json(new { result = false, message = "温馨提示:" + dname }, JsonRequestBehavior.AllowGet);
rs.ContentType = "text/html";
return rs;
}
string fileName = DateTime.Now.ToString("yyyyMMddHHmmffff") + ".xls";
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length); //将流的内容读到缓冲区
FileStream fs = new FileStream(Server.MapPath("~/UploadFile/" + fileName), FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
fs.Close();
JsonResult rb = Json(new { result = true, src = fileName });
rb.ContentType = "text/html";
return rb;
}
public ActionResult ResIdExcelExport(string fileName, decimal? t_type)
{
string dname = "筛选未外呼客户ID";
if (t_type != null && t_type == 1)
dname = "筛选无效外呼客户ID";
else if (t_type != null && t_type == 2)
dname = "筛选未开户客户ID";
else if (t_type != null && t_type == 8)
dname = "去除连续5次无效工单";
else if (t_type != null && t_type == 9)
dname = "去除绑定微信";
else if (t_type != null && t_type == 10)
dname = "去除首次汇款工单";
string filepath = Server.MapPath("~/UploadFile/" + fileName);
FileStream fs = new FileStream(filepath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.ContentType = "application/ms-excel";
Response.AddHeader("Content-Disposition", "attachment; filename=" + PageRequest.GetDlownLoadName(dname + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
if (System.IO.File.Exists(filepath))
{
System.IO.File.Delete(filepath);
}
return new EmptyResult();
}
#endregion ID
public ActionResult Index()
{
return View();
}
/// <summary>
/// isFromHg是否来着合规
/// </summary>
[Inject]
public IRES_VIPCUSTOMER _RES_VIPCUSTOMER { get; set; }
[AuthorizeRedirect(Roles = InitRights.CONST_公共权限)]
public ActionResult CustomerDetail(string resid, int isFromHg = 0, int isOther = 0, int isFromComplaint = 0, string umid = "")
{
//ControlResource.JudgeSYQ();
//var isShowFxh = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_IsShowFXH);
//if (string.IsNullOrEmpty(isShowFxh))
// isShowFxh = "true";
//ViewBag.isShowFxh = isShowFxh;
//ViewBag.IsOpen_TradeCode = cacheQ.IsOpen_TradeCode(resid); //_MN_GJS_CUSTOMER.IsOpen_TradeCode(resid);
//ViewBag.IsOpen_TradeCode = false;
//var tgcrmUrl = cacheQ.GetValue_Parameter("TGCRMUrl");
//ViewBag.TGCRMUrl = string.IsNullOrEmpty(tgcrmUrl)?"": (tgcrmUrl + "/Csvr/CustomerInfoMn/Index?resid="+resid);
RES_CUSTOMERDETAIL model = null;
if (!string.IsNullOrEmpty(resid))
{
model = customerdetailBiz_Q.GetModel_RES_CUSTOMERDETAIL(resid);//Old Version
}
else if (!string.IsNullOrEmpty(umid))
{
model = customerdetailBiz_Q.GetModel_RES_CUSTOMERDETAIL_UMID(umid);
}
else
{
Response.Redirect(Url.Action("ErrorView", "Error", new { message = "缺少resid/umid" }));
}
if (isFromComplaint == 1 && (model == null || string.IsNullOrWhiteSpace(model.CNAME)))
{
//合规风险用户进来的
var url = cacheQ.GetValue_Parameter(Parameter.Core_ZxdService_Api);
url += "OrderService.svc/Order/GetResCustomerByResId";
var theModel = new ResCustomerDto
{
resId = resid,
};
string json = Utility.ConvertToJSON<ResCustomerDto>(theModel);
json = sHelper.createSignEncodingStr(json, SecurityHelper.OrderClientIdKey);//数据参数加密
string retmsg = Utility.PostData(url + "?" + json, Encoding.UTF8);//实现中心点先入库
retmsg = sHelper.decyptData(SecurityHelper.OrderClientIdKey, retmsg);
retMsgNew<List<ResCustomerModel>> retmessage = JsonHelper.JsonDivertToObj<retMsgNew<List<ResCustomerModel>>>(retmsg);//返回信息
var uname = "";
if (retmessage.retcode == (int)NodeJsOrderEnum.)//成功
{
uname = retmessage.data.FirstOrDefault(n => !string.IsNullOrWhiteSpace(n.uname))?.uname;
foreach (var ord in retmessage.data)
{
var qq = _customer.ResgisterCustomer(ord.mobile, ord.resId, "isHgComplaint");
}
}
//修改客户姓名
if (string.IsNullOrWhiteSpace(model?.CNAME) && !string.IsNullOrWhiteSpace(uname))
{
using (var db = new crmContext())
{
var customerDetail = db.RES_CUSTOMERDETAIL.FirstOrDefault(n => n.RESID == resid);
if (customerDetail != null)
{
customerDetail.CNAME = uname;
db.SaveChanges();
}
}
}
model = customerdetailBiz_Q.GetModel_RES_CUSTOMERDETAIL(resid);//Old Version
}
if (model == null)
Response.Redirect(Url.Action("ErrorView", "Error", new { message = "错误提示:没有这个客户!" }));
CustomerInfo info = new CustomerInfo();
//if (!string.IsNullOrEmpty(model.CNAME))
//{
// var roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId);
// if (!(roleCodes.Contains("[SH]") || roleCodes.Contains("[GLY]")))
// {
// if (model.CNAME.Length > 4)
// {
// model.CNAME = model.CNAME.Substring(0, 4);
// }
// }
//}
info.RequsetResId = resid;
//info.ResCustomerList = _customerQ.GetList_CustomerByResid(resid);//Old Version
//info.CustomerId = info.ResCustomerList.Select(p => p.CUSTOMERID).FirstOrDefault();//Old Version
//string[] resids = info.ResCustomerList.Select(m => m.RESID.Trim()).ToArray();//Old Version
//info.GjsCustomerList = gjs_customerQ.getGjsCustomersByResIds(resids);//Old Version
info.CustomerName = model.CNAME;
info.CustomerId = _customerQ.getResCustomerByResId(model.RESID).CUSTOMERID;
try
{
_customer.res_customerdetial_log(Utility.GetIp(), info.CustomerId, UserId, Eid);
}
catch (Exception ex)
{
LogHelper.Error("记录访问日志出错:" + ex.ToString());
}
string[] resids = _customerQ.GetAllResidByCustomerId(info.CustomerId);
info.ResCustomerList = redisFactory.GetList_Rescustomer(resids, info.CustomerId);//
//info.ResCustomerList = customerRedisBL.GetList_Res_Customer(resids);
//info.GjsCustomerList = redisFactory.GetList_Gjscustomer(resids); //customerRedisBL.GetList_Gjs_Customer(resids);
//info.FxhCustomerList = _fxh_customerQ.getFxhByResIds(resids);
// 1005778 找不到时修改CustomerId为ResId 然后再找一次
if (info.ResCustomerList == null || info.ResCustomerList.Count == 0)
{
info.CustomerId = resid;
_customerQ.ResetCustomerId(resid);
info.ResCustomerList = redisFactory.GetList_Rescustomer(resids, info.CustomerId);
}
string isShowMobileArea = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Is_ShowCustomerMobileArea);
var isMiniCustomerInfo = cacheQ.GetValue_Parameter(Model.Enum.Parameter.Sys_IsMiniCustomerInfo);
if (null != info.ResCustomerList)
{
var vipcustomer = _RES_VIPCUSTOMER.GetByResIds(info.ResCustomerList.Select(obj => obj.RESID).ToArray());
foreach (RES_CUSTOMER item in info.ResCustomerList)
{
item.IsVip = vipcustomer.Any(obj => obj.RESID == item.RESID);
//LogHelper.Info("isShowMobileArea:" + isShowMobileArea);
if (isShowMobileArea == "true")
{
item.map_MobileArea = mobileareaQ.GetMobileArea(item.RESID);
}
else
item.map_MobileArea = "";
}
}
var residsArr = info.ResCustomerList.Select(obj => obj.RESID);
var fxModel = _label.Get(p => residsArr.Contains(p.RESID));
//查询出公司的业务
//List<BAS_COMPANY> companyList = DataCacheHelper.GetCache().GetList_innerCompany();
//BAS_COMPANY company = companyList.Where(m => m.COMPANYID == companyId).FirstOrDefault();
//int businessValue = 0;
//if (company != null)
// businessValue = Convert.ToInt32(company.BUSINESSVALUE);
List<string> customerMessage_UC = new List<string>();//客户信息 控件集合
List<string> memoMessage_UC = new List<string>();//工单信息 控件集合
//List<string> SalememoMessage_UC = new List<string>();//投顾工单信息 控件集合
List<string> ordeMessage_UC = new List<string>();//订单信息 控件集合
List<string> Level2orderMessage_UC = new List<string>();//订单信息 控件集合
List<string> ActivityMessage_UC = new List<string>();//活动信息 控件集合
//List<string> futureMessage_UC = new List<string>();//渤海 控件集合
//List<string> silverMessage_UC = new List<string>();// 控件集合
var fastmemo = cacheQ.GetValue_Parameter("fastmemo");
if (!string.IsNullOrEmpty(fastmemo))
{
customerMessage_UC.Add("FastMemo");//快速创建工单
}
customerMessage_UC.Add("CustomerBaseInfoUC");//-客户基本信息
customerMessage_UC.Add("ContactUC");//联系方式
//customerMessage_UC.Add("CustomerCategoryUC");//-客户分类
if (string.IsNullOrEmpty(isMiniCustomerInfo) || isMiniCustomerInfo == "0")
{
customerMessage_UC.Add("CustomerExtendUC");//客户扩展信息
customerMessage_UC.Add("CustomerUserUC");//用户信息
customerMessage_UC.Add("CustomerAddWWUserUC");//添加企业微信
//customerMessage_UC.Add("CustomerAddWxUserUC");//添加微信用户
customerMessage_UC.Add("CustomerCheckUC");//客户质检信息
//customerMessage_UC.Add("CustomerLoginInfo");//客户最近信息
//customerMessage_UC.Add("CustomerOtherInfo");//客户其它基本信息
//customerMessage_UC.Add("RelationCustomerUC");//相关客户
}
else
{
customerMessage_UC.Add("CustomerAllMemoUC");
}
if (string.IsNullOrEmpty(isMiniCustomerInfo) || isMiniCustomerInfo == "0")
{
memoMessage_UC.Add("CustomerAllMemoUC");//客户所有工单信息
}
//sSalememoMessage_UC.Add("SaleDptAllMemoUC");//投顾客户所有工单信息
ordeMessage_UC.Add("CustomerOrderUC");//客户订单
Level2orderMessage_UC.Add("CustomerLevel2OrderUC");//投顾免费订单
// ordeMessage_UC.Add("CustomerModuleUC");//模块
ActivityMessage_UC.Add("CustomerActivityUC");//活动信息
//渤海和 需要公司有这个业务才能被显示出来
//info.BusinessNames = companyBusiness;
//futureMessage_UC.Add("CustomerFutureUC");//客户渤海信息
////}
////if (info.BusinessNames.IndexOf("[]") > -1)
////{
//silverMessage_UC.Add("CustomerFutureUcSilver");//客户信息
////}
ViewBag.QHType = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_QHData);
//if (ViewBag.QHType=="1")
//{
// List<QH_CUSTOMER_RESID> qH_CUSTOMER_RESID = _iqh_Customer_Resid.GetList(resids);
// if (qH_CUSTOMER_RESID.Count == 0)
// {
// ViewBag.CustomerQH_UC = "CustomerResid";
// }
// else
// {
// ViewBag.CustomerQH_UC = "CustomerQH";
// }
//}
ViewBag.WwMessage_Url = cacheQ.GetValue_Parameter("WwMessage_Url");
//string[] extids = ww_extuser.ExtUserBandGet(model.RESID);//获取企业微信付费版本绑定的ID
var userlist = new List<string>();
try
{
var webapi = cache_BL.GetValue_Parameter(Parameter.ZXD_CORE_WEBAPI);
webapi = $"{webapi}/Api/Customer/ExtUserBandGet";
var para = $"resId={info.CustomerId}";
var result = Utility.GetData(webapi, para, Encoding.UTF8);
var rsp = Newtonsoft.Json.JsonConvert.DeserializeObject<WX.CRM.Common.StockHelper.ApiResult<List<string>>>(result);
if (rsp != null && rsp.Data != null && rsp.Data.Count > 0)
{
userlist.AddRange(rsp.Data);
}
}
catch
{ }
string[] extids = userlist.ToArray();
string myids = "";
if (extids != null && extids.Length > 0)
{
myids = string.Join(";", extids);
}
var lineList = line_BL.GetBusinessLineByRoot(UserId);
if (lineList.Count > 0)
{
ViewBag.lineCompany = string.Join(",", lineList.Select(n => n.COMPANYCODE).ToList());
}
info.IsFromHg = isFromHg;
info.IsOther = isOther;
ViewBag.extuserids = myids;//企业微信外部联系人关联
if (info.ResCustomerList != null && info.ResCustomerList.Count > 0)
{
ViewBag.ResCustomerList = string.Join(";", info.ResCustomerList.Select(r => r.RESID));
}
else
{
ViewBag.ResCustomerList = "";
}
var appid = System.Configuration.ConfigurationManager.AppSettings["appid"];
ViewBag.appid = appid;
ViewBag.eid = Eid;
ViewBag.CustomerInfo = info;//--所有控件用到的数据
ViewBag.customerMessage_UC = customerMessage_UC;
ViewBag.memoMessage_UC = memoMessage_UC;
//ViewBag.SalememoMessage_UC = SalememoMessage_UC;
ViewBag.ordeMessage_UC = ordeMessage_UC;
ViewBag.Level2orderMessage_UC = Level2orderMessage_UC;
ViewBag.ActivityMessage_UC = ActivityMessage_UC; //活动
//ViewBag.futureMessage_UC = futureMessage_UC;
//ViewBag.silverMessage_UC = silverMessage_UC;
ViewBag.DeptCode = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_Environment_DeptCode);
ViewBag.ProjectType = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_ProjectType);
ViewBag.isMiniCustomerInfo = isMiniCustomerInfo;
ViewBag.IsHg = userRoleCodes.Contains("[HGZJ]") || userRoleCodes.Contains("[GLY]");
ViewBag.IsFx = (fxModel != null && fxModel.RFMTYPE == 1) ? true : false;
try
{
PopupMessageFactory.AllocateResMessage.SetView(UserId, resid);
}
catch (Exception ex)
{
LogHelper.Error("清除资源提示错误:" + ex.ToString());
}
return View(model);
}
public ActionResult SearchCustomer()
{
ViewBag.ProjectType = cacheQ.GetValue_Parameter(WX.CRM.Model.Enum.Parameter.Sys_ProjectType);
ViewBag.roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId);
ViewBag.eid = Eid;
return View();
}
/// <summary>
/// 查询出Resid方便查找
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
[HttpPost]
[AuthorizeRedirect(Roles = InitRights.CONST_公共权限)]
public JsonResult GetResData(string type)
{
int relust = 1;
string msg = "";
string resid = Request.Form["txt_resid"].GetString();
string username = Request.Form["txt_username"].GetString();
string oldUsername = Request.Form["txt_Oldusername"].GetString();
string userno = Request.Form["txt_userno"].GetString();
string mobile = Request.Form["txt_mobile"].GetString();
string customerId = Request.Form["txt_customerid"].GetString();
string tradeCode = Request.Form["txt_tradeCode"].GetString();
string OldId = Request.Form["txt_OldId"].GetString();
string customerName = Request.Form["txt_customerName"].GetString();
string nickName = Request.Form["txt_nickname"].GetString();
string mome = Request.Form["txt_mome"].GetString();
string unionid = Request.Form["txt_UnionId"].GetString();
string extuser = Request.Form["txt_extuserid"].GetString();
switch (type)
{
case "username": resid = SeachByuserName(username, ref relust, ref msg); break;
case "OlduserName": resid = SeachByOlduserName(oldUsername, ref relust, ref msg); break;
case "userno": resid = SeachByuserNo(userno, ref relust, ref msg); break;
case "mobile": resid = SeachByMobile(mobile, ref relust, ref msg); break;
case "tradeCode": resid = SeachByTradeCode(tradeCode, ref relust, ref msg); break;
case "resid": resid = SeachByResId(resid, ref relust, ref msg); break;//空置·不需要做处理
case "OldId": resid = SeachByOldId(OldId, ref relust, ref msg); break;
case "customerName": resid = SeachByCustomerName(customerName, ref relust, ref msg); break;
case "unionid": resid = SeachByUnionid(unionid, ref relust, ref msg); break;
//case "extuserid":
// var eeid = Request.Form["txt_eeid"].GetString();
// resid = SeachByExtUser(extuser, eeid, ref relust, ref msg);
// break;
case "nickname":
var neid = Request.Form["txt_neid"].GetString();
resid = SeachByNickName(nickName, neid, ref relust, ref msg);
break;
case "mome":
var meid = Request.Form["txt_meid"].GetString();
resid = SeachByReMark(mome, meid, ref relust, ref msg);
break;
}
try
{
switch (type)
{
case "username":
LogHelper.Info(string.Format("IP{3}工号{0}在{1}查询用户名——{2}", Eid, DateTime.Now.ToString(), username, WX.CRM.Common.Utility.GetIp()));
break;
case "mobile":
LogHelper.Info(string.Format("IP{3}工号{0}在{1}查询手机号——{2}", Eid, DateTime.Now.ToString(), mobile, WX.CRM.Common.Utility.GetIp()));
break;
}
}
catch (Exception)
{
}
//if (!string.IsNullOrEmpty(resid))
//{
// RES_CUSTOMER res = _customerQ.getResCustomerByResId(resid);
// if (res == null)
// {
// msg = "不存在此用户"; relust = 0;
// }
//}
//else { msg = "请填写查询条件"; relust = 0; }
ViewBag.ResID = resid;
return Json(new { reslust = relust, message = msg, ResId = resid });
}
public string SeachByOlduserName(string username, ref int relust, ref string msg)
{
try
{
if (string.IsNullOrWhiteSpace(username))
{
msg = "请填写查询条件"; relust = 0;
return "";
}
List<RES_CUSTOMERUSER> list = new List<RES_CUSTOMERUSER>();
list = redisFactory.GetList_Rescustomeruser_Username(username);
if (list == null || list.Count() <= 0)
{
msg = "不存在此用户名"; relust = 0;
return "";
}
if (list != null && list.Count() == 1)
{
return list.FirstOrDefault().RESID;
}
else
{
msg = "存在多个客户ID";
List<string> strList = new List<string>();
list = list.OrderBy(m => m.PKID).ToList();
foreach (var model in list)
{
strList.Add(model.RESID + "-" + (model.PKID == 0 ? "注册" : "活动"));
}
return string.Join(";", strList);
}
}
catch (Exception ex)
{
LogHelper.Error("根据用户名查询:" + username + ":" + ex.Message + ex.StackTrace);
msg = "系统查询出错,请联系管理员"; relust = 0;
return "";
}
}
public string SeachByOldId(string OldCustomerId, ref int relust, ref string msg)
{
//string resid = string.Empty;
List<string> list = new List<string>();
try
{
if (string.IsNullOrWhiteSpace(OldCustomerId))
{
msg = "请填写查询条件"; relust = 0;
return "";
}
//resid = csvr_idmap.GetResId(OldCustomerId);
//if (string.IsNullOrEmpty(resid))
//{
// msg = "找不到这个旧客户ID"; relust = 0;
// return "";
//}
list = csvr_idmap.GetResId(OldCustomerId);
if (list == null || list.Count <= 0)
{
msg = "找不到这个旧客户ID"; relust = 0;
return "";
}
if (list != null && list.Count == 1)
{
return list[0];
}
else
{
msg = "存在多个客户ID";
return string.Join(";", list);
}
//return resid;
}
catch (Exception ex)
{
LogHelper.Error(ex.Message + ex.StackTrace);
msg = "系统查询出错,请联系管理员"; relust = 0;
return "";
}
}
public string SeachByResId(string resid, ref int relust, ref string msg)
{
try
{
if (string.IsNullOrWhiteSpace(resid))
{
msg = "请填写查询条件"; relust = 0;
return "";
}
else if (_customerQ.getResCustomerByResId(resid) == null)
{
msg = "请填写正确的ResId"; relust = 0;
return "";
}
//else if(redisFactory.GetInfo_Rescustomer(resid)==null)
//{
// msg = "请填写正确的ResId"; relust = 0;
// return "";
//}
return resid;
}
catch (Exception ex)
{
LogHelper.Error("根据resid查询客户" + resid + ";" + ex.Message + ex.StackTrace);
msg = "系统查询出错,请联系管理员"; relust = 0;
return "";
}
}
public string SeachByMobile(string mobile, ref int relust, ref string msg)
{
try
{
if (string.IsNullOrWhiteSpace(mobile))
{
msg = "请填写查询条件"; relust = 0;
return "";
}
if (!Utility.ChekMobile(mobile) && !Utility.ValidateTelCode2(mobile))//判断是否为手机号码或者电话号码
{
msg = "请填写正确的号码"; relust = 0;
return "";
}
return ResUtil.CreateResId(mobile);
}
catch (Exception ex)
{
LogHelper.Error(ex.Message + ex.StackTrace);
msg = "系统查询出错,请联系管理员"; relust = 0;
return "";
}
}
public string SeachByuserName(string username, ref int relust, ref string msg)
{
try
{
if (string.IsNullOrWhiteSpace(username))
{
msg = "请填写查询条件"; relust = 0;
return string.Empty;
}
var model = _wxRcontact.Get(p => p.USERNAME == username || p.ALIAS == username);
if (model == null)
{
msg = "不存在此用户名"; relust = 0;
return string.Empty;
}
return model.RESID;
}
catch (Exception ex)
{
LogHelper.Error("根据用户名查询:" + username + ":" + ex.Message + ex.StackTrace);
msg = "系统查询出错,请联系管理员"; relust = 0;
return string.Empty;
}
}
#region
public string SeachByNickName(string nickname, string eidStr, ref int relust, ref string msg)
{
try
{
if (string.IsNullOrWhiteSpace(nickname))
{
msg = "请填写查询条件"; relust = 0;
return string.Empty;
}
decimal eid = 0;
IList<string> kfuserid = new List<string>();
if (!string.IsNullOrEmpty(eidStr) && decimal.TryParse(eidStr, out eid))
{
kfuserid = _customer.QueryKFuseridByEid(eid);
}
var wwuser = _wwhuserbll.WorkListGetByNickName(nickname, kfuserid);
if (!wwuser.Any())
{
msg = "不存在此用户名"; relust = 0;
return string.Empty;
}
var extUserList = wwuser.Select(m => m.userid).ToList();//查找到的用户id
var userlist = _wwExtUserResId.GetList(p => extUserList.Contains(p.USERID)).ToList();
var extids = userlist.Select(m => m.USERID).Distinct().ToList();//赛选坐席已有extid
var resids = userlist.Select(m => m.RESID).Distinct().ToList();//赛选坐席已有resid
#region
IList<string> ZXDResid = new List<string>();
var useridExc = extUserList.Except(extids).ToList();//坐席内缺少的extid
if (useridExc.Any())
{ //存在缺少的extuserid
ZXDResid = QueryZXDResid(useridExc).Select(m => m.Value).ToList();
}
#endregion
resids.AddRange(ZXDResid);
resids = resids.Distinct().ToList();
if (resids.Count() == 0)
{
msg = "不存在此用户名"; relust = 0;
return string.Empty;
}
else if (resids.Count() == 1)
{
return resids.First();
}
else
{
msg = "存在多个客户ID";
List<string> strList = new List<string>();
//var wwextuser = ww_extuser.GetList(m => extUserList.Contains(m.USERID)).ToList();
foreach (var resid in resids)
{
//var name = wwextuser.FirstOrDefault(m => m.USERID == model.USERID)?.NAME ?? "";
strList.Add(resid + "-" + nickname);
}
return string.Join(";", strList);
}
}
catch (Exception ex)
{
LogHelper.Error("根据昵称查询:" + nickname + ":" + ex.Message + ex.StackTrace);
msg = "系统查询出错,请联系管理员"; relust = 0;
return string.Empty;
}
}
public string SeachByReMark(string remark, string eidStr, ref int relust, ref string msg)
{
try
{
if (string.IsNullOrWhiteSpace(remark))
{
msg = "请填写查询条件"; relust = 0;
return string.Empty;
}
decimal eid = 0;
IList<string> kfuserid = new List<string>();
if (!string.IsNullOrEmpty(eidStr) && decimal.TryParse(eidStr, out eid))
{
kfuserid = _customer.QueryKFuseridByEid(eid);
}
var wwuser = _wwhuserbll.WorkListGetByRemark(remark, kfuserid);
if (!wwuser.Any())
{
msg = "不存在此备注"; relust = 0;
return string.Empty;
}
var extUserList = wwuser.Select(m => m.userid).ToList();
var userlist = _wwExtUserResId.GetList(p => extUserList.Contains(p.USERID)).ToList();
var extids = userlist.Select(m => m.USERID).Distinct().ToList();
var resids = userlist.Select(m => m.RESID).Distinct().ToList();
#region
IList<string> needResgisterResid = new List<string>();
var useridExc = extUserList.Except(extids).ToList();
if (useridExc.Any())
{ //存在缺少的extuserid
needResgisterResid = QueryZXDResid(useridExc).Select(m => m.Value).ToList();
}
#endregion
resids.AddRange(needResgisterResid);
resids = resids.Distinct().ToList();
if (resids.Count() == 0)
{
msg = "不存在此用户名"; relust = 0;
return string.Empty;
}
else if (resids.Count() == 1)
{
return resids.First();
}
else
{
msg = "存在多个客户ID";
List<string> strList = new List<string>();
var wwextuser = ww_extuser.GetList(m => extUserList.Contains(m.USERID)).ToList();
foreach (var resid in resids)
{
var extid = userlist.FirstOrDefault(m => m.RESID == resid);
if (extid != null)
{
var name = wwuser.FirstOrDefault(m => m.userid == extid.USERID)?.name;
strList.Add(resid + "-" + name);
}
else
{
strList.Add(resid);
}
}
strList.AddRange(needResgisterResid);
return string.Join(";", strList);
}
}
catch (Exception ex)
{
LogHelper.Error("根据备注查询:" + remark + ":" + ex.Message + ex.StackTrace);
msg = "系统查询出错,请联系管理员"; relust = 0;
return string.Empty;
}
}
public string SeachByUnionid(string unionid, ref int relust, ref string msg)
{
try
{
if (string.IsNullOrWhiteSpace(unionid))
{
msg = "请填写查询条件"; relust = 0;
return string.Empty;
}
//unionid 只查找一个客户
var customerqw = _customer.QueryCustomerQwByUnionId(unionid);
if (customerqw != null)
{
#region res_customerqw中查询到客户信息
var resid = _customer.FindResidByExtUser(unionid);
if (!string.IsNullOrEmpty(resid))//匹配到手机号
{
//找到resid
return resid;
}
else
{ //如果无法找到手机号resid 调用中心点接口 从Soft_Userinfo_Sub查找手机号
var phonelist = QueryZXDPhone(unionid);
if (phonelist.Any())
{
List<string> residlist = new List<string>();
//找到手机号 注册
foreach (var phone in phonelist)
{
string mresid = WX.CRM.Common.ResUtil.CreateResId(phone);
var qq = _customer.ResgisterCustomer(phone, mresid, "fandUserByUnionid");//注册
//维护绑定关系
//
residlist.Add(mresid);
}
return string.Join(";", residlist);
}
else
{
//直接返回无手机号的 extuserid
return customerqw.RESID;
}
}
#endregion res_customerqw中查询到客户信息
}
else//找不到并维护res_customerqw
{
//从ww_extuser 中查找
var wwuser = _wwhuserbll.WorkListGetByUnionId(unionid);
if (wwuser.Any())
{
var extUserList = wwuser.Select(m => m.userid).ToList();//查找到的用户id
var userlist = _wwExtUserResId.GetList(p => extUserList.Contains(p.USERID)).ToList();
var extids = userlist.Select(m => m.USERID).Distinct().ToList();//赛选坐席已有extid
var resids = userlist.Select(m => m.RESID).Distinct().ToList();//赛选坐席已有resid
#region
IDictionary<string, string> ZXDExtResid = new Dictionary<string, string>();
var useridExc = extUserList.Except(extids).ToList();//坐席内缺少的extid
if (useridExc.Any())
{ //存在缺少的extuserid
ZXDExtResid = QueryZXDResid(useridExc);
}
#endregion
#region res_customerqw
List<RES_CUSTOMERQW> qwList = new List<RES_CUSTOMERQW>();
var twwuser = wwuser.Where(m => userlist.Select(x => x.USERID).Contains(m.userid) ||
ZXDExtResid.Select(x => x.Key).Contains(m.userid));
foreach (var item in twwuser)
{
RES_CUSTOMERQW model = new RES_CUSTOMERQW();
model.APPID = item.corpid;
model.APPUSERID = item.userid;
model.RESID = item.unionid;
model.SCENENAME = "查找客户写入";
model.CTIME = DateTime.Now;
model.CREATETIME = DateTime.Now;
qwList.Add(model);
}
_customer.InitCustomerqw(qwList);
#endregion res_customerqw
#region
IDictionary<string, string> ExtResid = new Dictionary<string, string>();
foreach (var item in userlist)
{
var user = wwuser.FirstOrDefault(m => m.userid == item.USERID);
_customer.BindCustomerResid(item.RESID, user?.unionid);
}
foreach (var item in ZXDExtResid)
{
_customer.BindCustomerResid(item.Value.Replace("c_", ""), item.Key);
}
#endregion
var ZXDResid = ZXDExtResid.Select(m => m.Value).Distinct().ToList();
//添加需要注册的resid
resids.AddRange(ZXDResid);
resids = resids.Distinct().ToList();
if (resids.Count() == 0)
{
msg = "不存在此用户名"; relust = 0;
return string.Empty;
}
else if (resids.Count() == 1)
{
return resids.First();
}
else
{
msg = "存在多个客户ID";
List<string> strList = new List<string>();
var wwextuser = ww_extuser.GetList(m => extUserList.Contains(m.USERID)).ToList();
foreach (var model in userlist)
{
var name = wwextuser.FirstOrDefault(m => m.USERID == model.USERID)?.NAME ?? "";
strList.Add(model.RESID + "-" + name);
}
strList.AddRange(ZXDResid);
return string.Join(";", strList);
}
}
else
{
msg = "不存在此用户名"; relust = 0;
return string.Empty;
}
}
}
catch (Exception ex)
{
LogHelper.Error("根据unionid查询" + unionid + ":" + ex.Message + ex.StackTrace);
msg = "系统查询出错,请联系管理员"; relust = 0;
return string.Empty;
}
}
private List<string> QueryZXDPhone(string unionid)
{
var url = cacheQ.GetValue_Parameter(Parameter.ZXD_CORE_WEBAPI);
url += "/Api/Customer/GetPhoneByUnionid";
string retmsg = Utility.GetData(url, "unionid=" + unionid, Encoding.UTF8);//从中心点获取 resid
ZXDCoreApiRes<List<string>> retmessage = JsonHelper.JsonDivertToObj<ZXDCoreApiRes<List<string>>>(retmsg);//返回信息
if (retmessage.code == 0)
{
return retmessage.data;
}
return new List<string>();
}
private IDictionary<string, string> QueryZXDResid(List<string> extUser)
{
Dictionary<string, object> param = new Dictionary<string, object>();
param.Add("extUser", string.Join(",", extUser));
string json = Utility.ConvertToJSON(string.Join(",", extUser));
var url = cacheQ.GetValue_Parameter(Parameter.ZXD_CORE_WEBAPI);
url += "/Api/Customer/GetResidByExtUser";
string retmsg = Utility.PostAjaxData(url, json, Encoding.UTF8);//从中心点获取 resid
ZXDCoreApiRes<List<string>> retmessage = JsonHelper.JsonDivertToObj<ZXDCoreApiRes<List<string>>>(retmsg);//返回信息
if (retmessage.code == 0)
{
var res = new Dictionary<string, string>();
foreach (var extres in retmessage.data)
{
if (extres.Contains(":"))
{
var kv = extres.Split(':');
if (!res.ContainsKey(kv[0]))
{
res.Add(kv[0], "c_" + kv[1]);
}
}
}
return res;
}
return new Dictionary<string, string>();
}
#endregion
public string SeachByuserNo(string userNo, ref int relust, ref string msg)
{
try
{
if (string.IsNullOrWhiteSpace(userNo))
{
msg = "请填写用户号!"; relust = 0;
return "";
}
var model = _resCustomerdetail.Get(p => p.ZX_USERID == userNo);
if (model == null)
{
msg = "不存在此用户号"; relust = 0;
return string.Empty;
}
return model.RESID;
}
catch (Exception ex)
{
LogHelper.Error(ex.Message + ex.StackTrace);
msg = "系统查询出错,请联系管理员"; relust = 0;
return "";
}
}
public string SeachByTradeCode(string tradeCode, ref int relust, ref string msg)
{
string resid = string.Empty;
try
{
if (string.IsNullOrWhiteSpace(tradeCode))
{
msg = "请填写查询条件"; relust = 0;
return "";
}
return resid;
}
catch (Exception ex)
{
LogHelper.Error("根据tradecode查询客户" + tradeCode + ":" + ex.Message + ex.StackTrace);
msg = "系统查询出错,请联系管理员"; relust = 0;
return "";
}
}
public string SeachByCustomerName(string customerName, ref int relust, ref string msg)
{
try
{
if (string.IsNullOrWhiteSpace(customerName))
{
msg = "请填写查询条件"; relust = 0;
return "";
}
var list = customerdetailBiz_Q.GetList(p => p.CNAME.Contains(customerName));
if (list == null || list.Count() <= 0)
{
msg = "不存在此用户名"; relust = 0;
return "";
}
if (list != null && list.Count() == 1)
{
return list.FirstOrDefault().RESID;
}
else
{
msg = "存在多个客户ID";
List<string> strList = new List<string>();
foreach (var model in list)
{
strList.Add(model.RESID + "-" + model.CNAME);
}
return string.Join(";", strList);
}
}
catch (Exception ex)
{
LogHelper.Error("根据用户名查询:" + customerName + ":" + ex.Message + ex.StackTrace);
msg = "系统查询出错,请联系管理员"; relust = 0;
return "";
}
}
public string GetResId<T>(T model)
{
string resid = string.Empty;
if (model != null)
{
var tt = model.GetType().GetProperty("RESID").GetValue(model, null);
resid = tt.ToString();
}
return resid;
}
#region
[HttpGet]
public ActionResult getResIdsByCustomerIds()
{
return View();
}
// [HttpPost]
public string getCustomerIdsAndResIds()
{
HttpContext.Response.ContentType = "text/html;characset=utf-8";
// Response.ContentType = "text/html;characset=utf-8";
bool result = false;
string msg = "未找到客户ID";
string type = "";
string resids = "";
string path = "";
List<string> mbs = new List<string>();
string t = string.Format("{0}", Request.Form["FileType"]);
string selecttype = string.Format("{0}", Request.Form["TrunType"]);
if (t == "批量转换")
{
string customerids = string.Format("{0}", Request.Form["txtoldId"]);
type = "批量";
if (!string.IsNullOrWhiteSpace(customerids))
{
string[] _ids = customerids.Replace("\r\n", ",").Replace("\r", ",").Replace("\n", ",").Split(',');
if (selecttype == "1" || selecttype == "2")
{
List<temp_customerturn> customerturn = new List<temp_customerturn>();
foreach (var model in _ids)
{
temp_customerturn temp = new temp_customerturn();
temp.CUSTOMERID = model.Trim();
customerturn.Add(temp);
}
if (customerturn.Count > 0)
{
DataTable tb = Utility.ToOracleDataTable<temp_customerturn>(customerturn);
List<CSVR_IDMAP> idmaps = csvr_idmap.GetResIdList(tb, selecttype);
if (idmaps != null && idmaps.Count > 0)
{
foreach (var model in idmaps)
{
if (selecttype == "1")
{
resids += model.RESID + "\r\n";
}
else
{
resids += model.CUSTOMERID + "\r\n";
}
}
}
}
}
else if (selecttype == "6")
{
foreach (var id in _ids)
{
var resid = ResUtil.CreateResId(id);
resids += resid.Trim() + "\r\n";
}
}
else
{
List<temp_resimportid> resimportid = new List<temp_resimportid>();
string importId = DateTime.Now.ToString("yyyyMMddHHmmss");
foreach (var model in _ids)
{
temp_resimportid temp = new temp_resimportid();
temp.IMPORTID = Convert.ToDecimal(importId);
temp.IMPORTDATA = model.Trim();
resimportid.Add(temp);
}
DataTable tb = Utility.ToOracleDataTable<temp_resimportid>(resimportid);
List<string> list = _customerQ.ResIDNoOutboundFilter(ref errors, tb, importId, DateTime.Now, DateTime.Now, selecttype.GetDecimal(0), "", "");
if (list != null && list.Count > 0)
{
foreach (var model in list)
{
resids += model + "\r\n";
}
}
}
if (string.IsNullOrEmpty(resids)) { result = false; msg = "数据为空"; }
else
{
result = true;
msg = "";
}
}
// return Json(new { result = result, type = type, message = msg, ResIds = resids }, JsonRequestBehavior.AllowGet);
}
else if (t == "文件上传导入")
{
type = "文件";
// mbs = GetByTxtFile();
path = GetByTxtFile();
if (path != null)
{
result = true;
msg = "";
}
// return Json(new { result = result, type = type, path = path, selecttype = selecttype, message = msg }, JsonRequestBehavior.AllowGet);
}
Getresult getresult = new Getresult();
getresult.result = result;
getresult.type = type;
getresult.ResIds = resids;
getresult.path = path;
getresult.selecttype = selecttype;
getresult.message = msg;
string json = JsonHelper.ObjDivertToJson(getresult);
return json;
}
private string GetByTxtFile()
{
string vPath = System.Configuration.ConfigurationManager.AppSettings["UploadTemFileDic"];
List<string> lis = new List<string>();
HttpFileCollectionBase files = Request.Files;
HttpPostedFileBase file = files["FileMobile"];
string fileName = "";
if (file != null && file.ContentLength > 0)
{
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);
// System.IO.File.Delete(path);
}
else
{
throw new Exception("文件格式不正确!");
}
}
else
{
throw new Exception("文件不存在!");
}
return fileName;
}
[AuthorizeRedirect(Roles = InitRights.CONST_公共权限)]
public FileResult CustomerIdOrResId(string path, string selecttype)
{
HttpContext.Response.ContentType = "text/html;characset=utf-8";
string vPath = System.Configuration.ConfigurationManager.AppSettings["UploadTemFileDic"];
if (path.LastIndexOf("\\") > -1)
{
path = path.Substring(path.LastIndexOf("\\") + 1);
}
if (path.ToLower().IndexOf(".txt") > -1)
{
if (!System.IO.Directory.Exists(Server.MapPath(vPath)))
{
System.IO.Directory.CreateDirectory(Server.MapPath(vPath));
}
path = Server.MapPath((vPath + "/") + path);
}
List<string> lis = new List<string>();
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();
lis.Add(number);
}
sr.Close();
fs.Close();
System.IO.File.Delete(path);
if (selecttype == "1" || selecttype == "2")
{
List<temp_customerturn> customerturn = new List<temp_customerturn>();
List<temp_customerturn> customerturn2 = new List<temp_customerturn>();
foreach (var model in lis)
{
temp_customerturn temp = new temp_customerturn();
temp.CUSTOMERID = model;
customerturn.Add(temp);
}
if (customerturn.Count > 0)
{
DataTable tb = Utility.ToOracleDataTable<temp_customerturn>(customerturn);
List<CSVR_IDMAP> idmaps = csvr_idmap.GetResIdList(tb, selecttype);
if (idmaps != null && idmaps.Count > 0)
{
foreach (var model in idmaps)
{
temp_customerturn turn = new temp_customerturn();
if (selecttype == "1")
{
turn.CUSTOMERID = model.RESID;
}
else
{
turn.CUSTOMERID = model.CUSTOMERID;
}
customerturn2.Add(turn);
}
}
}
return File(ExcelHelper.ExportListModelToExcel<temp_customerturn>(customerturn2, "Id转换", 60000, null), "application/ms-excel", PageRequest.GetDlownLoadName("Id转换.xls"));
}
else if (selecttype == "6")
{
//手机号码批量生成resid
//ResUtil.CreateResId
var list = new List<string>();
foreach (var model in lis)
{
try
{
var resid = ResUtil.CreateResId(model);
list.Add(resid);
}
catch (Exception ex)
{
LogHelper.Info("错误的号码:" + model);
}
}
return File(ExcelHelper.ExportListObjectToExcel<string>(list, "结果", "数据转换", null), "application/ms-excel", PageRequest.GetDlownLoadName("数据转换.xls"));
}
else
{
List<temp_resimportid> resimportid = new List<temp_resimportid>();
string importId = DateTime.Now.ToString("yyyyMMddHHmmss");
foreach (var model in lis)
{
temp_resimportid temp = new temp_resimportid();
temp.IMPORTID = Convert.ToDecimal(importId);
temp.IMPORTDATA = model.Trim();
resimportid.Add(temp);
}
DataTable tb = Utility.ToOracleDataTable<temp_resimportid>(resimportid);
List<string> list = _customerQ.ResIDNoOutboundFilter(ref errors, tb, importId, DateTime.Now, DateTime.Now, selecttype.GetDecimal(0), "", "");
return File(ExcelHelper.ExportListObjectToExcel<string>(list, "结果", "数据转换", null), "application/ms-excel", PageRequest.GetDlownLoadName("数据转换.xls"));
}
}
public class temp_customerturn
{
public string CUSTOMERID { get; set; }
}
public class temp_resimportid
{
public decimal IMPORTID { get; set; }
public string IMPORTDATA { get; set; }
}
public class Getresult
{
public bool result { get; set; }
public string type { get; set; }
public string message { get; set; }
public string ResIds { get; set; }
public string path { get; set; }
public string selecttype { get; set; }
}
#endregion
}
}