public ActionResult PosApplyProvide(string isEdit) { string message = string.Empty; bool isSuccess = true; if (!ValidatorPos(ref message)) { return(JsonMessage(false, message)); } //用户最近的一笔申请[未撤销] PosApply apply2 = _posApplyService.GetUnique(pos => pos.MpUserId == MpUserID && pos.Status == 0, "CreateDate", false); //有未过期的贷款申请 if (apply2 != null && !(isEdit == "1" && (DateTime.Now - apply2.CreateDate).Hours <= 24)) { return(RedirectToAction("PosMessage", new { })); } try { _posApplyService.BeginTransaction(); //当前登录用户 MpUser mpUser = _mpUserService.GetById(MpUserID); PosAuth posAuth = _posAuthService.GetUnique(pos => pos.MpUserId == mpUser.Id); ViewBag.IsAuth = false; if (posAuth != null) { ViewBag.IsAuth = posAuth.IsAuth > 0; } //进行手机验证 if (!ViewBag.IsAuth) { int useCount = _mobileCodeService.GetMobileCodeCount(this.MpUserID, 3);//当天使用次数 if (useCount <= 5) { MobileCode lastCode = _mobileCodeService.GetMobileCode(this.MpUserID, 3);//是否存在未使用的证码 if (lastCode != null) { //验证 MobileCode mobileCode = _mobileCodeService.GetMobileCode(RQuery["MobilePhone"], RQuery["Code"], MpUserID, 3); if (mobileCode != null) { TimeSpan ts = DateTime.Now.Subtract(mobileCode.CreateDate).Duration(); if (ts.Minutes > 10) { ViewBag.CodeError = "验证码已经失效,请重新获取"; isSuccess = false; } PosAuth auth = new PosAuth(); auth.MpUserId = MpUserID; auth.Name = RQuery["Name"]; auth.MobilePhone = RQuery["MobilePhone"]; auth.IsAuth = 1; _posAuthService.Insert(auth); } else { lastCode.Time += 1; _mobileCodeService.Update(lastCode); ViewBag.CodeError = "对不起,验证码有误,请检查!"; isSuccess = false; } } else { ViewBag.CodeError = "对不起,您还未点击发送验证码!"; isSuccess = false; } } else { ViewBag.CodeError = "对不起,您今天最多只能发起5次验证码!"; isSuccess = false; } } //处理贷款业务 if (isEdit == "1") { if (apply2 != null) { TryUpdateModel <PosApply>(apply2); if (isSuccess) { _posApplyService.Update(apply2); } } else { throw new OceanException("对不起,您的参数有误,请联系客服!"); } } else { apply2 = new PosApply(); TryUpdateModel <PosApply>(apply2); apply2.MpUserId = MpUserID; apply2.Status = apply2.AssignStatus = apply2.ProcessStatus = 0; if (isSuccess) { _posApplyService.Insert(apply2); } } } catch (Exception ex) { _posApplyService.Rollback(); throw new OceanException(string.Format("对不起,{0}!", ex.Message)); } finally { _posApplyService.Commit(); } if (isSuccess) { return(RedirectToAction("PosApply")); } else { return(View("PosApply", apply2)); } }
public ActionResult GetMobileCode(string mobile, int operateType) { if (_mobileCodeService.GetMobileCodeCount(this.MpUserID, operateType) > 5) { return(JsonMessage(false, "短信获取失败[您当天获取验证码的次数不能超过5次]")); } else { UserLogin.Instance.WriteCookie("mobilecode" + operateType, mobile + "," + operateType.ToString(), 10, "/", ""); //验证参数格式 long lSMID = 0; string smID = GlobalConfig.GetConfig()["SMID"]; if (!long.TryParse(smID, out lSMID)) { _log.Debug("SMID格式错误"); return(JsonMessage(false, "验证码获取失败,请稍后重试")); } #if DEBUG //创建验证码 MobileCode mobileCode = new MobileCode { MpUserId = MpUserID, Mobile = mobile, Code = StringHelper.GetRandomInt(6), Time = 0, OperationType = operateType, Status = 0 }; _mobileCodeService.Insert(mobileCode); return(JsonMessage(true, string.Format("{0}", mobileCode.Code))); #else string message = string.Empty; try { //短信猫发送短信 IList <string> mobiles = new List <string>(); mobiles.Add(mobile); string code = StringHelper.GetRandomInt(6); string yzMsg = string.Empty; if (operateType == 1) { yzMsg = string.Format("您本次申请福农宝额度调整的验证码为{0},验证码10分钟内有效,详询4000896336。", code); } else if (operateType == 2) { yzMsg = string.Format("您本次申请贷款的验证码为{0},验证码10分钟内有效,详询4000896336。", code); } else if (operateType == 3) { yzMsg = string.Format("您本次申请POS的验证码为{0},验证码10分钟内有效,详询4000896336。", code); } else if (operateType == 4) { yzMsg = string.Format("您本次申请摇奖的验证码为{0},验证码10分钟内有效,详询4000896336。", code); } else { yzMsg = string.Format("您本次查询POS的验证码为{0},验证码10分钟内有效,详询4000896336。", code); } SendSmsRequest sendSmsRequest = new SendSmsRequest(mobiles, yzMsg, lSMID); //if(true) if (new SmsClient().Execute(sendSmsRequest, ref message)) { //创建验证码 MobileCode mobileCode = new MobileCode { MpUserId = MpUserID, Mobile = mobile, Code = code, Time = 0, OperationType = operateType, Status = 0 }; _mobileCodeService.Insert(mobileCode); //return JsonMessage(true, "验证码获取成功"); return(JsonMessage(true, string.Format("{0}", string.Empty))); } else { Log4NetImpl.Write("验证码获取失败:" + message); SmsClient.ReleaseAPIClient();//释放资源 return(JsonMessage(false, "验证码获取失败")); } } catch (Exception ex) { string errMsg = ""; if (string.IsNullOrWhiteSpace(message)) { errMsg = string.Format("验证码获取失败[{0}]", ex.Message); } else { errMsg = string.Format("验证码获取失败[{0}]{1}", message, ex.Message); } Log4NetImpl.Write(errMsg); SmsClient.ReleaseAPIClient();//释放资源 return(JsonMessage(false, "验证码获取失败")); } #endif } }
public ActionResult GongzhiBaoApplyProvide(Loan loan) { string message = string.Empty; //用户最近的一笔贷款申请[未撤销] Loan loan2 = _loanService.GetNewestLoanApplyByMpUserId(MpUserID); //有未过期的贷款申请 if (loan2 != null && DateTime.Now < loan2.CreateDate.AddMonths(1)) { return(JsonMessage(false, "您当前已经申请过贷款")); } try { _loanService.BeginTransaction(); //当前登录用户 MpUser mpUser = _mpUserService.GetById(MpUserID); //进行手机验证 if (mpUser.IsAuth == 0) { int useCount = _mobileCodeService.GetMobileCodeCount(this.MpUserID, 2);//当天使用次数 if (useCount <= 5) { MobileCode lastCode = _mobileCodeService.GetMobileCode(this.MpUserID, 2);//是否存在未使用的证码 if (lastCode != null) { //验证 MobileCode mobileCode = _mobileCodeService.GetMobileCode(loan.Phone, RQuery["Code"], MpUserID, 2); if (mobileCode != null) { TimeSpan ts = DateTime.Now.Subtract(mobileCode.CreateDate).Duration(); if (ts.Minutes > 10) { return(JsonMessage(false, "验证码已经失效,请重新获取")); } mpUser.Name = loan.LoanName; mpUser.MobilePhone = loan.Phone; mpUser.IsAuth = 1; _mpUserService.Update(mpUser); } else { lastCode.Time += 1; _mobileCodeService.Update(lastCode); return(JsonMessage(false, "对不起,验证码有误,请检查!")); } } else { return(JsonMessage(false, "对不起,您还未点击发送验证码!")); } } else { return(JsonMessage(false, "对不起,您今天最多只能发起5次验证码")); } } //处理贷款业务 loan.MpUserId = MpUserID; loan.Status = loan.AssignStatus = loan.ProcessStatus = 0; _loanService.Insert(loan); } catch (Exception ex) { _loanService.Rollback(); throw new OceanException(string.Format("对不起,{0}!", ex.Message)); } finally { _loanService.Commit(); } return(JsonMessage(true, "提交成功,等待管理员审核")); }
public ActionResult Index() { if (!string.IsNullOrEmpty(this.OpenID)) { Funongbao fnb = _funongbaoService.GetFunongbaoByOpenid(this.OpenID); if (fnb != null) { return(new RedirectResult("/funongbao/apply")); } } Funongbao funongbao = new Funongbao(); if (WebHelper.IsPost()) { ViewBag.AuthStatus = 0; TryUpdateModel <Funongbao>(funongbao); int useCount = _mobileCodeService.GetMobileCodeCount(this.MpUserID, 1);//当天使用次数 if (useCount <= 5) { MobileCode lastCode = _mobileCodeService.GetMobileCode(this.MpUserID, 1);//是否存在未使用的证码 if (lastCode != null) { MobileCode checkCode = _mobileCodeService.GetMobileCode(funongbao.MobilePhone, WebHelper.GetString("Code"), this.MpUserID, 1);//检查验证码 if (checkCode != null) { TimeSpan ts = DateTime.Now.Subtract(checkCode.CreateDate).Duration(); if (ts.Minutes > 10) { checkCode.Time += 1; checkCode.Status = 1; _mobileCodeService.Update(lastCode); ViewBag.CodeError = "验证码已经失效,请重新获取!"; } else { Funongbao authFnb = null; int authStatus = _funongbaoService.IdentAuth2(funongbao, out authFnb); if (authStatus == -1) { ViewBag.CodeError = "对不起,该客户已经被绑定了,您无法再次绑定!"; } else { if (authStatus == 1) { //更新用户认证并更新cookie MpUser user = _mpUserservice.GetById(this.MpUserID); user.Name = funongbao.Name; user.PassportNO = funongbao.PassportNO; user.MobilePhone = funongbao.MobilePhone; user.IsAuth = 1; //更新当前验证码失败 checkCode.Status = 1;//已用 //更新福农保信息 authFnb.IsAuth = 1; authFnb.IsSignAgreement = WebHelper.GetInt("IsSignAgreement", 1); authFnb.MpUserId = this.MpUserID; authFnb.OpenId = this.OpenID; try { Log4NetImpl.Write("测试事务写入"); _funongbaoService.BeginTransaction(); _mpUserservice.Update(user); _mobileCodeService.Update(checkCode); _funongbaoService.Update(authFnb); _funongbaoService.Commit(); WriteMpUserCookie(user); Log4NetImpl.Write("测试获取cookie"); var a = MpUserArr; if (!string.IsNullOrEmpty(WebHelper.GetString("refUrl"))) { return(Redirect(WebHelper.GetString("refUrl"))); } else { return(RedirectToAction("index", "funongbao")); } } catch (Exception ex) { _funongbaoService.Rollback(); Log4NetImpl.Write(ex.ToString()); throw new OceanException("对不起,系统异常,身份认证失败!", ex); } } else { ViewBag.AuthStatus = authStatus; } } } } else { lastCode.Time += 1; _mobileCodeService.Update(lastCode); ViewBag.CodeError = "对不起,验证码有误,请检查!"; } } else { ViewBag.CodeError = "对不起,您还未点击发送验证码!"; } } else { ViewBag.CodeError = "对不起,您今天最多只能发起5次验证码"; } } return(View(funongbao)); }