216 lines
9.9 KiB
C#
216 lines
9.9 KiB
C#
namespace Zxd.Domain
|
||
{
|
||
public class RegUserDomain : IRegUserDomain
|
||
{
|
||
private readonly IRepositoryBase<ZxdDbContext, SOFT_USER> _softUserRepository;
|
||
private readonly IRepositoryBase<ZxdDbContext, Soft_User_CH> _softUserChRepository;
|
||
private readonly IRepositoryBase<ZxdDbContext, Bas_CompanyChannel> _companyChannelRepository;
|
||
private readonly IRepositoryBase<ZxdDbContext, RES_APPLY> _resApplyRepository;
|
||
private readonly IBaseRepository<ZxdDbContext> _repository;
|
||
private readonly IResCustomerDomain _resCustomerService;
|
||
private readonly ISystemConfigDomain _systemConfigService;
|
||
|
||
public RegUserDomain(IBaseRepository<ZxdDbContext> repository, IResCustomerDomain resCustomerService
|
||
, IRepositoryBase<ZxdDbContext, Soft_User_CH> softUserChRepository,
|
||
IRepositoryBase<ZxdDbContext, RES_APPLY> resApplyRepository
|
||
, ISystemConfigDomain systemConfigService)
|
||
{
|
||
_repository = repository;
|
||
_softUserRepository = _repository.GetRepository<SOFT_USER>();
|
||
_resCustomerService = resCustomerService;
|
||
_softUserChRepository = softUserChRepository;
|
||
_companyChannelRepository = _repository.GetRepository<Bas_CompanyChannel>();
|
||
_resApplyRepository = resApplyRepository;
|
||
_systemConfigService = systemConfigService;
|
||
}
|
||
|
||
/*接口返回的字符串: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 emial, string ip, 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)
|
||
public async Task RegUser(SynInnerModel dto)
|
||
{
|
||
//88888888888,5001,6299377,565,2013/9/9 14:44:54,600
|
||
List<string> errors = new List<string>();
|
||
try
|
||
{
|
||
//注册customer
|
||
string v_resid = string.Empty;
|
||
if (!string.IsNullOrEmpty(dto.mobile))
|
||
{
|
||
v_resid = ResUtil.CreateResId(dto.mobile);
|
||
await _resCustomerService.ResgisterCustomer(dto.mobile, v_resid, dto.ch);
|
||
}
|
||
DateTime? rgd = null;
|
||
if (dto.regDate.HasValue)
|
||
{
|
||
rgd = TimeHelper.GetTimeFromLinuxTime(dto.regDate.Value);
|
||
}
|
||
var ch = Convert.ToInt32(dto.ch);
|
||
var regUser = _softUserRepository.Query().FirstOrDefault(p => p.USERNAME == dto.username);
|
||
if (regUser == null)
|
||
{
|
||
var softUser = new SOFT_USER
|
||
{
|
||
USERNAME = dto.username,
|
||
USERPASS = "string.Empty",
|
||
CTIME = DateTime.Now,
|
||
COMPANYID = 0,
|
||
REGCAMPAINID = ch,
|
||
REGDATE = rgd,
|
||
RESID = v_resid,
|
||
REGPLATFORM = dto.plat,
|
||
EMAIL = dto.em,
|
||
IP = dto.ip,
|
||
OPENID = dto.openid,// ***第三方用户ID * **
|
||
OPENPLAT = dto.openplat,//***第三方平台***
|
||
LIVECODE = dto.liveCode,
|
||
REGSOURCE = dto.regSource
|
||
};
|
||
if (!string.IsNullOrWhiteSpace(dto.refeid))
|
||
{
|
||
softUser.EID = Convert.ToInt32(dto.refeid);
|
||
dto.eid = dto.refeid;
|
||
}
|
||
if (!string.IsNullOrEmpty(dto.mobile))
|
||
{
|
||
softUser.ISACTIVE = 1;
|
||
softUser.ACTIVERESID = v_resid;
|
||
softUser.ACTIVETIME = rgd;
|
||
}
|
||
softUser.UNIONID = dto.unionId;
|
||
await _softUserRepository.InsertAsync(softUser);
|
||
|
||
var softUserCH = new Soft_User_CH() { UserName = softUser.USERNAME, CH = Convert.ToInt32(dto.ch), CTime = DateTime.Now };
|
||
|
||
if (!string.IsNullOrEmpty(dto.eid))
|
||
{
|
||
softUserCH.Eid = int.Parse(dto.eid);
|
||
}
|
||
await _softUserChRepository.InsertAsync(softUserCH);
|
||
if (!string.IsNullOrWhiteSpace(dto.eid) && !string.IsNullOrEmpty(dto.mobile))
|
||
{
|
||
var eid = int.Parse(dto.eid);
|
||
SetQuantity(ch, eid, dto.groupid ?? 0, v_resid);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(dto.refeid))
|
||
{
|
||
regUser.EID = Convert.ToInt32(dto.refeid);
|
||
}
|
||
if (!string.IsNullOrEmpty(dto.unionId))
|
||
{
|
||
regUser.UNIONID = dto.unionId;
|
||
}
|
||
|
||
var softUserExists = _softUserChRepository.Query().Any(p => p.UserName == dto.username && p.CH == ch);
|
||
|
||
if (!softUserExists)
|
||
{
|
||
var softUserCH = new Soft_User_CH() { UserName = dto.username, CH = Convert.ToInt32(dto.ch), CTime = DateTime.Now };
|
||
|
||
if (!string.IsNullOrEmpty(dto.eid))
|
||
{
|
||
softUserCH.Eid = int.Parse(dto.eid);
|
||
}
|
||
await _softUserChRepository.InsertAsync(softUserCH);
|
||
|
||
if (!string.IsNullOrWhiteSpace(dto.eid) && !string.IsNullOrEmpty(dto.mobile))
|
||
{
|
||
var eid = int.Parse(dto.eid);
|
||
SetQuantity(ch, eid, dto.groupid ?? 0, v_resid);
|
||
}
|
||
}
|
||
//LogHelper.Info("regUser.EID:" + regUser.EID.ToString() + ",regUser.UNIONID:" + regUser.UNIONID);
|
||
}
|
||
Log.Information($"日志打印 regUser{v_resid}");
|
||
if (!string.IsNullOrEmpty(v_resid))
|
||
{
|
||
await _resCustomerService.ContractUser(v_resid, dto.username);
|
||
}
|
||
Log.Information($"日志打印 ContractUser{v_resid}");
|
||
//进入资源系统
|
||
bool r = ImportResApply(errors, dto.mobile, dto.ch, string.Empty, dto.username, rgd, null, null, null, null);
|
||
if (r == false)
|
||
throw new Exception(string.Join(",", errors));
|
||
Log.Information($"日志打印 ImportResApply{v_resid}");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Log.Error($"日志错误{ex.Message}");
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
/// <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(List<string> errors, string mobile, string tag, string cardNo, string userName, DateTime? regDate, string jsonData = null, string dataType = null, string extXML = null, string kWord = null)
|
||
{
|
||
try
|
||
{
|
||
string clientid = _systemConfigService.GetSystemConfig().CRMClientKey;
|
||
var client = _systemConfigService.GetClientKey(clientid);
|
||
if (string.IsNullOrEmpty(mobile))
|
||
return true;
|
||
|
||
var model = new RES_APPLY
|
||
{
|
||
RESOURCETAG = tag,
|
||
RESID = ResUtil.CreateResId(mobile),
|
||
USERNAME = userName,
|
||
JSONDATA = jsonData,
|
||
RTIME = regDate,
|
||
JSONTYPE = 1,
|
||
STATUS = 0,
|
||
DATATYPE = dataType,
|
||
EXTXML = extXML,
|
||
KWORD = kWord,
|
||
CTIME = DateTime.Now,
|
||
ENMOBILE = ResUtil.NumberFormat(mobile.Trim()),
|
||
MOBILE = SecurityHelper.EncyptData(mobile.Trim(), client.AccessKey),
|
||
};
|
||
_resApplyRepository.InsertAsync(model);
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
errors.Add(ex.Message + ex.StackTrace);
|
||
//CRM.Core.Common.LogHelper.Error("----------"+ex.Message + ex.StackTrace);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public void SetQuantity(int ch, int eid, int gid, string resid)
|
||
{
|
||
try
|
||
{
|
||
//478361560401673707-1001-60974-27
|
||
Log.Information("SetQuantity-1:" + resid + "-" + ch.ToString() + "-" + eid.ToString() + "-" + gid.ToString());
|
||
|
||
var company = _companyChannelRepository.Query().FirstOrDefault(p => p.Min <= ch && p.Max >= ch);
|
||
|
||
Log.Information("SetQuantity-2:" + company.Defult);
|
||
_resCustomerService.SetQuantity(company.Defult, eid, gid);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Log.Error($"SetQuantity" + ex.Message);
|
||
}
|
||
}
|
||
}
|
||
} |