public ResponseMyAccountAdd MyAccountAdd(RequestMyAccountAdd request) { ResponseMyAccountAdd response = new ResponseMyAccountAdd(); using (cnn = GetConnection()) { var ts = cnn.BeginTransaction(); try { //根据邀请码获取账套信息 string sql = @"select * from TKS_FAS_AccountInfo where InvitationCode=@Code and IsInvitation=0"; var account = cnn.QueryFirstOrDefault <TKS_FAS_AccountInfo>(sql, new { Code = request.InvitationCode }, ts); if (account == null) { throw new NormalException("邀请码已经失效"); } var user = this.UserInfoGetButAccount(request.Token, ts); var d = cnn.Query("select * from TKS_FAS_MyAccount where AccountId=@AccountId and NodeId=@NodeId", new { AccountId = account.Id, NodeId = user.Node.CreditCode }, ts); if (d.Count() > 0) { throw new NormalException("已关联账套"); } TKS_FAS_MyAccount myAccount = new TKS_FAS_MyAccount(); myAccount.Id = Guid.NewGuid().ToString("N"); myAccount.AccountId = account.Id; myAccount.AccountName = account.QY_Name; myAccount.NodeId = user.Node.CreditCode; myAccount.CreateUser = user.User.TrueName; myAccount.CreateDate = DateTime.Now; cnn.Insert <TKS_FAS_MyAccount>(myAccount, ts); cnn.Execute(@"update TKS_FAS_AccountInfo set IsInvitation=1 , InvitationQYCode=@InvitationQYCode, InvitationQYName=@InvitationQYName where id=@Id", new { InvitationQYCode = user.Node.CreditCode, InvitationQYName = user.Node.Name, Id = account.Id }, ts); ts.Commit(); response.IsSuccess = true; response.Message = "关联成功"; return(response); } catch (Exception ex) { ts.Rollback(); return(this.DealException(response, ex) as ResponseMyAccountAdd); } } }
/// <summary> /// 微信小程序验证邀请码 /// </summary> /// <param name="request"></param> /// <returns></returns> public ResponseBase WX_CheckInvitation(RequestMyAccountAdd request) { ResponseBase response = new ResponseBase(); using (cnn = GetConnection()) { var ts = cnn.BeginTransaction(); try { var user = this.UserInfoGet(request.Token, ts); //根据邀请码获取账套信息 string sql = @"select * from TKS_FAS_AccountInfo where InvitationCode=@Code"; var account = cnn.QueryFirstOrDefault <TKS_FAS_AccountInfo>(sql, new { Code = request.InvitationCode }, ts); if (account == null) { response.IsSuccess = false; response.Message = "验证码失效"; return(response); } else { var Account2User = cnn.QueryFirstOrDefault <TKS_FAS_Account2User>(@"select * from TKS_FAS_Account2User where AccountId=@AccountId and UserId=@UserId", new { AccountId = account.Id, UserId = user.User.Id }, ts); if (Account2User == null) { TKS_FAS_Account2User newAccount2User = new TKS_FAS_Account2User(); newAccount2User.Id = Guid.NewGuid().ToString("N"); newAccount2User.AccountId = account.Id; newAccount2User.UserId = user.User.Id; newAccount2User.CreateDate = DateTime.Now; cnn.Insert <TKS_FAS_Account2User>(newAccount2User, ts); } //激活账套 string sql_active = @"delete from TKS_FAS_UserCurrentAccount where userId=@UserId"; cnn.Execute(sql_active, new { UserId = user.User.Id }, ts); TKS_FAS_UserCurrentAccount cur = new TKS_FAS_UserCurrentAccount(); cur.Id = Guid.NewGuid().ToString("N"); cur.UserId = user.User.Id; //cur.AccountId = request.Data.Id; cur.AccountId = account.Id; cnn.Insert <TKS_FAS_UserCurrentAccount>(cur, ts); response.IsSuccess = true; response.Message = "登陆成功"; } ts.Commit(); return(response); } catch (Exception ex) { ts.Rollback(); return(this.DealException(response, ex) as ResponseBase); } } }
public ResponseBase WX_CheckInvitation([FromBody] RequestMyAccountAdd request) { try { UserBLL bll = new UserBLL(); return(bll.WX_CheckInvitation(request)); } catch (Exception ex) { throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public ResponseMyAccountAdd MyAccountAdd([FromBody] RequestMyAccountAdd request) { try { MyAccountBLL bll = new MyAccountBLL(); return(bll.MyAccountAdd(request)); } catch (Exception ex) { throw new HttpResponseException( Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }