Esempio n. 1
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, "验证失败!")));
 }
Esempio n. 2
0
        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, "获取用户失败,请检查是否登陆")));
        }
Esempio n. 3
0
        /// <summary>
        /// 设置加密密码
        /// </summary>
        /// <param name="userBase">用户实体</param>
        /// <param name="password">密码</param>
        /// <param name="hashName">加密算法(默认MD5)</param>
        public static void SetPasswordHashed(UserBase userBase, string password, string hashName = "MD5")
        {
            string saltString;
            var    hashstring = EncrypHelper.HashEncrypt(password, hashName, out saltString);

            userBase.HashAlgorithm = hashName;
            userBase.Password      = hashstring;
            userBase.PasswordSalt  = saltString;
        }
Esempio n. 4
0
        /// <summary>
        /// 发送短信(短信类型)
        /// </summary>
        /// <param name="smstype">短信类型(修改密码=1,找回密码=2,添加银行卡=3,佣金提现=4,)</param>
        /// <returns>发送短信结果状态信息</returns>
        public HttpResponseMessage SendSmsForbroker([FromBody] string smstype)
        {
            var user = (UserBase)_workContext.CurrentUser;

            if (user != null)
            {
                var broker = _brokerService.GetBrokerByUserId(user.Id); //获取当前经纪人
                if (broker == null)
                {
                    return(PageHelper.toJson(PageHelper.ReturnValue(false, "获取用户失败,请检查是否登陆")));
                }
                var messageConfigName = Enum.GetName(typeof(MessageConfigTypeEnum), Convert.ToInt32(smstype));
                //获取短信模版名称
                var messageTemplate = _messageConfigService.GetMessageConfigByName(messageConfigName).Template;
                //获取到的短信模版
                string messages;
                if (messageConfigName == "推荐经纪人")                  //不需要生成数字验证码
                {
                    messages = string.Format(messageTemplate, ""); //更改模版
                    //添加到短信表中去
                    AddMessageDetails(new MessageDetailEntity
                    {
                        Content = messages,
                        Mobile  = broker.Phone,
                        Sender  = broker.Phone,
                        Title   = messageConfigName,
                        Addtime = DateTime.Now
                    });

                    return(PageHelper.toJson(SMSHelper.Sending(broker.Phone, messages)));
                }
                var strNumber = new Random().Next(100000, 1000000).ToString();
                //生成大于等于100000,小于等于999999的随机数,也就是六位随机数
                var nowTimestr = DateTime.Now.ToLongTimeString();
                var strs       = EncrypHelper.Encrypt(strNumber + "$" + nowTimestr, "Hos2xNLrgfaYFY2MKuFf3g==");
                //EMS 加密短信验证码
                messages = string.Format(messageTemplate, strNumber); //更改模版

                //添加到短信表中去
                AddMessageDetails(new MessageDetailEntity
                {
                    Content = messages,
                    Mobile  = broker.Phone,
                    Sender  = broker.Phone,
                    Title   = messageConfigName,
                    Addtime = DateTime.Now
                });


                //返回到前台的加密内容  和短信发送返回值
                return(PageHelper.toJson(new { Desstr = strs, Message = SMSHelper.Sending(broker.Phone, messages) }));
            }
            return(PageHelper.toJson(PageHelper.ReturnValue(false, "获取用户失败,请检查是否登陆")));
        }
Esempio n. 5
0
        /// <summary>
        /// 发送短信验证码
        /// </summary>
        /// <param name="phone">手机号码</param>
        /// <param name="salt">用户密钥,DES加密用</param>
        ///
        /// <returns></returns>
        public static HttpResponseMessage SendMessage6(string phone, string salt)
        {
            string messa = new Random().Next(100000, 1000000).ToString();//生成大于等于100000,小于等于999999的随机数,也就是六位随机数

            if (!string.IsNullOrEmpty(phone))
            {
                var    p      = SMSHelper.Sending(phone, messa);                //给用户发送验证码
                string time   = DateTime.Now.ToLongTimeString();
                var    source = EncrypHelper.Encrypt(messa + "$" + time, salt); //EMS 加密短信验证码
                return(PageHelper.toJson(new { sou = source, messP = p }));
            }
            return(PageHelper.toJson(0));
        }
