/// <summary> /// 保存医生登录信息 /// </summary> /// <param name="model"></param> /// <returns></returns> internal async Task <bool> SaveDoctorLoginAsync(CHIS_Sys_Login model) { CHIS_Code_Customer cus = null; var fd = await _db.CHIS_Sys_Login.FirstOrDefaultAsync(m => m.LoginId == model.LoginId); fd.DoctorId = model.DoctorId; if (fd.LoginName != model.LoginName && model.LoginName.IsNotEmpty()) { fd.LoginName = model.LoginName; cus = await _db.CHIS_Code_Customer.AsNoTracking().FirstOrDefaultAsync(m => m.CustomerID == fd.CustomerId); cus.LoginName = model.LoginName; } if (model.LoginPassword.IsNotEmpty()) { fd.LoginPassword = model.LoginPassword; } fd.IsLock = model.IsLock; fd.LockTime = (model.IsLock == true) ? (model.LockTime ?? DateTime.Now) : (DateTime?)null; fd.WhyLock = model.WhyLock; if (cus != null) { _db.CHIS_Code_Customer.Update(cus); } if (fd != null) { _db.CHIS_Sys_Login.Update(fd); } await _db.SaveChangesAsync(); return(true); }
/// <summary> /// 添加一个用户 /// </summary> /// <param name="cus"></param> /// <param name="health"></param> /// <returns></returns> public async Task <CHIS_Code_Customer> CreateCustomerAsync(CHIS_Code_Customer cus, CHIS_Code_Customer_HealthInfo health = null, int opId = 0, string opMan = "") { _db.BeginTransaction(); try { cus.CustomerCreateDate = cus.sysLatestActiveTime = cus.OpTime = DateTime.Now; cus.IsVIP = cus.IsVIP == true; cus.NamePY = Ass.Data.Chinese2Spell.GetFstAndFullLettersLower(cus.CustomerName); cus.OpID = opId; cus.CustomerCreateDate = cus.OpTime = cus.sysLatestActiveTime = DateTime.Now; cus.OpMan = opMan; cus = _db.CHIS_Code_Customer.Add(cus).Entity; await _db.SaveChangesAsync(); if (health == null) { health = new CHIS_Code_Customer_HealthInfo(); } health.CustomerId = cus.CustomerID; await _db.CHIS_Code_Customer_HealthInfo.AddAsync(health); await _db.SaveChangesAsync(); var login = _db.CHIS_Sys_Login.FirstOrDefault(m => m.CustomerId == cus.CustomerID); if (login == null) { await _db.CHIS_Sys_Login.AddAsync(new CHIS_Sys_Login { CustomerId = cus.CustomerID, Email = cus.Email, Mobile = cus.CustomerMobile, IdCardNumber = cus.IDcard, LoginName = cus.LoginName, LoginPassword = "******", IsLock = false }); await _db.SaveChangesAsync(); } _db.CommitTran(); //注册用户赠送 _pointsService.ChangePoints(new Models.InputModel.PointsDetailInputModel { CustomerId = cus.CustomerID, Description = "注册赠送1000分", Points = 1000 }); } catch (Exception ex) { _db.RollbackTran(); throw ex; } return(cus); }
/// <summary> /// 客户申请医生 /// </summary> /// <param name="customer"></param> /// <returns></returns> public async Task <bool> CustomerRegistDoctor(CHIS_Code_Customer customer) { var add = _db.CHIS_Code_Doctor.Add(new CHIS_Code_Doctor { CustomerId = customer.CustomerID, DoctorCreateTime = DateTime.Now, IsEnable = true }).Entity; _db.SaveChanges(); var login = _db.CHIS_Sys_Login.FirstOrDefault(m => m.CustomerId == customer.CustomerID); if (login != null) { login.DoctorId = add.DoctorId; } await _db.SaveChangesAsync(); //给一个基本的工作站信息 await _db.CHIS_Sys_Rel_DoctorStations.AddAsync(new CHIS_Sys_Rel_DoctorStations { DoctorId = add.DoctorId, StationId = MPS.TestNetStationId, StationIsEnable = true, }); //给全责医生的测试角色 await _db.CHIS_Sys_Rel_DoctorStationRoles.AddAsync(new CHIS_Sys_Rel_DoctorStationRoles { DoctorId = add.DoctorId, StationId = MPS.TestNetStationId, MyRoleIsEnable = true, MyStationIsEnable = true, RoleId = MPS.RoleTreatAllDoctorId }); await _db.SaveChangesAsync(); return(true); }
/// <summary> /// 添加一个用户 /// </summary> /// <param name="model"></param> /// <param name="opId"></param> /// <param name="opMan"></param> /// <returns></returns> public async Task <CHIS_Code_Customer> CreateCustomerAsync(vwCHIS_Code_Customer model, int opId, string opMan) { var cus = new CHIS_Code_Customer { }; cus.CustomerName = model.CustomerName; cus.Gender = model.Gender; cus.Birthday = model.Birthday; cus.LoginName = model.LoginName; cus.CustomerMobile = model.CustomerMobile; cus.IDcard = model.IDcard; cus.Email = model.Email; cus.sysSource = model.sysSource; cus.IsVIP = model.IsVIP == true; var health = new CHIS_Code_Customer_HealthInfo { CustomerId = cus.CustomerID, Allergic = model.Allergic, PastMedicalHistory = model.PastMedicalHistory }; return(await CreateCustomerAsync(cus, health, opId, opMan)); }
/// <summary> /// 微信注册 新用户 /// </summary> public bool WXRegistCustomer(ah.Models.ViewModel.WechatBindingModel model) { var mobile = model.mobile; if (mobile.IsEmpty()) { throw new Exception("手机号码为空"); } if (model.openid.IsEmpty()) { throw new Exception("微信openid为空"); } if (!model.Gender.HasValue) { throw new Exception("没有选择性别"); } if (model.CustomerName.IsEmpty()) { throw new Exception("没有输入用户名"); } if (!model.Birthday.HasValue) { throw new Exception("没有传入出生日期"); } if (!(mobile.GetStringType().IsMobile)) { throw new Exception("输入的账号非手机号码"); } using (var tx = MainDbContext.Database.BeginTransaction()) { try { var cus = new CHIS_Code_Customer { NickName = model.NickName, CustomerName = model.CustomerName, Gender = model.Gender, Birthday = model.Birthday, WXPic = model.WxPicUrl, WXOpenId = model.openid, CustomerMobile = mobile, IsVIP = false, CustomerCreateDate = DateTime.Now, OpTime = DateTime.Now, sysLatestActiveTime = DateTime.Now }; var count = MainDbContext.CHIS_Sys_Login.Where(m => m.Mobile == mobile).Count() + MainDbContext.CHIS_Code_Customer.Where(m => m.CustomerMobile == mobile).Count(); if (count > 0) { //强制清空手机账号 var find0 = MainDbContext.CHIS_Code_Customer.Where(m => m.CustomerMobile == mobile); foreach (var fd0 in find0) { fd0.CustomerMobile = null; } var find1 = MainDbContext.CHIS_Sys_Login.Where(m => m.Mobile == mobile); foreach (var fd1 in find1) { fd1.Mobile = null; fd1.MobileAuthenticatedTime = null; fd1.MobileIsAuthenticated = false; } MainDbContext.SaveChanges(); } var add0 = MainDbContext.Add(cus).Entity; MainDbContext.SaveChanges(); //增加注册用户 var login = MainDbContext.CHIS_Sys_Login.FirstOrDefault(m => m.Mobile == mobile); if (login == null) { MainDbContext.Add(new CHIS_Sys_Login { Mobile = mobile, CustomerId = add0.CustomerID, IsLock = false }); MainDbContext.SaveChanges(); cus = add0; } tx.Commit(); } catch (Exception ex) { tx.Rollback(); throw ex; } return(true); } }
public IActionResult Json_CustomerQuickRegist(string account, string customerName, int gender, DateTime birthday, string vcode = null) { return(TryCatchFunc((dd) => { if (account.GetStringType().IsEmail || account.GetStringType().IsMobile) { if (vcode.IsEmpty()) { throw new Exception("手机或者邮箱注册必须输入验证码"); } CheckRegVCode(account, vcode);//验证信息 } var cus = new CHIS_Code_Customer { CustomerName = customerName, Gender = gender, Birthday = birthday, IsVIP = false, sysLatestActiveTime = DateTime.Now, OpTime = DateTime.Now, CustomerCreateDate = DateTime.Now //创建时间 }; if (account.GetStringType().IsMobile) { var count = MainDbContext.CHIS_Sys_Login.Where(m => m.Mobile == account).Count() + MainDbContext.CHIS_Code_Customer.Where(m => m.CustomerMobile == account).Count(); if (count > 0) { throw new Exception("该手机号已经注册了"); } cus.CustomerMobile = account; var add0 = MainDbContext.Add(cus).Entity; MainDbContext.SaveChanges(); //增加注册用户 var login = MainDbContext.CHIS_Sys_Login.FirstOrDefault(m => m.Mobile == account); if (login == null) { MainDbContext.Add(new CHIS_Sys_Login { Mobile = account, CustomerId = add0.CustomerID, IsLock = false }); MainDbContext.SaveChanges(); cus = add0; } } else if (account.GetStringType().IsEmail) { var count = MainDbContext.CHIS_Sys_Login.Where(m => m.Email == account).Count() + MainDbContext.CHIS_Code_Customer.Where(m => m.Email == account).Count(); if (count > 0) { throw new Exception("该邮件地址已经注册了"); } cus.Email = account; var add1 = MainDbContext.Add(cus).Entity; MainDbContext.SaveChanges(); //增加注册用户 var login = MainDbContext.CHIS_Sys_Login.FirstOrDefault(m => m.Email == account); if (login == null) { MainDbContext.Add(new CHIS_Sys_Login { Email = account, CustomerId = add1.CustomerID, IsLock = false }); MainDbContext.SaveChanges(); cus = add1; } } else if (account.GetStringType().IsIdCardNumber) { var count = MainDbContext.CHIS_Sys_Login.Where(m => m.IdCardNumber == account).Count() + MainDbContext.CHIS_Code_Customer.Where(m => m.IDcard == account).Count(); if (count > 0) { throw new Exception("该身份证已经注册了"); } cus.IDcard = account; var add2 = MainDbContext.Add(cus).Entity; MainDbContext.SaveChanges(); //增加注册用户 var login = MainDbContext.CHIS_Sys_Login.FirstOrDefault(m => m.IdCardNumber == account); if (login == null) { MainDbContext.Add(new CHIS_Sys_Login { IdCardNumber = account, CustomerId = add2.CustomerID, IsLock = false }); MainDbContext.SaveChanges(); cus = add2; } } else { throw new Exception("输入错误账号"); } dd.customerId = cus.CustomerID; return null; }, bUseTrans: true)); }