public async Task<HttpResponseMessage> PostInitialize([FromBody]LoginParameter postParameter) { string openid = postParameter.openID; if (string.IsNullOrEmpty(openid)) { return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments); } using (UserRepository userRepository = new UserRepository()) { userinfo = await userRepository.GetUserInfoByOpenid(openid); if (userinfo == null) { return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound); } userinfo.NumOfContacts = await userRepository.GetUserContactNumber(userinfo.uuid); userinfo.NumOfVisitor = await userRepository.GetUserVisitorNumber(userinfo.uuid); userinfo.NumOfFavorite = await userRepository.GetuserFavoriteNumber(userinfo.uuid); using(SystemRepository systemRepository = new SystemRepository()) { userinfo.Hometown = await systemRepository.GetShortAddress(userinfo.HometownProvince,userinfo.HometownCity); } return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, userinfo, HttpStatusCode.OK, customStatus.Success); } }
public async Task<HttpResponseMessage> PostFindProfessors([FromBody]BaseParameter postParameter) { string openid = postParameter.openID; if (string.IsNullOrEmpty(openid)) { return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments); } //获取用户uuid 学校与院系与专业信息。 Guid useruuid; string xuexiaoname, yuanxiname; long? rf; using (UserRepository userRepository = new UserRepository()) { var userinfo = await userRepository.GetUserInfoByOpenid(openid); useruuid = userinfo.uuid; xuexiaoname = userinfo.Unit; yuanxiname = userinfo.Faculty; rf = userinfo.ResearchFieldId; if (string.IsNullOrEmpty(xuexiaoname) || string.IsNullOrEmpty(yuanxiname)) return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, "学校,院系有个为空!", HttpStatusCode.OK, customStatus.InvalidArguments); //获取score double univScore, depScore; FindHelper.GetUnivDeptScore(xuexiaoname, yuanxiname, out univScore, out depScore); //return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, "学校,院系名称不正规!", HttpStatusCode.OK, customStatus.InvalidArguments); //拿到三个集合 double rfScore = Convert.ToDouble(rf.Value); var set = await FindHelper.GetThreeSet(true, univScore, depScore, rfScore); var retUuid = FindHelper.FindProfessorRule(useruuid,set.Item1, set.Item2, set.Item3, postParameter.pageIndex, postParameter.pageSize); List<Tuple<UserInfo, string, bool>> ret = new List<Tuple<UserInfo, string, bool>>(); if (retUuid != null && retUuid.Count > 0) { using (UserRepository repo = new UserRepository()) { List<string> eduList = await ProfessorManager.GetUserEducations(userinfo.uuid); var list = await ProfessorManager.Search_UUid(retUuid); foreach (var v in list) { Guid uuid = Guid.Parse(v.Id); var tempUserinfo = await repo.GetUserInfoByUuidAsync(uuid); string three = !string.IsNullOrEmpty(v.Diwei) ? v.Diwei.Trim() : ""; bool isXY = ProfessorManager.IsXiaoYou(eduList, v.Education); ret.Add(Tuple.Create(tempUserinfo, three, isXY)); } } } return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, ret, HttpStatusCode.OK, customStatus.Success); } }
public static async Task<bool> SaveUserInfo(ComplementParameter complementParameter, pre_register preRegister) { bool saveresult = false; bool createresult = false; UserInfoRedis userinfoRedis = await GetUserInfoRedisByOpenid(complementParameter.openID); UserInfo userinfo = null; using (UserRepository userRepository = new UserRepository()) { userinfo = await userRepository.GetUserInfoByOpenid(complementParameter.openID); if (userinfo == null) { userinfo = new UserInfo() { AccountEmail = preRegister.accountemail, Password = preRegister.password, CreateTime = preRegister.createtime, Name = preRegister.name, Gender = userinfoRedis.Sex, Phone = preRegister.accountemail.Substring(0, 11), IsBusiness = preRegister.validate }; createresult = true; } else { userinfo.Name = complementParameter.name; userinfo.Gender = complementParameter.Gender; } await CheckUserInfoPhoto(userinfo, userinfoRedis); userinfo.Unit = complementParameter.university; userinfo.Faculty = complementParameter.faculty; userinfo.ResearchFieldId = complementParameter.researchFieldId; userinfo.Degree = complementParameter.degree; if (userinfo.IsBusiness==2) userinfo.Enrollment = complementParameter.enrollment; if (userinfo.IsBusiness == 0 && !string.IsNullOrEmpty(complementParameter.position)) userinfo.Position = complementParameter.position; userinfo.Province = complementParameter.province; userinfo.City = complementParameter.city; userinfo.Birthday = complementParameter.birthday; userinfo.HometownProvince = complementParameter.hometownProvince; userinfo.HometownCity = complementParameter.hometownCity; userinfo.Position = complementParameter.position; saveresult = await userRepository.SaveUserInfo(userinfo); if (saveresult & createresult) await userRepository.SaveUserOpenid(userinfo.uuid, userinfoRedis.Openid, userinfoRedis.Unionid); } return saveresult; }
public async Task<HttpResponseMessage> PostSearchrf([FromBody]ProfessorSearchParameter postParameter) { string openid = postParameter.openID; int diwei = string.IsNullOrEmpty(postParameter.labels) ? 0 : ProfessorManager.GetDiweiScore(postParameter.labels); bool xiaoyou = postParameter.xiaoyou != null ? postParameter.xiaoyou.Value : false; string danwei = postParameter.danwei; int index = postParameter.pageIndex; int size = postParameter.pageSize; if (string.IsNullOrEmpty(openid)) { return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments); } Guid Myuuid; using (UserRepository repo = new UserRepository()) { Myuuid = (await repo.GetUserInfoByOpenid(openid)).uuid; } var list = await ProfessorManager.Search_rf3(Myuuid, xiaoyou, danwei, diwei, postParameter.address, postParameter.pageIndex, postParameter.pageSize); List<Tuple<UserInfo, string, bool>> ret = new List<Tuple<UserInfo, string, bool>>(); if (list != null && list.Count > 0) { using (UserRepository repo = new UserRepository()) { List<string> eduList = await ProfessorManager.GetUserEducations(Myuuid); foreach (var v in list) { Guid uuid = Guid.Parse(v.Id); var userinfo = await repo.GetUserInfoByUuidAsync(uuid); string three = !string.IsNullOrEmpty(v.Diwei) ? v.Diwei.Trim() : ""; bool isXY = ProfessorManager.IsXiaoYou(eduList, v.Education); ret.Add(Tuple.Create(userinfo, three, isXY)); } } } return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, ret, HttpStatusCode.OK, customStatus.Success); }
public async Task<HttpResponseMessage> PostEkCommentAdd([FromBody]EKCommentParameter postParameter) { string openid = postParameter.openID; long ekid = postParameter.Id; string content = postParameter.Content; if (string.IsNullOrEmpty(openid) || ekid == 0 || string.IsNullOrEmpty(content)) { return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments); } using (UserRepository userR = new UserRepository()) { var userinfo = await userR.GetUserInfoByOpenid(openid); if (EKCommentMessageMQOp.SendMessage(userinfo.uuid.ToString(), ekid, content)) { await EKArticleManager.AddCommentCountAsync(ekid);//评论数增加 return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, "OK", HttpStatusCode.OK, customStatus.Success); } return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, "Failed", HttpStatusCode.OK, customStatus.Fail); } }
public async Task<HttpResponseMessage> PostSearch([FromBody]EKCommentParameter postParameter) { string openid = postParameter.openID; string queryStr = postParameter.Content; int index = postParameter.pageIndex; int size = postParameter.pageSize; if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(queryStr)) { return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments); } UserInfo myUserInfo = null; using (UserRepository repo = new UserRepository()) { myUserInfo = await repo.GetUserInfoByOpenid(openid); } List<Tuple<UserInfo, string, bool>> ret = new List<Tuple<UserInfo, string, bool>>(); var list = await ProfessorManager.Search(myUserInfo.uuid,queryStr, index, size); if (list != null && list.Count > 0) { using (UserRepository repo = new UserRepository()) { List<string> eduList = await ProfessorManager.GetUserEducations(myUserInfo.uuid); foreach (var v in list) { Guid uuid = Guid.Parse(v.Id); var userinfo = await repo.GetUserInfoByUuidAsync(uuid); string three = !string.IsNullOrEmpty(v.Diwei) ? v.Diwei.Trim() : ""; bool isXY = ProfessorManager.IsXiaoYou(eduList, v.Education); ret.Add(Tuple.Create(userinfo, three, isXY)); } } } return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, ret, HttpStatusCode.OK, customStatus.Success); }
public async Task<HttpResponseMessage> PostInitialize([FromBody]LoginParameter loginParameter) { string openid = loginParameter.openID; if (string.IsNullOrEmpty(openid)) { return WebApiHelper.HttpRMtoJson(loginParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments); } using (UserRepository userRepository = new UserRepository()) { userinfo = await userRepository.GetUserInfoByOpenid(openid); if (userinfo == null) { return WebApiHelper.HttpRMtoJson(loginParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound); } userinfo.NumOfContacts = await userRepository.GetUserContactNumber(userinfo.uuid); userinfo.NumOfBeenTo = await userRepository.GetUserBeenToNumber(userinfo.uuid); userinfo.NumOfFavorite = await userRepository.GetuserFavoriteNumber(userinfo.uuid); return WebApiHelper.HttpRMtoJson(userinfo, HttpStatusCode.OK, customStatus.Success); } }
public async Task<HttpResponseMessage> PostUpdateResearchField([FromBody]DualParameter postParameter) { string openid = postParameter.openID; if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(postParameter.textMsg)) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments); } using (UserRepository userRepository = new UserRepository()) { var userUuid = await userRepository.GetUserUuidByOpenid(openid); if (userUuid == Guid.Empty) { return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound); } else { UserInfo userinfo = await userRepository.GetUserInfoByOpenid(openid); //更新研究兴趣 userinfo.Interests = postParameter.textMsg; bool flag = await userRepository.SaveUserInfo(userinfo); if(flag) return WebApiHelper.HttpRMtoJson(flag, HttpStatusCode.OK, customStatus.Success); else return WebApiHelper.HttpRMtoJson("没有保存成功", HttpStatusCode.OK, customStatus.Fail); } } }
public async Task<HttpResponseMessage> PostChatInitialize([FromBody]DualParameter postParameter) { string openid = postParameter.openID; Guid uuid = postParameter.uuid; int pageIndex = postParameter.pageIndex; if(string.IsNullOrEmpty(openid)) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments); } using(UserRepository userRepository = new UserRepository()) { var user = await userRepository.GetUserInfoByOpenid(openid); var touser = await userRepository.GetUserInfoByUuidAsync(uuid); if(user == null || touser == null) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound); } var chatList = await WeChatReceiveHelper.GetMessage(user.uuid.ToString().ToUpper(), touser.uuid.ToString().ToUpper(), pageIndex); return WebApiHelper.HttpRMtoJson(Tuple.Create(user, touser, chatList), HttpStatusCode.OK, customStatus.Success); } }
protected virtual async Task<ActionResult> LoginCallBack(string code, string state, string xueshengUrl,string jiaoshouUrl) { try { if (code == null) return Content("code是空!"); //LogHelper.LogInfoAsync(typeof(WeChatCallBackController), @"1\code=" + code); var config = BK.Configuration.BK_ConfigurationManager.GetConfig<WeixinConfig>(); bool Isbinded = true; var openid = await WXAuthHelper.GetOpenIdWXCallBackAsync(config.WeixinAppId, config.WeixinAppSecret, code, async delegate (OAuthAccessTokenResult result) { //是否需要绑定账号 using (UserRepository userRepository = new UserRepository()) { //如果OPenid绑定了,就不需要再向微信请求userinfo的信息了. //如果没有绑定,则需要刷新accesstoken,然后请求userinfo;并将userinfo存入redis。 Isbinded = await userRepository.IsUserOpenidExist(result.openid); } if (!Isbinded) //如果没有绑定就要存储token信息 await WeChatCallBackControllerHelper.SaveOAuthUserTokenAsync(result); return !Isbinded;//如果绑定了就不需要获取userinfo信息了 }, async delegate (OAuthUserInfo user) { //如果需要绑定用户信息则,此处存储用户信息 return await WeChatCallBackControllerHelper.SaveOAuthUserInfoToRedis(user); }); //再次判断是否需要绑定 //存入cookie供前端代码调用 Response.Cookies["openid"].Value = openid; Response.Cookies["openid"].Expires = DateTime.Now.AddYears(1); //如果是tester则不管怎么样都要去注册。 //可以通过wechat.51science.cn/weixinapi/addtester/?openid=xxx来添加 //wechat.51science.cn/weixinapi/rmtester/?openid=xxx删除 bool isToRegister = !Isbinded || await WXAuthHelper.IsTester(openid); //BKLogger.LogInfoAsync(typeof(MVCNeedWeixinCallBackBaseController), "isToRegister:"+isToRegister); //BKLogger.LogInfoAsync(typeof(MVCNeedWeixinCallBackBaseController), "Isbinded:" + Isbinded); if (!isToRegister) { //记录用户行为 await UserLoginBehaviorOp.AddLoginCountAsync(openid); await UserLoginBehaviorOp.AddUpdateLastLoginTimeAsync(openid); //跳转到个人主页 UserInfo userinfo = null; using (UserRepository userRepository = new UserRepository()) { userinfo = await userRepository.GetUserInfoByOpenid(openid); } BKLogger.LogInfoAsync(typeof(MVCNeedWeixinCallBackBaseController), "userinfo:"+userinfo.uuid.ToString()+" type:"+userinfo.IsBusiness.Value.ToString()); BizMQ bizobj = new BizMQ("微信登陆", openid, userinfo.uuid,userinfo.Name+ " 登陆了!"); BKLogger.LogBizAsync(typeof(MVCNeedWeixinCallBackBaseController), bizobj); //存cookie var cookieResult = Response.Cookies["type"].Value = userinfo.IsBusiness.Value.ToString(); Response.Cookies["type"].Expires = DateTime.Now.AddYears(1); Response.Cookies["uuid"].Value = userinfo.uuid.ToString(); Response.Cookies["uuid"].Expires = DateTime.Now.AddYears(1); //LogHelper.LogInfoAsync(typeof(MVCNeedWeixinCallBackBaseController), cookieResult.ToString()); if (userinfo.IsBusiness.Value == 0) return Redirect(jiaoshouUrl); else return Redirect(xueshengUrl); } else { // login页面 return Redirect(LOGIN_PAGE_URL); } } catch (Exception ex) { BKLogger.LogErrorAsync(typeof(MVCNeedWeixinCallBackBaseController), ex); return Content(ex.ToString()); } }
public async Task<HttpResponseMessage> PostResetPassword([FromBody]PasswordParameter postParameter) { string openid = postParameter.openID; string old = postParameter.oldPassword; string newp = postParameter.newPassword; if (string.IsNullOrEmpty(openid)|| string.IsNullOrEmpty(old) || string.IsNullOrEmpty(newp)) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments); } using (UserRepository userRepository = new UserRepository()) { userinfo = await userRepository.GetUserInfoByOpenid(openid); if (userinfo == null) return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound); else { if (userinfo.AccountEmail.Contains("@phone.51science.cn")) return WebApiHelper.HttpRMtoJson(userinfo.AccountEmail.Replace("@phone.51science.cn", ""), HttpStatusCode.OK, customStatus.Success); else return WebApiHelper.HttpRMtoJson(userinfo.AccountEmail, HttpStatusCode.OK, customStatus.Success); } } }
public async Task<HttpResponseMessage> PostGetArticleById([FromBody]EKCommentParameter postParameter) { string openid = postParameter.openID; long ekid = postParameter.Id; if (string.IsNullOrEmpty(openid) || ekid == 0) { return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments); } Guid user; using (UserRepository repo = new UserRepository()) { var userinfo = await repo.GetUserInfoByOpenid(openid); user = userinfo.uuid; } var ret = await EKArticleManager.GetById(ekid); //将文章插图的地址转义 ret.BodyText = WebApiHelper.GetEscapedBodyText(ret); await EKArticleManager.AddReadCountAsync(ekid); await EKArticleManager.SetReadPeopleAsync(ekid, user, DateTime.Now); return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, ret, HttpStatusCode.OK, customStatus.Success); }
public async Task<HttpResponseMessage> PostInitializeProfessorRecords([FromBody]BaseParameter postParameter) { string openid = postParameter.openID; if (string.IsNullOrEmpty(openid)) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments); } using (UserRepository userRepository = new UserRepository()) { var userUuid = await userRepository.GetUserUuidByOpenid(openid); if (userUuid == Guid.Empty) { return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound); } else { Dictionary<string, object> tempResult = new Dictionary<string, object>(); UserInfo userinfo = await userRepository.GetUserInfoByOpenid(openid); //研究兴趣 string researchField = userinfo.Interests; tempResult.Add("yjly", researchField); //学术地位 List<UserAcademic> userAcademicList = await userRepository.GetUserRecords(new UserAcademic { AccountEmail_uuid = userUuid }); List<string> acadmeicList = RepositoryHelper.ConvertUserAcademicToString(userAcademicList); tempResult.Add("xsdw", Tuple.Create("UserAcademic", acadmeicList)); //项目资助 List<UserAwards> userAwardList = await userRepository.GetUserRecords(new UserAwards() { AccountEmail_uuid = userUuid }); tempResult.Add("zzxm", Tuple.Create("UserAwards", userAwardList)); //教育经历 List<UserEducation> userEducationList = await userRepository.GetUserRecords(new UserEducation() { AccountEmail_uuid = userUuid }); tempResult.Add("jyjl", Tuple.Create("UserEducation", userEducationList)); //工作经历 List<UserExperience> userExperienceList = await userRepository.GetUserRecords(new UserExperience() { AccountEmail_uuid = userUuid }); tempResult.Add("gzjl", Tuple.Create("UserExperience", userExperienceList)); //论文数 int userArticleNumber = await userRepository.GetUserRecordsNumber(new UserArticle() { AccountEmail_uuid = userUuid }); tempResult.Add("lws", Tuple.Create("UserArticle", userArticleNumber)); //专利数 int userPatendNumber = await userRepository.GetUserRecordsNumber(new UserPatent() { AccountEmail_uuid = userUuid }); tempResult.Add("zls", Tuple.Create("UserPatent", userPatendNumber)); //访问过我的人还访问过谁 int visitorsBeenToNumber = await userRepository.GetVisitorBeenToNumber(userUuid); List<UserInfo> visitorsBeenTo = await userRepository.GetVisitorBeenTo(userUuid, 6); tempResult.Add("visitorsBeenToNumber", visitorsBeenToNumber); tempResult.Add("visitorsBeenToTopSix", visitorsBeenTo); return WebApiHelper.HttpRMtoJson(tempResult, HttpStatusCode.OK, customStatus.Success); } } }
public async Task<HttpResponseMessage> PostGetReadUsers([FromBody]EKCommentParameter postParameter) { string openid = postParameter.openID; long ekid = postParameter.Id; int pageIndex = postParameter.pageIndex; int pageSize = postParameter.pageSize; int fromNo = pageIndex * pageSize; int toNo = fromNo + pageSize; if (string.IsNullOrEmpty(openid) || ekid == 0) { return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments); } using (UserRepository userR = new UserRepository()) { UserInfo user = await userR.GetUserInfoByOpenid(openid); var redis = new RedisManager2<WeChatRedisConfig>(); var zans = await redis.GetRangeByRankAsync<EKTodayRedis, EKReadPepleZsetAttribute>(ekid.ToString(), from: fromNo, to: toNo); List<UserInfo> ret = new List<UserInfo>(); if (zans != null && zans.Count() > 0) { foreach (var v in zans) { UserInfo tmp = await userR.GetUserInfoByUuidAsync(Guid.Parse(v.Key)); ret.Add(tmp); } } return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, ret, HttpStatusCode.OK, customStatus.Success); } }
public async Task<HttpResponseMessage> PostIsZaned([FromBody]EKCommentParameter postParameter) { string openid = postParameter.openID; long ekid = postParameter.Id; if (string.IsNullOrEmpty(openid) || ekid == 0) { return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments); } using (UserRepository userR = new UserRepository()) { UserInfo user = await userR.GetUserInfoByOpenid(openid); var redis = new RedisManager2<WeChatRedisConfig>(); double score = await redis.GetScoreEveryKeyAsync<EKTodayRedis, EKZanPepleZsetAttribute>(ekid.ToString(), user.uuid.ToString()); if(score==0) return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, false, HttpStatusCode.OK, customStatus.Success); return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, true, HttpStatusCode.OK, customStatus.Success); } }
public async Task<HttpResponseMessage> PostFindStudents([FromBody]BaseParameter postParameter) { string openid = postParameter.openID; if (string.IsNullOrEmpty(openid)) { return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments); } //获取用户uuid 学校与院系与专业信息。 Guid useruuid; string xuexiaoname, yuanxiname; long? rf; using (UserRepository userRepository = new UserRepository()) { var userinfo = await userRepository.GetUserInfoByOpenid(openid); useruuid = userinfo.uuid; xuexiaoname = userinfo.Unit; yuanxiname = userinfo.Faculty; rf = userinfo.ResearchFieldId; if (string.IsNullOrEmpty(xuexiaoname) || string.IsNullOrEmpty(yuanxiname)) return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, "学校,院系有个为空!", HttpStatusCode.OK, customStatus.InvalidArguments); //获取score double univScore, depScore; if (!FindHelper.GetUnivDeptScore(xuexiaoname, yuanxiname, out univScore, out depScore)) return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, "学校,院系名称不正规!", HttpStatusCode.OK, customStatus.InvalidArguments); //拿到三个集合 double rfScore = Convert.ToDouble(rf.Value); var set = await FindHelper.GetThreeSet(false, univScore, depScore, rfScore); var retUuid = await FindHelper.FindStudtenRule(useruuid.ToString().ToUpper(), set.Item1, set.Item2, set.Item3, postParameter.pageIndex, postParameter.pageSize); List<UserInfo> ret = new List<UserInfo>(); foreach (var s in retUuid) { var v = await userRepository.GetUserInfoByUuidAsync(Guid.Parse(s)); if (v != null) ret.Add(v); //if (v.ResearchFieldId == 0) // v.SubResearchFieldId = 120513;//未知 } return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, ret, HttpStatusCode.OK, customStatus.Success); } }
public async Task<HttpResponseMessage> PostInitialize([FromBody]RegisterParameter registerParam, [FromUri]string type) { string openid = registerParam.openID; if(string.IsNullOrEmpty(openid)) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments); } pre_register prereg = null; using(UserRepository userRepository = new UserRepository()) { var userinfoRedis = await BK.CommonLib.Weixin.User.WXAuthHelper.GetUserInfoByOPenId(openid); if(type != "update") { prereg = await userRepository.GetPreRegisterByOpenid(openid); if(prereg == null) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound); } userinfo = new UserInfo() { Photo = userinfoRedis.HeadImageUrl.Substring(0, userinfoRedis.HeadImageUrl.LastIndexOf("/0")) + "/96", Name = prereg.name, Gender = userinfoRedis.Sex, }; } else { userinfo = await userRepository.GetUserInfoByOpenid(openid); userinfo.Gender = userinfoRedis.Sex; } return WebApiHelper.HttpRMtoJson(userinfo, HttpStatusCode.OK, customStatus.Success); } }
public async Task<HttpResponseMessage> PostGetInterests([FromBody]BaseParameter postParameter) { string openid = postParameter.openID; if (string.IsNullOrEmpty(openid)) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments); } using (UserRepository userRepository = new UserRepository()) { var userUuid = await userRepository.GetUserUuidByOpenid(openid); if (userUuid == Guid.Empty) { return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.NotFound); } else { UserInfo userinfo = await userRepository.GetUserInfoByOpenid(openid); //研究兴趣 string researchField = userinfo.Interests; return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, researchField, HttpStatusCode.OK, customStatus.Success); } } }
public async Task<HttpResponseMessage> PostComplement([FromBody]ComplementParameter registerParam, [FromUri]string type) { string openid = registerParam.openID; string university = registerParam.university; string faculty = registerParam.faculty; int researchFieldId = registerParam.researchFieldId; short degree = registerParam.degree; short enrollment = registerParam.enrollment; string gender = registerParam.Gender; string name = registerParam.name; string position = registerParam.position; short isBusiness = registerParam.isBusiness; if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(university) || string.IsNullOrEmpty(faculty) || researchFieldId == 0 || string.IsNullOrEmpty(gender) || string.IsNullOrEmpty(name)) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments); } if (string.IsNullOrEmpty(position) && isBusiness == 0) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments); } if (isBusiness == 2 && enrollment == 0) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments); } var preRegisterRedis = await UserInfoControllerHelper.GetUserInfoRedisByOpenid(openid); string preRegisterAccount = preRegisterRedis.PreRegisterAccount; pre_register preRegister = null; if (type != "update") { using (UserRepository userRepository = new UserRepository()) { userinfo = await userRepository.GetUserInfoByAccount(preRegisterAccount); preRegister = await userRepository.GetPreRegisterByOpenid(openid); } if (userinfo != null) return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.AccountExist); if (preRegister == null) return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound); } //更新数据库的userinfo bool result = await UserInfoControllerHelper.SaveUserInfo(registerParam, preRegister); if (result) { //更新redis的性别 UserInfoRedis redisUser = new UserInfoRedis(); redisUser.Openid = openid; redisUser.Sex = gender; await RedisManager.SaveObjectAsync(redisUser); using (UserRepository userRepository = new UserRepository()) { userinfo = await userRepository.GetUserInfoByOpenid(openid); } if (await ComplexLocationManager.UpdateComplexLocationAsync(openid, userinfo.IsBusiness ?? 0, int.Parse(userinfo.Gender), userinfo.ResearchFieldId ?? 0)) { //位置索引添加供筛选字段 } return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Success); } else { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Fail); } }
public async Task<HttpResponseMessage> PostInitialize([FromBody]LocationParameter postParameter) { string openid = postParameter.openID; int? radius = postParameter.Radius; int pageIndex = postParameter.pageIndex; int pageSize = postParameter.pageSize; int? isBusiness = postParameter.IsBusiness; int? gender = postParameter.Gender; int? researchFieldId = postParameter.ResearchFieldId; if(string.IsNullOrEmpty(openid) || pageIndex == 0 || pageSize == 0) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments); } if(radius == null) radius = 3; List<UserInfo> lcList = new List<UserInfo>(); if(researchFieldId == 0) { using(UserRepository userRepository = new UserRepository()) { UserInfo ui = await userRepository.GetUserInfoByOpenid(openid); if(ui != null) researchFieldId = (int?)ui.ResearchFieldId; else researchFieldId = null; } } List<ComplexLocation> locationList = await ComplexLocationManager.GetDistanceInKmByIdAsync(openid, (int)radius, isBusiness, gender, researchFieldId); if(locationList == null) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound); } if(locationList.Count > 0) { ComplexLocation myLocation = null; //有可能第一个值是自己 if(locationList[0].Id == openid) { myLocation = locationList[0]; locationList.RemoveAt(0); } else { myLocation = await ComplexLocationManager.GetLocationObjectByOpenidAsync(openid); } //只有自己 if(locationList.Count == 0) { return WebApiHelper.HttpRMtoJson(lcList, HttpStatusCode.OK, customStatus.Success); } using(UserRepository userRepository = new UserRepository()) { //去除未绑定等 for(int i = 0; i < locationList.Count; i++) { if(!await userRepository.IsUserOpenidExist(locationList[i].Id)) { locationList.RemoveAt(i); } } //保留分页内的数据 int itemCount = locationList.Count; int PageCount = PageCount = itemCount % pageSize == 0 ? itemCount / pageSize : itemCount / pageSize + 1; if(pageIndex > 0) { locationList = locationList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); } //取出userinfo数据 填充距离数据 foreach(ComplexLocation l in locationList) { var ui = await userRepository.GetUserInfoByOpenid(l.Id); if(ui != null) { ui.Distance = ComplexLocationManager.GetDistanceBetween(myLocation.Coordinate, l.Coordinate); lcList.Add(ui); } } return WebApiHelper.HttpRMtoJson(Tuple.Create(itemCount, PageCount, lcList), HttpStatusCode.OK, customStatus.Success); } } else return WebApiHelper.HttpRMtoJson(lcList, HttpStatusCode.OK, customStatus.Success); }
public async Task<HttpResponseMessage> PostSubmitUserIntroduction([FromBody]RegisterParameter postParameter) { string openid = postParameter.openID; string name = postParameter.name; if(string.IsNullOrEmpty(openid)) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments); } using(UserRepository userRepository = new UserRepository()) { var uclist = await userRepository.GetUserInfoByOpenid(openid); if(uclist == null) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound); } uclist.UserIntroduction = name; if(await userRepository.SaveUserInfo(uclist)) return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Success); else return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Fail); } }
public async Task<HttpResponseMessage> PostInitializeUserIntroduction([FromBody]BaseParameter postParameter) { string openid = postParameter.openID; if (string.IsNullOrEmpty(openid)) { return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments); } using (UserRepository userRepository = new UserRepository()) { var uclist = await userRepository.GetUserInfoByOpenid(openid); if (uclist == null) { return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound); } return WebApiHelper.HttpRMtoJson(uclist.UserIntroduction, HttpStatusCode.OK, customStatus.Success); } }