コード例 #1
0
        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));
        }