Пример #1
0
        /// <summary>
        /// 新增银行卡简单绑定
        /// </summary>
        public void addsimplebankaccount()
        {
            Guid userid = WebUserAuth.UserId.Value;
            //UserBasicInfo basicmodel = db.UserBasicInfo.FirstOrDefault(p => p.Id == userid);
            var basicmodel = new UserBLL().GetUserBasicInfoModelById(userid);

            if (basicmodel == null)
            {
                PrintJson("-1", "用户不存在");
            }

            if (basicmodel.IsValidateIdentity != true || basicmodel.IsValidateMobile != true)
            {
                PrintJson("-10", "绑定银行卡前需完成身份证验证和手机验证");
            }

            if (!string.IsNullOrWhiteSpace(basicmodel.BankAccountNo))
            {
                PrintJson("-4", "最多添加1张银行卡");
            }
            int userBankCount = 0;
            //using (SqlConnection connection = PubConstant.CrateReadConnection())
            //{
            string            strSqlBank = @"SELECT Count(0) FROM UserBankInfo WITH(NOLOCK) WHERE UserId = @userId";
            DynamicParameters paramBank  = new Dapper.DynamicParameters();

            paramBank.Add("@userId", basicmodel.Id);
            userBankCount = TuanDai.DB.TuanDaiDB.QueryFirstOrDefault <int>(TdConfig.DBRead, strSqlBank, ref paramBank);
            //    userBankCount = connection.Query<int>(strSqlBank, paramBank).FirstOrDefault();
            //    connection.Close();
            //    connection.Dispose();
            //}

            if (userBankCount >= 1)
            {
                PrintJson("-4", "最多添加1张银行卡");
            }

            bool   status   = !string.IsNullOrEmpty(basicmodel.BankAccountNo) ? false : true;
            string account  = Context.Request["account"];
            int    bankType = Tool.SafeConvert.ToInt32(Context.Request["bankType"]);
            Regex  reg      = new Regex("^[\u4e00-\u9fa5]+$");

            //if (bankType == 9999)
            //{
            //    PrintJson("-2", "对不起!系统暂不支持该银行");
            //}

            if (!string.IsNullOrWhiteSpace(account))
            {
                account = account.Replace(" ", "");
            }

            Regex numreg = new Regex("^[0-9]*$");

            if (!numreg.IsMatch(account))
            {
                PrintJson("-5", "银行卡号输入有误");
            }

            //UserBasicInfo bankUser = db.UserBasicInfo.FirstOrDefault(p => p.BankAccountNo == account && p.Id != userid);
            //var bankUser = new UserBLL().WXGetUserBasicInfo(" BankAccountNo = @BankAccountNo and Id <>@Id",
            //    new SqlParameter[]
            //    {
            //        new SqlParameter("@BankAccountNo", account), new SqlParameter("@Id", userid)
            //    });
            if (BankNoExists(account, userid))
            {
                PrintJson("-3", "新的银行账号已经绑定另一用户,不能再绑定。");
            }

            basicmodel.BankAccountNo = account;
            basicmodel.BankType      = bankType;

            int iAuthenState = -1;   //-1代表不更新该字段

            if (basicmodel.IsValidateEmail && basicmodel.IsValidateIdentity && basicmodel.IsValidateMobile && basicmodel.IsSafeQuestion)
            {
                iAuthenState = 4;
            }
            int iResult = 0;
            //using (SqlConnection connection = PubConstant.CrateConnection())
            //{
            string            strSql = @"BEGIN TRANSACTION
                                DECLARE @errorSum INT
                                SET @errorSum = 0
                                if not exists(select 1 from UserBankInfo where UserId=@userId)
                                begin
                                    INSERT INTO UserBankInfo(UserId,BankNo,BankType) VALUES(@userId, @bankNo, @bankType)
                                end
                                SET @errorSum  = @errorSum + @@error
                                INSERT INTO BankInfoLog([Id],[UserId],[BankNo],[RealName],[AddDate],[type],[UpdateUserId],[CardNo])
                                VALUES(NEWID(), @userId, @bankNo, @realName, @addDate, @type, @updateUserId, @cardNo)
                                SET @errorSum  = @errorSum + @@error
                                IF(@AuthenState = 4)
                                BEGIN
                                UPDATE UserBasicInfo SET AuthenState = 4 WHERE ID = @userId
                                SET @errorSum  = @errorSum + @@error
                                END
                                IF(@errorSum = 0)
                                BEGIN
                                COMMIT TRANSACTION
                                END
                                ELSE
                                BEGIN
                                ROLLBACK TRANSACTION
                                END";
            DynamicParameters param  = new Dapper.DynamicParameters();

            param.Add("@userId", basicmodel.Id);
            param.Add("@bankNo", account);
            param.Add("@bankType", bankType);
            param.Add("@realName", basicmodel.RealName);
            param.Add("@addDate", DateTime.Now);
            param.Add("@type", 1);
            param.Add("@updateUserId", basicmodel.Id);
            param.Add("@cardNo", basicmodel.IdentityCard);
            param.Add("@AuthenState", iAuthenState);
            iResult = TuanDai.DB.TuanDaiDB.Execute(TdConfig.DBUserWrite, strSql, ref param);
            //    iResult = connection.Execute(strSql, param);
            //}
            string updateUserbasicinfoBank = "UPDATE dbo.UserBasicInfo SET BankAccountNo=@BankAccountNo,BankType=@BankType WHERE Id=@Id";
            var    userbasicinfoBankParam  = new Dapper.DynamicParameters();

            userbasicinfoBankParam.Add("@Id", basicmodel.Id);
            userbasicinfoBankParam.Add("@BankAccountNo", account);
            userbasicinfoBankParam.Add("@BankType", bankType);
            TuanDai.DB.TuanDaiDB.Execute(TdConfig.DBUserWrite, updateUserbasicinfoBank, ref userbasicinfoBankParam);
            if (iResult > 0)
            {
                if (status)
                {
                    TuanDai.PortalSystem.BLL.VipGetWorthBLL.AddGetWorth(userid, (int)ConstString.UserGrowthType.BindBankCard, null, 0);
                }
                WebLog log = new WebLog();
                log.AddDate        = DateTime.Now;
                log.BusinessId     = userid.ToString();
                log.BusinessTypeId = (int)ConstString.LogBusinessType.Add;
                log.UserId         = userid.ToString();
                log.UserTypeId     = (int)ConstString.LogUserType.WebUser;
                log.HandlerTypeId  = (int)ConstString.LogType.BankAccount;
                log.Content1       = "新增银行卡绑定";
                log.Content2       = "银行账号为:" + account;
                log.Content5       = "银行类型:" + bankType.ToString();
                log.Id             = Guid.NewGuid().ToString();
                WebLogInfo.WriteLoginHandler(log);

                #region 发送通知消息

                var isNewSmsRequest = ConfigHelper.getConfigString("IsNewSmsRequest", "0");
                if (isNewSmsRequest == "0")
                {
                    MessageSend ms  = new MessageSend();
                    var         dic = new Dictionary <string, object>();
                    dic.Add("UserName", basicmodel.RealName);
                    dic.Add("CurrentDate", DateTime.Now);
                    ms.SendMessage2(eventCode: MessageTemplates.ModifyBankAccount, parameters: dic,
                                    mobile: basicmodel.TelNo, email: basicmodel.Email, userId: basicmodel.Id);
                }
                else
                {
                    SmsRequest modifyBankAccountSuccess = new SmsRequest();
                    modifyBankAccountSuccess.EventCode      = MsgTemplatesType.ModifyBankAccountSuccess;
                    modifyBankAccountSuccess.PlatformSource = PlatformSource.WeiXin;
                    modifyBankAccountSuccess.UserId         = userid;
                    modifyBankAccountSuccess.Mobile         = basicmodel.TelNo;
                    modifyBankAccountSuccess.EmailAddress   = basicmodel.Email;
                    modifyBankAccountSuccess.Parameters     = new Dictionary <string, object>();
                    modifyBankAccountSuccess.Parameters.Add("ApplyDate", DateTime.Now);

                    string errorMessage = string.Empty;
                    SmsClient.SendMessage(modifyBankAccountSuccess, ref errorMessage);
                }


                #endregion

                var startDate = DateTime.Parse("2015-04-30 10:00:00");
                if (!string.IsNullOrEmpty(basicmodel.ExtenderKey))
                {
                    var extenderKey = basicmodel.ExtenderKey;
                    //var invitedUsers = db.UserBasicInfo.Where(x =>
                    //    x.ExtenderKey == extenderKey &&
                    //    x.IsValidateIdentity &&
                    //    x.BankAccountNo != null &&
                    //    x.AddDate >= startDate).Count();
                    var invitedUsers = GetInvitedUserCount(extenderKey, startDate);

                    //这种方式查询较慢,先注释掉.
                    //邀请人每邀请五个实名且绑定银行卡的用户可获得1个月VIP超级会员
                    //第101位客户开始不奖励
                    //if (invitedUsers >= 5 && invitedUsers <= 100 && (invitedUsers % 5 == 0))
                    //{
                    //    //var user = db.UserBasicInfo.FirstOrDefault(x => x.ExtendKey == extenderKey);
                    //    //var user = new UserBLL().WXGetUserBasicInfo(" ExtendKey=@ExtendKey",
                    //    //    new SqlParameter[] { new SqlParameter("@ExtendKey",extenderKey) });
                    //    var user = new UserBLL().GetUserBasicInfoByExtendKey(extenderKey);
                    //    if (user != null)
                    //    {
                    //        //var parameters = new ObjectParameter("outStatus", 0);
                    //        //db.p_GiveMember(user.Id, 0, "邀请好友注册赢VIP超级会员", 1, null, parameters);
                    //        var para = new Dapper.DynamicParameters();
                    //        para.Add("@userid", user.Id);
                    //        para.Add("@type", 0);
                    //        para.Add("@desc", "邀请好友注册赢VIP超级会员");
                    //        para.Add("@months", 1);
                    //        para.Add("@handlerUserId", null);
                    //        para.Add("@outStatus", 0, DbType.Int32, ParameterDirection.Output);
                    //        PublicConn.ExecuteTD(PublicConn.DBWriteType.UserWrite, "p_GiveMember", ref para);
                    //    }
                    //}
                }

                PrintJson("1", "操作成功");
            }
            else
            {
                PrintJson("0", "操作失败");
            }
        }
