public SignonDTO BindingAccount(string merhcantAccount, string posSN) { var accountDac = new MerchantAccountDAC(); MerchantAccount account = accountDac.GetByUsername(merhcantAccount); SecurityVerify.Verify <BindAccountVerify>(new CustomVerifier("BindAccount"), SystemPlatform.FiiiPOS, merhcantAccount, (model) => { bool result = true; result = result && merhcantAccount.Equals(model.MerchantAccount); result = result && model.CellphoneVerified && model.PinVerified; if (account == null) { return(false); } if (ValidationFlagComponent.CheckSecurityOpened(account.ValidationFlag, ValidationFlag.GooogleAuthenticator)) { result = result && model.GoogleVerified; } return(result); }); var posDac = new POSDAC(); if (account.Status == AccountStatus.Locked) { throw new CommonException(ReasonCode.ACCOUNT_LOCKED, Resources.帐号已锁定); } var pos = posDac.GetBySn(posSN); if (pos == null) { throw new GeneralException(Resources.SN码不存在); } if (account.POSId.HasValue) { if (account.POSId == pos.Id) { throw new GeneralException(Resources.AccountHasBoundThisPOS); } else { throw new GeneralException(Resources.AccountHasBoundOtherPOS); } } if (pos.Status) { throw new GeneralException(Resources.POSHasBoundOtherAccount); } UserAccount userAccount = null; if (!string.IsNullOrEmpty(account.InvitationCode)) { userAccount = new UserAccountDAC().GetByInvitationCode(account.InvitationCode); } POSMerchantBindRecord posBindRecord = new POSMerchantBindRecord { POSId = pos.Id, SN = pos.Sn, MerchantId = account.Id, MerchantUsername = account.Username, BindTime = DateTime.UtcNow, BindStatus = (byte)POSBindStatus.Binded }; using (var scope = new TransactionScope()) { account.POSId = pos.Id; accountDac.BindPos(account); posDac.ActivePOS(pos); new POSMerchantBindRecordDAC().Insert(posBindRecord); if (!string.IsNullOrEmpty(account.InvitationCode) && userAccount != null) { ReBindInviter(posSN, account.Id, userAccount.Id, account.InvitationCode); } scope.Complete(); } return(GetAccessToken(pos, account)); }
public SignonDTO Signup(int countryId, string cellphone, string merchantAccount, string merchantName, string posSn, string invitationCode, string pin) { SecurityVerify.Verify <FiiiPosSignUpVerify>(new CustomVerifier("FiiiPosSignUp"), SystemPlatform.FiiiPOS, $"{countryId}:{cellphone}", (model) => { return(model.CellphoneVerified); }); var country = new CountryComponent().GetById(countryId); if (country == null) { throw new CommonException(10000, Resources.国家不存在); } var cacheKey = $"{countryId}{cellphone}"; var verifier = new FiiiPosRegisterVerifier(); var dic = verifier.GetRegisterModel(SystemPlatform.FiiiPOS, cacheKey, false); MerchantAccount excistAccount = new MerchantAccountDAC().GetByUsername(merchantAccount); if (excistAccount != null) { throw new CommonException(ReasonCode.ACCOUNT_EXISTS, Resources.帐号已存在); } UserAccount inviterAccount = new UserAccount(); if (!string.IsNullOrEmpty(invitationCode)) { inviterAccount = new UserAccountDAC().GetUserAccountByInviteCode(invitationCode); if (inviterAccount == null) { throw new CommonException(ReasonCode.INVITORCODE_NOT_EXISTS, Resources.邀请码不存在); } } var posDac = new POSDAC(); var pos = posDac.GetInactivedBySn(posSn); if (pos == null) { throw new CommonException(ReasonCode.POSSN_ERROR, Resources.SN码不存在); } var merchantMS = new MasterSettingDAC().SelectByGroup("Merchant"); Guid beInvitedAccountId = Guid.NewGuid(); MerchantAccount account = new MerchantAccount { CountryId = countryId, Cellphone = cellphone, Username = merchantAccount, MerchantName = merchantName, PIN = PasswordHasher.HashPassword(pin), Id = beInvitedAccountId, POSId = pos.Id, IsVerifiedEmail = false, PhoneCode = dic["PhoneCode"], RegistrationDate = DateTime.UtcNow, Status = AccountStatus.Active, SecretKey = beInvitedAccountId.ToString(), FiatCurrency = dic["FiatCurrency"], Markup = Convert.ToDecimal(merchantMS.First(e => e.Name == "Merchant_Markup").Value), Receivables_Tier = Convert.ToDecimal(merchantMS.First(e => e.Name == "Merchant_TransactionFee").Value), //默认开启手机验证 ValidationFlag = (byte)ValidationFlag.Cellphone, InvitationCode = invitationCode }; POSMerchantBindRecord posBindRecord = new POSMerchantBindRecord { POSId = pos.Id, SN = pos.Sn, MerchantId = account.Id, MerchantUsername = merchantAccount, BindTime = DateTime.UtcNow, BindStatus = (byte)POSBindStatus.Binded }; MerchantProfile profile = new MerchantProfile { MerchantId = account.Id, Country = account.CountryId, Cellphone = account.Cellphone, L1VerifyStatus = VerifyStatus.Uncertified, L2VerifyStatus = VerifyStatus.Uncertified }; MerchantProfileAgent agent = new MerchantProfileAgent(); bool addProfileResult = agent.AddMerchant(profile); if (!addProfileResult) { throw new CommonException(ReasonCode.GENERAL_ERROR, "Add merchant profile error."); } int recordId = default(int); try { using (var scope = new TransactionScope()) { posDac.ActivePOS(pos); new MerchantAccountDAC().Insert(account); recordId = new POSMerchantBindRecordDAC().Insert(posBindRecord); if (!string.IsNullOrEmpty(invitationCode)) { BindInviter(posSn, beInvitedAccountId, inviterAccount.Id, invitationCode); } scope.Complete(); } } catch (Exception ex) { agent.RemoveMerchantById(profile); //LogHelper.Error(ex); throw; } if (!string.IsNullOrEmpty(invitationCode)) { RabbitMQSender.SendMessage("InvitePosBindSuccess", new Tuple <Guid, long>(inviterAccount.Id, recordId)); } verifier.DeleteCacheModel(SystemPlatform.FiiiPOS, cacheKey); return(GetAccessToken(pos, account)); }