/// <summary> /// 通过code获取session /// </summary> /// <param name="code">小程序login获取的Code</param> /// <returns></returns> public string GetSessionByCode(string code) { string strJson = ""; BLL.Common.Logger.Error("GetSessionByCode方法接受到的参数code:" + code); JavaScriptSerializer js = new JavaScriptSerializer(); Dictionary <string, object> dic = new Dictionary <string, object>(); string str_OpenidAndSessinKey = ""; if (!string.IsNullOrEmpty(code)) { //获取openid和Session_Key WeChatAppDecrypt Wechat = new WeChatAppDecrypt(); str_OpenidAndSessinKey = Wechat.GetOpenIdAndSessionKeyString(code); BLL.Common.Logger.Error("GetSessionByCode方法获取到openid和Sessionkey:" + str_OpenidAndSessinKey); var openidAndSessionKey = js.Deserialize <Dictionary <string, object> >(str_OpenidAndSessinKey); string strOpenID = openidAndSessionKey["openid"].ToString(); string strSession_Key = openidAndSessionKey["session_key"].ToString(); //通过openID获取用户记录 SB_UserEL userEL = new SB_UserEL(); userEL.OpenID = strOpenID; DataTable dt = userEL.ExecDT(43); string sessionResult = ""; string isHadRegister = ""; if (dt != null && dt.Rows.Count > 0) { sessionResult = dt.Rows[0]["Session_True"].ToString(); isHadRegister = "1"; } else { //生成session //生成6位随机数 string strRandom = new Random().Next(100000, 1000000).ToString(); //session_Key格式:q/jk63En5ojUGqgi6vLHmA==(24个字符) //openID格式:oFQX10O9zkRnsNYefrc48KfQWi9o(28个字符) //strSession_true=strSession_Key+strOpenID+strRandom //session等于sesion_key去掉后两位的“=”号(22位),加openid(28位),加六位随机数(6位) //sessionResult=q/jk63En5ojUGqgi6vLHmAoFQX10O9zkRnsNYefrc48KfQWi9o654321 string strSession_true = strSession_Key.Substring(0, strSession_Key.Length - 2) + strOpenID + strRandom; sessionResult = strSession_true; isHadRegister = "0"; } dic.Add("Session", sessionResult); dic.Add("IsHadRegister", isHadRegister); strJson = js.Serialize(dic); HF.Cloud.BLL.Common.Logger.Error("GetSessionByCode方法返回的数据为:" + strJson); } else { strJson = "error"; } return(strJson); }
/// <summary> /// 给公司递名片 /// </summary> /// <param name="session">session</param> /// <param name="companyID">公司ID</param> /// <returns></returns> public string SendCard(string session, string companyID) { string resStr = ""; HF.Cloud.BLL.Common.Logger.Error("SendCard方法接受的参数session:" + session + "---companyID:" + companyID); //通过session获取UserID UserBLL userBLL = new UserBLL(); long userID = userBLL.GetUserIDBySession(session); //通过companyID查询企业的所有员工 SB_UserEL userEL = new SB_UserEL(); userEL.CompanyID = long.Parse(companyID); DataTable dt = userEL.ExecDT(44); HF.Cloud.BLL.Common.Logger.Error("SendCard方法获取到企业员工数为:" + dt.Rows.Count); NoticeEL noticeEL = new NoticeEL(); int i = 0; foreach (DataRow dr in dt.Rows) { noticeEL.UserID = (long)dr["ID"]; //接受通知用户的userID noticeEL.UserID_Friend = userID; // noticeEL.NoticeType = 1; noticeEL.NoticeState = 0; noticeEL.IsLook = 0; noticeEL.CreateTime = DateTime.Now.ToString(); noticeEL.Valid = 1; int ra; long notiExec = noticeEL.ExecNonQuery(1, out ra); if (notiExec > 0) { i = i + 1; } } if (dt.Rows.Count == i) { resStr = "seccess"; } else { resStr = "error"; } return(resStr); }
/// <summary> /// 获取好友公司信息 /// </summary> /// <param name="companyID">companyID</param> /// <returns></returns> public string GetFriendCompanyInfo(string session, string companyID) { string strJson = ""; HF.Cloud.BLL.Common.Logger.Error("GetFriendCompanyInfo方法接受的参数session:" + session + "---companyID:" + companyID); if (!string.IsNullOrEmpty(session) && !string.IsNullOrEmpty(companyID)) { JavaScriptSerializer js = new JavaScriptSerializer(); Dictionary <string, object> dic = new Dictionary <string, object>(); SB_UserEL userEL = new SB_UserEL(); userEL.Session_True = session; userEL.ExecuteEL(41); string isMyCompany = "";//是否是自己公司 if (userEL.CompanyID.ToString() == companyID) { isMyCompany = "1"; } else { isMyCompany = "0"; } long _companyID = long.Parse(companyID); //通过公司ID获取公司信息 CompanysEL companysEL = new CompanysEL(); companysEL.ID = _companyID; companysEL.ExecuteEL(2); HF.Cloud.BLL.Common.Logger.Error("GetFriendCompanyInfo方法查询公司信息结果公司名称:" + companysEL.CompanyName); dic.Add("CompanyID", companyID); dic.Add("CompanyName", companysEL.CompanyName); dic.Add("CompanyIcon", companysEL.CompanyIcon); dic.Add("Introduce", companysEL.Introduce); dic.Add("IsMyCompany", isMyCompany); //通过companyID获取公司关键字 string companyTags = GetCompanyTag_String(companyID.ToString()); dic.Add("Tags", companyTags); //3判断是否给此公司递过名片 string userid = userEL.ID.ToString(); //3.1查找第一个加入当前公司的用户ID string userid_Company = ""; userEL.CompanyID = _companyID; DataTable dt_company = userEL.ExecDT(44); if (dt_company != null && dt_company.Rows.Count > 0) { userid_Company = dt_company.Rows[0]["ID"].ToString(); } //3.2Notice表中查找此人是否给公司提交过名片的记录 NoticeEL noticeEL = new NoticeEL(); noticeEL.UserID = long.Parse(userid_Company); //第一个加入公司的人 noticeEL.UserID_Friend = long.Parse(userid); //自己 noticeEL.NoticeType = 1; DataTable dt_Notice = noticeEL.ExecDT(23); string isSend = "";//是否递过,0没递过,1递过 if (dt_Notice != null && dt_Notice.Rows.Count > 0) { isSend = "1"; } else { isSend = "0"; } dic.Add("IsSend", isSend); strJson = js.Serialize(dic); } else { strJson = "error"; } HF.Cloud.BLL.Common.Logger.Error("GetFriendCompanyInfo方法返回的用户信息json数据:" + strJson); return(strJson); }
/// <summary> /// 红包开关 /// </summary> /// <param name="companyId">公司ID</param> /// <returns></returns> public string OpenRedBag(string companyID) { HF.Cloud.BLL.Common.Logger.Error("OpenRedBag 获取到的参数CompanyID:" + companyID); //查看时间,过期则不可打开 //if(DateTime.Now.ToString()<"2018-02-16 23:12:12:123") //{ //} string resultStr = ""; long companyIdLong = 0;//公司ID if (long.TryParse(companyID, out companyIdLong)) { //1通过公司id在用户表中看当前公司够5个人不够 SB_UserEL userEL = new SB_UserEL(); userEL.CompanyID = companyIdLong; DataTable dt_User = userEL.ExecDT(44); //1.1够5个人则开始在红包表里面添加红包数据 if (dt_User != null && dt_User.Rows.Count >= 5) { //2 查看已经发了多少钱,发过的总数大于1000停止发送 DataTable dt_HongBalAllVa = DbHelperSQL.Query("select sum(HongBaoValue) as AllValue from T_HongBao where Valid=1").Tables[0]; string allValueStr = dt_HongBalAllVa.Rows[0][0].ToString(); //2.1已经发送的总金额小于900的话继续发 if (string.IsNullOrEmpty(allValueStr) || double.Parse(allValueStr) < 850) { T_HongBaoEL hongBaoEl = new T_HongBaoEL(); //查看红包表是否已经存在记录,存在则不添加红包记录 hongBaoEl.CompanyID = companyIdLong; DataTable dt_HongBao = hongBaoEl.ExecDT(33); if (dt_HongBao == null || dt_HongBao.Rows.Count < 1) { //3发红包表添加记录 //3.1生成公司红包金额10-100随机数,红包个数是金额的0.5-1倍 Random ran = new Random(); //3.1.1红包金额,取下不取上 int comAllValue = ran.Next(10, 100); //3.1.2人数 int comNumber = (int)Math.Floor(ran.Next(5, 10) * 0.1 * comAllValue); HF.Cloud.BLL.Common.Logger.Error("OpenRedBag方法红包总金额是:" + comAllValue + "---总人数:" + comNumber); //3.2通过总金额和人数获取评分后的红包值 List <Double> listHongV = HongBao.GetRedBagList(double.Parse(comAllValue.ToString()), comNumber, 1.00); //3.3通过获取到的红包值列表,给红包表添加记录 for (int i = 0; i < listHongV.Count; i++) { //ID,CompanyID,HongBaoValue,GetUserID,IsGet, //CreateTime,GiveOutTime,Valid //HF.Cloud.BLL.Common.Logger.Error("OpenRedBag方法获得的红包值listHongV是:" + listHongV[i]); hongBaoEl.CompanyID = companyIdLong; //hongBaoEl.HongBaoValue = decimal.Round((decimal)listHongV[i],2); hongBaoEl.HongBaoValue = decimal.Parse(listHongV[i].ToString()); hongBaoEl.IsGet = 1; hongBaoEl.CreateTime = DateTime.Now.ToString(); hongBaoEl.GiveOutTime = ""; hongBaoEl.Valid = 1; int ra; hongBaoEl.ExecNonQuery(1, out ra); } HF.Cloud.BLL.Common.Logger.Error("OpenRedBag方法生成的红包个数:" + listHongV.Count); resultStr = "success"; } else //已经激活不能再次激活 { resultStr = "actived"; } } else //2.2红包奖金池已经用完额度 { resultStr = "empty"; } } else//1.2不够5个人则提示人数不够 { resultStr = "notenough"; } } else { resultStr = "error"; } HF.Cloud.BLL.Common.Logger.Error("OpenRedBag 结果:" + resultStr); return(resultStr); }
/// <summary> /// 添加用户 /// </summary> /// <param name="strAddUser"></param> /// <returns></returns> public string InsertUser(string strAddUser) { BLL.Common.Logger.Error("InsertUser方法新增加用户接受到的参数string:" + strAddUser); string InsertUserRes = "";//返回的数据 JavaScriptSerializer js = new JavaScriptSerializer(); var info = js.Deserialize <Dictionary <string, object> >(strAddUser); SB_UserEL SB_User_el = new SB_UserEL(); SB_User_el.UserName = info["UserName"].ToString(); SB_User_el.UserTel = info["UserTel"].ToString(); SB_User_el.Duty = info["Duty"].ToString(); SB_User_el.UserEmail = info["UserEmail"].ToString(); SB_User_el.Detail = info["Detail"].ToString(); SB_User_el.ImgUrl = info["ImgUrl"].ToString(); SB_User_el.CompanyID = long.Parse(info["CompanyID"].ToString()); SB_User_el.Popularity = 0; SB_User_el.Thumbs = 0; SB_User_el.CreateTime = DateTime.Now.ToString(); SB_User_el.Valid = 1; SB_User_el.UnionID = ""; //string strOpneID = info["OpenID"].ToString(); //SB_User_el.OpenID = strOpneID; //string strSession_Key= info["Session_Key"].ToString(); //SB_User_el.Session_Key = strSession_Key; //SB_User_el.UnionID = ""; //string strSession_true = ""; //string strRandom = new Random().Next(100000, 1000000).ToString(); //strSession_true = strSession_Key.Substring(0, strSession_Key.Length - 2) + strOpneID + strRandom; //SB_User_el.Session_True = strSession_true; //---------------------------------------------------------------------------------- //string code = info["Code"].ToString(); //string strSession_true = ""; //string strOpneID = ""; //if (!string.IsNullOrEmpty(code)) //{ // //获取openid和Session_Key // WeChatAppDecrypt Wechat = new WeChatAppDecrypt(); // string str_res = Wechat.GetOpenIdAndSessionKeyString(code); // BLL.Common.Logger.Error("新增加用户获取到openid和Sessionkey:" + str_res); // var openidAndSessionKey = js.Deserialize<Dictionary<string, object>>(str_res); // strOpneID = openidAndSessionKey["openid"].ToString(); // SB_User_el.OpenID = strOpneID; // SB_User_el.Session_Key = openidAndSessionKey["session_key"].ToString(); // SB_User_el.UnionID = ""; // string strRandom = new Random().Next(100000, 1000000).ToString(); // strSession_true = openidAndSessionKey["session_key"].ToString() + strRandom; // SB_User_el.Session_True = strSession_true; //} //string strOpneID = ""; //string strSession_key = ""; ////如果传过来OpenID和Session_Key(小程序获取手机号从而得到OpenID和Session_key) //if (!string.IsNullOrEmpty(info["OpenID"].ToString()) && !string.IsNullOrEmpty(info["Session_Key"].ToString())) //{ // strOpneID = info["OpenID"].ToString(); // strSession_key = info["Session_Key"].ToString(); //} ////如果没有openID和Session_Key的话就用Code去换取(小程序中直接填写的手机号,没有获取) //else if (!string.IsNullOrEmpty(info["Code"].ToString())) //{ // //获取openid和Session_Key // WeChatAppDecrypt Wechat = new WeChatAppDecrypt(); // string str_res = Wechat.GetOpenIdAndSessionKeyString(info["Code"].ToString()); // BLL.Common.Logger.Error("InsertUser方法新增加用户获取到openid和Sessionkey:" + str_res); // var openidAndSessionKey = js.Deserialize<Dictionary<string, object>>(str_res); // strOpneID = openidAndSessionKey["openid"].ToString(); // strSession_key = openidAndSessionKey["session_key"].ToString(); //} //SB_User_el.OpenID = strOpneID; //SB_User_el.Session_Key = strSession_key; string session_True = info["Session_True"].ToString(); //判断Session_True是否为空 if (!string.IsNullOrEmpty(session_True) && session_True != "") { //User表中判断Session_True,看是否有Session_True,有的话就是修改,没有的话就是添加 SB_UserEL SB_User_el_IsHadSession = new SB_UserEL(); SB_User_el_IsHadSession.Session_True = session_True; DataTable dt = SB_User_el_IsHadSession.ExecDT(45); BLL.Common.Logger.Error("InsertUser方法用户表中查询用户个数为:" + dt.Rows.Count); if (dt != null && dt.Rows.Count > 0) { //修改用户记录 SB_User_el.Session_True = session_True; int aff; long executeResul = SB_User_el.ExecNonQuery(24, out aff); BLL.Common.Logger.Error("InsertUser方法修改用户信息结果为:" + aff); if (aff > 0) { //返回数据库中的Session_True InsertUserRes = session_True; BLL.Common.Logger.Error("InsertUser方法这里是修改用户信息成功,返回的session为:" + InsertUserRes); } else { InsertUserRes = "error"; } } else//添加用户 { SB_User_el.Session_True = session_True; //拆分sesison_True,获取openid和sesison_key string str_session_key = session_True.Substring(0, 22) + "=="; string str_openid = session_True.Substring(22, 28); SB_User_el.Session_Key = str_session_key; SB_User_el.OpenID = str_openid; //添加 int aff; long executeResul = SB_User_el.ExecNonQuery(1, out aff); BLL.Common.Logger.Error("InsertUser方法添加用户信息结果为:" + executeResul); if (executeResul > 0) { InsertUserRes = session_True; BLL.Common.Logger.Error("InsertUser方法添加用户信息成功!返回的session为:" + InsertUserRes); } else { InsertUserRes = "error"; } } } ////User表中判断openid,看是否有openid,有的话就是修改,没有的话就是添加 //SB_UserEL SB_User_el_IsHaveOpenID = new SB_UserEL(); //SB_User_el_IsHaveOpenID.OpenID = strOpneID; //SB_User_el_IsHaveOpenID.ExecuteEL(43); //if (SB_User_el_IsHaveOpenID.ID > 0) //{ // //修改用户记录 // int aff; // long executeResul = SB_User_el.ExecNonQuery(24, out aff); // if (aff > 0) // { // //返回数据库中的Session_True // InsertUserRes = SB_User_el_IsHaveOpenID.Session_True; // BLL.Common.Logger.Error("InsertUser方法这里是修改用户信息成功,返回的session为:" + InsertUserRes); // } // else // { // InsertUserRes = ""; // } //} //else //{ // //添加用户记录 // //生成session // string strSession_true = ""; // string strRandom = new Random().Next(100000, 1000000).ToString(); // strSession_true = strSession_key.Substring(0, strSession_key.Length - 2) + strOpneID + strRandom; // SB_User_el.Session_True = strSession_true; // //添加 // int aff; // long executeResul = SB_User_el.ExecNonQuery(1, out aff); // if (executeResul > 0) // { // InsertUserRes = strSession_true; // BLL.Common.Logger.Error("InsertUser方法添加用户信息成功!返回的session为:" + InsertUserRes); // } // else // { // InsertUserRes = ""; // } //} return(InsertUserRes); }
/// <summary> /// 群组人员置顶 取消置顶 删除 /// </summary> /// <param name="userID">人员ID</param> /// <param name="groupID">群组ID</param> /// <param name="cookie">操作的功能(top置顶distop取消置顶delete删除)</param> /// <returns></returns> public string EditUser(string session, string userID, string groupID, string cookie) { string retunStr = ""; HF.Cloud.BLL.Common.Logger.Error("EditUser编辑群组人员方法,获取的参数userID:" + userID + "------groupID:" + groupID + "------cookie:" + cookie); UserUniteGroupEL userGroupEL = new UserUniteGroupEL(); if (!string.IsNullOrEmpty(userID) && !string.IsNullOrEmpty(groupID) && !string.IsNullOrEmpty(cookie)) { userGroupEL.UserID = long.Parse(userID); userGroupEL.GroupID = long.Parse(groupID); if (cookie == "top")//置顶 { //获取当前置顶的istop最大值 int maxIsTop = 0; DataTable dtUserGroup = userGroupEL.ExecDT(35); if (dtUserGroup != null && dtUserGroup.Rows.Count > 0) { maxIsTop = Int32.Parse(dtUserGroup.Rows[0]["IsTop"].ToString()); } userGroupEL.IsTop = maxIsTop + 1; int ra; long returnVel = userGroupEL.ExecNonQuery(22, out ra); if (ra > 0) { retunStr = GetGroupFriendList(session, groupID); } else { retunStr = "error"; } } if (cookie == "distop")//取消置顶 { userGroupEL.IsTop = 0; int ra; long returnVel = userGroupEL.ExecNonQuery(23, out ra); if (ra > 0) { retunStr = GetGroupFriendList(session, groupID); } else { retunStr = "error"; } } if (cookie == "del")//删除 { //不可删自己 //通过groupID获取群信息 GroupEL groupEL = new GroupEL(); long groupID_long = long.Parse(groupID); groupEL.ID = groupID_long; groupEL.ExecuteEL(3); //群主ID string userID_Group = groupEL.OwnerUserID.ToString(); //通过sesison 获取userID SB_UserEL userEL = new SB_UserEL(); userEL.Session_True = session; DataTable dtUserEl = userEL.ExecDT(41); string userID_User = ""; if (dtUserEl != null && dtUserEl.Rows.Count > 0) { userID_User = dtUserEl.Rows[0]["ID"].ToString(); } //如果不是群主 if (userID_Group != userID_User) { int ra; long returnVel = userGroupEL.ExecNonQuery(2, out ra); if (ra < 0) { retunStr = "error"; } } retunStr = GetGroupFriendList(session, groupID); } } return(retunStr); }