Example #1
0
        public override Deposit Insert(Deposit deposit)
        {
            var userDeposit = new UserDeposit
            {
                UserAccountId = deposit.AccountId,
                UserWalletId  = deposit.WalletId,
                FromType      = deposit.FromType,
                FromAddress   = deposit.FromAddress,
                FromTag       = deposit.FromTag,
                ToAddress     = deposit.ToAddress,
                ToTag         = deposit.ToTag,
                Amount        = deposit.Amount,
                Status        = deposit.Status,
                Timestamp     = deposit.Timestamp,
                OrderNo       = deposit.OrderNo,
                TransactionId = deposit.TransactionId,
                RequestId     = deposit.RequestId,
                SelfPlatform  = false,
                Remark        = null,
                CryptoCode    = deposit.CryptoCode
            };

            userDeposit = new UserDepositDAC().Insert(userDeposit);
            deposit.Id  = userDeposit.Id;
            return(deposit);
        }
        public void PushDepositCancel(long id)
        {
            var order  = new UserDepositDAC().GetById(id);
            var wallet = new UserWalletDAC().GetById(order.UserWalletId);
            var coin   = new CryptocurrencyDAC().GetById(wallet.CryptoId);

            var regId = RedisHelper.StringGet($"FiiiPay:Notice:UserId:{order.UserAccountId}");

            var lang        = RedisHelper.StringGet(REDIS_LANGUAGE_DBINDEX, $"FiiiPay:Language:{order.UserAccountId}") ?? "en";
            var titleKey    = "DepositCancelTitle";
            var subTitleKey = "DepositCancelSubTitle";

            if (!(_resourcePropertyNames.Contains(titleKey) && _resourcePropertyNames.Contains(subTitleKey)))
            {
                throw new Exception("没有找到资源");
            }
            var content  = ResourceHelper.FiiiPay.GetFormatResource(titleKey, lang, coin.Code);
            var subTitle = ResourceHelper.FiiiPay.GetFormatResource(subTitleKey, lang, coin.Code);

            string noticeId = "";

            //写MongoDB [充币失败]
            MessagesComponent.AddMessage(order.UserAccountId, UserType.User, order.Id.ToString(), FiiiPayPushType.TYPE_DEPOSIT_CANCEL, titleKey, subTitleKey, coin.Code, content, subTitle, out noticeId);

            RegPush(FiiiPayPushType.TYPE_DEPOSIT_CANCEL, new List <string> {
                regId
            }, order.Id, content, subTitle, noticeId);
            LogHelper.Info($"--------{lang}------{content}----------{subTitle}");
        }
        public DetailOM Detail(UserAccount user, long id, bool isZH)
        {
            var data = new UserDepositDAC().GetById(user.Id, id);

            if (data == null || data.UserAccountId != user.Id)
            {
                throw new SystemErrorException();
            }

            var om = new DetailOM
            {
                CryptoAmount  = data.Amount.ToString(),
                Code          = data.CryptoCode,
                Id            = data.Id,
                OrderNo       = data.OrderNo,
                StatusStr     = new UserStatementComponent().GetStatusStr(0, (int)data.Status, isZH),
                Status        = data.Status,
                Timestamp     = data.Timestamp.ToUtcTimeTicks().ToString(),
                Type          = Resources.Deposit,
                SelfPlatform  = data.SelfPlatform,
                TransactionId = data.SelfPlatform ? null : data.TransactionId,
            };

            bool showCheckTime = data.CryptoCode != "XRP";

            if (showCheckTime && !data.SelfPlatform &&
                om.Status == TransactionStatus.Pending &&
                data.RequestId.HasValue)
            {
                var agent      = new FiiiFinanceAgent();
                var statusInfo = agent.GetDepositStatus(data.RequestId.Value);
                om.CheckTime = $"{statusInfo.TotalConfirmation}/{statusInfo.MinRequiredConfirmation}";
            }
            return(om);
        }
