425 lines
19 KiB
C#
425 lines
19 KiB
C#
//using CRM.Core.DTO;
|
||
using System;
|
||
using System.Linq;
|
||
using WX.CRM.BLL.Base;
|
||
using WX.CRM.BLL.Csvr;
|
||
using WX.CRM.BLL.Res;
|
||
using WX.CRM.BLL.Util;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.Model.Entity;
|
||
|
||
namespace WX.CRM.BLL.Soft
|
||
{
|
||
/// <summary>
|
||
/// 抓取接口数据,旧系统为JMDUSER
|
||
/// </summary>
|
||
public class GET_REGUSER
|
||
{
|
||
private CACHE_BL cacheQ = new CACHE_BL();
|
||
|
||
//RES_ACTIVITY_BL _resActivityQ = new RES_ACTIVITY_BL();
|
||
private CSVR_FAVORITECUSTOMER_BL _favCustomerQ = new CSVR_FAVORITECUSTOMER_BL();
|
||
|
||
private CSVR_TODOITEM_BL _todoItem = new CSVR_TODOITEM_BL();
|
||
|
||
//RES_DISTRIBUTE_DETAIL_BL _resDistributeDetial = new RES_DISTRIBUTE_DETAIL_BL();
|
||
private RES_APPLY_BL _apply = new RES_APPLY_BL();
|
||
|
||
private RES_MYALLOCATERES_BL _resMyAllocateRes = new RES_MYALLOCATERES_BL();
|
||
private BAS_INNERUSER_BL _user = new BAS_INNERUSER_BL();
|
||
private BAS_PARAMETER_BL _para = new BAS_PARAMETER_BL();
|
||
|
||
/*接口返回的字符串:18696548545,5001,6201075,5001,2013-8-7 13:54:16【手机号,标签,卡号,用户名,注册时间】*/
|
||
|
||
/// <summary>
|
||
/// 从接口抓取到的注册用户,旧系统名称为jmdUser
|
||
/// </summary>
|
||
/// <param name="mobile">手机号</param>
|
||
/// <param name="tag">注册标签</param>
|
||
/// <param name="cardNo">卡号</param>
|
||
/// <param name="userName">用户名</param>
|
||
/// <param name="regDate">注册时间</param>
|
||
public void RegUser(string mobile, string tag, string cardNo, string userName, DateTime? regDate, int companyId, string activeMobile = null, string platform = null, string jsonData = null, string dataType = null, string extXML = null, string kWord = null, string eid = null, string openid = null, string openplat = null, string unionid = null, string liveCode = null, string regSource = null, string refeid = null, int? sgid = null)
|
||
{
|
||
ValidationErrors errors = new ValidationErrors();
|
||
try
|
||
{
|
||
var userList = cacheQ.GetUserList();
|
||
var pici = new SEQUENCES_BL().Seq_base_get();
|
||
|
||
var v_resid = string.Empty;
|
||
var v_umid = string.Empty;
|
||
if (!string.IsNullOrEmpty(mobile))
|
||
{
|
||
v_resid = ResUtil.CreateResId(mobile);
|
||
LogHelper.Info($"开始获取umid{v_resid}");
|
||
v_umid = cacheQ.GetUMid(mobile);
|
||
new BLL.Res.RES_CUSTOMER_BL().ResgisterCustomer(mobile, v_resid, tag);
|
||
}
|
||
using (var db = new crmContext())
|
||
{
|
||
//注册customer
|
||
var regUser = db.SOFT_USER.FirstOrDefault(p => p.USERNAME == userName);
|
||
if (regUser == null)
|
||
{
|
||
var softUser = new SOFT_USER();
|
||
softUser.USERNAME = userName;
|
||
softUser.USERPASS = "string.Empty";
|
||
if (!string.IsNullOrEmpty(cardNo))
|
||
softUser.USERNO = decimal.Parse(cardNo);
|
||
softUser.CTIME = System.DateTime.Now;
|
||
softUser.COMPANYID = companyId;
|
||
softUser.REGCAMPAINID = Convert.ToInt32(tag);
|
||
softUser.REGDATE = regDate;
|
||
softUser.RESID = v_resid;
|
||
softUser.REGPLATFORM = platform ?? "0";
|
||
softUser.OPENID = openid;//***第三方用户ID***
|
||
softUser.OPENPLAT = openplat;//***第三方平台***
|
||
if (!string.IsNullOrWhiteSpace(refeid))
|
||
{
|
||
softUser.EID = Convert.ToInt32(refeid);
|
||
eid = refeid;
|
||
}
|
||
if (!string.IsNullOrEmpty(activeMobile))
|
||
{
|
||
softUser.ISACTIVE = 1;
|
||
softUser.ACTIVERESID = v_resid;
|
||
softUser.ACTIVETIME = regDate;
|
||
}
|
||
if (!string.IsNullOrEmpty(unionid))
|
||
softUser.UNIONID = unionid;
|
||
softUser.LIVECODE = liveCode;
|
||
softUser.REGSOURCE = regSource;
|
||
|
||
db.SOFT_USER.Add(softUser);
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(refeid))
|
||
{
|
||
regUser.EID = Convert.ToInt32(refeid);
|
||
}
|
||
if (!string.IsNullOrEmpty(unionid))
|
||
{
|
||
regUser.UNIONID = unionid;
|
||
}
|
||
|
||
//LogHelper.Info("regUser.EID:" + regUser.EID.ToString() + ",regUser.UNIONID:" + regUser.UNIONID);
|
||
}
|
||
|
||
//分配EID不是空的,直接分配资源
|
||
if (!string.IsNullOrWhiteSpace(eid) && !string.IsNullOrEmpty(v_resid))
|
||
{
|
||
var isExe = false;
|
||
|
||
var myRes = db.RES_MYALLOCATERES.FirstOrDefault(p => p.RESID == v_resid);
|
||
|
||
var para = _para.GetModel_Patameter("IgnoreManager");
|
||
if (para != null && myRes != null)
|
||
{
|
||
var manager = _user.GetModel(myRes.INNERUSERID);
|
||
|
||
if (!string.IsNullOrEmpty(para.PARAVALUE))
|
||
{
|
||
var manageList = para.PARAVALUE.Split(',');
|
||
foreach (var item in manageList)
|
||
{
|
||
if (item == manager.EID.ToString())
|
||
{
|
||
isExe = true;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//如果不存在分配关系,才需要分配
|
||
if (myRes == null || isExe)
|
||
{
|
||
var eid32 = Convert.ToInt32(eid);
|
||
//var user = userList.FirstOrDefault(p => p.EID == eid32);
|
||
var user = _user.getInnerUserByEid(eid32);
|
||
if (user != null)
|
||
{
|
||
var info = new RES_ALLCOTE_USER()
|
||
{
|
||
ID = new SEQUENCES_BL().Seq_base_get(),
|
||
INNERUSERID = user.PKID,
|
||
EID = eid32,
|
||
NUM = 1,
|
||
CTIME = DateTime.Now,
|
||
PICI = pici,
|
||
RESID = v_resid,
|
||
TYPE = 1
|
||
};
|
||
if (sgid.HasValue)
|
||
{
|
||
info.SGID = sgid.Value;
|
||
}
|
||
|
||
db.RES_ALLCOTE_USER.Add(info);
|
||
}
|
||
}
|
||
}
|
||
db.SaveChanges();
|
||
}
|
||
//资源绑定关系
|
||
if (!string.IsNullOrEmpty(v_resid))
|
||
{
|
||
new BLL.Res.RES_CUSTOMERUSER_BL().ContractUser(v_resid, userName);
|
||
}
|
||
|
||
//资源分配关系
|
||
if (!string.IsNullOrWhiteSpace(eid) && !string.IsNullOrEmpty(v_resid))
|
||
{
|
||
var eid1000 = userList.FirstOrDefault(p => p.EID == 10000).PKID;
|
||
|
||
_resMyAllocateRes.ExeSeniorDistributeByResId(eid1000, pici, "扫码直接分配");
|
||
}
|
||
|
||
//进入资源流程
|
||
if (!string.IsNullOrEmpty(mobile))
|
||
{
|
||
ImportResApply(mobile, tag, cardNo, userName, regDate);
|
||
}
|
||
|
||
#region 提醒
|
||
|
||
if (!string.IsNullOrEmpty(v_resid))
|
||
{
|
||
try
|
||
{
|
||
var user10000 = cacheQ.GetUserList().Find(p => p.EID == 10000).PKID;
|
||
var favCustomer = _favCustomerQ.GetModel_FavoriteCustomer(v_resid, null);
|
||
if (favCustomer != null)
|
||
{
|
||
//说明这个用户有人收藏,提醒业务员
|
||
var todoItem = new CSVR_TODOITEM()
|
||
{
|
||
PKID = new SEQUENCES_BL().Seq_base_get(),
|
||
SENDEDUSERID = user10000,
|
||
RECEIVEDUSERID = favCustomer.SALESID,
|
||
ISPRIVATE = 1,
|
||
RESID = v_resid,
|
||
MEMO = "您收藏的客户注册了",
|
||
STARTTIME = DateTime.Now,
|
||
URL = "/Csvr/CustomerInfo/CustomerDetail?resid=" + v_resid,
|
||
URLTITLE = "客户详细"
|
||
};
|
||
_todoItem.Create(ref errors, todoItem);
|
||
LogHelper.Info(todoItem.ToJson());
|
||
}
|
||
}
|
||
catch (Exception exx)
|
||
{
|
||
LogHelper.Error(exx.ToString());
|
||
}
|
||
}
|
||
|
||
#endregion 提醒
|
||
}
|
||
catch (System.Data.Entity.Validation.DbEntityValidationException exception)
|
||
{
|
||
var errorMessages =
|
||
exception.EntityValidationErrors
|
||
.SelectMany(validationResult => validationResult.ValidationErrors)
|
||
.Select(m => m.ErrorMessage);
|
||
|
||
var fullErrorMessage = string.Join(", ", errorMessages);
|
||
//记录日志
|
||
//Log.Error(fullErrorMessage);
|
||
var exceptionMessage = string.Concat(exception.Message, " 验证异常消息是:", fullErrorMessage);
|
||
LogHelper.Error(exceptionMessage);
|
||
|
||
throw new System.Data.Entity.Validation.DbEntityValidationException(exceptionMessage, exception.EntityValidationErrors);
|
||
}
|
||
catch
|
||
{
|
||
throw;
|
||
}
|
||
}
|
||
|
||
//public void BindUser(BindRegUserDto dto)//string username, string unionid, int eid, int ch)
|
||
//{
|
||
// try
|
||
// {
|
||
// //var resid = string.Empty;
|
||
// var userList = cacheQ.GetUserList();
|
||
// var isExe = true;
|
||
// var pici = new SEQUENCES_BL().Seq_base_get();
|
||
|
||
// using (var db = new crmContext())
|
||
// {
|
||
// var user = new SOFT_USER();
|
||
// if (!string.IsNullOrEmpty(dto.unionId))
|
||
// user = db.SOFT_USER.FirstOrDefault(p => p.UNIONID == dto.unionId);
|
||
// if (!string.IsNullOrEmpty(dto.username))
|
||
// user = db.SOFT_USER.FirstOrDefault(p => p.USERNAME == dto.username);
|
||
|
||
// if (user == null)
|
||
// {
|
||
// LogHelper.Info("找不到客户username:" + dto.username + "|||unionid:" + dto.unionId);
|
||
// return;
|
||
// }
|
||
// if (string.IsNullOrEmpty(user.RESID))
|
||
// {
|
||
// LogHelper.Info("客户资源resid为空:" + dto.username + " |||unionid:" + dto.unionId);
|
||
// return;
|
||
// }
|
||
|
||
// //resid = user.RESID;
|
||
|
||
// //user.EID = eid;
|
||
// user.UNIONID = dto.unionId;
|
||
// //LogHelper.Info("regUser.EID:" + user.EID.ToString() + ",regUser.UNIONID:" + user.UNIONID);
|
||
// if (dto.eid > 0)
|
||
// {
|
||
// var eid32 = Convert.ToInt32(dto.eid);
|
||
// //var userId = userList.FirstOrDefault(p => p.EID == eid32).PKID;
|
||
// var userId = _user.getInnerUserByEid(eid32).PKID;
|
||
// var info = new RES_ALLCOTE_USER()
|
||
// {
|
||
// ID = new SEQUENCES_BL().Seq_base_get(),
|
||
// INNERUSERID = userId,
|
||
// EID = eid32,
|
||
// NUM = 1,
|
||
// CTIME = DateTime.Now,
|
||
// PICI = pici,
|
||
// RESID = user.RESID,
|
||
// TYPE = 1
|
||
// };
|
||
// if (dto.groupid.HasValue)
|
||
// {
|
||
// info.SGID = dto.groupid.Value;
|
||
// }
|
||
|
||
// var isExists = db.RES_MYALLOCATERES.Any(p => p.RESID == info.RESID);
|
||
// var isFav = db.CSVR_FAVORITECUSTOMER.Any(p => p.RESID == info.RESID);
|
||
// var isOrder = db.WX_SZZYORDER.Any(p => p.RESID == info.RESID && p.OTIME != null);
|
||
|
||
// if (isExists)
|
||
// {
|
||
// var para = _para.GetModel_Patameter("IgnoreManager");
|
||
// if (para != null)
|
||
// {
|
||
// var myRes = db.RES_MYALLOCATERES.FirstOrDefault(p => p.RESID == info.RESID);
|
||
// if (myRes != null)
|
||
// {
|
||
// var manager = _user.GetModel(myRes.INNERUSERID);
|
||
|
||
// if (!string.IsNullOrEmpty(para.PARAVALUE))
|
||
// {
|
||
// var manageList = para.PARAVALUE.Split(',');
|
||
// foreach (var item in manageList)
|
||
// {
|
||
// if (item == manager.EID.ToString())
|
||
// {
|
||
// isExists = false;
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
// if (isExists || isFav || isOrder)
|
||
// {
|
||
// isExe = false;
|
||
// }
|
||
// else
|
||
// {
|
||
// db.RES_ALLCOTE_USER.Add(info);
|
||
// db.SaveChanges();
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
// //资源分配关系
|
||
// if (dto.eid > 0 && isExe)
|
||
// {
|
||
// var eid1000 = userList.FirstOrDefault(p => p.EID == 10000).PKID;
|
||
|
||
// _resMyAllocateRes.ExeSeniorDistributeByResId(eid1000, pici, "扫码直接分配");
|
||
// }
|
||
// }
|
||
// catch (Exception ex)
|
||
// {
|
||
// LogHelper.Error("更新软件用户:" + ex.ToString());
|
||
// }
|
||
//}
|
||
|
||
/// <summary>
|
||
/// (当手机号不为空时时进入资源系统,等清洗)从接口抓取到的注册用户,旧系统名称为jmdUser
|
||
/// </summary>
|
||
/// <param name="mobile">手机号</param>
|
||
/// <param name="tag">注册标签</param>
|
||
/// <param name="cardNo">卡号</param>
|
||
/// <param name="userName">用户名</param>
|
||
/// <param name="regDate">注册时间</param>
|
||
public bool ImportResApply(string mobile, string tag, string cardNo, string userName, DateTime? regDate, string jsonData = null, string dataType = null, string extXML = null, string kWord = null)
|
||
{
|
||
ValidationErrors errors = new ValidationErrors();
|
||
try
|
||
{
|
||
if (string.IsNullOrEmpty(mobile))
|
||
return true;
|
||
//WX.CRM.Common.LogHelper.Error("ImportResApply**************************************************");
|
||
var model = new WX.CRM.Model.Entity.RES_APPLY
|
||
{
|
||
PKID = new Base.SEQUENCES_BL().Seq_base_get(WX.CRM.Model.Enum.PKIDType.LargeTable),
|
||
RESOURCETAG = tag,
|
||
RESID = Common.ResUtil.CreateResId(mobile),
|
||
USERNAME = userName,
|
||
JSONDATA = jsonData,
|
||
RTIME = regDate,
|
||
JSONTYPE = 1,
|
||
STATUS = 0,
|
||
MOBILE = mobile.Trim(),
|
||
DATATYPE = dataType,
|
||
EXTXML = extXML,
|
||
KWORD = kWord
|
||
};
|
||
_apply.Create(ref errors, model);
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
errors.Add(ex.Message + ex.StackTrace);
|
||
//WX.CRM.Common.LogHelper.Error("----------"+ex.Message + ex.StackTrace);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public DateTime GetServiceLastExecTime()
|
||
{
|
||
DateTime rdate = System.DateTime.Now;
|
||
try
|
||
{
|
||
WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext();
|
||
var par = db.BAS_PARAMETER.FirstOrDefault(p => p.PARAKEY.Trim() == "RegUserServiceExecLastTime" && p.GROUPID.Trim() == "SysServiceExecTime");
|
||
if (par != null)
|
||
rdate = DateTime.Parse(par.PARAVALUE);
|
||
else
|
||
throw new Exception("RegUserServiceExecLastTime参数错误");
|
||
}
|
||
catch
|
||
{
|
||
rdate = System.DateTime.Now;
|
||
}
|
||
return rdate;
|
||
}
|
||
|
||
public void UpdateExecLastTime(DateTime lastTime)
|
||
{
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
var par = db.BAS_PARAMETER.FirstOrDefault(p => p.PARAKEY.Trim() == "RegUserServiceExecLastTime" && p.GROUPID.Trim() == "SysServiceExecTime");
|
||
if (par == null)
|
||
{
|
||
throw new Exception("RegUserServiceExecLastTime参数错误");
|
||
}
|
||
par.PARAVALUE = lastTime.ToString();
|
||
db.SaveChanges();
|
||
}
|
||
}
|
||
}
|
||
} |