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); } }
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)); } }