Пример #2
0
        private string UserInsertByPhone(string phone)
        {
            string pwd = new UserBLL().GetRandomPassword(8);//随机密码

            if (!phone.IsPhone())
            {
                return("手机号码格式不正确");
            }

            string strIp = Tool.WebFormHandler.GetIP();

            string[] ips    = strIp.Split(',');
            string   realIp = ips.Length > 1 ? ips[1] : ips[0];
            string   result = Users.UserIsRegByIP(realIp);

            if (result != "1")
            {
                string dt = result.Split('|')[1];
                return("注册失败:为防止恶意注册,请在" + dt + "后重新注册");
            }

            Guid userid = Guid.NewGuid();
            //var model = WXRegister.AddUserInfo(userid, _app, pwd, phone, "", "",
            //    "", "", 0, realIp);


            string from = _app;

            if (!string.IsNullOrEmpty(_appUserId))
            {
                from += "_" + _appUserId;
            }
            #region 写用户信息
            UserRegisterInfo registerUser = new UserRegisterInfo();
            registerUser.Id             = userid;
            registerUser.ExtenderKey    = "";
            registerUser.UserName       = string.Format("{0}wx{1}", phone, DateTime.Now.ToString("yyMMdd")); //针对重复注册特殊处理
            registerUser.Pwd            = pwd;
            registerUser.Email          = string.Empty;
            registerUser.TelNo          = phone;
            registerUser.ThirdPartyId   = string.Empty;
            registerUser.ThirdPartyType = (int)ConstString.ThirdPartyType.TuandaiUser;
            registerUser.RegisterFrom   = from;
            registerUser.RegisterIP     = realIp;
            registerUser.OpenId         = GlobalUtils.OpenId;
            registerUser.NickName       = registerUser.UserName;
            string msg = string.Empty;
            var    userBasicInfoInfo = new UserBLL().RegiserUser(registerUser, ref msg);
            if (userBasicInfoInfo != null && !string.IsNullOrEmpty(userBasicInfoInfo.ExtenderKey))
            {
                //记录日志
                SysLogHelper.WriteErrorLog("会员推广_AddUserInfo", "UserName:" + userBasicInfoInfo.UserName + ";ExtendKey:" + userBasicInfoInfo.ExtenderKey);
            }
            #endregion

            if (userBasicInfoInfo != null)
            {
                RegisterUserHandler.AsyncAfterRegister(_app, userBasicInfoInfo);

                if ((userBasicInfoInfo.uStatus ?? 0) == 1)
                {
                    var isNewSmsRequest = ConfigHelper.getConfigString("IsNewSmsRequest", "0");
                    if (isNewSmsRequest == "0")
                    {
                        //改用新的发短信,邮件,系统消息
                        var messageSender = new MessageSend();
                        //var parameters = new Dictionary<string, object>();
                        //parameters.Add("User", model);
                        //parameters.Add("CurrentDate", DateTime.Now);
                        //parameters.Add("ExtenderKey", model.ExtenderKey);
                        //messageSender.SendMessage2(eventCode: MessageTemplates.RegisterSuccess, parameters: parameters, mobile: model.TelNo, email: model.Email, userId: model.Id);

                        //将生成的密码已短信方式发送给用户
                        var parameters = new Dictionary <string, object>();
                        parameters.Add("PassWord", pwd);
                        messageSender.SendMessage2(option: SendOption.Sms, eventCode: MessageTemplates.BindMobile,
                                                   parameters: parameters, mobile: userBasicInfoInfo.TelNo);
                    }
                    else
                    {
                        SmsRequest rechargeSuccessSmsRequest = new SmsRequest();
                        rechargeSuccessSmsRequest.EventCode      = MsgTemplatesType.BindMobile;
                        rechargeSuccessSmsRequest.PlatformSource = PlatformSource.WeiXin;
                        rechargeSuccessSmsRequest.UserId         = userBasicInfoInfo.Id;
                        rechargeSuccessSmsRequest.EmailAddress   = userBasicInfoInfo.Email;
                        rechargeSuccessSmsRequest.Mobile         = userBasicInfoInfo.TelNo;
                        rechargeSuccessSmsRequest.Parameters     = new Dictionary <string, object>();
                        rechargeSuccessSmsRequest.Parameters.Add("PassWord", pwd);

                        string errorMessage = string.Empty;
                        SmsClient.SendMessage(rechargeSuccessSmsRequest, ref errorMessage);
                    }

                    try
                    {
                        TuanDai.InfoSystem.Model.LoginLog loginLogEntity = new TuanDai.InfoSystem.Model.LoginLog();
                        loginLogEntity.Id         = Guid.NewGuid().ToString();
                        loginLogEntity.UserId     = userBasicInfoInfo.Id.ToString();
                        loginLogEntity.IpAddress  = Tool.WebFormHandler.GetIP();
                        loginLogEntity.LoginDate  = DateTime.Now;
                        loginLogEntity.DeviceType = "WeiXin";
                        loginLogEntity.DeviceName = _app + "自动注册登录";
                        //LoginLogService logApi = new LoginLogService();
                        //logApi.AddLoginLog(loginLogEntity);
                        TuanDai.WXApiWeb.SysLogHelper.AddLoginLog(loginLogEntity);
                    }
                    catch (Exception ex)
                    {
                        NetLog.WriteLoginHandler("写入注册成功登录日志出错", Tool.ExceptionHelper.GetExceptionMessage(ex));
                    }
                }

                #region 注册成功后自动登录

                if (GlobalUtils.IsWeiXinBrowser)
                {
                    string strOpenId = TuanDai.WXApiWeb.Common.WeiXinApi.GetUserWXOpenId(userBasicInfoInfo.Id);
                    if (strOpenId.IsNotEmpty())
                    {
                        GlobalUtils.WriteOpenIdToCookie(strOpenId.ToText());
                    }
                }
                WebUserAuth.SignIn(userid.ToString());

                #endregion
            }
            else
            {
                return("添加用户失败");
            }
            return(string.Empty);
        }