public HttpResponseMessage AddBroker([FromBody]BrokerModel brokerModel) { var validMsg = ""; if (!brokerModel.ValidateModel(out validMsg)) { return PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证错误,请重新输入")); } #region 验证码判断 解密 var strDes = EncrypHelper.Decrypt(brokerModel.Hidm, "Hos2xNLrgfaYFY2MKuFf3g==");//解密 string[] str = strDes.Split('$'); if (str.Count() < 2) { return PageHelper.toJson(PageHelper.ReturnValue(false, "验证码错误,请重新发送!")); } string source = str[0];//获取验证码和手机号 DateTime date = Convert.ToDateTime(str[1]);//获取发送验证码的时间 DateTime dateNow = Convert.ToDateTime(DateTime.Now.ToLongTimeString());//获取当前时间 TimeSpan ts = dateNow.Subtract(date); double secMinu = ts.TotalMinutes;//得到发送时间与现在时间的时间间隔分钟数 if (secMinu > 3) //发送时间与接受时间是否大于3分钟 { return PageHelper.toJson(PageHelper.ReturnValue(false, "你已超过时间验证,请重新发送验证码!")); } else { // source.Split('#')[0] 验证码 // source.Split('#')[1] 手机号 if (brokerModel.Phone != source.Split('#')[1])//判断手机号是否一致 { return PageHelper.toJson(PageHelper.ReturnValue(false, "验证码错误,请重新发送!")); } if (brokerModel.MobileYzm != source.Split('#')[0])//判断验证码是否一致 { return PageHelper.toJson(PageHelper.ReturnValue(false, "验证码错误,请重新发送!")); } } #endregion #region 判断两次密码是否一致 if (brokerModel.Password != brokerModel.SecondPassword) { return PageHelper.toJson(PageHelper.ReturnValue(false, "手机号不能为空")); } #endregion #region 判断邀请码是否存在真实 (brokerInfoController 中GetBrokerByInvitationCode方法也同一判断) MessageDetailEntity messageDetail = null; if (!string.IsNullOrEmpty(brokerModel.inviteCode)) { MessageDetailSearchCondition messageSearchcondition = new MessageDetailSearchCondition { InvitationCode = brokerModel.inviteCode, Title = "推荐经纪人" }; messageDetail = _MessageService.GetMessageDetailsByCondition(messageSearchcondition).FirstOrDefault();//判断邀请码是否存在 if (messageDetail == null) { return PageHelper.toJson(PageHelper.ReturnValue(false, "邀请码错误!")); } } #endregion #region UC用户创建 杨定鹏 2015年5月28日14:52:48 var user = _userService.GetUserByName(brokerModel.UserName); if(user!=null) { return PageHelper.toJson(PageHelper.ReturnValue(false, "用户名已经存在")); } var condition = new BrokerSearchCondition { OrderBy = EnumBrokerSearchOrderBy.OrderById, State = 1, Phone = brokerModel.Phone }; //判断user表和Broker表中是否存在用户名 int user2 = _brokerService.GetBrokerCount(condition); if (user2 != 0) return PageHelper.toJson(PageHelper.ReturnValue(false, "手机号已经存在")); var brokerRole = _roleService.GetRoleByName("user"); //User权限缺少时自动添加 if (brokerRole == null) { brokerRole = new Role { RoleName = "user", RolePermissions = null, Status = RoleStatus.Normal, Description = "刚注册的用户默认归为普通用户user" }; } var newUser = new UserBase { UserName = brokerModel.UserName, Password = brokerModel.Password, RegTime = DateTime.Now, NormalizedName = brokerModel.UserName.ToLower(), //注册用户添加权限 UserRoles = new List<UserRole>(){new UserRole() { Role = brokerRole }}, Status = 0 }; PasswordHelper.SetPasswordHashed(newUser, brokerModel.Password); #endregion #region Broker用户创建 杨定鹏 2015年5月28日14:53:32 var model = new BrokerEntity(); model.UserId = _userService.InsertUser(newUser).Id; model.Brokername = brokerModel.Phone; model.Nickname = brokerModel.Nickname; model.Phone = brokerModel.Phone; model.Totalpoints = 0; model.Amount = 0; model.Usertype = EnumUserType.普通用户; model.Regtime = DateTime.Now; model.State = 1; model.Adduser = 0; model.Addtime = DateTime.Now; model.Upuser = 0; model.Uptime = DateTime.Now; //判断初始等级是否存在,否则创建 var level = _levelService.GetLevelsByCondition(new LevelSearchCondition { Name = "默认等级" }).FirstOrDefault(); if (level == null) { var levelModel = new LevelEntity { Name = "默认等级", Describe = "系统默认初始创建", Url = "", Uptime = DateTime.Now, Addtime = DateTime.Now, }; _levelService.Create(levelModel); } model.Level = level; var newBroker = _brokerService.Create(model); #endregion #region 推荐经纪人 if (!string.IsNullOrEmpty(brokerModel.inviteCode)) { //添加经纪人 var entity = new RecommendAgentEntity { PresenteebId = newBroker.Id, Qq = newBroker.Qq.ToString(), Agentlevel = newBroker.Agentlevel, Brokername = newBroker.Brokername, Phone = newBroker.Phone, Regtime = DateTime.Now, Broker = _brokerService.GetBrokerById(Convert.ToInt32(messageDetail.InvitationId)), Uptime = DateTime.Now, Addtime = DateTime.Now, }; _recommendagentService.Create(entity); } #endregion return PageHelper.toJson(PageHelper.ReturnValue(true, "注册成功")); }
public HttpResponseMessage SearchMessageDetail(string endTime, string startTime, string type, EnumMessageDetailSearchOrderBy orderByAll = EnumMessageDetailSearchOrderBy .OrderById, bool isDes = true, int page = 1, int pageSize = 10) { //================================================赵旭初 by 2015-05-13 start=============================================================== string strStarttime = ""; string strEndtime = ""; string strType = ""; if (startTime == null || startTime.Length <= 0) strStarttime = "1900-01-01"; else strStarttime = startTime.Substring(0, 10); if (endTime == null || endTime.Length <= 0) strEndtime = string.Format(DateTime.Now.ToShortDateString(), "yyyy-mm-dd"); else strEndtime = endTime.Substring(0, 10); if(!string.IsNullOrEmpty(type)) { strType = type; } var mDetailCondition = new MessageDetailSearchCondition() { AddtimeBegin = Convert.ToDateTime(strStarttime), AddtimeEnd = Convert.ToDateTime(strEndtime).AddDays(1), Title = strType, Page = Convert.ToInt32(page), PageCount = pageSize, OrderBy =orderByAll , isDescending =isDes }; var list = _messageDetailService.GetMessageDetailsByCondition(mDetailCondition).Select(c => new { c.Id, c.Title, c.Sender, c.Mobile, c.Content, c.Addtime }).ToList(); var listCount = _messageDetailService.GetMessageDetailCount(mDetailCondition); return PageHelper.toJson(new { List = list, Condition = mDetailCondition, totalCount = listCount }); //================================================赵旭初 by 2015-05-13 end=============================================================== }
public int GetMessageDetailCount (MessageDetailSearchCondition condition) { var query = _messagedetailRepository.Table; try { if (condition.AddtimeBegin.HasValue) { query = query.Where(q => q.Addtime>= condition.AddtimeBegin.Value); } if (condition.AddtimeEnd.HasValue) { query = query.Where(q => q.Addtime < condition.AddtimeEnd.Value); } if (!string.IsNullOrEmpty(condition.Title)) { query = query.Where(q => q.Title.Contains(condition.Title)); } if (!string.IsNullOrEmpty(condition.Content)) { query = query.Where(q => q.Content.Contains(condition.Content)); } if (condition.Ids != null && condition.Ids.Any()) { query = query.Where(q => condition.Ids.Contains(q.Id)); } if (!string.IsNullOrEmpty(condition.InvitationCode)) { query = query.Where(q => q.InvitationCode == (condition.InvitationCode)); } if (!string.IsNullOrEmpty(condition.InvitationId)) { query = query.Where(q => q.InvitationId == (condition.InvitationId)); } if (condition.Senders != null && condition.Senders.Any()) { query = query.Where(q => condition.Senders.Contains(q.Sender)); } return query.Count(); } catch(Exception e) { _log.Error(e,"数据库操作出错"); return -1; } }
public IQueryable<MessageDetailEntity> GetMessageDetailsByCondition(MessageDetailSearchCondition condition) { var query = _messagedetailRepository.Table; try { if (condition.AddtimeBegin.HasValue) { query = query.Where(q => q.Addtime>= condition.AddtimeBegin.Value); } if (condition.AddtimeEnd.HasValue) { query = query.Where(q => q.Addtime < condition.AddtimeEnd.Value); } if (!string.IsNullOrEmpty(condition.Title)) { query = query.Where(q => q.Title.Contains(condition.Title)); } if (!string.IsNullOrEmpty(condition.Content)) { query = query.Where(q => q.Content.Contains(condition.Content)); } if (!string.IsNullOrEmpty(condition.InvitationCode)) { query = query.Where(q => q.InvitationCode == (condition.InvitationCode)); } if (!string.IsNullOrEmpty(condition.InvitationId)) { query = query.Where(q => q.InvitationId == (condition.InvitationId)); } if (condition.Ids != null && condition.Ids.Any()) { query = query.Where(q => condition.Ids.Contains(q.Id)); } if (condition.Senders != null && condition.Senders.Any()) { query = query.Where(q => condition.Senders.Contains(q.Sender)); } if(condition.OrderBy.HasValue) { switch (condition.OrderBy.Value) { case EnumMessageDetailSearchOrderBy.OrderById: query = condition.isDescending?query.OrderByDescending(q=>q.Id):query.OrderBy(q=>q.Id); break; case EnumMessageDetailSearchOrderBy.OrderByTitle: query = condition.isDescending ? query.OrderByDescending(q => q.Title) : query.OrderBy(q => q.Title); break; case EnumMessageDetailSearchOrderBy.OrderByContent: query = condition.isDescending ? query.OrderByDescending(q => q.Content) : query.OrderBy(q => q.Content); break; case EnumMessageDetailSearchOrderBy.OrderByMobile: query = condition.isDescending ? query.OrderByDescending(q => q.Mobile) : query.OrderBy(q => q.Mobile); break; case EnumMessageDetailSearchOrderBy.OrderByAddtime: query = condition.isDescending ? query.OrderByDescending(q => q.Addtime) : query.OrderBy(q => q.Addtime); break; } } else { query = query.OrderByDescending(q=>q.Id); } if (condition.Page.HasValue && condition.PageCount.HasValue) { query = query.Skip((condition.Page.Value - 1)*condition.PageCount.Value).Take(condition.PageCount.Value); } return query; } catch(Exception e) { _log.Error(e,"数据库操作出错"); return null; } }
public HttpResponseMessage GetBrokerByInvitationCode([FromBody] string invitationCode) { if (!string.IsNullOrEmpty(invitationCode)) { MessageDetailSearchCondition messageSearchcondition = new MessageDetailSearchCondition { InvitationCode = invitationCode, Title = "推荐经纪人" }; var messageDetail = _MessageService.GetMessageDetailsByCondition(messageSearchcondition).FirstOrDefault(); if (messageDetail != null) { return PageHelper.toJson(new { invitationCode = invitationCode }); } return PageHelper.toJson(PageHelper.ReturnValue(false, "数据错误")); } return PageHelper.toJson(PageHelper.ReturnValue(false, "数据错误")); }