Esempio n. 6
0
        /// <summary>
        /// 密码修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ValidateResult> UpdateUserPwd(UserLoginRequest model)
        {
            var userInfo       = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
            var validateResult = new ValidateResult();

            try
            {
                var       crmRequestHelper = new CrmRequestHelper();
                XDocument fetchXdoc        = null;
                fetchXdoc = await _repository.GetUserPwd(model);

                var entities = await crmRequestHelper.ExecuteAsync(_crmService, "mcs_userkeys", fetchXdoc);

                if (entities.Results.Count > 0)
                {
                    var res    = entities.Results[0];
                    var entity = new CrmExecuteEntity("mcs_userkeys", res.Id);
                    model.pwd = EncrypHelper.encrypt(model.pwd);
                    if (!string.IsNullOrEmpty(model.pwd))
                    {
                        entity.Attributes.Add("mcs_hashvalue", model.pwd);
                    }
                    //c端用户实体
                    await _crmService.Update(entity, userInfo?.systemuserid);

                    #region 组装数据返回
                    validateResult.Result      = true;
                    validateResult.Description = "操作成功";
                }
                else
                {
                    validateResult.Result      = false;
                    validateResult.Description = "操作失败";
                }

                #endregion
            }
            catch (Exception e)
            {
                validateResult.Result      = false;
                validateResult.Description = e.Message;
            }

            return(validateResult);
        }
Esempio n. 7
0
        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, "密码修改失败!请检查输入是否正确!")));
        }
