private bool checkParas(Dictionary <string, object> dicParas, out int userId, out int authorId, out string errMsg) { errMsg = string.Empty; userId = 0; authorId = 0; try { string workId = dicParas.ContainsKey("workId") ? dicParas["workId"].ToString() : string.Empty; if (string.IsNullOrEmpty(workId)) { errMsg = "工单号workId参数不能为空"; return(false); } //验证工单 IXC_WorkInfoService xC_WorkInfoService = BLLContainer.Resolve <IXC_WorkInfoService>(); var xC_WorkInfoList = xC_WorkInfoService.GetModels(p => p.WorkID.ToString().Equals(workId, StringComparison.OrdinalIgnoreCase)); int xC_WorkInfoCount = xC_WorkInfoList.Count <XC_WorkInfo>(); if (xC_WorkInfoCount == 0) { errMsg = "工单号" + workId + "不存在"; return(false); } //验证用户 var xC_WorkInfo = xC_WorkInfoList.FirstOrDefault <XC_WorkInfo>(); IBase_UserInfoService userInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); var userList = userInfoService.GetModels(p => p.UserID.Equals(xC_WorkInfo.SenderID.Value)); if (userList.Count <Base_UserInfo>() == 0) { errMsg = "工单号" + workId + "的用户ID不存在"; return(false); } userId = userList.FirstOrDefault <Base_UserInfo>().UserID; //验证审核人 userList = userInfoService.GetModels(p => p.UserID.Equals(xC_WorkInfo.AuditorID.Value)); if (userList.Count <Base_UserInfo>() == 0) { errMsg = "工单号" + workId + "的审核人ID不存在"; return(false); } authorId = userList.FirstOrDefault <Base_UserInfo>().UserID; return(true); } catch (Exception e) { errMsg = e.Message; return(false); } }
public ActionResult EditUser(int id) { IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); var base_UserInfoModel = base_UserInfoService.GetModels(p => p.ID == id).FirstOrDefault(); return(View(base_UserInfoModel)); }
public static void XcUserInit() { IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); var list = base_UserInfoService.GetModels(p => p.UserType == (int)UserType.Xc).ToList(); listXcUser = Utils.GetCopyList <UserInfoCacheModel, Base_UserInfo>(list); }
public object GetStoreWeightList(Dictionary <string, object> dicParas) { try { string errMsg = string.Empty; string storeId = dicParas.ContainsKey("storeId") ? (dicParas["storeId"] + "") : string.Empty; if (string.IsNullOrEmpty(storeId)) { errMsg = "门店ID不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>(resolveNew: true); IBase_StoreWeightService base_StoreWeightService = BLLContainer.Resolve <IBase_StoreWeightService>(resolveNew: true); var result = from a in base_UserInfoService.GetModels(p => p.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase) && p.UserType == (int)UserType.StoreBoss) join b in base_StoreWeightService.GetModels(p => p.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase)) on a.UserID equals b.BossID select new { RealName = a.RealName, LogName = a.LogName, WeightValue = b.WeightValue, ID = b.ID }; return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn, result)); } catch (Exception e) { return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message)); } }
public ActionResult SendSms(int id) { string errMsg = string.Empty; var userIDs = getFinalBiddingInfoList(id).GroupBy(g => g.UserID).Select(o => o.Key).ToList(); IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); var userMobiles = base_UserInfoService.GetModels(p => userIDs.Contains(p.ID)).Select(o => o.Mobile).ToList(); string phones = string.Join(",", userMobiles); IData_SmsManageService data_SmsManageService = BLLContainer.Resolve <IData_SmsManageService>(); var data_SmsManage = new Data_SmsManage(); data_SmsManage.CreateTime = DateTime.Now; data_SmsManage.Phones = phones; data_SmsManage.State = (int)SmsType.Send; if (!data_SmsManageService.Add(data_SmsManage)) { return(RedirectToAction("NoticePublish", "NoticeManage", new { errMsg = "发送失败" })); } //发送短信 if (!SMSBusiness.SendSMSNotice("2", data_SmsManage.Phones, "", out errMsg)) { return(RedirectToAction("NoticePublish", "NoticeManage", new { errMsg = errMsg })); } return(RedirectToAction("NoticePublish", "NoticeManage", new { errMsg = "发送成功" })); }
public static void Init() { IBase_UserInfoService userInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); List <Base_UserInfo> list = userInfoService.GetModels(p => p.State == (int)UserState.Normal).ToList(); listUser = Utils.GetCopyList <UserInfoCacheModel, Base_UserInfo>(list); }
public object GetDigitDestroy(Dictionary <string, object> dicParas) { try { string errMsg = string.Empty; string destroyTime = dicParas.ContainsKey("destroyTime") ? (dicParas["destroyTime"] + "") : string.Empty; string iCardID = dicParas.ContainsKey("iCardID") ? (dicParas["iCardID"] + "") : string.Empty; XCCloudUserTokenModel userTokenKeyModel = (XCCloudUserTokenModel)dicParas[Constant.XCCloudUserTokenModel]; string storeId = (userTokenKeyModel.DataModel as UserDataModel).StoreID; if (!string.IsNullOrEmpty(destroyTime)) { try { Convert.ToDateTime(destroyTime); } catch { errMsg = "销毁时间参数格式不正确"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } IData_DigitCoinDestroyService data_DigitCoinDestroyService = BLLContainer.Resolve <IData_DigitCoinDestroyService>(); var query = data_DigitCoinDestroyService.GetModels(p => p.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrEmpty(destroyTime)) { var dt = Convert.ToDateTime(destroyTime); query = query.Where(w => DbFunctions.DiffDays(w.DestroyTime, dt) == 0); } if (!string.IsNullOrEmpty(iCardID)) { query = query.Where(w => w.ICCardID.Contains(iCardID)); } IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); var linq = base_UserInfoService.GetModels(p => p.UserType == (int)UserType.Store).Select(o => new { UserID = o.UserID, LogName = o.LogName, RealName = o.RealName }); var result = query.ToList().Select(o => new { ID = o.ID, StoreID = o.StoreID, ICardID = o.ICCardID, DestroyTime = o.DestroyTime, UserID = o.UserID, Note = o.Note, LogName = linq.SingleOrDefault(p => p.UserID == o.UserID).LogName, RealName = linq.SingleOrDefault(p => p.UserID == o.UserID).RealName }); return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn, result.ToList())); } catch (Exception e) { return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message)); } }
public ActionResult EditCustomer(int id) { IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); var base_UserInfoModel = base_UserInfoService.GetModels(p => p.ID == id).FirstOrDefault(); GetUserLvls(base_UserInfoModel.UserLvl.HasValue ? base_UserInfoModel.UserLvl.ToString() : null); GetProductTypes(base_UserInfoModel.ProductType.HasValue ? base_UserInfoModel.ProductType.ToString() : null); return(View(base_UserInfoModel)); }
public ActionResult ModifyPassword() { string errMsg = "修改成功"; try { string oldPassword = Utils.MD5(Request.Form["oldpass"]); var userInfoCacheModel = Session["loginUser"] as UserInfoCacheModel; if (userInfoCacheModel.Password != oldPassword) { errMsg = "旧密码输入错误"; return(RedirectToAction("ChangePassword", "UserManage", new { errMsg = errMsg })); } int id = userInfoCacheModel.ID; string newPassword = Utils.MD5(Request.Form["newpass"]); IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); var base_UserInfoModel = base_UserInfoService.GetModels(p => p.ID == id).FirstOrDefault(); if (base_UserInfoModel == null) { errMsg = "该用户不存在"; return(RedirectToAction("ChangePassword", "UserManage", new { errMsg = errMsg })); } base_UserInfoModel.Password = newPassword; if (base_UserInfoService.Update(base_UserInfoModel)) { userInfoCacheModel.Password = newPassword; UserBusiness.Init(); } else { errMsg = "修改失败"; } } catch (Exception e) { errMsg = e.Message; } return(RedirectToAction("ChangePassword", "UserManage", new { errMsg = errMsg })); }
public string DelUser(int id) { IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); var base_UserInfo = base_UserInfoService.GetModels(p => p.ID == id).FirstOrDefault(); if (base_UserInfo == null) { return("该用户已不存在"); } base_UserInfo.State = (int)UserState.Canceled; if (!base_UserInfoService.Update(base_UserInfo)) { return("注销用户失败"); } //更新缓存 UserBusiness.Init(); return("操作成功"); }
public object CheckUser(Dictionary <string, object> dicParas) { try { string errMsg = string.Empty; string token = string.Empty; string userName = dicParas.ContainsKey("userName") ? dicParas["userName"].ToString() : string.Empty; string password = dicParas.ContainsKey("password") ? dicParas["password"].ToString() : string.Empty; if (string.IsNullOrWhiteSpace(userName)) { errMsg = "用户名不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrWhiteSpace(password)) { errMsg = "密码不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } password = Utils.MD5(password); UserLogResponseModel userLogResponseModel = new UserLogResponseModel(); IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); if (base_UserInfoService.Any(p => p.LogName.Equals(userName, StringComparison.OrdinalIgnoreCase) && p.LogPassword.Equals(password, StringComparison.OrdinalIgnoreCase))) { var base_UserInfoModel = base_UserInfoService.GetModels(p => p.LogName.Equals(userName, StringComparison.OrdinalIgnoreCase) && p.LogPassword.Equals(password, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <Base_UserInfo>(); int userId = base_UserInfoModel.UserID; int userType = (int)base_UserInfoModel.UserType; int logType = (int)RoleType.XcUser; //默认普通员工登录 int isXcAdmin = base_UserInfoModel.Auditor ?? 0; int switchable = base_UserInfoModel.Switchable ?? 0; if (userType == (int)UserType.Xc && isXcAdmin == 0) { logType = (int)RoleType.XcAdmin; userLogResponseModel.Token = XCCloudUserTokenBusiness.SetUserToken(userId.ToString(), logType); } else if (userType == (int)UserType.Store || userType == (int)UserType.StoreBoss) { logType = (int)RoleType.StoreUser; string storeId = base_UserInfoModel.StoreID; IBase_StoreInfoService base_StoreInfoService = BLLContainer.Resolve <IBase_StoreInfoService>(); if (!base_StoreInfoService.Any(a => a.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase))) { errMsg = "该门店不存在"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } string merchId = base_StoreInfoService.GetModels(p => p.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault().MerchID; var dataModel = new UserDataModel { StoreID = storeId, MerchID = merchId }; userLogResponseModel.Token = XCCloudUserTokenBusiness.SetUserToken(userId.ToString(), logType, dataModel); } else { logType = (int)RoleType.MerchUser; string merchId = base_UserInfoModel.MerchID; IBase_MerchantInfoService base_MerchantInfoService = BLLContainer.Resolve <IBase_MerchantInfoService>(); if (!base_MerchantInfoService.Any(p => p.MerchID.Equals(merchId, StringComparison.OrdinalIgnoreCase))) { errMsg = "该商户不存在"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } var base_MerchantInfoModel = base_MerchantInfoService.GetModels(p => p.MerchID.Equals(merchId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); var dataModel = new MerchDataModel { MerchID = merchId, MerchType = base_MerchantInfoModel.MerchType, CreateType = base_MerchantInfoModel.CreateType, CreateUserID = base_MerchantInfoModel.CreateUserID }; userLogResponseModel.Token = XCCloudUserTokenBusiness.SetUserToken(userId.ToString(), logType, dataModel); userLogResponseModel.MerchTag = base_MerchantInfoModel.MerchTag; } userLogResponseModel.LogType = logType; userLogResponseModel.UserType = userType; userLogResponseModel.Switchable = switchable; return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn, userLogResponseModel)); } else { errMsg = "用户名或密码错误"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } catch (Exception e) { return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message)); } }
public object SaveUserInfo(Dictionary <string, object> dicParas) { string errMsg = string.Empty; int userId, authorId; string workId = dicParas.ContainsKey("workId") ? dicParas["workId"].ToString() : string.Empty; string state = dicParas.ContainsKey("state") ? dicParas["state"].ToString() : string.Empty; string switchable = dicParas.ContainsKey("switchable") ? dicParas["switchable"].ToString() : string.Empty; string userType = dicParas.ContainsKey("userType") ? dicParas["userType"].ToString() : string.Empty; string reason = dicParas.ContainsKey("reason") ? dicParas["reason"].ToString() : string.Empty; string isAdmin = dicParas.ContainsKey("isAdmin") ? dicParas["isAdmin"].ToString() : string.Empty; if (string.IsNullOrEmpty(state)) { errMsg = "审核状态state参数不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrEmpty(userType)) { errMsg = "用户类型userType参数不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } int iUserType = Convert.ToInt32(userType); if (state == ((int)WorkState.Pass).ToString()) //审核通过 { if (!dicParas.ContainsKey("userGroup") || dicParas["userGroup"] == null) { errMsg = "工作组userGroup参数不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!dicParas.ContainsKey("userGrant") || dicParas["userGrant"] == null) { errMsg = "授权功能列表userGrant参数不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } if (!checkParas(dicParas, out userId, out authorId, out errMsg)) { LogHelper.SaveLog("错误:" + errMsg); return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } //开启EF事务 using (TransactionScope ts = new TransactionScope()) { try { if (state == ((int)WorkState.Pass).ToString()) //审核通过 { //修改用户信息 Dictionary <string, object> userGroup = new Dictionary <string, object>((IDictionary <string, object>)dicParas["userGroup"], StringComparer.OrdinalIgnoreCase); IBase_UserGroupService base_UserGroupService = BLLContainer.Resolve <IBase_UserGroupService>(); int ugid = Convert.ToInt32(userGroup["id"]); if (!base_UserGroupService.Any(w => w.ID.Equals(ugid))) { errMsg = "工作组" + userGroup["groupName"] + "不存在"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } IBase_UserInfoService userInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); var base_UserInfo = userInfoService.GetModels(p => p.UserID.Equals(userId)).FirstOrDefault <Base_UserInfo>(); base_UserInfo.UserGroupID = ugid; base_UserInfo.Auditor = authorId; base_UserInfo.AuditorTime = DateTime.Now; base_UserInfo.Status = (int)UserStatus.Pass; base_UserInfo.IsAdmin = !string.IsNullOrEmpty(isAdmin) ? Convert.ToInt32(isAdmin) : (int?)null; base_UserInfo.UserType = Convert.ToInt32(userType); base_UserInfo.Switchable = !string.IsNullOrEmpty(switchable) ? Convert.ToInt32(switchable) : (int?)null; string storeId = base_UserInfo.StoreID; if (base_UserInfo.IsAdmin == 1 && userInfoService.Any(a => a.UserID != userId && a.IsAdmin == 1 && a.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase))) { errMsg = "同一个门店只能有一个管理员"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!userInfoService.Update(base_UserInfo)) { errMsg = "修改用户信息失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } //添加或修改授权功能表 var dbContext = DbContextFactory.CreateByModelNamespace(typeof(Base_UserGrant).Namespace); var userGrant = (object[])dicParas["userGrant"]; foreach (IDictionary <string, object> iUgr in userGrant) { if (iUgr != null) { var ugr = new Dictionary <string, object>(iUgr, StringComparer.OrdinalIgnoreCase); int ugrid = Convert.ToInt32(ugr["id"]); if (!dbContext.Set <Base_UserGrant>().Any(w => w.GrantID.Value.Equals(ugrid) && w.UserID.Value.Equals(userId))) { var base_UserGrant = new Base_UserGrant(); base_UserGrant.GrantID = ugrid; base_UserGrant.UserID = userId; base_UserGrant.GrantEN = Convert.ToInt32(ugr["grantEn"]); dbContext.Entry(base_UserGrant).State = EntityState.Added; } else { var base_UserGrant = dbContext.Set <Base_UserGrant>().Where(p => p.GrantID == ugrid && p.UserID == userId).FirstOrDefault(); base_UserGrant.GrantEN = Convert.ToInt32(ugr["grantEn"]); dbContext.Entry(base_UserGrant).State = EntityState.Modified; } } } if (dbContext.SaveChanges() < 0) { errMsg = "保存授权功能失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } //修改工单 IXC_WorkInfoService xC_WorkInfoService = BLLContainer.Resolve <IXC_WorkInfoService>(); var xC_WorkInfo = xC_WorkInfoService.GetModels(p => p.WorkID.ToString().Equals(workId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <XC_WorkInfo>(); xC_WorkInfo.AuditorID = authorId; xC_WorkInfo.AuditTime = DateTime.Now; xC_WorkInfo.WorkState = (int)WorkState.Pass; xC_WorkInfo.AuditBody = "审核通过"; xC_WorkInfo.WorkType = (int)WorkType.UserCheck; if (!xC_WorkInfoService.Update(xC_WorkInfo)) { errMsg = "修改工单失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } //添加日志 ILog_OperationService log_OperationService = BLLContainer.Resolve <ILog_OperationService>(); var log_Operation = new Log_Operation(); log_Operation.UserID = userId; log_Operation.AuthorID = authorId; log_Operation.Content = "审核通过"; if (!log_OperationService.Add(log_Operation)) { errMsg = "添加日志失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } else if (state == ((int)WorkState.Reject).ToString()) //审核拒绝 { //修改工单 IXC_WorkInfoService xC_WorkInfoService = BLLContainer.Resolve <IXC_WorkInfoService>(); var xC_WorkInfo = xC_WorkInfoService.GetModels(p => p.WorkID.ToString().Equals(workId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <XC_WorkInfo>(); xC_WorkInfo.AuditorID = authorId; xC_WorkInfo.AuditTime = DateTime.Now; xC_WorkInfo.WorkState = (int)WorkState.Reject; xC_WorkInfo.AuditBody = "拒绝理由:" + reason; xC_WorkInfo.WorkType = (int)WorkType.UserCheck; if (!xC_WorkInfoService.Update(xC_WorkInfo)) { errMsg = "修改工单失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } //添加日志 ILog_OperationService log_OperationService = BLLContainer.Resolve <ILog_OperationService>(); var log_Operation = new Log_Operation(); log_Operation.UserID = userId; log_Operation.AuthorID = authorId; log_Operation.Content = "拒绝理由:" + reason; if (!log_OperationService.Add(log_Operation)) { errMsg = "添加日志失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } else { errMsg = "不明确的审核状态"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } ts.Complete(); return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn)); } catch (Exception ex) { LogHelper.SaveLog("错误:" + ex.Message); return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, ex.Message)); } } }
protected void Page_Load(object sender, EventArgs e) { try { string errMsg = string.Empty; string md5 = Request["state"] ?? ""; string url = Request.Url.GetLeftPart(UriPartial.Path); string code = Request["code"] ?? ""; LogHelper.SaveLog("code:" + code); //if (!TokenMana.GetTokenMd5(url, md5)) //{ // errMsg = url + WeiXinConfig.Md5key; // LogHelper.SaveLog("错误:" + errMsg); // Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("登录失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false); // return; //} string accsess_token = string.Empty; string refresh_token = string.Empty; string openId = string.Empty; string unionId = string.Empty; string token = string.Empty; int? merchTag = null; if (TokenMana.GetOpenTokenForScanQR(code, out accsess_token, out refresh_token, out openId, out unionId)) { if (string.IsNullOrEmpty(unionId)) { if (!TokenMana.GetUnionIdFromOpen(openId, accsess_token, out unionId, out errMsg)) { Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("登录失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false); return; } } //验证用户 IBase_UserInfoService userInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); if (userInfoService.Any(w => w.UnionID.ToString().Equals(unionId, StringComparison.OrdinalIgnoreCase))) { var base_UserInfoModel = userInfoService.GetModels(w => w.UnionID.ToString().Equals(unionId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <Base_UserInfo>(); int userId = base_UserInfoModel.UserID; int userType = (int)base_UserInfoModel.UserType; int logType = (int)RoleType.XcUser; //默认普通员工登录 int isXcAdmin = base_UserInfoModel.Auditor ?? 0; int switchable = base_UserInfoModel.Switchable ?? 0; if (userType == (int)UserType.Xc && isXcAdmin == 0) { logType = (int)RoleType.XcAdmin; token = XCCloudUserTokenBusiness.SetUserToken(userId.ToString(), logType); } else if (userType == (int)UserType.Store || userType == (int)UserType.StoreBoss) { logType = (int)RoleType.StoreUser; var storeId = base_UserInfoModel.StoreID; IBase_StoreInfoService base_StoreInfoService = BLLContainer.Resolve <IBase_StoreInfoService>(); if (!base_StoreInfoService.Any(a => a.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase))) { errMsg = "该门店不存在"; Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("登录失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false); } string merchId = base_StoreInfoService.GetModels(p => p.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault().MerchID; var dataModel = new UserDataModel { StoreID = storeId, MerchID = merchId }; token = XCCloudUserTokenBusiness.SetUserToken(userId.ToString(), logType, dataModel); } else { logType = (int)RoleType.MerchUser; string merchId = base_UserInfoModel.MerchID; IBase_MerchantInfoService base_MerchantInfoService = BLLContainer.Resolve <IBase_MerchantInfoService>(); if (!base_MerchantInfoService.Any(p => p.MerchID.Equals(merchId, StringComparison.OrdinalIgnoreCase))) { errMsg = "该商户不存在"; Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("登录失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false); } var base_MerchantInfoModel = base_MerchantInfoService.GetModels(p => p.MerchID.Equals(merchId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); var dataModel = new MerchDataModel { MerchID = merchId, MerchType = base_MerchantInfoModel.MerchType, CreateType = base_MerchantInfoModel.CreateType, CreateUserID = base_MerchantInfoModel.CreateUserID }; token = XCCloudUserTokenBusiness.SetUserToken(userId.ToString(), logType, dataModel); merchTag = base_MerchantInfoModel.MerchTag; } Response.Redirect(WeiXinConfig.RedirectMainPage + "?token=" + token + "&logType=" + logType + "&userType=" + userType + "&merchTag=" + merchTag + "&switchable=" + switchable, false); } else { errMsg = "用户未注册"; LogHelper.SaveLog("失败:" + errMsg); Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("登录失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false); } } else { errMsg = "获取openId失败"; LogHelper.SaveLog("错误:" + errMsg); Response.Redirect(WeiXinConfig.RedirectLogoutPage, false); } } catch (Exception ex) { LogHelper.SaveLog("错误:" + ex.Message); Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("登录失败") + "&message=" + HttpUtility.UrlEncode(ex.Message), false); } }
protected void Page_Load(object sender, EventArgs e) { try { string openId = string.Empty; string errMsg = string.Empty; string storeId = string.Empty; string merchId = string.Empty; string revOpenId = string.Empty; int userType = (int)UserType.Store; string code = Request["code"] != null ? Request["code"].ToString() : string.Empty; string state = Request["state"] != null ? Request["state"].ToString() : string.Empty; string mobile = Request["mobile"] != null ? Request["mobile"].ToString() : string.Empty; string username = Request["username"] != null ? Request["username"].ToString() : string.Empty; string realname = Request["realname"] != null ? Request["realname"].ToString() : string.Empty; string password = Request["password"] != null ? Request["password"].ToString() : string.Empty; string message = Request["message"] != null ? Request["message"].ToString() : string.Empty; //获取用户openid if (!TokenMana.GetOpenId(code, state, out openId)) { errMsg = "获取openId失败"; LogHelper.SaveLog("错误:" + errMsg); Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("注册失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false); return; } LogHelper.SaveLog("openId:" + openId); //获取用户基本信息 string unionId = string.Empty; if (!TokenMana.GetUnionId(openId, out unionId, out errMsg)) { LogHelper.SaveLog("错误:" + errMsg); Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("注册失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false); return; } if (!checkRegisterParas(openId, out storeId, out merchId, out userType, out revOpenId, out errMsg)) { Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("注册失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false); return; } LogHelper.SaveLog("unionId:" + unionId); LogHelper.SaveLog("storeId:" + storeId); //注册成功后,给商户管理员发送审核消息模板 string sql = " exec SP_RegisterUserFromWx @StoreId,@MerchId,@UserType,@Mobile,@Username,@Realname,@UserPassword,@Message,@WXOpenID,@UnionID,@WorkID output,@Return output "; SqlParameter[] parameters = new SqlParameter[12]; parameters[0] = new SqlParameter("@StoreId", storeId); parameters[1] = new SqlParameter("@MerchId", merchId); parameters[2] = new SqlParameter("@UserType", userType); parameters[3] = new SqlParameter("@Mobile", mobile); parameters[4] = new SqlParameter("@Username", username); parameters[5] = new SqlParameter("@Realname", realname); parameters[6] = new SqlParameter("@UserPassword", Utils.MD5(password)); parameters[7] = new SqlParameter("@Message", message); parameters[8] = new SqlParameter("@WXOpenID", openId); parameters[9] = new SqlParameter("@UnionID", unionId); parameters[10] = new SqlParameter("@WorkID", 0); parameters[10].Direction = ParameterDirection.Output; parameters[11] = new SqlParameter("@Return", 0); parameters[11].Direction = ParameterDirection.Output; System.Data.DataSet ds = XCCloudBLL.ExecuteQuerySentence(sql, parameters); var workId = parameters[10].Value + ""; var ret = parameters[11].Value + ""; if (ret == "1") { IBase_UserInfoService userInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); var userList = userInfoService.GetModels(p => p.OpenID.ToString().Equals(openId, StringComparison.OrdinalIgnoreCase)); var userInfo = userList.FirstOrDefault <Base_UserInfo>(); MessagePush(revOpenId, username, userInfo.CreateTime.Value.ToString("f"), workId, userType, message); var succMsg = "已递交工单,等待管理员审核"; LogHelper.SaveLog("成功:" + succMsg); Response.Redirect(WeiXinConfig.RedirectSuccessPage + "?realname=" + HttpUtility.UrlEncode(realname) + "&openid=" + openId + "&title=" + HttpUtility.UrlEncode("注册成功") + "&message=" + HttpUtility.UrlEncode(succMsg), false); } else { errMsg = "注册失败"; LogHelper.SaveLog("错误:" + errMsg); Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("注册失败") + "&message=" + HttpUtility.UrlEncode(errMsg), false); } } catch (Exception ex) { LogHelper.SaveLog("错误:" + ex.Message); Response.Redirect(WeiXinConfig.RedirectErrorPage + "?title=" + HttpUtility.UrlEncode("注册失败") + "&message=" + HttpUtility.UrlEncode(ex.Message), false); } }
/// <summary> /// 验证注册参数 /// </summary> /// <returns></returns> private bool checkRegisterParas(string openId, out string storeId, out string merchId, out int userType, out string revOpenId, out string errMsg) { errMsg = string.Empty; storeId = string.Empty; merchId = string.Empty; revOpenId = string.Empty; userType = (int)UserType.Store; string scode = Request["scode"] != null ? Request["scode"].ToString() : string.Empty; string mobile = Request["mobile"] != null ? Request["mobile"].ToString() : string.Empty; string storeOrMerchId = Request["storeOrMerchId"] != null ? Request["storeOrMerchId"].ToString() : string.Empty; string username = Request["username"] != null ? Request["username"].ToString() : string.Empty; string password = Request["password"] != null ? Request["password"].ToString() : string.Empty; #region 验证参数 //如果用户未获取短信验证码 string key = mobile + "_" + scode; if (!SMSCodeCache.IsExist(key)) { errMsg = "短信验证码无效"; return(false); } if (string.IsNullOrEmpty(storeOrMerchId)) { errMsg = "门店ID或商户ID参数不能为空"; return(false); } if (string.IsNullOrEmpty(openId)) { errMsg = "用户openId参数不能为空"; return(false); } if (openId.Length > 64) { errMsg = "用户openId参数长度不能超过64个字符"; return(false); } if (string.IsNullOrEmpty(username)) { errMsg = "用户名参数不能为空"; return(false); } if (username.Length > 20) { errMsg = "用户名参数长度不能超过20个字符"; return(false); } if (!Utils.CheckMobile(mobile)) { errMsg = "手机号码参数不正确"; return(false); } if (string.IsNullOrEmpty(password)) { errMsg = "密码参数不能为空"; return(false); } #endregion //验证商户 var mId = storeOrMerchId; IBase_MerchantInfoService base_MerchantInfoService = BLLContainer.Resolve <IBase_MerchantInfoService>(); if (!base_MerchantInfoService.Any(p => p.MerchID.Equals(mId, StringComparison.OrdinalIgnoreCase))) { //验证门店 var sId = storeOrMerchId; IBase_StoreInfoService storeInfoService = BLLContainer.Resolve <IBase_StoreInfoService>(); if (!storeInfoService.Any(p => p.StoreID.Equals(sId, StringComparison.OrdinalIgnoreCase))) { errMsg = "门店不存在"; return(false); } mId = storeInfoService.GetModels(p => p.StoreID.Equals(sId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault().MerchID; storeId = storeOrMerchId; } else { merchId = storeOrMerchId; } //验证发起人 IBase_UserInfoService userInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); var userList = userInfoService.GetModels(p => p.OpenID.ToString().Equals(openId, StringComparison.OrdinalIgnoreCase)); int userInfoCount = userList.Count <Base_UserInfo>(); if (userInfoService.Any(p => p.OpenID.ToString().Equals(openId, StringComparison.OrdinalIgnoreCase))) { errMsg = "用户不能重复注册"; return(false); } //验证接收人 if (!base_MerchantInfoService.Any(a => a.MerchID.Equals(mId, StringComparison.OrdinalIgnoreCase))) { errMsg = "接收商户不存在"; return(false); } var base_MerchantInfoModel = base_MerchantInfoService.GetModels(p => p.MerchID.Equals(mId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); var wxOpenId = base_MerchantInfoModel.WxOpenID; revOpenId = wxOpenId; if (!userInfoService.Any(p => p.OpenID.Equals(wxOpenId, StringComparison.OrdinalIgnoreCase))) { errMsg = "接收人不存在"; return(false); } //验证用户类别 if (!string.IsNullOrEmpty(merchId)) { userType = (int)base_MerchantInfoModel.MerchType; } else { userType = (int)UserType.Store; } return(true); }
public object EditMerch(Dictionary <string, object> dicParas) { try { string errMsg = string.Empty; string merchId = dicParas.ContainsKey("merchId") ? dicParas["merchId"].ToString() : string.Empty; string merchType = dicParas.ContainsKey("merchType") ? dicParas["merchType"].ToString() : string.Empty; string merchTag = dicParas.ContainsKey("merchTag") ? dicParas["merchTag"].ToString() : string.Empty; string merchStatus = dicParas.ContainsKey("merchStatus") ? dicParas["merchStatus"].ToString() : string.Empty; string merchAccount = dicParas.ContainsKey("merchAccount") ? dicParas["merchAccount"].ToString() : string.Empty; string merchName = dicParas.ContainsKey("merchName") ? dicParas["merchName"].ToString() : string.Empty; string openId = dicParas.ContainsKey("openId") ? dicParas["openId"].ToString() : string.Empty; string mobil = dicParas.ContainsKey("mobil") ? dicParas["mobil"].ToString() : string.Empty; string allowCreateSub = dicParas.ContainsKey("allowCreateSub") ? dicParas["allowCreateSub"].ToString() : string.Empty; string allowCreateCount = dicParas.ContainsKey("allowCreateCount") ? dicParas["allowCreateCount"].ToString() : string.Empty; string comment = dicParas.ContainsKey("comment") ? dicParas["comment"].ToString() : string.Empty; object[] merchFunction = dicParas.ContainsKey("merchFunction") ? (object[])dicParas["merchFunction"] : null; XCCloudUserTokenModel userTokenKeyModel = (XCCloudUserTokenModel)dicParas[Constant.XCCloudUserTokenModel]; string createUserId = userTokenKeyModel.LogId; int logType = userTokenKeyModel.LogType; #region 验证参数 if (string.IsNullOrEmpty(merchId)) { errMsg = "商户编号不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrWhiteSpace(merchType)) { errMsg = "商户类型不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!Utils.isNumber(merchType)) { errMsg = "商户类别不是Int类型"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrWhiteSpace(merchStatus)) { errMsg = "商户状态不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!Utils.isNumber(merchStatus)) { errMsg = "商户状态不是Int类型"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrEmpty(merchTag)) { errMsg = "商户标签不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!Utils.isNumber(merchTag)) { errMsg = "商户标签不是Int类型"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrWhiteSpace(merchAccount)) { errMsg = "商户账号不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (merchAccount.Length > 100) { errMsg = "商户账号不能超过100个字符"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrWhiteSpace(merchName)) { errMsg = "负责人不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (merchName.Length > 50) { errMsg = "负责人名称不能超过50个字符"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrWhiteSpace(openId)) { errMsg = "请选择微信昵称"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (string.IsNullOrWhiteSpace(mobil)) { errMsg = "手机号不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!Utils.CheckMobile(mobil)) { errMsg = "手机号不正确"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!string.IsNullOrEmpty(allowCreateSub) && !Utils.isNumber(allowCreateSub)) { errMsg = "是否允许创建子账号不是Int类型"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!string.IsNullOrEmpty(allowCreateCount) && !Utils.isNumber(allowCreateCount)) { errMsg = "账号数量不是Int类型"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!string.IsNullOrEmpty(comment) && comment.Length > 500) { errMsg = "备注不能超过500个字符"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } //获取用户基本信息 string unionId = string.Empty; if (!TokenMana.GetUnionId(openId, out unionId, out errMsg)) { return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } #endregion //开启EF事务 using (TransactionScope ts = new TransactionScope()) { try { IBase_MerchantInfoService base_MerchantInfoService = BLLContainer.Resolve <IBase_MerchantInfoService>(); if (base_MerchantInfoService.GetCount(p => !p.MerchID.Equals(merchId) && p.MerchAccount.Equals(merchAccount, StringComparison.OrdinalIgnoreCase)) > 0) { errMsg = "该商户账号名称已存在"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } var base_MerchantInfo = base_MerchantInfoService.GetModels(p => p.MerchID.Equals(merchId)).FirstOrDefault(); base_MerchantInfo.MerchType = Convert.ToInt32(merchType); base_MerchantInfo.MerchStatus = Convert.ToInt32(merchStatus); base_MerchantInfo.MerchAccount = merchAccount; base_MerchantInfo.MerchName = merchName; base_MerchantInfo.Mobil = mobil; base_MerchantInfo.WxOpenID = openId; base_MerchantInfo.WxUnionID = unionId; base_MerchantInfo.AllowCreateSub = !string.IsNullOrEmpty(allowCreateSub) ? Convert.ToInt32(allowCreateSub) : default(int?); base_MerchantInfo.AllowCreateCount = !string.IsNullOrEmpty(allowCreateCount) ? Convert.ToInt32(allowCreateCount) : default(int?); base_MerchantInfo.CreateUserID = createUserId; base_MerchantInfo.CreateType = (logType == (int)RoleType.XcUser || logType == (int)RoleType.XcAdmin) ? (int)CreateType.Xc : (logType == (int)RoleType.MerchUser ? (int)CreateType.Agent : 0); base_MerchantInfo.Comment = comment; base_MerchantInfo.MerchTag = Convert.ToInt32(merchTag); if (!base_MerchantInfoService.Update(base_MerchantInfo)) { errMsg = "修改商户信息失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>(); var base_UserInfo = base_UserInfoService.GetModels(p => p.OpenID.Equals(openId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (base_UserInfo == null) { base_UserInfo = new Base_UserInfo(); base_UserInfo.OpenID = openId; base_UserInfo.UserType = Convert.ToInt32(merchType); if (!base_UserInfoService.Add(base_UserInfo)) { errMsg = "添加商户负责人信息失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } if (merchFunction != null && merchFunction.Count() >= 0) { //先删除已有数据,后添加 var dbContext = DbContextFactory.CreateByModelNamespace(typeof(Base_MerchFunction).Namespace); var base_MerchFunctionList = dbContext.Set <Base_MerchFunction>().Where(p => p.MerchID.Equals(merchId, StringComparison.OrdinalIgnoreCase)).ToList(); foreach (var base_MerchFunction in base_MerchFunctionList) { dbContext.Entry(base_MerchFunction).State = EntityState.Deleted; } foreach (IDictionary <string, object> el in merchFunction) { if (el != null) { var dicPara = new Dictionary <string, object>(el, StringComparer.OrdinalIgnoreCase); string functionId = dicPara.ContainsKey("functionId") ? dicPara["functionId"].ToString() : string.Empty; string functionEn = dicPara.ContainsKey("functionEn") ? dicPara["functionEn"].ToString() : string.Empty; if (string.IsNullOrEmpty(functionId)) { errMsg = "功能编号不能为空"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!Utils.isNumber(functionId)) { errMsg = "功能编号不是Int类型"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } if (!string.IsNullOrEmpty(functionEn) && !Utils.isNumber(functionEn)) { errMsg = "功能启停不是Int类型"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } var base_MerchFunction = new Base_MerchFunction(); base_MerchFunction.MerchID = merchId; base_MerchFunction.FunctionID = Convert.ToInt32(functionId); base_MerchFunction.FunctionEN = !string.IsNullOrEmpty(functionEn) ? Convert.ToInt32(functionEn) : default(int?); dbContext.Entry(base_MerchFunction).State = EntityState.Added; } else { errMsg = "提交数据包含空对象"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } if (dbContext.SaveChanges() < 0) { errMsg = "保存商户功能菜单信息失败"; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } ts.Complete(); } catch (Exception ex) { errMsg = ex.Message; return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg)); } } //更新缓存 MerchBusiness.Init(); return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn)); } catch (Exception e) { return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message)); } }