/// <summary> /// 保存用户 /// </summary> public string SaveUserData() { var responseData = new ResponseData(); LoggingSessionInfo loggingSessionInfo = null; if (CurrentUserInfo != null) { loggingSessionInfo = CurrentUserInfo; } else { if (string.IsNullOrEmpty(Request("CustomerID"))) { responseData.success = false; responseData.msg = "缺少商户标识"; return(responseData.ToString()); } else if (string.IsNullOrEmpty(Request("CustomerUserID"))) { responseData.success = false; responseData.msg = "缺少登陆员工的标识"; return(responseData.ToString()); } else if (string.IsNullOrEmpty(Request("CustomerUserID"))) { responseData.success = false; responseData.msg = "缺少登陆员工的标识"; return(responseData.ToString()); } else { loggingSessionInfo = Default.GetBSLoggingSession(Request("CustomerID"), Request("CustomerUserID")); } } var userService = new cUserService(loggingSessionInfo);//兼容模式 UserInfo user = new UserInfo(); string content = string.Empty; string error = ""; // var responseData = new ResponseData(); string key = string.Empty; string user_id = string.Empty; if (Request("user") != null && Request("user") != string.Empty) { key = Request("user").ToString().Trim(); } if (Request("user_id") != null && Request("user_id") != string.Empty) { user_id = Request("user_id").ToString().Trim(); } user = key.DeserializeJSONTo <UserInfo>(); if (userService.IsExistUserCode(user.User_Code, loggingSessionInfo, user_id))//使用兼容模式 { responseData.success = false; responseData.msg = "用户名已存在!"; return(responseData.ToJSON()); } if (user.User_Status == null || user.User_Status.Trim().Length == 0) { user.User_Status = "1"; } if (user_id.Trim().Length == 0 && string.IsNullOrEmpty(user.User_Password))//新增用户才需要提交密码 { responseData.success = false; responseData.msg = "用户密码不能为空"; return(responseData.ToJSON()); } if (user_id.Trim().Length == 0) { user.User_Id = Utils.NewGuid(); //user.UnitList = loggingSessionInfo.CurrentUserRole.UnitId; } else { user.User_Id = user_id; } if (user.User_Code == null || user.User_Code.Trim().Length == 0) { responseData.success = false; responseData.msg = "用户名不能为空"; return(responseData.ToJSON()); } if (user.User_Name == null || user.User_Name.Trim().Length == 0) { responseData.success = false; responseData.msg = "姓名不能为空"; return(responseData.ToJSON()); } //if (user.Fail_Date == null || user.Fail_Date.Trim().Length == 0) //{ // responseData.success = false; // responseData.msg = "用户有效日期不能为空"; // return responseData.ToJSON(); //} user.Fail_Date = "2030-12-30";//转换成最大的日期 //if (user.User_Telephone == null || user.User_Telephone.Trim().Length == 0) //{ // responseData.success = false; // responseData.msg = "用户手机不能为空"; // return responseData.ToJSON(); //} //if (user.User_Email == null || user.User_Email.Trim().Length == 0) //{ // responseData.success = false; // responseData.msg = "用户邮箱不能为空"; // return responseData.ToJSON(); //} if (user.userRoleInfoList == null || user.userRoleInfoList.Count == 0) { responseData.success = false; responseData.msg = "请添加角色配置"; return(responseData.ToJSON()); } //设为归属单位有且只能有一个*** int countDefaultFlag = user.userRoleInfoList.Where(p => p.DefaultFlag == 1).Count(); if (countDefaultFlag < 1) { responseData.success = false; responseData.msg = "必须设置一个单位为归属单位"; return(responseData.ToJSON()); } if (countDefaultFlag > 1) { responseData.success = false; responseData.msg = "只能设置一个单位为默认单位"; return(responseData.ToJSON()); } UserRoleInfo roleinfo = user.userRoleInfoList.Where(p => p.DefaultFlag == 1).ToArray()[0]; t_unitBLL t_unitBLL = new BLL.t_unitBLL(loggingSessionInfo);//使用兼容模式 t_unitEntity UnitEn = t_unitBLL.GetByID(roleinfo.UnitId); string unitName = ""; if (UnitEn != null && UnitEn.unit_name != null) { unitName = UnitEn.unit_name; } //增加用户标识 foreach (var userRoleItem in user.userRoleInfoList) { userRoleItem.UserId = user.User_Id; } user.Create_Time = Utils.GetNow(); user.Create_User_Id = loggingSessionInfo.CurrentUser.User_Id; //使用兼容模式 user.Modify_Time = Utils.GetNow(); user.Modify_User_Id = loggingSessionInfo.CurrentUser.User_Id; //使用兼容模式 userService.SetUserInfo(user, user.userRoleInfoList, out error); #region 生成员工二维码 /** * //微信 公共平台 * var wapentity = new WApplicationInterfaceBLL(CurrentUserInfo).QueryByEntity(new WApplicationInterfaceEntity * { * CustomerId = CurrentUserInfo.ClientID, * IsDelete = 0 * }, null).FirstOrDefault();//取默认的第一个微信 * * var QRCodeId = Guid.NewGuid(); * var QRCodeManagerentity = new WQRCodeManagerBLL(this.CurrentUserInfo).QueryByEntity(new WQRCodeManagerEntity * { * ObjectId = user.User_Id * }, null).FirstOrDefault(); * if (QRCodeManagerentity != null) * { * QRCodeId = (Guid)QRCodeManagerentity.QRCodeId; * } * if (QRCodeManagerentity == null) * { * //二维码类别 * var wqrentity = new WQRCodeTypeBLL(this.CurrentUserInfo).QueryByEntity( * new WQRCodeTypeEntity { TypeCode = "UserQrCode" } * , null).FirstOrDefault(); * if (wqrentity == null) * { * responseData.success = false; * responseData.msg = "无法获取员工二维码类别"; * return responseData.ToJSON(); * } * //生成了微信二维码 * var wxCode = CretaeWxCode(); * //如果名称不为空,就把图片放在一定的背景下面 * if (!string.IsNullOrEmpty(user.User_Name)) * { * string apiDomain = ConfigurationManager.AppSettings["original_url"]; * wxCode.ImageUrl = CombinImage(apiDomain + @"/HeadImage/qrcodeBack.jpg", wxCode.ImageUrl, unitName + "-" + user.User_Name); * } * * var WQRCodeManagerbll = new WQRCodeManagerBLL(CurrentUserInfo); * * // Guid QRCodeId = Guid.NewGuid(); * * if (!string.IsNullOrEmpty(wxCode.ImageUrl)) * { * WQRCodeManagerbll.Create(new WQRCodeManagerEntity * { * QRCodeId = QRCodeId, * QRCode = wxCode.MaxWQRCod.ToString(), * QRCodeTypeId = wqrentity.QRCodeTypeId, * IsUse = 1, * ObjectId = user.User_Id, * CreateBy = CurrentUserInfo.UserID, * ApplicationId = wapentity.ApplicationId, * IsDelete = 0, * ImageUrl = wxCode.ImageUrl, * CustomerId = CurrentUserInfo.ClientID * * }); * } * * * } * * * **/ #endregion string errorMsg = ""; //下载的时候再生成,这里就不生成了,业务太多 // string wxCodeImageUrl = CreateUserWxCode(user, unitName,loggingSessionInfo, out errorMsg); if (errorMsg != "") { responseData.success = false; responseData.msg = errorMsg; return(responseData.ToJSON()); } responseData.success = true; responseData.msg = error; content = responseData.ToJSON(); return(content); }