namespace Zxd.Domain { public class RegUserDomain : IRegUserDomain { private readonly IRepositoryBase _softUserRepository; private readonly IRepositoryBase _softUserChRepository; private readonly IRepositoryBase _companyChannelRepository; private readonly IRepositoryBase _resApplyRepository; private readonly IBaseRepository _repository; private readonly IResCustomerDomain _resCustomerService; private readonly ISystemConfigDomain _systemConfigService; public RegUserDomain(IBaseRepository repository, IResCustomerDomain resCustomerService , IRepositoryBase softUserChRepository, IRepositoryBase resApplyRepository , ISystemConfigDomain systemConfigService) { _repository = repository; _softUserRepository = _repository.GetRepository(); _resCustomerService = resCustomerService; _softUserChRepository = softUserChRepository; _companyChannelRepository = _repository.GetRepository(); _resApplyRepository = resApplyRepository; _systemConfigService = systemConfigService; } /*接口返回的字符串:18696548545,5001,6201075,5001,2013-8-7 13:54:16【手机号,标签,卡号,用户名,注册时间】*/ /// /// 从接口抓取到的注册用户,旧系统名称为jmdUser /// /// 手机号 /// 注册渠道 /// 卡号 /// 用户名 /// 注册时间 //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 errors = new List(); 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; } } /// /// (当手机号不为空时时进入资源系统,等清洗)从接口抓取到的注册用户,旧系统名称为jmdUser /// /// 手机号 /// 注册标签 /// 卡号 /// 用户名 /// 注册时间 public bool ImportResApply(List 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); } } } }