Exemplo n.º 1
0
        public string FiiiPayTransferInto(UserAccount account, Cryptocurrency coin, decimal amount)
        {
            var walletDac = new UserWalletDAC();
            var wallet    = walletDac.GetByAccountId(account.Id, coin.Id);
            UserExTransferOrder order;

            using (var scope = new TransactionScope())
            {
                if (wallet == null)
                {
                    wallet = new UserWalletComponent().GenerateWallet(account.Id, coin.Id);
                }

                walletDac.Increase(wallet.Id, amount);

                order = new UserExTransferOrder
                {
                    Timestamp  = DateTime.UtcNow,
                    OrderNo    = CreateOrderNo(),
                    OrderType  = ExTransferType.FromEx,
                    AccountId  = account.Id,
                    WalletId   = wallet.Id,
                    CryptoId   = coin.Id,
                    CryptoCode = coin.Code,
                    Amount     = amount,
                    Status     = 1,
                    Remark     = null,
                    ExId       = null
                };

                new UserExTransferOrderDAC().Create(order);

                scope.Complete();
            }

            try
            {
                FiiiEXTransferMSMQ.PubUserTransferFromEx(order.Id, 0);
            }
            catch (Exception ex)
            {
                LogHelper.Info("PubUserTransferFromEx - error", ex);
            }
            return(order.OrderNo);
        }
Exemplo n.º 2
0
        public TransferResult FiiiPayTransferFromEx(UserAccount account, int cryptoId, decimal amount, string pin)
        {
            new SecurityComponent().VerifyPin(account, pin);

            var openAccountDac = new OpenAccountDAC();
            var openAccount    = openAccountDac.GetOpenAccount(FiiiType.FiiiPay, account.Id);

            if (openAccount == null)
            {
                throw new CommonException(ReasonCode.GENERAL_ERROR, R.FiiiExAccountNotExist);
            }

            var crypto = new CryptocurrencyDAC().GetById(cryptoId);

            if (crypto == null)
            {
                throw new CommonException(ReasonCode.GENERAL_ERROR, R.CurrencyForbidden);
            }

            var balance = this.FiiiExBalance(FiiiType.FiiiPay, account.Id, crypto);

            if (balance < amount)
            {
                throw new CommonException(ReasonCode.GENERAL_ERROR, Resources.余额不足);
            }

            //10091=参数不符合要求 10013=用户信息不存在 10024=用户币不存在 10025=用户币种余额不足 0=成功
            int result = FiiiExCoinOut(openAccount.OpenId, crypto.Code, amount, out string recordId);

            if (result == 10025)
            {
                throw new CommonException(ReasonCode.GENERAL_ERROR, Resources.余额不足);
            }
            if (result != 0)
            {
                throw new CommonException(ReasonCode.GENERAL_ERROR, Resources.从FiiiEx划转失败);
            }

            var walletDac = new UserWalletDAC();
            var wallet    = walletDac.GetByAccountId(account.Id, crypto.Id);
            UserExTransferOrder order;

            using (var scope = new TransactionScope())
            {
                if (wallet == null)
                {
                    wallet = new UserWalletComponent().GenerateWallet(account.Id, crypto.Id);
                }

                walletDac.Increase(wallet.Id, amount);
                order = new UserExTransferOrder
                {
                    Timestamp  = DateTime.UtcNow,
                    OrderNo    = CreateOrderNo(),
                    OrderType  = ExTransferType.FromEx,
                    AccountId  = account.Id,
                    WalletId   = wallet.Id,
                    CryptoId   = crypto.Id,
                    CryptoCode = crypto.Code,
                    Amount     = amount,
                    Status     = 1,
                    Remark     = null,
                    ExId       = recordId
                };

                order = new UserExTransferOrderDAC().Create(order);
                scope.Complete();
            }


            try
            {
                FiiiEXTransferMSMQ.PubUserTransferFromEx(order.Id, 0);
            }
            catch (Exception ex)
            {
                LogHelper.Info("PubUserTransferFromEx - error", ex);
            }
            return(new TransferResult
            {
                Id = order.Id,
                Amount = order.Amount.ToString(crypto.DecimalPlace),
                OrderNo = order.OrderNo,
                Timestamp = order.Timestamp.ToUnixTime(),
                CryptoCode = crypto.Code
            });
        }