/// <summary> /// 用户登录实现 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <SysAdmin> > LoginAsync(SysAdminLogin parm) { var res = new ApiResult <SysAdmin>(); try { parm.password = DES3Encrypt.EncryptString(parm.password); var model = Db.Queryable <SysAdmin>() .Where(m => m.LoginName == parm.loginname).First(); if (model != null) { if (model.LoginPwd.Equals(parm.password)) { //修改登录时间 model.LoginDate = DateTime.Now; model.UpLoginDate = model.LoginDate; SysAdminDb.Update(model); #region 保存操作日志 var logModel = new SysLog() { Guid = Guid.NewGuid().ToString(), LoginName = model.LoginName, DepartName = model.DepartmentName, OptionTable = "SysAdmin", Summary = "登录操作", IP = Utils.GetIp(), LogType = (int)LogEnum.Login, Urls = Utils.GetUrl(), AddTime = DateTime.Now }; SysLogDb.Insert(logModel); #endregion res.success = true; res.message = "获取成功!"; res.data = model; } else { res.success = false; res.statusCode = (int)ApiEnum.Error; res.message = "密码错误~"; } } else { res.success = false; res.statusCode = (int)ApiEnum.Error; res.message = "账号错误~"; } } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; res.statusCode = (int)ApiEnum.Error; } return(await Task.Run(() => res)); }
public async Task <ApiResult <List <SysAdmin> > > GetListAsync() { ApiResult <List <SysAdmin> > res = new ApiResult <List <SysAdmin> > { statusCode = 200, data = SysAdminDb.GetList() }; return(res); }
/// <summary> /// 用户登录实现 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <SysAdminMenuDto> > LoginAsync(SysAdminLogin parm) { var res = new ApiResult <SysAdminMenuDto>() { statusCode = (int)ApiEnum.Error }; try { var adminModel = new SysAdminMenuDto(); parm.password = DES3Encrypt.EncryptString(parm.password); var model = await Db.Queryable <SysAdmin>() .Where(m => m.LoginName == parm.loginname).FirstAsync(); if (model == null) { res.message = "账号错误"; return(res); } if (!model.LoginPwd.Equals(parm.password)) { res.message = "密码错误~"; return(res); } if (!model.Status) { res.message = "登录账号被冻结,请联系管理员~"; return(res); } adminModel.menu = GetMenuByAdmin(model.Guid); if (adminModel == null) { res.message = "当前账号没有授权功能模块,无法登录~"; return(res); } //修改登录时间 model.LoginDate = DateTime.Now; model.UpLoginDate = model.LoginDate; model.LoginSum = model.LoginSum + 1; SysAdminDb.Update(model); res.statusCode = (int)ApiEnum.Status; adminModel.admin = model; res.data = adminModel; } catch (Exception ex) { res.message = ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(res); }
/// <summary> /// 添加部门信息 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <string> > AddAsync(SysAdmin parm) { var res = new ApiResult <string> { statusCode = (int)ApiEnum.ParameterError }; try { //判断用吗是否存在 var isExisteName = await Db.Queryable <SysAdmin>().AnyAsync(m => m.LoginName == parm.LoginName); if (isExisteName) { res.message = "用户名已存在,请更换~"; return(res); } parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd); if (string.IsNullOrEmpty(parm.HeadPic)) { parm.HeadPic = "/themes/img/avatar.jpg"; } parm.Guid = Guid.NewGuid().ToString(); parm.AddDate = DateTime.Now; if (!string.IsNullOrEmpty(parm.DepartmentGuid)) { // 说明有父级 根据父级,查询对应的模型 var model = SysOrganizeDb.GetById(parm.DepartmentGuid); parm.DepartmentGuidList = model.ParentGuidList; } SysAdminDb.Insert(parm); //查询授权表,type=2 更新新的权限值 //添加新的 var authorityList = new List <SysPermissions>(); foreach (var item in parm.RoleList) { authorityList.Add(new SysPermissions() { RoleGuid = item.guid, AdminGuid = parm.Guid, Types = 2 }); } await Db.Insertable(authorityList).ExecuteCommandAsync(); res.statusCode = (int)ApiEnum.Status; } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(await Task.Run(() => res)); }
/// <summary> /// 修改菜单 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <string> > ModifyAsync(SysAdmin parm) { var res = new ApiResult <string> { statusCode = 200 }; try { //修改,判断用户是否和其它的重复 var isExisteName = SysAdminDb.IsAny(m => m.LoginName == parm.LoginName && m.Guid != parm.Guid); if (isExisteName) { res.message = "用户名已存在,请更换~"; res.statusCode = (int)ApiEnum.ParameterError; return(await Task.Run(() => res)); } parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd); if (!string.IsNullOrEmpty(parm.DepartmentGuid)) { // 说明有父级 根据父级,查询对应的模型 var model = SysOrganizeDb.GetById(parm.DepartmentGuid); parm.DepartmentGuidList = model.ParentGuidList; } var dbres = Db.Updateable <SysAdmin>().UpdateColumns(m => new SysAdmin() { LoginName = parm.LoginName, LoginPwd = parm.LoginPwd, DepartmentName = parm.DepartmentName, DepartmentGuid = parm.DepartmentGuid, DepartmentGuidList = parm.DepartmentGuidList, TrueName = parm.TrueName, Number = parm.Number, Sex = parm.Sex, Mobile = parm.Mobile, Email = parm.Email, Status = parm.Status }).Where(m => m.Guid == parm.Guid).ExecuteCommand(); if (dbres > 1) { res.statusCode = (int)ApiEnum.Error; res.message = "更新失败!"; } } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; res.statusCode = (int)ApiEnum.Error; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(await Task.Run(() => res)); }
/// <summary> /// 删除部门 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <string> > DeleteAsync(string parm) { var list = Utils.StrToListString(parm); var isok = SysAdminDb.Delete(m => list.Contains(m.Guid)); var res = new ApiResult <string> { statusCode = isok ? 200 : 500, data = isok ? "1" : "0", message = isok ? "删除成功~" : "删除失败~" }; return(await Task.Run(() => res)); }
/// <summary> /// 根据唯一编号查询一条部门信息 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <SysAdmin> > GetByGuidAsync(string parm) { var model = SysAdminDb.GetById(parm); var res = new ApiResult <SysAdmin> { statusCode = 200 }; res.data = model ?? new SysAdmin() { }; return(await Task.Run(() => res)); }
/// <summary> /// 修改菜单 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <string> > ModifyAsync(SysAdmin parm) { if (!string.IsNullOrEmpty(parm.DepartmentGuid)) { // 说明有父级 根据父级,查询对应的模型 var model = SysOrganizeDb.GetById(parm.DepartmentGuid); parm.DepartmentGuidList = model.ParentGuidList; } var res = new ApiResult <string> { statusCode = 200, data = SysAdminDb.Update(parm) ? "1" : "0" }; return(await Task.Run(() => res)); }
/// <summary> /// 添加部门信息 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <string> > AddAsync(SysAdmin parm) { parm.Guid = Guid.NewGuid().ToString(); parm.AddDate = DateTime.Now; if (!string.IsNullOrEmpty(parm.DepartmentGuid)) { // 说明有父级 根据父级,查询对应的模型 var model = SysOrganizeDb.GetById(parm.DepartmentGuid); parm.DepartmentGuidList = model.ParentGuidList; } SysAdminDb.Insert(parm); var res = new ApiResult <string> { statusCode = 200, data = "1" }; return(await Task.Run(() => res)); }
/// <summary> /// 添加部门信息 /// </summary> /// <param name="parm"></param> /// <returns></returns> public new async Task <ApiResult <string> > AddAsync(SysAdmin parm) { var res = new ApiResult <string> { statusCode = 200, data = "1" }; try { //判断用吗是否存在 var isExisteName = SysAdminDb.IsAny(m => m.LoginName == parm.LoginName); if (isExisteName) { res.message = "用户名已存在,请更换~"; res.statusCode = (int)ApiEnum.ParameterError; return(await Task.Run(() => res)); } parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd); if (string.IsNullOrEmpty(parm.HeadPic)) { parm.HeadPic = "/themes/img/avatar.jpg"; } parm.Guid = Guid.NewGuid().ToString(); parm.AddDate = DateTime.Now; if (!string.IsNullOrEmpty(parm.DepartmentGuid)) { // 说明有父级 根据父级,查询对应的模型 var model = SysOrganizeDb.GetById(parm.DepartmentGuid); parm.DepartmentGuidList = model.ParentGuidList; } SysAdminDb.Insert(parm); } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; res.statusCode = (int)ApiEnum.Error; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(await Task.Run(() => res)); }
/// <summary> /// 用户登录实现 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <SysAdminMenuDto> > LoginAsync(SysAdminLogin parm) { var res = new ApiResult <SysAdminMenuDto>() { statusCode = (int)ApiEnum.Error }; try { var adminModel = new SysAdminMenuDto(); parm.password = DES3Encrypt.EncryptString(parm.password); var model = await Db.Queryable <SysAdmin>().Where(m => m.LoginName == parm.loginname).FirstAsync(); if (model == null) { res.message = "账号错误"; return(res); } if (!model.LoginPwd.Equals(parm.password)) { res.message = "密码错误~"; return(res); } if (!model.Status) { res.message = "登录账号被冻结,请联系管理员~"; return(res); } var(isSystem, isAgent, isSubAdmin) = await roleService.GetRoleByAdminGuid(model.Guid); if (isSystem) { } else if (isAgent) { var exist = await Db.Queryable <CmsAgent>().AnyAsync(p => p.Admin_Guid == model.Guid && p.Status); if (!exist) { res.message = "代理商已经被冻结,请联系管理员"; return(res); } } else if (isSubAdmin) { var exist = await Db.Queryable <CmsMerchant>().AnyAsync(p => p.admin_guid == model.Guid && p.status); if (!exist) { res.message = "商户已经被冻结,请联系管理员"; return(res); } } else { var exist = await Db.Queryable <CmsMerchant>().AnyAsync(p => p.admin_guid == model.CreateBy && p.status); if (!exist) { res.message = "商户已经被冻结,请联系管理员"; return(res); } } adminModel.menu = GetMenuByAdmin(model.Guid); if (adminModel == null) { res.message = "当前账号没有授权功能模块,无法登录~"; return(res); } //修改登录时间 model.LoginDate = DateTime.Now; model.UpLoginDate = model.LoginDate; model.LoginSum = model.LoginSum + 1; SysAdminDb.Update(model); var roleList = await Db.Queryable <SysRole>().Where(m => m.IsSystem).Select(m => m.Guid).ToListAsync(); model.IsSystem = roleList.Intersect(model.RoleList.Select(p => p.guid)).Any(); res.statusCode = (int)ApiEnum.Status; adminModel.admin = model; res.data = adminModel; } catch (Exception ex) { res.message = ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(res); }
/// <summary> /// 添加部门信息 /// </summary> /// <param name="parm"></param> /// <returns></returns> public async Task <ApiResult <string> > AddAsync(SysAdmin parm) { var res = new ApiResult <string> { statusCode = (int)ApiEnum.ParameterError }; try { //判断用吗是否存在 var isExisteName = await Db.Queryable <SysAdmin>().AnyAsync(m => m.LoginName == parm.LoginName); if (isExisteName) { res.message = $"用户名【{parm.LoginName}】已经存在"; return(res); } if (parm.RoleList == null || parm.RoleList.Count == 0) { res.message = $"请至少选择一个角色"; return(res); } parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd); if (string.IsNullOrEmpty(parm.Guid)) { parm.Guid = Guid.NewGuid().ToString(); } parm.AddDate = DateTime.Now; using var tran = new TransactionScope(); var succ = SysAdminDb.Insert(parm); var authorityList = parm.RoleList .Select(p => new SysPermissions { RoleGuid = p.guid, AdminGuid = parm.Guid, Types = 2 }).ToList(); await Db.Insertable(authorityList).ExecuteCommandAsync(); tran.Complete(); //var rel = await Db.Queryable<CmsAdminMerchantRel>().Where(p => p.Admin_Guid == parm.CreateBy).FirstAsync(); //if (rel != null) //{ // CmsAdminMerchantRelDb.Insert(new CmsAdminMerchantRel // { // Admin_Guid = parm.Guid, // Out_Mch_Id = rel.Out_Mch_Id, // out_sub_mch_id = rel.out_sub_mch_id // }); //} res.statusCode = (int)ApiEnum.Status; res.data = parm.Guid; } catch (Exception ex) { res.message = ApiEnum.Error.GetEnumText() + ex.Message; Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message); } return(res); }
public List <SysAdmin> GetList() { return(SysAdminDb.GetList()); }