public HttpResponseMessage AddBankCard([FromBody] AddBankCardEntity bankcard)
        {
            #region 验证码判断 解密
            var      strDes  = EncrypHelper.Decrypt(bankcard.Hidm, "Hos2xNLrgfaYFY2MKuFf3g=="); //解密
            string[] str     = strDes.Split('$');
            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 > 30)                                                                   //发送时间与接受时间是否大于3分钟
            {
                return(PageHelper.toJson(PageHelper.ReturnValue(false, "你已超过时间验证,请重新发送验证码!")));
            }
            else
            {
                if (bankcard.MobileYzm != source)//判断验证码是否一致
                {
                    return(PageHelper.toJson(PageHelper.ReturnValue(false, "验证码错误,请重新发送!")));
                }
            }

            #endregion


            var user = (UserBase)_workContext.CurrentUser;
            if (user != null)
            {
                var broker = _brokerService.GetBrokerByUserId(user.Id);//获取当前经纪人
                if (broker != null)
                {
                    var entity = new BankCardEntity
                    {
                        Addtime  = DateTime.Now,
                        Uptime   = DateTime.Now,
                        Address  = bankcard.Address,
                        Adduser  = broker.Id,
                        Type     = "储蓄卡",
                        Upuser   = broker.Id,
                        Bank     = _bankService.GetBankById(Convert.ToInt32(bankcard.Bank)),
                        Broker   = broker,
                        Num      = bankcard.Num,
                        Deadline = Convert.ToDateTime("2000-01-01 00:00:00")
                    };

                    try
                    {
                        if (_bankcardService.Create(entity) != null)
                        {
                            return(PageHelper.toJson(PageHelper.ReturnValue(true, "数据添加成功!")));
                        }
                    }
                    catch
                    {
                        return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据添加失败!")));
                    }
                }
            }
            return(PageHelper.toJson(PageHelper.ReturnValue(false, "获取用户失败,请检查是否登陆")));
        }
