public BrokerEntity Update(BrokerEntity entity) { try { _brokerRepository.Update(entity); return entity; } catch (Exception e) { _log.Error(e, "数据库操作出错"); return null; } }
public bool Delete(BrokerEntity entity) { try { _brokerRepository.Delete(entity); return true; } catch (Exception e) { _log.Error(e, "数据库操作出错"); return false; } }
public HttpResponseMessage AddAdmin([FromBody] BrokerModel brokerModel) { var model = new BrokerEntity { Id = brokerModel.Id, }; if (brokerModel.Type == "add") { try { if (_brokerService.Create(model) != null) { return PageHelper.toJson(PageHelper.ReturnValue(true, "添加成功")); } } catch (Exception) { return PageHelper.toJson(PageHelper.ReturnValue(false, "添加失败")); } } if (brokerModel.Type == "edit") { try { if (_brokerService.Update(_brokerService.GetBrokerById(model.Id)) != null) { return PageHelper.toJson(PageHelper.ReturnValue(true, "修改成功")); } } catch (Exception) { return PageHelper.toJson(PageHelper.ReturnValue(false, "修改失败")); } } return PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证失败")); }
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 ExternalLoginOrAdd([FromBody]UserModel model) { if(!string.IsNullOrEmpty( model.Phone) && !string.IsNullOrEmpty( model.Password)) { //1 先判断手机号是否存在 var condition = new BrokerSearchCondition { State = 1, Phone = model.Phone }; //判断Broker表中是否存在手机号 int brokerCount = _brokerService.GetBrokerCount(condition); if (brokerCount != 0) { //存在 就进行登录 #region 登录 BrokerEntity broker = _brokerService.GetBrokersByCondition(condition).FirstOrDefault(); if (broker == null) { return PageHelper.toJson(PageHelper.ReturnValue(false, "手机号或密码错误")); } var user = _userService.FindUser(broker.UserId); if (user == null) { return PageHelper.toJson(PageHelper.ReturnValue(false, "用户名或密码错误")); } if (!PasswordHelper.ValidatePasswordHashed(user, model.Password)) { return PageHelper.toJson(PageHelper.ReturnValue(false, "用户名或密码错误")); } _authenticationService.SignIn(user, model.Remember); return PageHelper.toJson(PageHelper.ReturnValue(true, "ok")); #endregion } else //不存在 就进行注册 { #region UC用户创建 杨定鹏 2015年5月28日14:52:48 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 = model.Phone, Password = model.Password, RegTime = DateTime.Now, NormalizedName = model.Phone, //注册用户添加权限 UserRoles = new List<UserRole>(){new UserRole() { Role = brokerRole }}, Status = 0 }; PasswordHelper.SetPasswordHashed(newUser, model.Password); #endregion #region Broker用户创建 杨定鹏 2015年5月28日14:53:32 var models = new BrokerEntity(); models.UserId = _userService.InsertUser(newUser).Id; models.Brokername = model.Phone; models.Nickname = model.Phone; models.Phone = model.Phone; models.Totalpoints = 0; models.Amount = 0; models.Usertype = EnumUserType.普通用户; models.Regtime = DateTime.Now; models.State = 1; models.Adduser = 0; models.Addtime = DateTime.Now; models.Upuser = 0; models.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); } models.Level = level; var newBroker = _brokerService.Create(models); #endregion return PageHelper.toJson(PageHelper.ReturnValue(true, "ok")); } } return PageHelper.toJson(PageHelper.ReturnValue(false, "请填写手机号和密码")); }
public HttpResponseMessage SetPay([FromBody]PayModel payModel) { var user = (UserBase) _workContext.CurrentUser; var broker = new BrokerEntity { }; var BrokeAccount = new BrokeAccountEntity { }; var BrokerWithdraw = new BrokerWithdrawEntity { }; var BrokerWithDrawDetail = new BrokerWithdrawDetailEntity { }; //var condition = new BrokerWithdrawDetailSearchCondition //{ // BrokerWithdraw = payModel.Id //}; if (user == null) { //broker = _brokerService.GetBrokerByUserId(user.Id); //获取当前经纪人 //if (broker == null) //{ return PageHelper.toJson(PageHelper.ReturnValue(false, "获取用户失败,请检查是否登陆")); //} } if (string.IsNullOrEmpty(payModel.Id)) { return PageHelper.toJson(PageHelper.ReturnValue(false, "数据不能为空")); } //根据经纪人提现ID查询经纪人体现信息 BrokerWithdraw = _brokerwithdrawService.GetBrokerWithdrawById(Convert.ToInt32(payModel.Id)); // 判断提现状态,如果状态为一,则表示已经提现 if (BrokerWithdraw.State == 1) { return PageHelper.toJson(PageHelper.ReturnValue(false, "财务已经打款")); } //////////////////////////////////////////////////////////////////////////////////////////////// //if (string.IsNullOrEmpty(payModel.Ids)) //{ // return PageHelper.toJson(PageHelper.ReturnValue(false, "数据不能为空")); //} //if (string.IsNullOrEmpty(payModel.BrokeAccountId)) //{ // return PageHelper.toJson(PageHelper.ReturnValue(false,"数据不能为空")); //} //构建查询实体 var seach = new BrokerWithdrawDetailSearchCondition { OrderBy = EnumBrokerWithdrawDetailSearchOrderBy.OrderByTime, BrokerWithdraw = _brokerwithdrawService.GetBrokerWithdrawById(Convert.ToInt32(payModel.Id)), }; var list = _brokerwithdrawDetailService.GetBrokerWithdrawDetailsByCondition(seach).Select(b => new { b.Id, b.Withdrawnum, b.BrokeAccount_Id, b.Withdrawtime, b.Type, b.BrokerWithdraw.WithdrawDesc, b.BrokerWithdraw.BankCard.Num, }).ToList().Select(a => new { a.Id, a.Withdrawnum, a.BrokeAccount_Id, a.Type, a.Num, WithdrawDesc = a.WithdrawDesc, Withdrawtime = a.Withdrawtime.ToString("yyy-MM-dd"), }); foreach (var p in list) { if (p == null) { return PageHelper.toJson(PageHelper.ReturnValue(false, "数据错误")); } if (Convert.ToInt32(p.Type) == 0) { var blModel = new BLPayEntity { Name = payModel.Name, Describe = payModel.Describe, BankCard = p.Num, Accountantid = user.Id, Amount = p.Withdrawnum, Adduser = user.Id, Upuser = user.Id, Addtime = DateTime.Now, Uptime = DateTime.Now, }; _blPayService.Create(blModel); } if (Convert.ToInt32(p.Type) == 1) { var breModel = new BRECPayEntity { Name = payModel.Name, Describe = payModel.Describe, BankCard = p.Num, Accountantid = user.Id, Amount = p.Withdrawnum, Adduser = user.Id, Upuser = user.Id, Addtime = DateTime.Now, Uptime = DateTime.Now, }; _brecPayService.Create(breModel); } BrokeAccount = _brokerAcountService.GetBrokeAccountById(p.BrokeAccount_Id.Id); BrokeAccount.State = 1; BrokeAccount.Uptime = DateTime.Now; BrokeAccount.Upuser = user.Id; _brokerAcountService.Update(BrokeAccount); } //string[] strBrokeAccountId = payModel.BrokeAccountId.Split(','); //foreach (var BrokeAccountId in strBrokeAccountId) //{ // if (string.IsNullOrEmpty(BrokeAccountId)) // { // return PageHelper.toJson(PageHelper.ReturnValue(false, "数据错误")); // } // BrokeAccount = _brokerAcountService.GetBrokeAccountById(Convert.ToInt32(BrokeAccountId)); // if (BrokeAccount.State == 1) // { // break; // } //} //string[] strIds = payModel.Ids.Split(','); //foreach (var id in strIds) //{ // if(string.IsNullOrEmpty(id)) // { // break; // } // var model = _brokerwithdrawDetailService.GetBrokerWithdrawDetailById(Convert.ToInt32(id)); // if (Convert.ToInt32(model.Type) == 0) // { // var blModel = new BLPayEntity // { // Name = payModel.Name, // Describe = payModel.Describe, // BankCard = Convert.ToInt32(model.BankCard.Num), // Accountantid = broker.Id, // Amount = model.Withdrawnum, // Adduser = broker.Id, // Upuser = broker.Id, // Addtime = DateTime.Now, // Uptime = DateTime.Now, // }; // _blPayService.Create(blModel); // } // if (Convert.ToInt32(model.Type) == 1) // { // var breModel = new BRECPayEntity // { // Name = payModel.Name, // Describe = payModel.Describe, // BankCard = Convert.ToInt32(model.BankCard.Num), // Accountantid = broker.Id, // Amount = model.Withdrawnum, // Adduser = broker.Id, // Upuser = broker.Id, // Addtime = DateTime.Now, // Uptime = DateTime.Now, // }; // _brecPayService.Create(breModel); // } //} BrokerWithdraw.State = 1; //BrokerWithdraw.AccAccountantId.UserId = user.Id; BrokerWithdraw.Uptime = DateTime.Now; BrokerWithdraw.Upuser = user.Id; BrokerWithdraw.WithdrawDesc = payModel.Describe; BrokerWithdraw.BankSn = payModel.BankSn; _brokerwithdrawService.Update(BrokerWithdraw); return PageHelper.toJson(PageHelper.ReturnValue(true, "打款成功")); }
public HttpResponseMessage AddBroker([FromBody]BrokerModel brokerModel) { if (string.IsNullOrEmpty(brokerModel.UserName)) return PageHelper.toJson(PageHelper.ReturnValue(false, "用户名不能为空")); if (string.IsNullOrEmpty(brokerModel.Password)) return PageHelper.toJson(PageHelper.ReturnValue(false, "密码不能为空")); if (string.IsNullOrEmpty(brokerModel.Phone)) return PageHelper.toJson(PageHelper.ReturnValue(false, "手机号不能为空")); // 创建推荐用户 var condition = new BrokerSearchCondition { OrderBy = EnumBrokerSearchOrderBy.OrderById, Phone = brokerModel.Phone }; //判断user表和Broker表中是否存在用户名 int user2 = _brokerService.GetBrokerCount(condition); if (user2 != 0) return PageHelper.toJson(PageHelper.ReturnValue(false, "用户名已经存在")); //检测规则表中是否存在权限,不存在则添加 var role = "broker"; switch (brokerModel.UserType) { case EnumUserType.经纪人: role = "broker"; break; case EnumUserType.商家: role = "merchant"; break; case EnumUserType.场秘: role = "secretary"; break; case EnumUserType.带客人员: role = "waiter"; break; case EnumUserType.普通用户: role = "user"; break; case EnumUserType.管理员: role = "admin"; break; case EnumUserType.财务: role = "accountant"; break; } var brokerRole = _roleService.GetRoleByName(role); //User权限缺少时自动添加 if (brokerRole == null) { brokerRole = new Role { RoleName = role, RolePermissions = null, Status = RoleStatus.Normal, Description = "后台添加新权限类别:" + role }; } 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); var model = new BrokerEntity(); model.UserId = _userService.InsertUser(newUser).Id; model.Brokername = brokerModel.UserName; model.Phone = brokerModel.Phone; model.Totalpoints = 0; model.Amount = 0; model.Usertype = brokerModel.UserType; 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; _brokerService.Create(model); return PageHelper.toJson(PageHelper.ReturnValue(true, "注册成功")); }
public HttpResponseMessage AddBroker([FromBody] BrokerEntity broker) { if (!string.IsNullOrEmpty(broker.Brokername)) { var brokerEntity = new BrokerEntity { Brokername = broker.Brokername, Uptime = DateTime.Now, Addtime = DateTime.Now, }; try { if (_brokerService.Create(brokerEntity) != null) { return PageHelper.toJson(PageHelper.ReturnValue(true, "数据添加成功!")); } } catch { return PageHelper.toJson(PageHelper.ReturnValue(false, "数据添加失败!")); } } return PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证错误!")); }
public HttpResponseMessage LogoutAdmin([FromBody] int id) { try { var model = new BrokerEntity() { Id = id, State = -1, }; _brokerService.Update(model); return PageHelper.toJson(PageHelper.ReturnValue(true, "注销成功")); } catch (Exception) { return PageHelper.toJson(PageHelper.ReturnValue(false, "注销失败")); } }
public HttpResponseMessage DelAdmin([FromBody]int id) { try { var model = new BrokerEntity { Id = id, State = 0, Usertype = EnumUserType.管理员 }; _brokerService.Update(model); return PageHelper.toJson(PageHelper.ReturnValue(true, "删除成功")); } catch (Exception) { return PageHelper.toJson(PageHelper.ReturnValue(false, "删除失败")); } }