Esempio n. 8
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="passWord"></param>
        /// <returns></returns>
        public DefaultResult <int> LogonUser(string userName, string passWord)
        {
            var ret = new ThirdResult <int>("注册");

            try
            {
                string password = EncrypHelper.DesEncrypt(passWord);
                var    user     = new UserList
                {
                    UserName  = userName,
                    PassWord  = password,
                    BlogName  = userName,
                    AddDate   = DateTime.Now.Date,
                    AddTime   = DateTime.Now,
                    BirthDate = new DateTime(1977, 1, 1)
                };
                return(Client <UserList> .Add(user));
            }
            catch (Exception ex)
            {
                return(ret.End(TError.WCF_ConnError, "服务器运行报错." + ex.Message));
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 账户登陆
        /// </summary>
        /// <param name="dealerListRequest"></param>
        /// <returns></returns>
        public async Task <ValidateResult <CrmEntity> > LoginAccount(UserLoginRequest request)
        {
            try
            {
                //密码加密MD5
                request.pwd = EncrypHelper.encrypt(request.pwd);
                var       validateResult   = new ValidateResult <CrmEntity>();
                var       crmRequestHelper = new CrmRequestHelper();
                XDocument fetchXdoc        = null;
                fetchXdoc = await _repository.LoginAccount(request);

                var entities = await crmRequestHelper.ExecuteAsync(_crmService, entityName, fetchXdoc);

                if (entities.Results.Count > 0)
                {
                    LoginLog(request, entities.Results[0].Id, (int)UserEnum.LoginlogEnum.成功);
                    validateResult.Result = true;
                    validateResult.Data   = entities.Results[0];
                }
                else
                {
                    fetchXdoc = await _repository.GetUser(request);

                    var ent = await crmRequestHelper.ExecuteAsync(_crmService, entityName, fetchXdoc);

                    LoginLog(request, ent.Results[0].Id, (int)UserEnum.LoginlogEnum.失败);
                    validateResult.Result      = false;
                    validateResult.Description = "账号密码错误!";
                }
                return(validateResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 10
0
        public HttpResponseMessage SendSMS([FromBody] YzMsg yzmsg)
        {
            if (!string.IsNullOrEmpty(yzmsg.Mobile) && !string.IsNullOrEmpty(yzmsg.SmsType))
            {
                var messageConfigName = Enum.GetName(typeof(MessageConfigTypeEnum), Convert.ToInt32(yzmsg.SmsType));
                //获取短信模版名称
                var messageTemplate = _messageConfigService.GetMessageConfigByName(messageConfigName).Template;
                //获取到的短信模版
                string messages;

                var strNumber = new Random().Next(100000, 1000000).ToString();
                //生成大于等于100000,小于等于999999的随机数,也就是六位随机数
                var nowTimestr = DateTime.Now.ToLongTimeString();
                var strs       = EncrypHelper.Encrypt(strNumber + "#" + yzmsg.Mobile + "$" + nowTimestr, "Hos2xNLrgfaYFY2MKuFf3g==");
                //EMS 加密短信验证码

                if (messageConfigName == "推荐经纪人") //不需要生成数字验证码
                {
                    var user = (UserBase)_workContext.CurrentUser;
                    if (user != null)
                    {
                        var broker = _brokerService.GetBrokerByUserId(user.Id); //获取当前经纪人
                        if (broker == null)
                        {
                            return(PageHelper.toJson(PageHelper.ReturnValue(false, "获取用户失败,请检查是否登陆")));
                        }
                        if (broker.Phone == yzmsg.Mobile) //不能给自己发
                        {
                            return(PageHelper.toJson(PageHelper.ReturnValue(false, "对不起,不能给自己发送短信")));
                        }

                        //添加到短信表中去
                        messages = string.Format(messageTemplate, strNumber, broker.Brokername); //更改模版
                        AddMessageDetails(new MessageDetailEntity
                        {
                            Content        = messages,
                            InvitationCode = strNumber,
                            InvitationId   = broker.Id.ToString(),
                            Mobile         = yzmsg.Mobile,
                            Sender         = yzmsg.Mobile,
                            Title          = messageConfigName,
                            Addtime        = DateTime.Now
                        });
                        return(PageHelper.toJson(SMSHelper.Sending(yzmsg.Mobile, messages)));
                    }
                    return(PageHelper.toJson(PageHelper.ReturnValue(false, "获取用户失败,请检查是否登陆")));
                }

                messages = string.Format(messageTemplate, strNumber); //更改模版

                //添加到短信表中去
                AddMessageDetails(new MessageDetailEntity
                {
                    Content = messages,
                    Mobile  = yzmsg.Mobile,
                    Sender  = yzmsg.Mobile,
                    Title   = messageConfigName,
                    Addtime = DateTime.Now
                });


                //返回到前台的加密内容  和短信发送返回值
                return(PageHelper.toJson(new { Desstr = strs, Message = SMSHelper.Sending(yzmsg.Mobile, messages) }));
            }

            return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据错误,不能发送短信")));
        }
Esempio n. 11
0
        /// <summary>
        /// 修改新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ValidateResult> AddUser(UserAddRequest model)
        {
            var userInfo       = ContextContainer.GetValue <UserInfo>(ContextExtensionTypes.CurrentUserInfo);
            var validateResult = new ValidateResult();

            try
            {
                //C端用户ID
                Guid id = Guid.NewGuid();
                //用户会员实体ID
                Guid memberid = Guid.NewGuid();

                var member = new CrmExecuteEntity("mcs_member", memberid);
                var entity = new CrmExecuteEntity(entityName, id);
                if (!string.IsNullOrEmpty(model.account))
                {
                    member.Attributes.Add("mcs_mobilephonemask", model.account);
                    member.Attributes.Add("mcs_mobile", model.account);
                    entity.Attributes.Add("mcs_phone", model.account);
                }
                if (!string.IsNullOrEmpty(model.birthday))
                {
                    entity.Attributes.Add("mcs_birthday", DateTime.Parse(model.birthday).ToUniversalTime());
                }
                if (!string.IsNullOrEmpty(model.company))
                {
                    entity.Attributes.Add("company", model.company);
                }
                if (!string.IsNullOrEmpty(model.description))
                {
                    entity.Attributes.Add("mcs_description", model.description);
                }
                if (model.gender != null)
                {
                    entity.Attributes.Add("mcs_gender", model.gender);
                }
                if (model.marriagestatus != null)
                {
                    entity.Attributes.Add("mcs_marriagestatus", model.marriagestatus);
                }
                if (!string.IsNullOrEmpty(model.mcs_cardid))
                {
                    entity.Attributes.Add("mcs_cardid", model.mcs_cardid);
                }
                if (!string.IsNullOrEmpty(model.mcs_email))
                {
                    entity.Attributes.Add("mcs_email", model.mcs_email);
                    member.Attributes.Add("mcs_email", model.mcs_email);
                }
                if (!string.IsNullOrEmpty(model.name))
                {
                    entity.Attributes.Add("mcs_name", model.name);
                }
                if (!string.IsNullOrEmpty(model.nickname))
                {
                    member.Attributes.Add("mcs_name", model.nickname);
                    member.Attributes.Add("mcs_nickname", model.nickname);
                    entity.Attributes.Add("mcs_nickname", model.nickname);
                }
                if (!string.IsNullOrEmpty(model.profession))
                {
                    entity.Attributes.Add("mcs_profession", model.profession);
                }
                if (!string.IsNullOrEmpty(model.signature))
                {
                    entity.Attributes.Add("mcs_signature", model.signature);
                }
                entity.Attributes.Add("mcs_memberid", new CrmEntityReference("mcs_member", memberid));

                member.Attributes.Add("mcs_userid", id.ToString());

                //添加会员实例
                var mcs_memberinstanceid = ContextContainer.GetValue <Guid>(ContextExtensionTypes.MemberInstanceId);
                if (mcs_memberinstanceid != Guid.Empty)
                {
                    member.Attributes.Add("mcs_memberinstanceid", new CrmEntityReference("mcs_memberinstance", mcs_memberinstanceid));
                }

                ////查询潜客是否存在
                //Guid contactEntityId = Guid.Empty;
                //for (int i = 0; i < 10; i++)
                //{
                //    if (contactEntityId == Guid.Empty)
                //    {
                //        XDocument cfetchXdoc = await _repository.GetContactByMobilePhone(model.account);
                //        var centities = await new CrmRequestHelper().ExecuteAsync(_crmService, "contact", cfetchXdoc);
                //        if (centities.Results != null && centities.Results.Count > 0)
                //        {
                //            contactEntityId = centities.Results[0].Id;
                //            member.Attributes.Add("mcs_customerid", new CrmEntityReference("contact", contactEntityId));
                //            break;
                //        }
                //    }
                //}
                //创建会员
                await _crmService.Create(member, userInfo?.systemuserid);

                //c端用户实体
                await _crmService.Create(entity, userInfo?.systemuserid);

                ///用户密码
                Guid userkeyid = Guid.NewGuid();
                entity            = new CrmExecuteEntity("mcs_userkeys", userkeyid);
                model.userkey.pwd = EncrypHelper.encrypt(model.userkey.pwd);
                entity.Attributes.Add("mcs_userid", new CrmEntityReference(entityName, id));
                entity.Attributes.Add("mcs_hashvalue", model.userkey.pwd);
                entity.Attributes.Add("mcs_keytype", model.userkey.keytype);
                entity.Attributes.Add("mcs_status", model.userkey.status);
                entity.Attributes.Add("mcs_certificationtype", model.userkey.certificationtype);
                await _crmService.Create(entity, userInfo?.systemuserid);

                //用户登陆
                Guid loginnamekeyid = Guid.NewGuid();
                entity = new CrmExecuteEntity("mcs_loginname", loginnamekeyid);
                entity.Attributes.Add("mcs_userid", new CrmEntityReference(entityName, id));
                entity.Attributes.Add("mcs_logintype", model.logintype);
                entity.Attributes.Add("mcs_name", model.account);
                entity.Attributes.Add("mcs_status", 1);
                await _crmService.Create(entity, userInfo?.systemuserid);

                ///唯一线索
                Guid leadid = Guid.NewGuid();
                entity = new CrmExecuteEntity("lead", leadid);
                entity.Attributes.Add("lastname", model.nickname);
                entity.Attributes.Add("mobilephone", model.phone);
                entity.Attributes.Add("mcs_userid", id.ToString());
                var       crmRequestHelper = new CrmRequestHelper();
                XDocument fetchXdoc        = null;
                fetchXdoc = await _repository.GetBehavior(_behavior);

                var entities = await crmRequestHelper.ExecuteAsync(_crmService, "mcs_behavior", fetchXdoc);

                if (entities.Results.Count > 0)
                {
                    entity.Attributes.Add("mcs_behaviorid", new CrmEntityReference("mcs_behavior", entities.Results[0].Id));
                }
                await _crmService.Create(entity, userInfo?.systemuserid);

                ///问题选择
                foreach (var item in model.quests)
                {
                    if (!string.IsNullOrEmpty(item.securityquestion) && !string.IsNullOrEmpty(item.answer))
                    {
                        Guid usersecurityquestionid = Guid.NewGuid();
                        entity = new CrmExecuteEntity("mcs_usersecurityquestion", usersecurityquestionid);
                        entity.Attributes.Add("mcs_userid", new CrmEntityReference(entityName, id));
                        entity.Attributes.Add("mcs_securityquestionid", new CrmEntityReference("mcs_securityquestion", Guid.Parse(item.securityquestion)));
                        entity.Attributes.Add("mcs_answer", item.answer);
                        await _crmService.Create(entity, userInfo?.systemuserid);
                    }
                }

                //积分充值接口调用
                //await IntegralCreate(IntegralReg_Key, id.ToString());

                #region 组装数据返回
                validateResult.Result      = true;
                validateResult.Description = "操作成功";
                #endregion
            }
            catch (Exception e)
            {
                validateResult.Result      = false;
                validateResult.Description = e.Message;
            }

            return(validateResult);
        }
Esempio n. 12
0
        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, "数据更新成功!")));
        }
Esempio n. 13
0
        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, "注册成功")));
        }
Esempio n. 14
0
 /// <summary>
 /// 验证密码
 /// </summary>
 /// <param name="userBase">用户实体</param>
 /// <param name="password">密码</param>
 /// <returns>是否通过</returns>
 public static bool ValidatePasswordHashed(UserBase userBase, string password)
 {
     return(EncrypHelper.ValidateHashValue(password, userBase.PasswordSalt, userBase.Password, userBase.HashAlgorithm));
 }
        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, "获取用户失败,请检查是否登陆")));
        }