Example #4
0
        public override Deposit GetByRequestId(Guid accountId, long requestId)
        {
            var baseDeposit = new UserDepositDAC().GetByRequestId(accountId, requestId);

            if (baseDeposit == null)
            {
                return(null);
            }
            return(new Deposit
            {
                Id = baseDeposit.Id,
                AccountId = baseDeposit.UserAccountId,
                WalletId = baseDeposit.UserWalletId,
                FromAddress = baseDeposit.FromAddress,
                ToAddress = baseDeposit.ToAddress,
                Amount = baseDeposit.Amount,
                Status = baseDeposit.Status,
                Timestamp = baseDeposit.Timestamp,
                OrderNo = baseDeposit.OrderNo,
                TransactionId = baseDeposit.TransactionId,
                RequestId = baseDeposit.RequestId
            });
        }
Example #5
0
        public TransferResult Transfer(InvestorAccount account, int countryId, string cellphone, decimal amount, string pinToken)
        {
            new SecurityVerification(SystemPlatform.FiiiCoinWork).VerifyToken(pinToken, SecurityMethod.Pin);

            CountryDAC     countryDac     = new CountryDAC();
            UserAccountDAC userAccountDac = new UserAccountDAC();
            Country        country        = countryDac.GetById(countryId);

            if (country == null)
            {
                throw new CommonException(ReasonCode.GENERAL_ERROR, R.AccountNotExist);
            }
            UserAccount userAccount = userAccountDac.GetByCountryIdAndCellphone(countryId, cellphone);

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

            InvestorAccountDAC accountDac = new InvestorAccountDAC();

            if (account.Balance < amount)
            {
                throw new CommonException(ReasonCode.GENERAL_ERROR, R.余额不足);
            }

            UserWalletDAC userWalletDac = new UserWalletDAC();

            UserWallet userWallet = userWalletDac.GetByAccountId(userAccount.Id, FiiiCoinUtility.Cryptocurrency.Id);

            InvestorOrder investorOrder;
            UserDeposit   userDeposit;

            using (var scope = new TransactionScope())
            {
                if (userWallet == null)
                {
                    userWallet = new UserWalletComponent().GenerateWallet(userAccount.Id, FiiiCoinUtility.Cryptocurrency.Id);
                }
                accountDac.Decrease(account.Id, amount);
                investorOrder = new InvestorOrderDAC().Insert(new InvestorOrder
                {
                    Id                 = Guid.NewGuid(),
                    OrderNo            = CreateOrderNo(),
                    TransactionType    = InvestorTransactionType.Transfer,
                    Status             = 1,
                    InverstorAccountId = account.Id,
                    UserAccountId      = userAccount.Id,
                    CryptoId           = FiiiCoinUtility.Cryptocurrency.Id,
                    CryptoAmount       = amount,
                    Timestamp          = DateTime.UtcNow
                });
                new InvestorWalletStatementDAC().Insert(new InvestorWalletStatement
                {
                    Id           = Guid.NewGuid(),
                    InvestorId   = account.Id,
                    TagAccountId = userAccount.Id,
                    Action       = InvestorTransactionType.Transfer,
                    Amount       = -amount,
                    Balance      = account.Balance - amount,
                    Timestamp    = DateTime.UtcNow
                });
                // 2018-06-26: new rules IncreaseFrozen -> Increase
                userWalletDac.Increase(userWallet.Id, amount);
                userDeposit = new UserDepositDAC().Insert(new UserDeposit
                {
                    UserAccountId = userAccount.Id,
                    UserWalletId  = userWallet.Id,
                    FromAddress   = null,
                    FromTag       = null,
                    ToAddress     = null,
                    ToTag         = null,
                    Amount        = amount,
                    Status        = TransactionStatus.Confirmed,
                    Timestamp     = DateTime.UtcNow,
                    OrderNo       = CreateOrderNo(),
                    TransactionId = account.Id.ToString(),
                    SelfPlatform  = true,
                    RequestId     = null
                });


                scope.Complete();
            }

            InvestorMSMQ.PubUserDeposit(userDeposit.Id, 0);

            return(new TransferResult
            {
                OrderId = investorOrder.Id,
                OrderNo = investorOrder.OrderNo,
                TargetAccount = GetMaskedCellphone(country.PhoneCode, userAccount.Cellphone),
                Timestamp = DateTime.UtcNow.ToUnixTime()
            });
        }
        //private MerchantWithdrawal WithdrawalToMerchantAccount(MerchantWallet fromWallet, MerchantWithdrawal fromWithdraw, MerchantWallet toWallet)
        //{
        //    MerchantDeposit deposit = null;
        //    using (var scope = new TransactionScope())
        //    {
        //        //提币
        //        fromWithdraw.Status = TransactionStatus.Confirmed;
        //        fromWithdraw.TransactionId = toWallet.MerchantAccountId.ToString("N");
        //        fromWithdraw.SelfPlatform = true;//平台内提币
        //        fromWithdraw = new MerchantWithdrawalDAC().Create(fromWithdraw);

        //        var fromWithdrawFee = new MerchantWithdrawalFee
        //        {
        //            Amount = fromWithdraw.Amount,
        //            Timestamp = DateTime.UtcNow,
        //            Fee = fromWithdraw.Amount * WithdrawalMasterSetting.ToMerchantHandleFeeTier,
        //            WithdrawalId = fromWithdraw.Id
        //        };
        //        new MerchantWithdrawalFeeDAC().Create(fromWithdrawFee);

        //        new MerchantWalletDAC().Decrease(fromWallet.Id, fromWithdraw.Amount);

        //        new MerchantWalletStatementDAC().Insert(new MerchantWalletStatement
        //        {
        //            WalletId = fromWallet.Id,
        //            Action = MerchantWalletStatementAction.Withdrawal,
        //            Amount = -fromWithdraw.Amount,
        //            Balance = fromWallet.Balance - fromWithdraw.Amount,
        //            Timestamp = DateTime.UtcNow
        //        });


        //        //充币
        //        var amount = fromWithdraw.Amount - fromWithdrawFee.Fee;
        //        if (amount <= 0)
        //        {
        //            throw new CommonException(ReasonCode.GENERAL_ERROR, Resources.到账数量不能为零或者负数);
        //        }

        //        deposit = new MerchantDepositDAC().Insert(new MerchantDeposit
        //        {
        //            MerchantAccountId = toWallet.MerchantAccountId,
        //            MerchantWalletId = toWallet.Id,
        //            FromAddress = fromWallet.Address,
        //            ToAddress = toWallet.Address,
        //            Amount = fromWithdraw.Amount - fromWithdrawFee.Fee,
        //            Status = TransactionStatus.Confirmed,
        //            Timestamp = DateTime.UtcNow,
        //            OrderNo = CreateOrderno(),
        //            TransactionId = fromWallet.MerchantAccountId.ToString("N"),
        //            SelfPlatform = true
        //        });
        //        new MerchantWalletDAC().Increase(toWallet.Id, amount);
        //        new MerchantWalletStatementDAC().Insert(new MerchantWalletStatement
        //        {
        //            WalletId = toWallet.Id,
        //            Action = MerchantWalletStatementAction.Deposit,
        //            Amount = amount,
        //            Balance = toWallet.Balance + amount,
        //            Timestamp = DateTime.UtcNow
        //        });


        //        scope.Complete();
        //    }

        //    var withdrawId = fromWithdraw.Id;
        //    var depositId = deposit.Id;

        //    var t1 = Task.Run(() => new FiiiPOSPushComponent().PushWithdrawCompleted(withdrawId));
        //    var t2 = Task.Run(() => new FiiiPOSPushComponent().PushDeposit(depositId));
        //    Task.WaitAll(t1, t2);

        //    return fromWithdraw;
        //}

        private MerchantWithdrawal WithdrawalToUserAccount(MerchantWallet fromWallet, MerchantWithdrawal fromWithdraw,
                                                           UserWallet toWallet, decimal fee)
        {
            UserDeposit deposit;

            using (var scope = new TransactionScope())
            {
                //提币
                fromWithdraw.Status        = TransactionStatus.Confirmed;
                fromWithdraw.TransactionId = toWallet.UserAccountId.ToString("N");
                fromWithdraw.SelfPlatform  = true;//平台内提币
                fromWithdraw = new MerchantWithdrawalDAC().Create(fromWithdraw);

                var fromWithdrawFee = new MerchantWithdrawalFee
                {
                    Amount       = fromWithdraw.Amount,
                    Timestamp    = DateTime.UtcNow,
                    Fee          = fee,
                    WithdrawalId = fromWithdraw.Id
                };
                new MerchantWithdrawalFeeDAC().Create(fromWithdrawFee);

                new MerchantWalletDAC().Decrease(fromWallet.Id, fromWithdraw.Amount);

                new MerchantWalletStatementDAC().Insert(new MerchantWalletStatement
                {
                    WalletId  = fromWallet.Id,
                    Action    = MerchantWalletStatementAction.Withdrawal,
                    Amount    = -fromWithdraw.Amount,
                    Balance   = fromWallet.Balance - fromWithdraw.Amount,
                    Timestamp = DateTime.UtcNow
                });

                //充币
                var amount = fromWithdraw.Amount - fromWithdrawFee.Fee;
                new UserWalletDAC().Increase(toWallet.Id, amount);
                new UserWalletStatementDAC().Insert(new UserWalletStatement
                {
                    WalletId      = toWallet.Id,
                    Action        = UserWalletStatementAction.Deposit,
                    Amount        = amount,
                    Balance       = toWallet.Balance + amount,
                    FrozenAmount  = 0,
                    FrozenBalance = toWallet.FrozenBalance,
                    Timestamp     = DateTime.UtcNow
                });

                deposit = new UserDepositDAC().Insert(new UserDeposit
                {
                    UserAccountId = toWallet.UserAccountId,
                    UserWalletId  = toWallet.Id,
                    FromAddress   = fromWallet.Address,
                    FromTag       = fromWallet.Tag,
                    ToAddress     = toWallet.Address,
                    ToTag         = toWallet.Tag,
                    Amount        = amount,
                    Status        = TransactionStatus.Confirmed,
                    Timestamp     = DateTime.UtcNow,
                    OrderNo       = NumberGenerator.GenerateUnixOrderNo(),
                    TransactionId = fromWallet.MerchantAccountId.ToString("N"),
                    SelfPlatform  = true,
                    CryptoCode    = toWallet.CryptoCode
                });

                new UserTransactionDAC().Insert(new UserTransaction
                {
                    Id         = Guid.NewGuid(),
                    AccountId  = toWallet.UserAccountId,
                    CryptoId   = toWallet.CryptoId,
                    CryptoCode = toWallet.CryptoCode,
                    Type       = UserTransactionType.Deposit,
                    DetailId   = deposit.Id.ToString(),
                    Status     = (byte)deposit.Status,
                    Timestamp  = deposit.Timestamp,
                    Amount     = amount,
                    OrderNo    = deposit.OrderNo
                });

                scope.Complete();
            }

            var withdrawId = fromWithdraw.Id;
            var depositId  = deposit.Id;

            MerchantMSMQ.PubMerchantWithdrawCompleted(withdrawId, 0);
            MerchantMSMQ.PubUserDeposit(depositId, 0);

            return(fromWithdraw);
        }
        private WithdrawOM WithdrawalToUserAccount(UserWallet fromWallet, UserWithdrawal fromWithdraw, UserWallet toWallet)
        {
            var         mastSettings = new MasterSettingDAC().SelectByGroup("UserWithdrawal");
            UserDeposit model        = new UserDeposit();

            using (var scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 0, 1, 30)))
            {
                fromWithdraw.Status        = TransactionStatus.Confirmed;
                fromWithdraw.TransactionId = toWallet.UserAccountId.ToString("N");
                fromWithdraw.SelfPlatform  = true;//平台内提币
                fromWithdraw.Id            = new UserWithdrawalDAC().Create(fromWithdraw);

                new UserTransactionDAC().Insert(new UserTransaction
                {
                    Id         = Guid.NewGuid(),
                    AccountId  = fromWithdraw.UserAccountId,
                    CryptoId   = fromWallet.CryptoId,
                    CryptoCode = fromWallet.CryptoCode,
                    Type       = UserTransactionType.Withdrawal,
                    DetailId   = fromWithdraw.Id.ToString(),
                    Status     = (byte)fromWithdraw.Status,
                    Timestamp  = fromWithdraw.Timestamp,
                    Amount     = fromWithdraw.Amount,
                    OrderNo    = fromWithdraw.OrderNo
                });

                var fromWithdrawFee = new UserWithdrawalFee
                {
                    Amount       = fromWithdraw.Amount,
                    WithdrawalId = fromWithdraw.Id,
                    Fee          = fromWithdraw.Amount *
                                   Convert.ToDecimal(mastSettings.First(e => e.Name == "UserWithdrawal_ToUser").Value),
                    Timestamp = DateTime.UtcNow
                };

                new UserWithdrawalFeeDAC().Create(fromWithdrawFee);

                new UserWalletDAC().Decrease(fromWallet.Id, fromWithdraw.Amount);

                new UserWalletStatementDAC().Insert(new UserWalletStatement
                {
                    WalletId      = fromWallet.Id,
                    Action        = MerchantWalletStatementAction.Withdrawal,
                    Amount        = -fromWithdraw.Amount,
                    Balance       = fromWallet.Balance - fromWithdraw.Amount,
                    FrozenAmount  = 0,
                    FrozenBalance = fromWallet.FrozenBalance,
                    Timestamp     = DateTime.UtcNow
                });

                //充币
                var amount = fromWithdraw.Amount - fromWithdrawFee.Fee;
                if (amount <= 0)
                {
                    throw new CommonException(ReasonCode.GENERAL_ERROR, MessageResources.ArrivalAmountError);
                }

                new UserWalletDAC().Increase(toWallet.Id, amount);
                new UserWalletStatementDAC().Insert(new UserWalletStatement
                {
                    WalletId      = toWallet.Id,
                    Action        = UserWalletStatementAction.Deposit,
                    Amount        = amount,
                    Balance       = toWallet.Balance + amount,
                    FrozenAmount  = 0,
                    FrozenBalance = toWallet.FrozenBalance,
                    Timestamp     = DateTime.UtcNow
                });

                model = new UserDepositDAC().Insert(new UserDeposit
                {
                    UserAccountId = toWallet.UserAccountId,
                    UserWalletId  = toWallet.Id,
                    FromAddress   = fromWallet.Address,
                    FromTag       = fromWallet.Tag,
                    ToAddress     = toWallet.Address,
                    ToTag         = toWallet.Tag,
                    Amount        = amount,
                    Status        = TransactionStatus.Confirmed,
                    Timestamp     = DateTime.UtcNow,
                    OrderNo       = IdentityHelper.OrderNo(),
                    TransactionId = fromWallet.UserAccountId.ToString("N"),
                    SelfPlatform  = true,
                    CryptoCode    = fromWallet.CryptoCode
                });
                new UserTransactionDAC().Insert(new UserTransaction
                {
                    Id         = Guid.NewGuid(),
                    AccountId  = model.UserAccountId,
                    CryptoId   = fromWallet.CryptoId,
                    CryptoCode = fromWallet.CryptoCode,
                    Type       = UserTransactionType.Deposit,
                    DetailId   = model.Id.ToString(),
                    Status     = (byte)model.Status,
                    Timestamp  = model.Timestamp,
                    Amount     = model.Amount,
                    OrderNo    = model.OrderNo
                });

                scope.Complete();
            }

            UserMSMQ.PubUserWithdrawCompleted(fromWithdraw.Id, 0);
            UserMSMQ.PubUserDeposit(model.Id, 0);

            return(new WithdrawOM
            {
                OrderId = fromWithdraw.Id,
                OrderNo = fromWithdraw.OrderNo,
                Timestamp = fromWithdraw.Timestamp.ToUnixTime().ToString()
            });
        }