Exemple #2
0
 /// <summary>
 /// 验证六位短信验证码
 /// </summary>
 /// <param name="sourc">加密后的字符串</param>
 /// <param name="messa">验证码</param>
 /// <param name="userid">用户密钥,DES加密用</param>
 /// <returns></returns>
 public static HttpResponseMessage validate(string sourc, string messa, string salt)
 {
     if ((!string.IsNullOrEmpty(sourc)) && (!string.IsNullOrEmpty(messa)))
     {
         string   sou     = EncrypHelper.Decrypt(sourc, salt);                   //解密
         string[] str     = sou.Split('$');
         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 > 30)
         {
             // SMSHelper.vali.Remove(userid + messa);
             return(PageHelper.toJson(PageHelper.ReturnValue(false, "你已超过时间验证,请重新发送验证码!")));
         }
         else if (messa == source)
         {
             return(PageHelper.toJson(PageHelper.ReturnValue(true, "成功验证!")));
         }
         else
         {
             return(PageHelper.toJson(PageHelper.ReturnValue(true, "验证失败!")));
         }
     }
     return(PageHelper.toJson(PageHelper.ReturnValue(false, "验证失败!")));
 }
        public HttpResponseMessage ChangePassword([FromBody] ChangePasswordModel model)
        {
            #region 首先判断发送到手机的验证码是否正确
            var      strDes  = EncrypHelper.Decrypt(model.Hidm, "Hos2xNLrgfaYFY2MKuFf3g=="); //解密
            string[] str     = strDes.Split('$');
            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
            {
                if (model.MobileYzm != source)//判断验证码是否一致
                {
                    return(PageHelper.toJson(PageHelper.ReturnValue(false, "验证码错误,请重新发送!")));
                }
            }


            #endregion



            //判断两次新密码是否一致
            if (model.Password != model.SecondPassword)
            {
                return(PageHelper.toJson(PageHelper.ReturnValue(true, "密码不一致!")));
            }
            //判读旧密码
            var user = (UserBase)_workContext.CurrentUser;
            if (user != null && PasswordHelper.ValidatePasswordHashed(user, model.OldPassword))
            {
                PasswordHelper.SetPasswordHashed(user, model.Password);
                _userService.ModifyUser(user);
                return(PageHelper.toJson(PageHelper.ReturnValue(true, "密码修改成功!")));
            }
            return(PageHelper.toJson(PageHelper.ReturnValue(false, "密码修改失败!请检查输入是否正确!")));
        }
        public HttpResponseMessage ForgetPassword([FromBody] ForgetPasswordModel model)
        {
            //判断用户是否存在
            var sech = new BrokerSearchCondition
            {
                OrderBy = EnumBrokerSearchOrderBy.OrderById,
                Phone   = model.Phone,
                State   = 1
            };
            var broker = _brokerService.GetBrokersByCondition(sech).FirstOrDefault();

            if (broker == null)
            {
                return(PageHelper.toJson(PageHelper.ReturnValue(false, "该用户不存在!")));
            }

            #region 首先判断发送到手机的验证码是否正确
            var      strDes = EncrypHelper.Decrypt(model.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 (model.Phone != source.Split('#')[1])//判断手机号是否一致
                {
                    return(PageHelper.toJson(PageHelper.ReturnValue(false, "验证码错误,请重新发送!")));
                }

                if (model.Yzm != source.Split('#')[0])//判断验证码是否一致
                {
                    return(PageHelper.toJson(PageHelper.ReturnValue(false, "验证码错误,请重新发送!")));
                }
            }


            #endregion

            //判断两次新密码是否一致
            if (model.first_password != model.second_password)
            {
                return(PageHelper.toJson(PageHelper.ReturnValue(true, "密码不一致!")));
            }

            //密码修改
            var user = _userService.FindUser(broker.UserId);
            PasswordHelper.SetPasswordHashed(user, model.first_password);
            _userService.ModifyUser(user);
            return(PageHelper.toJson(PageHelper.ReturnValue(true, "数据更新成功!")));
        }
        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 AddBrokerWithdrawDetail([FromBody] AddMoneyEntity MoneyEntity)
        {
            int     bankId        = 0; //银行Id
            decimal withdrawMoney = 0; //提现金额

            if (string.IsNullOrEmpty(MoneyEntity.Bank) || string.IsNullOrEmpty(MoneyEntity.Ids) || string.IsNullOrEmpty(MoneyEntity.Hidm) || string.IsNullOrEmpty(MoneyEntity.MobileYzm) || string.IsNullOrEmpty(MoneyEntity.Money))
            {
                return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证错误")));
            }
            if (!Int32.TryParse(MoneyEntity.Bank, out bankId))
            {
                return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证错误")));
            }

            //if (!Int32.TryParse(MoneyEntity.Money, out withdrawMoney))
            //{
            //    return PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证错误"));
            //}
            //else
            //{
            //    if (withdrawMoney <= 0)
            //    {
            //        return PageHelper.toJson(PageHelper.ReturnValue(false, "提现金额必须大于零"));
            //    }
            //}


            #region 验证码判断 解密
            var      strDes  = EncrypHelper.Decrypt(MoneyEntity.Hidm, "Hos2xNLrgfaYFY2MKuFf3g=="); //解密
            string[] str     = strDes.Split('$');
            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
            {
                if (MoneyEntity.MobileYzm != source)//判断验证码是否一致
                {
                    return(PageHelper.toJson(PageHelper.ReturnValue(false, "验证码错误,请重新发送!")));
                }
            }

            #endregion


            //非空验证

            var user = (UserBase)_workContext.CurrentUser;
            if (user != null)
            {
                var broker = _brokerService.GetBrokerByUserId(user.Id);//获取当前经纪人
                if (broker != null)
                {
                    //根据对应的经纪人账户明细Ids 添加到提现主表 附表中去
                    if (!string.IsNullOrEmpty(MoneyEntity.Ids))
                    {
                        var bankCard = _bankcardService.GetBankCardById(Convert.ToInt32(MoneyEntity.Bank));
                        if (bankCard.Broker.Id != broker.Id)
                        {
                            return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证错误")));
                        }


                        List <BrokerWithdrawDetailEntity> listBrokerWithDetail = new List <BrokerWithdrawDetailEntity>(); //提现明细List
                        var brokerWithdraw = new BrokerWithdrawEntity                                                     //提现主表
                        {
                            Addtime      = DateTime.Now,
                            Adduser      = broker.Id,
                            BankCard     = bankCard,
                            BankSn       = "",
                            Broker       = broker,
                            State        = 0,
                            Uptime       = DateTime.Now,
                            Upuser       = broker.Id,
                            WithdrawDesc = "",
                            WithdrawTime = DateTime.Now,
                        };

                        try
                        {
                            foreach (var p in MoneyEntity.Ids.Split(','))
                            {
                                if (string.IsNullOrEmpty(p))
                                {
                                    continue;
                                }
                                var broaccount = _brokeaccountService.GetBrokeAccountById(Convert.ToInt32(p)); //获取该笔账户
                                if (broaccount.Broker.Id != broker.Id)                                         //判断该笔账户金额是否是当前这个经纪人
                                {
                                    return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证错误")));
                                }
                                else
                                {
                                    withdrawMoney += broaccount.Balancenum;//提现总金额

                                    var bwithdrawDetail = new BrokerWithdrawDetailEntity
                                    {
                                        BankCard        = bankCard,
                                        Withdrawnum     = Convert.ToDecimal(broaccount.Balancenum),
                                        Withdrawtime    = DateTime.Now,
                                        Broker          = broker,
                                        Uptime          = DateTime.Now,
                                        Addtime         = DateTime.Now,
                                        Adduser         = broker.Id,
                                        Upuser          = broker.Id,
                                        Type            = broaccount.Type.ToString(),
                                        BrokeAccount_Id = broaccount
                                    };
                                    listBrokerWithDetail.Add(bwithdrawDetail);
                                }
                            }
                            //更新提现总金额
                            brokerWithdraw.WithdrawTotalNum = withdrawMoney;

                            brokerWithdraw = _brokerwithdrawService.Create(brokerWithdraw); //添加到提现主表

                            foreach (var browithdetail in listBrokerWithDetail)             //添加到提现附表
                            {
                                browithdetail.BrokerWithdraw = brokerWithdraw;

                                _brokerwithdrawdetailService.Create(browithdetail);

                                //更改账户表中 状态
                                var brokeraccount = browithdetail.BrokeAccount_Id;
                                brokeraccount.State = -1;
                                _brokeaccountService.Update(brokeraccount);
                            }
                            //更新到经纪人表中 可用金额
                            broker.Amount = Convert.ToDecimal(GetBrokerAmount());
                            _brokerService.Update(broker);

                            return(PageHelper.toJson(PageHelper.ReturnValue(true, "提现申请成功!")));
                        }
                        catch
                        {
                            return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证错误")));
                        }
                    }
                    else
                    {
                        return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据验证错误")));
                    }



                    #region 以前的逻辑
                    //decimal getMoney = Convert.ToDecimal(GetBrokerAmount());//计算得到的剩余总金额
                    //decimal syMoney = 0;//剩余金额
                    //// 提现金额逻辑判断(账户金额表 和提现表相减 跟经纪人表中‘提现金额’字段一致)

                    //if (Convert.ToDecimal(MoneyEntity.Money) > getMoney)
                    //{
                    //    return PageHelper.toJson(PageHelper.ReturnValue(false, "账户余额不足,不能提现"));
                    //}
                    //syMoney = getMoney - Convert.ToDecimal(MoneyEntity.Money);

                    ////将剩余金额更新到经纪人表中金额字段
                    ////broker.Amount = syMoney;
                    ////_brokerService.Update(broker);


                    ////更新到提现表中
                    //var entity = new BrokerWithdrawDetailEntity
                    //{
                    //    BankCard = _bankcardService.GetBankCardById(Convert.ToInt32(MoneyEntity.Bank)),
                    //    Withdrawnum = Convert.ToDecimal(MoneyEntity.Money),
                    //    Withdrawtime = DateTime.Now,
                    //    Broker = broker,
                    //    Uptime = DateTime.Now,
                    //    Addtime = DateTime.Now,
                    //    Adduser = broker.Id,
                    //    Upuser = broker.Id,
                    //    Type = "0"
                    //};

                    //try
                    //{
                    //    if (_brokerwithdrawdetailService.Create(entity) != null)
                    //    {
                    //        return PageHelper.toJson(PageHelper.ReturnValue(true, entity.Id.ToString()));
                    //    }
                    //}
                    //catch
                    //{
                    //    return PageHelper.toJson(PageHelper.ReturnValue(false, "数据添加失败!"));
                    //}

                    #endregion
                }
            }
            return(PageHelper.toJson(PageHelper.ReturnValue(false, "获取用户失败,请检查是否登陆")));
        }