Пример #1
0
        public void PushWithdrawReject(long id)
        {
            var order  = new UserWithdrawalDAC().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    = "WithdrawalRejectTitle";
            var subTitleKey = "WithdrawalRejectSubTitle";

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

            string noticeId = "";

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

            RegPush(FiiiPayPushType.TYPE_WITHDRAWAL_Reject, new List <string> {
                regId
            }, order.Id, content, subTitle, noticeId);
            LogHelper.Info($"--------{lang}------{content}----------{subTitle}");
        }
Пример #2
0
        public void ToggleShowInHomePage(UserAccount user, int coinId)
        {
            var wallet = new UserWalletDAC().GetByAccountId(user.Id, coinId)
                         ?? new UserWalletComponent().GenerateWallet(user.Id, coinId);

            new UserWalletDAC().UpdateShowInHomePage(wallet.Id, !wallet.ShowInHomePage);
        }
Пример #3
0
        public PreDepositOM PreDeposit(UserAccount user, int cryptoId)
        {
            var dac    = new UserWalletDAC();
            var wallet = dac.GetByAccountId(user.Id, cryptoId) ?? new UserWalletComponent().GenerateWallet(user.Id, cryptoId);
            var coin   = new CryptocurrencyDAC().GetById(cryptoId);

            if (string.IsNullOrEmpty(wallet.Address))
            {
                var agent       = new FiiiFinanceAgent();
                var addressInfo = agent.CreateWallet(coin.Code, user.Id, AccountTypeEnum.User, user.Email, user.Cellphone);
                if (string.IsNullOrWhiteSpace(addressInfo.Address))
                {
                    throw new CommonException(ReasonCode.GENERAL_ERROR, Resources.FailedGenerateAddress);
                }

                wallet.Address = addressInfo.Address;
                wallet.Tag     = addressInfo.DestinationTag;

                dac.UploadAddress(wallet.Id, wallet.Address, wallet.Tag);
            }

            return(new PreDepositOM
            {
                Address = wallet.Address,
                Tag = wallet.Tag,
                Code = coin.Code,
                NeedTag = coin.NeedTag
            });
        }
Пример #4
0
        public CryptoWalletDto GetFiiiBalance(Guid accountId)
        {
            string coinCode = "FIII";
            var    wallet   = new UserWalletDAC().GetByCryptoCode(accountId, coinCode);

            return(new CryptoWalletDto
            {
                Balance = (wallet == null ? 0 : wallet.Balance),
                FrozenBalance = (wallet == null ? 0 : wallet.FrozenBalance)
            });
        }
Пример #5
0
        public void Refund(long id)
        {
            var redPocket = _redPocketDac.GetById(id);

            if (redPocket == null)
            {
                _log.Error($"Red pocket is not found. {id}");
                return;
            }

            if (redPocket.RemainCount > 0)
            {
                var userWalletDAC          = new UserWalletDAC();
                var userWalletStatementDAC = new UserWalletStatementDAC();
                var userTransactionDAC     = new UserTransactionDAC();

                var wallet = userWalletDAC.GetByAccountId(redPocket.AccountId, redPocket.CryptoId);
                if (wallet == null)
                {
                    _log.Error($"Wallet exception. {redPocket.AccountId} RedPocketId={id}");
                    return;
                }

                using (var scope = new TransactionScope())
                {
                    userWalletDAC.Increase(wallet.Id, redPocket.Balance);
                    userWalletStatementDAC.Insert(new UserWalletStatement
                    {
                        WalletId      = wallet.Id,
                        Balance       = wallet.Balance + redPocket.Balance,
                        Amount        = redPocket.Balance,
                        FrozenAmount  = 0,
                        FrozenBalance = wallet.FrozenBalance,
                        Action        = "Refund Red Pocket",
                        Timestamp     = DateTime.UtcNow
                    });

                    _refundDac.Insert(new RedPocketRefund
                    {
                        Id        = redPocket.Id,
                        Amount    = redPocket.Balance,
                        OrderNo   = _identity.StringId(),
                        Timestamp = DateTime.UtcNow
                    });

                    _redPocketDac.UpdateStatus(redPocket.Id, redPocket.RemainCount == redPocket.Count ? RedPocketStatus.FullRefund : RedPocketStatus.Refund);

                    userTransactionDAC.UpdateStatus(UserTransactionType.PushRedPocket, redPocket.Id.ToString(), redPocket.AccountId, (byte)RedPocketStatus.Refund);

                    scope.Complete();
                }
            }
        }
Пример #6
0
        public PrePayOM PrePay(UserAccount user, PrePayIM im)
        {
            var merchantAccount = GetMerchantAccountByIdOrCode(im.MerchantId, im.MerchantCode);
            var userWallets     = new UserWalletDAC().GetUserWallets(user.Id);
            var merchantWallets = new MerchantWalletDAC().GetByAccountId(merchantAccount.Id);
            var coins           = new CryptocurrencyDAC().GetAllActived();
            var priceList       = new PriceInfoDAC().GetPrice(merchantAccount.FiatCurrency);

            bool showWhiteLable = false;

            if (merchantAccount.POSId.HasValue)
            {
                var pos = new POSDAC().GetById(merchantAccount.POSId.Value);
                if (pos.IsWhiteLabel)
                {
                    showWhiteLable = true;
                }
            }

            if (!showWhiteLable)
            {
                var whilteLabelCryptoCode = new POSDAC().GetWhiteLabelCryptoCode();
                coins.RemoveAll(t => t.Code == whilteLabelCryptoCode);
            }

            return(new PrePayOM
            {
                FiatCurrency = merchantAccount.FiatCurrency,
                MarkupRate = merchantAccount.Markup.ToString(CultureInfo.InvariantCulture),
                WaletList = coins.Select(a =>
                {
                    var userWallet = userWallets.FirstOrDefault(b => b.CryptoId == a.Id);
                    decimal rate = 0;
                    rate = priceList.Where(t => t.CryptoID == a.Id).Select(t => t.Price).FirstOrDefault();
                    return GetItem(userWallet, a, merchantWallets, rate);
                }).OrderByDescending(a => a.MerchantSupported).ThenBy(a => a.PayRank).Select(a => new WalletItem
                {
                    Code = a.Code,
                    NewStatus = a.NewStatus,
                    ExchangeRate = a.ExchangeRate,
                    FrozenBalance = a.FrozenBalance,
                    IconUrl = a.IconUrl,
                    Id = a.Id,
                    MerchantSupported = a.MerchantSupported,
                    Name = a.Name,
                    UseableBalance = a.UseableBalance,
                    FiatBalance = a.FiatBalance,
                    DecimalPlace = a.DecimalPlace,
                    CryptoEnable = a.CryptoEnable
                }).ToList()
            });
        }
Пример #7
0
        public IndexOM Index(UserAccount user)
        {
            try
            {
                var isBillerEnable   = bool.Parse(new MasterSettingDAC().Single("BillerMaxAmount", "BillerEnable").Value);
                var userWallets      = new UserWalletDAC().GetUserWallets(user.Id);
                var currencyId       = new CurrenciesDAC().GetByCode(user.FiatCurrency).ID;
                var exchangeRateList = new PriceInfoDAC().GetByCurrencyId(currencyId);
                var exchangeRate     = exchangeRateList.ToDictionary(item => item.CryptoID);
                var coins            = new CryptocurrencyDAC().GetAllActived().OrderBy(e => e.Sequence).ToList();
                var list             = coins.Select(a =>
                {
                    var userWallet = userWallets.FirstOrDefault(b => b.CryptoId == a.Id);
                    var rate       = exchangeRate.ContainsKey(a.Id) ? exchangeRate[a.Id].Price : 0m;
                    return(GetItem(userWallet, a, rate));
                }).Where(a => a.ShowInHomePage)
                                       //.OrderBy(a => a.HomePageRank)
                                       .Select(a => new CurrencyItem
                {
                    Id               = a.Id,
                    Code             = a.Code,
                    NewStatus        = a.NewStatus,
                    FrozenBalance    = a.FrozenBalance,
                    IconUrl          = a.IconUrl,
                    UseableBalance   = a.UseableBalance,
                    FiatBalance      = a.FiatBalance,
                    FiatExchangeRate = exchangeRate.ContainsKey(a.Id) ? exchangeRate[a.Id].Price.ToString(4) : 0m.ToString(4),
                    CryptoEnable     = a.CryptoEnable
                }).ToList();

                return(new IndexOM
                {
                    TotalAmount = GetUserTotalAmount(user, userWallets, coins, exchangeRateList),
                    CurrencyItemList = list,
                    IsLV1Verified = user.L1VerifyStatus == VerifyStatus.Certified,
                    HasSetPin = !string.IsNullOrEmpty(user.Pin),
                    FiatCurrency = user.FiatCurrency,
                    IsBillerEnable = isBillerEnable
                });
            }
            catch (Exception exception)
            {
                Error(exception.StackTrace);
                return(new IndexOM
                {
                    TotalAmount = "--",
                    CurrencyItemList = null,
                    FiatCurrency = user.FiatCurrency
                });
            }
        }
Пример #8
0
        //private string CreateOrderno()
        //{
        //    return DateTime.Now.ToUnixTime() + new Random().Next(0, 100).ToString("00");
        //}

        public WithdrawDetailOM Detail(UserAccount user, long id, bool isZH)
        {
            var data = new UserWithdrawalDAC().GetById(user.Id, id);
            //var agent = FiiiFinanceFactory.GetByCountryId(user.CountryId.Value);
            //var markPrice = agent.GetMarketPrice(user.FiatCurrency, data.CryptoCode);
            var wallet = new UserWalletDAC().GetById(data.UserWalletId);
            var coin   = new CryptocurrencyDAC().GetById(wallet.CryptoId);

            var fee = new UserWithdrawalFeeDAC().GetByWithdrawalId(id) ?? new UserWithdrawalFee {
                Amount = 0
            };

            data.Amount = data.Amount - fee.Fee;

            var om = new WithdrawDetailOM
            {
                Address      = data.Address,
                Tag          = data.Tag,
                CryptoAmount = data.Amount.ToString(coin.DecimalPlace),
                //FiatAmount = (markPrice.Price * data.Amount.Value).ToString(2),
                Code    = coin.Code,
                NeedTag = coin.NeedTag,
                //FiatCurrency = user.FiatCurrency,
                Id             = data.Id,
                OrderNo        = data.OrderNo,
                StatusStr      = new UserStatementComponent().GetStatusStr(1, (int)data.Status, isZH),
                Status         = data.Status,
                Timestamp      = data.Timestamp.ToUnixTime().ToString(),
                TransactionFee = data.WithdrawalFee.ToString(coin.DecimalPlace),
                Type           = Resources.Withdrawal,
                SelfPlatform   = data.SelfPlatform,
                TransactionId  = data.SelfPlatform ? "-" : data.TransactionId ?? "-",
                Remark         = data.Remark// data.Status == TransactionStatus.Cancelled ? MessageResources.提币失败备注 : null
            };

            bool showCheckTime = coin.Code != "XRP";

            if (showCheckTime && !data.SelfPlatform &&
                om.Status == TransactionStatus.Pending &&
                data.RequestId.HasValue)
            {
                var agent      = new FiiiFinanceAgent();
                var statusInfo = agent.GetStatus(data.RequestId.Value);
                om.CheckTime     = $"{statusInfo.TotalConfirmation}/{statusInfo.MinRequiredConfirmation}";
                om.TransactionId = statusInfo.TransactionID;
            }

            return(om);
        }
Пример #9
0
        /// <summary>
        /// 支付网关发起退款
        /// </summary>
        /// <param name="tradeId"></param>
        public void GatewayRefund(string tradeId)
        {
            //获取订单详情
            var orderDetail = new GatewayOrderDAC().GetByTradeNo(tradeId);

            if (orderDetail == null)
            {
                throw new Exception("Have no record of this order:tradeId=" + tradeId);
            }
            if (orderDetail.Status != GatewayOrderStatus.Completed)
            {
                throw new Exception($"The status of this order {tradeId} is not completed");
            }

            var uwComponent = new UserWalletComponent();
            var userWallet  = uwComponent.GetUserWallet(orderDetail.UserAccountId.Value, orderDetail.CryptoId);
            var goDAC       = new GatewayOrderDAC();
            var rgoDAC      = new GatewayRefundOrderDAC();
            var uwDAC       = new UserWalletDAC();
            var uwsDAC      = new UserWalletStatementDAC();

            using (var scope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, new TimeSpan(0, 0, 1, 30)))
            {
                orderDetail.Status = GatewayOrderStatus.Refunded;
                goDAC.Update(orderDetail);

                uwDAC.Increase(userWallet.Id, orderDetail.ActualCryptoAmount);
                uwsDAC.Insert(new UserWalletStatement
                {
                    WalletId      = userWallet.Id,
                    Action        = UserWalletStatementAction.TansferIn,
                    Amount        = orderDetail.ActualCryptoAmount,
                    Balance       = userWallet.Balance + orderDetail.ActualCryptoAmount,
                    FrozenAmount  = 0,
                    FrozenBalance = userWallet.FrozenBalance,
                    Timestamp     = DateTime.UtcNow
                });
                rgoDAC.Insert(new GatewayRefundOrder
                {
                    Id        = Guid.NewGuid(),
                    OrderId   = orderDetail.Id,
                    Timestamp = DateTime.UtcNow,
                    Status    = RefundStatus.Completed
                });

                scope.Complete();
            }
        }
Пример #10
0
        public ListForDepositOM ListForDepositAndWithdrawal(UserAccount user, string fiatCurrency)
        {
            try
            {
                var userWallets = new UserWalletDAC().GetUserWallets(user.Id);
                var coins       = new CryptocurrencyDAC().GetAllActived().OrderBy(e => e.Sequence);
                //var rates = GetExchangeRates(user.CountryId, user.FiatCurrency);
                var priceList = new PriceInfoDAC().GetPrice(fiatCurrency);
                var list      = coins.Select(a =>
                {
                    var userWallet = userWallets.FirstOrDefault(b => b.CryptoId == a.Id);
                    decimal rate   = 0;
                    if (userWallet != null)
                    {
                        rate = priceList.Where(t => t.CryptoID == userWallet.CryptoId).Select(t => t.Price).FirstOrDefault();
                    }
                    return(GetDepositOMItemTempItem(userWallet, a, rate));
                })
                                //.OrderBy(a => a.PayRank)
                                .Select(a => new ListForDepositOMItem
                {
                    Id             = a.Id,
                    Code           = a.Code,
                    NewStatus      = a.NewStatus,
                    FrozenBalance  = a.FrozenBalance,
                    DecimalPlace   = a.DecimalPlace,
                    IconUrl        = a.IconUrl,
                    FiatBalance    = a.FiatBalance,
                    UseableBalance = a.UseableBalance,
                    Name           = a.Name,
                    CryptoEnable   = a.CryptoEnable
                }).ToList();

                return(new ListForDepositOM
                {
                    FiatCurrency = user.FiatCurrency,
                    List = list
                });
            }
            catch (Exception exception)
            {
                Error(exception.Message);
            }

            return(null);
        }
Пример #11
0
        public TransactionFeeDTO TransactionFeeRate(int coinId, string address, string tag)
        {
            var  userWalletDAC     = new UserWalletDAC();
            var  merchantWalletDAC = new MerchantWalletDAC();
            var  coin             = new CryptocurrencyDAC().GetById(coinId);
            var  isUserWallet     = userWalletDAC.IsUserWalletAddress(address);
            var  isMerchantWallet = merchantWalletDAC.IsMerchantWalletAddress(address);
            bool isFiiiAccount    = isUserWallet || isMerchantWallet;

            if (isFiiiAccount)
            {
                var withdrawMasterSetting = GetMerchantWithdrawalMasterSetting();
                var result = new TransactionFeeDTO
                {
                    TransactionFee     = "0",
                    TransactionFeeRate = withdrawMasterSetting.ToUserHandleFeeTier.ToString(CultureInfo.InvariantCulture)
                };

                var userWallet = userWalletDAC.GetByAddressAndCrypto(coinId, address, tag);
                if (userWallet?.CryptoId == coinId)
                {
                    result.CryptoAddressType = CryptoAddressType.FiiiPay;
                    return(result);
                }

                var merchantWallet = new MerchantWalletDAC().GetByAddress(address, tag);
                if (merchantWallet?.CryptoId == coinId)
                {
                    result.CryptoAddressType = CryptoAddressType.FiiiPOS;
                    return(result);
                }

                result.CryptoAddressType = CryptoAddressType.InsideWithError;
                return(result);
            }
            else
            {
                return(new TransactionFeeDTO
                {
                    CryptoAddressType = CryptoAddressType.Outside,
                    TransactionFee = (coin.Withdrawal_Fee ?? 0).ToString(CultureInfo.InvariantCulture),
                    TransactionFeeRate = (coin.Withdrawal_Tier ?? 0).ToString(CultureInfo.InvariantCulture)
                });
            }
        }
Пример #12
0
        public SaveResult Reward(Guid id, int userId, string userName)
        {
            var settingCollection = new MasterSettingDAC().SelectByGroup("InviteReward");
            var inviteMoney       = decimal.Parse(settingCollection.Where(item => item.Name == "Invite_Reward_Amount").Select(item => item.Value).FirstOrDefault());

            var uwComponent = new UserWalletBLL();
            var uwsDAC      = new UserWalletStatementDAC();
            var uwDAC       = new UserWalletDAC();

            var cryptoId     = new CryptocurrencyDAC().GetByCode("FIII").Id;
            var inviteWallet = uwComponent.GetUserWallet(id, cryptoId);

            if (inviteWallet == null)
            {
                inviteWallet = uwComponent.GenerateWallet(id, cryptoId);
            }

            var adoResult = FiiiPayDB.DB.Ado.UseTran(() =>
            {
                //解冻奖励
                uwDAC.Increase(inviteWallet.Id, inviteMoney);
                //插入奖励流水
                uwsDAC.Insert(new UserWalletStatement
                {
                    WalletId  = inviteWallet.Id,
                    Action    = UserWalletStatementAction.Invite,
                    Amount    = inviteMoney,
                    Balance   = inviteWallet.Balance + inviteMoney,
                    Timestamp = DateTime.UtcNow,
                    Remark    = "BO Reward"
                });
            });
            ActionLog actionLog = new ActionLog();

            actionLog.IPAddress  = GetClientIPAddress();
            actionLog.AccountId  = userId;
            actionLog.CreateTime = DateTime.UtcNow;
            actionLog.ModuleCode = typeof(UserManageBLL).FullName + ".Reward";
            actionLog.Username   = userName;
            actionLog.LogContent = "Reward " + id + " Fiii:" + inviteMoney;
            new ActionLogBLL().Create(actionLog);


            return(new SaveResult(true, "Save Success"));
        }
Пример #13
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);
        }
Пример #14
0
        public bool BillerRefund(string orderNo)
        {
            var orderDac = new BillerOrderDAC();
            var order    = FiiiPayDB.DB.Queryable <BillerOrders>().Where(t => t.OrderNo.Equals(orderNo)).First();

            if (order == null)
            {
                throw new CommonException(10000, "Order does not exist!");
            }

            var merchantWalletDAC = new MerchantWalletDAC();
            var userWalletDAC     = new UserWalletDAC();

            var userWallet = userWalletDAC.GetByAccountId(order.AccountId, order.CryptoId);

            if (userWallet == null)
            {
                throw new CommonException(10001, "A currency that is not supported by the user");
            }
            using (var scope = new TransactionScope())
            {
                userWalletDAC.Increase(order.AccountId, order.CryptoId, order.CryptoAmount);
                new UserWalletStatementDAC().Insert(new UserWalletStatement
                {
                    WalletId  = userWallet.Id,
                    Action    = "REFUND",
                    Amount    = order.CryptoAmount,
                    Balance   = userWallet.Balance + order.CryptoAmount,
                    Timestamp = DateTime.UtcNow,
                    Remark    = $"Refund from billerorder({order.OrderNo})"
                });

                order.Status = BillerOrderStatus.Fail;
                orderDac.UpdateStatus(order);

                new RefundDAC().Insert(new Refund
                {
                    OrderId   = order.Id,
                    Status    = RefundStatus.Completed,
                    Timestamp = DateTime.UtcNow
                });
                scope.Complete();
            }
            return(true);
        }
Пример #15
0
        public override Wallet GetByAccountId(Guid accountId, int cryptoId)
        {
            var baseWallet = new UserWalletDAC().GetByAccountId(accountId, cryptoId);

            if (baseWallet == null)
            {
                return(null);
            }
            return(new Wallet
            {
                Id = baseWallet.Id,
                AccountId = baseWallet.UserAccountId,
                CryptoId = baseWallet.CryptoId,
                Balance = baseWallet.Balance,
                FrozenBalance = baseWallet.FrozenBalance,
                Address = baseWallet.Address
            });
        }
Пример #16
0
        public PrePayExistedOrderOM PrePayExistedOrder(UserAccount user, PrePayExistedOrderIM im)
        {
            var orderno = im.OrderNo;
            var order   = RedisHelper.Get <RedisOrderDTO>($"fiiipos:order:{orderno}");

            if (order == null)
            {
                throw im.Type == PrePayExistedOrderIMType.ScanCode
                    ? new CommonException(ReasonCode.INVALID_QRCODE, MessageResources.InvalidQRCode)
                    : new CommonException(ReasonCode.GENERAL_ERROR, MessageResources.OrderNotFound);
            }
            //if (order.ExpiredTime < DateTime.UtcNow)
            //    throw new ApplicationException(Resources.订单已过期);
            //if (order.Status != OrderStatus.Pending)
            //    throw new ApplicationException(Resources.订单已完成或者已退款);
            if (order.UserId != Guid.Empty)
            {
                if (order.UserId != user.Id)
                {
                    throw new ApplicationException(MessageResources.AccountNotMatch);
                }
            }
            if (new OrderDAC().GetByOrderNo(orderno) != null)
            {
                throw new ApplicationException(MessageResources.OrderComplated);
            }

            var userWallet = new UserWalletDAC().GetByAccountId(user.Id, order.CryptoId) ?? new UserWallet {
                Balance = 0, FrozenBalance = 0
            };
            var     coin            = new CryptocurrencyDAC().GetById(order.CryptoId);
            var     exchangeRate    = GetExchangeRate(order.CountryId, order.FiatCurrency, coin);
            decimal fiatTotalAmount = (order.FiatAmount * (1 + order.Markup)).ToSpecificDecimal(4);
            decimal cryptoAmount    = (fiatTotalAmount / exchangeRate).ToSpecificDecimal(coin.DecimalPlace);

            return(new PrePayExistedOrderOM
            {
                Amount = cryptoAmount.ToString(coin.DecimalPlace),
                Currency = coin.Code,
                MerchantName = new MerchantAccountDAC().GetById(order.MerchantGuid).MerchantName,
                Balance = userWallet.Balance.ToString(coin.DecimalPlace),
                CoinId = order.CryptoId
            });
        }
Пример #17
0
        public TransactionFeeRateOM TransactionFeeRate(int coinId, string address, string tag)
        {
            var  userWalletDAC     = new UserWalletDAC();
            var  merchantWalletDAC = new MerchantWalletDAC();
            var  coin             = new CryptocurrencyDAC().GetById(coinId);
            var  mastSettings     = new MasterSettingDAC().SelectByGroup("UserWithdrawal");
            var  isUserWallet     = userWalletDAC.IsUserWalletAddress(address);
            var  isMerchantWallet = merchantWalletDAC.IsMerchantWalletAddress(address);
            bool isFiiiAccount    = isUserWallet || isMerchantWallet;

            if (isFiiiAccount)
            {
                var userWallet = userWalletDAC.GetByAddressAndCrypto(coinId, address, tag);
                var result     = new TransactionFeeRateOM
                {
                    CryptoAddressType  = CryptoAddressType.FiiiPay,
                    TransactionFee     = "0",
                    TransactionFeeRate = mastSettings.First(e => e.Name == "UserWithdrawal_ToUser").Value
                };
                if (userWallet != null)
                {
                    return(result);
                }

                var merchantWallet = merchantWalletDAC.GetByAddressAndCrypto(coinId, address, tag);
                if (merchantWallet != null)
                {
                    result.CryptoAddressType = CryptoAddressType.FiiiPOS;
                    return(result);
                }

                result.CryptoAddressType = CryptoAddressType.InsideWithError;
                return(result);
            }
            else
            {
                return(new TransactionFeeRateOM
                {
                    CryptoAddressType = CryptoAddressType.Outside,
                    TransactionFee = (coin.Withdrawal_Fee ?? 0).ToString(CultureInfo.InvariantCulture),
                    TransactionFeeRate = (coin.Withdrawal_Tier ?? 0).ToString(CultureInfo.InvariantCulture)
                });
            }
        }
Пример #18
0
        public TransferFiiiExConditionOM FiiiPayTransferFiiiExCondition(UserAccount account, int cryptoId)
        {
            var crypto    = new CryptocurrencyDAC().GetById(cryptoId);
            var walletDac = new UserWalletDAC();
            var wallet    = walletDac.GetByAccountId(account.Id, crypto.Id);

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

            var minQuantity =
                (1M / (decimal)Math.Pow(10, crypto.DecimalPlace)).ToString(crypto.DecimalPlace);

            return(new TransferFiiiExConditionOM
            {
                Balance = (wallet?.Balance ?? 0M).ToString(crypto.DecimalPlace),
                MinQuantity = minQuantity,
                FiiiExBalance = fiiiExBalance.ToString(crypto.DecimalPlace),
                FiiiExMinQuantity = minQuantity
            });
        }
Пример #19
0
        private PrePayOM GetUserPrePayOM(Guid userAccountId, MerchantInformation merchantInfo)
        {
            var userDAC             = new UserAccountDAC();
            var merchantDAC         = new MerchantInformationDAC();
            var merchantUserAccount = userDAC.GetById(merchantInfo.MerchantAccountId);
            var supportList         = new MerchantSupportCryptoDAC().GetList(merchantInfo.Id).ToList();
            var userWallets         = new UserWalletDAC().GetUserWallets(userAccountId);
            var coins     = new CryptocurrencyDAC().GetAllActived();
            var priceList = new PriceInfoDAC().GetPrice(merchantUserAccount.FiatCurrency);

            var whilteLabelCryptoCode = new POSDAC().GetWhiteLabelCryptoCode();

            coins.RemoveAll(t => t.Code == whilteLabelCryptoCode);

            return(new PrePayOM
            {
                FiatCurrency = merchantUserAccount.FiatCurrency,
                MarkupRate = merchantInfo.Markup.ToString(CultureInfo.InvariantCulture),
                WaletList = coins.Select(a =>
                {
                    var userWallet = userWallets.FirstOrDefault(b => b.CryptoId == a.Id);
                    decimal rate = 0;
                    rate = priceList.Where(t => t.CryptoID == a.Id).Select(t => t.Price).FirstOrDefault();
                    return GetUserSupportItem(userWallet, a, supportList, rate);
                }).OrderByDescending(a => a.MerchantSupported).ThenBy(a => a.PayRank).Select(a => new WalletItem
                {
                    Code = a.Code,
                    NewStatus = a.NewStatus,
                    ExchangeRate = a.ExchangeRate,
                    FrozenBalance = a.FrozenBalance,
                    IconUrl = a.IconUrl,
                    Id = a.Id,
                    MerchantSupported = a.MerchantSupported,
                    Name = a.Name,
                    UseableBalance = a.UseableBalance,
                    FiatBalance = a.FiatBalance,
                    DecimalPlace = a.DecimalPlace,
                    CryptoEnable = a.CryptoEnable
                }).ToList()
            });
        }
Пример #20
0
        public WalletPreReOrderOM PreReOrder(UserAccount user)
        {
            var userWallets = new UserWalletDAC().GetUserWallets(user.Id);
            var coins       = new CryptocurrencyDAC().GetAll();
            var list        = coins.Select(a =>
            {
                var userWallet = userWallets.FirstOrDefault(b => b.CryptoId == a.Id);

                return(GetPreReOrderOMItemTempItem(userWallet, a));
            }).OrderBy(a => a.PayRank).Select(a => new WalletPreReOrderOMItem
            {
                Id      = a.Id,
                Code    = a.Code,
                IconUrl = a.IconUrl,
                Name    = a.Name,
                Fixed   = a.Fixed
            }).ToList();

            return(new WalletPreReOrderOM
            {
                List = list
            });
        }
Пример #21
0
        public PreReOrder1OM PreReOrder(UserAccount user)
        {
            var userWallets = new UserWalletDAC().GetUserWallets(user.Id);
            var coins       = new CryptocurrencyDAC().GetAllActived();
            var list        = coins.Select(a =>
            {
                var userWallet = userWallets.FirstOrDefault(b => b.CryptoId == a.Id);

                return(GetPreReOrderOMItemTempItem(userWallet, a));
            }).OrderByDescending(a => a.ShowInHomePage).ThenBy(a => a.HomePageRank).Select(a => new PreReOrder1OMItem
            {
                Id             = a.Id,
                Code           = a.Code,
                IconUrl        = a.IconUrl,
                Name           = a.Name,
                Fixed          = a.Fixed,
                ShowInHomePage = a.ShowInHomePage
            }).ToList();

            return(new PreReOrder1OM
            {
                List = list
            });
        }
Пример #22
0
        public RedPocketDetailOM Receive(UserAccount userAccount, string passcode, bool isZH = false)
        {
            if (userAccount == null)
            {
                throw new SystemErrorException();
            }

            if (string.IsNullOrWhiteSpace(passcode))
            {
                throw new CommonException(Argument_Error, MessageResources.InvalidDataFormat);
            }

            if (userAccount.L1VerifyStatus != Entities.Enums.VerifyStatus.Certified)
            {
                throw new CommonException(ReasonCode.NOT_VERIFY_LV1, Resources.EMNeedLV1Verfied);
            }

            var count = RedisHelper.StringGet(LockDbIndex, string.Format(KeyFormat, userAccount.Id));

            if (!string.IsNullOrWhiteSpace(count) && int.Parse(count) >= 10)
            {
                var ttl = RedisHelper.KeyTimeToLive(LockDbIndex, string.Format(KeyFormat, userAccount.Id));
                if (ttl != null)
                {
                    var message = "";
                    var t       = "";
                    try
                    {
                        t       = TimeConvert(ttl.Value, isZH);
                        message = string.Format(MessageResources.RedPocket_PassCodeErrorMaxCount, t);
                    }
                    catch (Exception exception)
                    {
                        _log.Error(exception.Message + "    " + MessageResources.RedPocket_PassCodeErrorMaxCount + "    " + t);
                    }

                    throw new CommonException(MaxError, message);
                }
            }

            var redPocketDAC = new RedPocketDAC();

            var redPocket = redPocketDAC.GetByPassCode(passcode);

            if (redPocket == null)
            {
                var errorCount = ErrorCount(userAccount.Id, count, isZH);
                throw new CommonException(PassCodeError, string.Format(MessageResources.RedPocket_PassCodeError, errorCount, 10 - errorCount));
            }

            if (redPocket.ExpirationDate < DateTime.UtcNow)
            {
                var errorCount = ErrorCount(userAccount.Id, count, isZH);
                throw new CommonException(PassCodeExpired, MessageResources.RedPocket_ReceiveExpired + Environment.NewLine + string.Format(MessageResources.RedPocket_PassCodeError, errorCount, 10 - errorCount));
            }

            var crypto = new CryptocurrencyDAC().GetByCode(redPocket.CryptoCode);

            if (!crypto.Status.HasFlag(Foundation.Entities.Enum.CryptoStatus.RedPocket) || crypto.Enable == 0)
            {
                throw new CommonException(ReasonCode.CURRENCY_FORBIDDEN, MessageResources.CurrencyForbidden);
            }

            var om = new RedPocketDetailOM();
            var redPocketReceiveDAC = new RedPocketReceiverDAC();

            var hasReceive = redPocketReceiveDAC.HasReceive(userAccount.Id, redPocket.Id);

            if (redPocket.Status == RedPocketStatus.Actived && hasReceive == null)
            {
                var userWalletDAC          = new UserWalletDAC();
                var userWalletStatementDAC = new UserWalletStatementDAC();
                var uwComponent            = new UserWalletComponent();
                var userTransactionDAC     = new UserTransactionDAC();

                var wallet = userWalletDAC.GetByCryptoCode(userAccount.Id, redPocket.CryptoCode);
                if (wallet == null)
                {
                    wallet = uwComponent.GenerateWallet(userAccount.Id, redPocket.CryptoCode);
                }

                var min = crypto.DecimalPlace == 8 ? 0.00000001M : crypto.DecimalPlace == 6 ? 0.000001M : 0.00000001M;
                var n   = crypto.DecimalPlace == 8 ? 100000000 : crypto.DecimalPlace == 6 ? 1000000 : 100000000;

                var amount = GetRandomMoney(redPocket, min, n);

                var priceDAC   = new PriceInfoDAC();
                var price      = priceDAC.GetPriceByName("USD", crypto.Code);
                var fiatAmount = price * amount;
                using (var scope = new TransactionScope())
                {
                    try
                    {
                        var redPocketReceiver = new RedPocketReceiver
                        {
                            PocketId      = redPocket.Id,
                            AccountId     = userAccount.Id,
                            SendAccountId = redPocket.AccountId,
                            CryptoCode    = redPocket.CryptoCode,
                            Amount        = amount,
                            Timestamp     = DateTime.UtcNow,
                            IsBestLuck    = redPocket.Count == 1,
                            OrderNo       = IdentityHelper.OrderNo(),
                            FiatAmount    = fiatAmount <= 0 ? 0M : Math.Round(fiatAmount, 8)
                        };
                        var id = redPocketReceiveDAC.Insert(redPocketReceiver);

                        userTransactionDAC.Insert(new UserTransaction
                        {
                            Id         = Guid.NewGuid(),
                            AccountId  = redPocketReceiver.AccountId,
                            CryptoId   = redPocket.CryptoId,
                            CryptoCode = redPocket.CryptoCode,
                            Type       = UserTransactionType.ReceiveRedPocket,
                            DetailId   = id.ToString(),
                            Status     = (byte)redPocket.Status,
                            Timestamp  = redPocketReceiver.Timestamp,
                            Amount     = redPocketReceiver.Amount,
                            OrderNo    = redPocketReceiver.OrderNo
                        });

                        userWalletDAC.Increase(wallet.Id, amount);
                        userWalletStatementDAC.Insert(new UserWalletStatement
                        {
                            WalletId      = wallet.Id,
                            Balance       = wallet.Balance + amount,
                            Amount        = amount,
                            FrozenAmount  = 0,
                            FrozenBalance = wallet.FrozenBalance,
                            Action        = "Receive Red Pocket",
                            Timestamp     = DateTime.UtcNow
                        });

                        redPocketDAC.UpdateRemain(redPocket.Id, amount);

                        if (redPocket.RemainCount == 0)
                        {
                            redPocketDAC.UpdateStatus(redPocket.Id, RedPocketStatus.Complate);
                            userTransactionDAC.UpdateStatus(UserTransactionType.PushRedPocket, redPocket.Id.ToString(), redPocket.AccountId, (byte)RedPocketStatus.Complate);

                            if (redPocket.Count > 1)
                            {
                                redPocketReceiveDAC.UpdateBestLuck(redPocket.Id);
                            }
                        }

                        scope.Complete();
                    }
                    catch (Exception ex)
                    {
                        _log.Error(ex);
                        throw new CommonException();
                    }
                }
                om.SelfAmount      = amount.ToString();
                om.ReceiveStatus   = ReceiveStatusEnum.Receive;
                om.HasExpried      = false;
                redPocket.Balance -= amount;
            }
            else
            {
                if (hasReceive != null)
                {
                    om.ReceiveStatus = ReceiveStatusEnum.HasReceive;
                    om.SelfAmount    = hasReceive.Amount.ToString();
                }
                else
                {
                    om.ReceiveStatus = ReceiveStatusEnum.None;
                    om.SelfAmount    = string.Empty;
                }
            }

            var account = new UserAccountComponent().GetById(redPocket.AccountId);

            om.Message        = redPocket.Message;
            om.SnederNickname = account.Nickname;

            om.TotalAmount   = redPocket.Amount.ToString();
            om.TotalCount    = redPocket.Count;
            om.CryptoCode    = redPocket.CryptoCode;
            om.ReceiveAmount = (redPocket.Amount - redPocket.Balance).ToString();
            om.ReceiveCount  = redPocket.Count - redPocket.RemainCount;
            om.Id            = redPocket.Id;
            om.HasExpried    = redPocket.ExpirationDate < DateTime.UtcNow;
            om.HasSelfSned   = redPocket.AccountId == userAccount.Id;

            return(om);
        }
Пример #23
0
        public BillerPayOM Pay(UserAccount account, BillerPayIM im, ref int errorCode)
        {
            var coin = new CryptocurrencyDAC().GetById(im.CryptoId);

            if (!coin.Status.HasFlag(CryptoStatus.Biller) || coin.Enable == 0)
            {
                throw new CommonException(ReasonCode.CURRENCY_FORBIDDEN, MessageResources.CurrencyForbidden);
            }
            var result = PrePay(new BillerPrePayIM()
            {
                CountryId = im.CountryId, CryptoAmount = im.CryptoAmount, CryptoCode = im.CryptoCode,
                CryptoId  = im.CryptoId, FiatAmount = im.FiatAmount, FiatCurrency = im.FiatCurrency
            }).Status;

            if (result != 0)
            {
                errorCode = 10400 + result;
                return(null);
            }

            new SecurityComponent().VerifyPin(account, im.Pin);
            var cryptoCurrency = new CryptocurrencyDAC().GetById(im.CryptoId);

            if (cryptoCurrency?.Id == null)
            {
                throw new CommonException(ReasonCode.CRYPTO_NOT_EXISTS, "Error: Invalid Cryptocurrency");
            }
            var uwComponent = new UserWalletComponent();
            var userWallet  = uwComponent.GetUserWallet(account.Id, im.CryptoId);

            if (userWallet == null)
            {
                throw new CommonException(ReasonCode.INSUFFICIENT_BALANCE, MessageResources.InsufficientBalance);
            }
            if (userWallet.Balance < im.CryptoAmount)
            {
                throw new CommonException(ReasonCode.INSUFFICIENT_BALANCE, MessageResources.InsufficientBalance);
            }
            var uwDAC       = new UserWalletDAC();
            var uwsDAC      = new UserWalletStatementDAC();
            var boDAC       = new BillerOrderDAC();
            var billerOrder = new BillerOrder()
            {
                Id           = Guid.NewGuid(),
                BillerCode   = im.BillerCode,
                CryptoAmount = im.CryptoAmount,
                CryptoCode   = im.CryptoCode,
                CryptoId     = im.CryptoId,
                Discount     = im.CryptoCode.Equals("Fiii", StringComparison.InvariantCultureIgnoreCase)
                    ? decimal.Parse(new MasterSettingDAC().SelectByGroup("BillerMaxAmount").First(item =>
                                                                                                  item.Name.Equals("DiscountRate", StringComparison.CurrentCultureIgnoreCase)).Value)
                    : 0,
                ExchangeRate    = im.ExchangeRate,
                FiatAmount      = im.FiatAmount,
                FiatCurrency    = im.FiatCurrency,
                ReferenceNumber = im.ReferenceNumber,
                Tag             = im.Tag,
                Status          = BillerOrderStatus.Pending,
                Timestamp       = DateTime.UtcNow,
                AccountId       = account.Id,
                OrderNo         = IdentityHelper.OrderNo(),
                PayTime         = DateTime.UtcNow,
                CountryId       = im.CountryId
            };
            var address = new BillerAddressDAC().GetAllAddresses(account.Id).FirstOrDefault(item =>
                                                                                            item.BillerCode == im.BillerCode && im.ReferenceNumber == item.ReferenceNumber);

            billerOrder.Tag = address?.Tag;
            using (var scope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, new TimeSpan(0, 0, 1, 30)))
            {
                uwDAC.Decrease(userWallet.Id, billerOrder.CryptoAmount);
                uwsDAC.Insert(new UserWalletStatement
                {
                    WalletId      = userWallet.Id,
                    Action        = UserWalletStatementAction.Consume,
                    Amount        = -billerOrder.CryptoAmount,
                    Balance       = userWallet.Balance - billerOrder.CryptoAmount,
                    FrozenAmount  = 0,
                    FrozenBalance = userWallet.FrozenBalance,
                    Timestamp     = DateTime.UtcNow
                });

                boDAC.Insert(billerOrder);
                new UserTransactionDAC().Insert(new UserTransaction
                {
                    Id         = Guid.NewGuid(),
                    AccountId  = billerOrder.AccountId,
                    CryptoId   = cryptoCurrency.Id,
                    CryptoCode = cryptoCurrency.Code,
                    Type       = UserTransactionType.BillOrder,
                    DetailId   = billerOrder.Id.ToString(),
                    Status     = (byte)billerOrder.Status,
                    Timestamp  = billerOrder.Timestamp,
                    Amount     = billerOrder.CryptoAmount,
                    OrderNo    = billerOrder.OrderNo
                });
                scope.Complete();
            }

            return(new BillerPayOM()
            {
                CryptoAmount = billerOrder.CryptoAmount.ToString(), OrderNo = billerOrder.OrderNo,
                CryptoCode = billerOrder.CryptoCode, OrderId = billerOrder.Id,
                Timestamp = billerOrder.PayTime.ToUnixTime().ToString(),
                SaveAddress = address != null
            });
        }
Пример #24
0
        public RedPocket Push(UserAccount userAccount, Guid accountId, int cryptoId, decimal amount, int count, string userPIN, string pin, string message = "")
        {
            if (userAccount.L1VerifyStatus != Entities.Enums.VerifyStatus.Certified)
            {
                throw new CommonException(ReasonCode.NOT_VERIFY_LV1, Resources.EMNeedLV1Verfied);
            }

            if (amount <= 0 || cryptoId <= 0)
            {
                throw new CommonException(Argument_Error, MessageResources.InvalidDataFormat);
            }
            if (count <= 0)
            {
                throw new CommonException(Argument_Error, MessageResources.InvalidDataFormat);
            }

            if (count > MaxCount)
            {
                throw new CommonException(Argument_Error, string.Format(MessageResources.RedPocket_MaxCount, MaxCount));
            }

            if (!string.IsNullOrWhiteSpace(message) && message.Length > 46)
            {
                throw new CommonException(Argument_Error, MessageResources.RedPocket_MaxMessage);
            }

            SecurityVerify.Verify(new PinVerifier(), SystemPlatform.FiiiPay, accountId.ToString(), userPIN, pin);

            var cryptoDAC = new CryptocurrencyDAC();
            var priceDAC  = new PriceInfoDAC();

            var crypto = cryptoDAC.GetById(cryptoId);

            if (crypto == null)
            {
                throw new SystemErrorException();
            }

            if (!crypto.Status.HasFlag(Foundation.Entities.Enum.CryptoStatus.RedPocket) || crypto.Enable == 0)
            {
                throw new CommonException(ReasonCode.CURRENCY_FORBIDDEN, MessageResources.CurrencyForbidden);
            }

            var min = crypto.DecimalPlace == 8 ? 0.00000001M : crypto.DecimalPlace == 6 ? 0.000001M : 0.00000001M;

            var minAmount = count * min;

            if (amount < minAmount)
            {
                throw new CommonException(Push_MinAmount, string.Format(MessageResources.RedPocket_MinAmount, minAmount, crypto.Code));
            }

            var price = priceDAC.GetPriceByName("USD", crypto.Code);

            var max       = crypto.DecimalPlace == 8 ? 999999999.999999999M : crypto.DecimalPlace == 6 ? 999999999.999999M : 999999999.999999999M;
            var maxAmount = Math.Round(MaxAmount / price, crypto.DecimalPlace);

            if (count > 1)
            {
                maxAmount = Math.Round(MaxAmount * count / price, crypto.DecimalPlace);
            }

            if (amount >= max || Math.Round(amount, crypto.DecimalPlace) > maxAmount)
            {
                throw new CommonException(Argument_Error, string.Format(MessageResources.RedPocket_MaxAmount, maxAmount, crypto.Code));
            }

            var userWalletDAC          = new UserWalletDAC();
            var redPocketDAC           = new RedPocketDAC();
            var userWalletStatementDAC = new UserWalletStatementDAC();
            var userTransactionDAC     = new UserTransactionDAC();

            var wallet = userWalletDAC.GetByAccountId(accountId, cryptoId);

            if (wallet == null || wallet.Balance < amount)
            {
                throw new CommonException(ReasonCode.INSUFFICIENT_BALANCE, MessageResources.InsufficientBalance);
            }

            var fiatAmount = price * amount;

            using (var scope = new TransactionScope())
            {
                try
                {
                    var redPocket = new RedPocket
                    {
                        AccountId      = accountId,
                        Status         = RedPocketStatus.Actived,
                        PassCode       = GeneralPassCode(),
                        CryptoCode     = crypto.Code,
                        Amount         = amount,
                        Balance        = amount,
                        Count          = count,
                        RemainCount    = count,
                        Message        = message,
                        Timestamp      = DateTime.UtcNow,
                        ExpirationDate = DateTime.UtcNow.AddMinutes(_expried),
                        CryptoId       = cryptoId,
                        OrderNo        = IdentityHelper.OrderNo(),
                        FiatAmount     = fiatAmount <= 0 ? 0M : Math.Round(fiatAmount, 8)
                    };

                    var redPocketId = redPocketDAC.Insert(redPocket);
                    userTransactionDAC.Insert(new UserTransaction
                    {
                        Id         = Guid.NewGuid(),
                        AccountId  = accountId,
                        CryptoId   = redPocket.CryptoId,
                        CryptoCode = redPocket.CryptoCode,
                        Type       = UserTransactionType.PushRedPocket,
                        DetailId   = redPocketId.ToString(),
                        Status     = (byte)redPocket.Status,
                        Timestamp  = redPocket.Timestamp,
                        Amount     = redPocket.Amount,
                        OrderNo    = redPocket.OrderNo
                    });

                    userWalletDAC.Decrease(wallet.Id, amount);
                    userWalletStatementDAC.Insert(new UserWalletStatement
                    {
                        WalletId      = wallet.Id,
                        Balance       = wallet.Balance - amount,
                        Amount        = 0 - amount,
                        FrozenAmount  = 0,
                        FrozenBalance = wallet.FrozenBalance,
                        Action        = "Push Red Pocket",
                        Timestamp     = DateTime.UtcNow
                    });

                    QueueHelper.DelaySender.Send("FiiiPay_RedPocket", redPocketId);

                    scope.Complete();

                    return(redPocket);
                }
                catch (Exception ex)
                {
                    _log.Error(ex);

                    throw new SystemErrorException();
                }
            }
        }
Пример #25
0
        private GatewayOrder ExcutePay(GatewayOrderOM orderDetail, Guid id)
        {
            var cryptoCurrency = new CryptocurrencyDAC().GetByCode(orderDetail.Crypto);

            if (cryptoCurrency == null || cryptoCurrency?.Id == null)
            {
                throw new CommonException(CRYPTO_NOT_EXISTS, "Error: Invalid Cryptocurrency");
            }
            //var uwComponent = new UserWalletComponent();
            var userWallet = new UserWalletDAC().GetUserWallet(orderDetail.UserAccountId.Value, cryptoCurrency.Id);

            if (userWallet.Balance < orderDetail.ActualCryptoAmount)
            {
                throw new CommonException(INSUFFICIENT_BALANCE, Resources.余额不足);
            }
            var uwDAC  = new UserWalletDAC();
            var uwsDAC = new UserWalletStatementDAC();
            var goDAC  = new GatewayOrderDAC();

            bool needAddOrder = true;
            var  gatewayOrder = goDAC.GetByTradeNo(orderDetail.Id.ToString());

            if (gatewayOrder != null)
            {
                if (gatewayOrder.Status != GatewayOrderStatus.Pending)
                {
                    throw new CommonException(ORDER_HAD_COMPLETE, Resources.订单已完成或者已退款);
                }
                needAddOrder = false;
            }
            else
            {
                gatewayOrder = new Entities.GatewayOrder()
                {
                    OrderNo            = CreateOrderno(),
                    TradeNo            = orderDetail.Id.ToString(),
                    Id                 = id,
                    CryptoId           = cryptoCurrency.Id,
                    MerchantAccountId  = orderDetail.MerchantAccountId,
                    FiatAmount         = orderDetail.FiatAmount,
                    MerchantName       = orderDetail.MerchantName,
                    UserAccountId      = orderDetail.UserAccountId,
                    CryptoAmount       = orderDetail.CryptoAmount,
                    ActualCryptoAmount = orderDetail.ActualCryptoAmount,
                    FiatCurrency       = orderDetail.FiatCurrency,
                    Markup             = orderDetail.MarkupRate,
                    ActualFiatAmount   = orderDetail.ActualFiatAmount,
                    Status             = GatewayOrderStatus.Completed,
                    ExchangeRate       = orderDetail.ExchangeRate,
                    ExpiredTime        = orderDetail.ExpiredTime,
                    TransactionFee     = orderDetail.TransactionFee,
                    Timestamp          = DateTime.UtcNow,
                    PaymentTime        = DateTime.UtcNow,
                    Remark             = orderDetail.Remark
                };
            }

            using (var scope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, new TimeSpan(0, 0, 1, 30)))
            {
                if (needAddOrder)
                {
                    goDAC.Insert(gatewayOrder);
                }
                uwDAC.Decrease(userWallet.Id, orderDetail.ActualCryptoAmount);
                uwsDAC.Insert(new UserWalletStatement
                {
                    WalletId      = userWallet.Id,
                    Action        = UserWalletStatementAction.TansferOut,
                    Amount        = -orderDetail.ActualCryptoAmount,
                    Balance       = userWallet.Balance - orderDetail.ActualCryptoAmount,
                    FrozenAmount  = 0,
                    FrozenBalance = userWallet.FrozenBalance,
                    Timestamp     = DateTime.UtcNow
                });

                scope.Complete();
            }

            return(gatewayOrder);
        }
Пример #26
0
        //private readonly Dictionary<string, int> _notificationErrorCount = new Dictionary<string, int>();

        public void Payment(string message)
        {
            var orderModel = JsonConvert.DeserializeObject <MallPaymentOrder>(message);

            var userWalletDac      = new UserWalletDAC();
            var walletStatementDac = new UserWalletStatementDAC();
            var gatewayOrderDac    = new GatewayOrderDAC();
            var mallDac            = new MallPaymentOrderDAC();
            var cryptoDac          = new CryptocurrencyDAC();

            var extsis = gatewayOrderDac.GetByOrderNo(orderModel.OrderId);

            if (extsis != null && extsis.Status == GatewayOrderStatus.Completed)
            {
                _log.Info("Order message " + message + " hased Payment.");
                return;
            }

            var cryptoFiii = cryptoDac.GetByCode("FIII");
            var fiiiWallet = userWalletDac.GetByAccountId(orderModel.UserAccountId, cryptoFiii.Id);

            if (fiiiWallet.Balance < orderModel.CryptoAmount)
            {
                _log.ErrorFormat("message {0}, Insufficient balance", message);
            }

            try
            {
                var fiiiPrice      = GetMarketPrice("USD", "FIII");
                var fiiiFiatAmount = Math.Round(orderModel.CryptoAmount * fiiiPrice, 2);

                var trdeNo = NumberGenerator.GenerateUnixOrderNo();
                var id     = Guid.NewGuid();
                using (var scope = new TransactionScope())
                {
                    userWalletDac.Decrease(fiiiWallet.Id, orderModel.CryptoAmount);
                    walletStatementDac.Insert(new UserWalletStatement
                    {
                        WalletId      = fiiiWallet.Id,
                        Action        = UserWalletStatementAction.Consume,
                        Amount        = -orderModel.CryptoAmount,
                        Balance       = fiiiWallet.Balance - orderModel.CryptoAmount,
                        FrozenAmount  = 0,
                        FrozenBalance = fiiiWallet.FrozenBalance,
                        Timestamp     = DateTime.UtcNow
                    });

                    var gatewayFiiiOrder = new GatewayOrder
                    {
                        Id                 = id,
                        OrderNo            = orderModel.OrderId,
                        MerchantAccountId  = Guid.Empty,
                        MerchantName       = "FiiiShop",
                        CryptoId           = cryptoFiii.Id,
                        CryptoCode         = "FIII",
                        FiatAmount         = fiiiFiatAmount,
                        FiatCurrency       = "USD",
                        Status             = GatewayOrderStatus.Completed,
                        ExpiredTime        = DateTime.UtcNow.AddMinutes(30),
                        Markup             = 0M,
                        ExchangeRate       = fiiiPrice,
                        PaymentTime        = DateTime.UtcNow,
                        Timestamp          = DateTime.UtcNow,
                        UserAccountId      = orderModel.UserAccountId,
                        ActualCryptoAmount = orderModel.CryptoAmount,
                        ActualFiatAmount   = fiiiFiatAmount,
                        CryptoAmount       = orderModel.CryptoAmount,
                        TransactionFee     = 0,
                        Remark             = null,
                        TradeNo            = trdeNo
                    };
                    gatewayOrderDac.Insert(gatewayFiiiOrder);

                    mallDac.UpdateStatus(orderModel.Id, (byte)OrderStatus.Completed);
                    mallDac.UpdateTradeNo(orderModel.Id, trdeNo);

                    scope.Complete();
                }

                RabbitMQSender.SendMessage("ShopPayment", id);
                SendNotificationMessage(TradeType.Payment, orderModel.Id, orderModel.OrderId, trdeNo, "success");
            }
            catch (Exception exception)
            {
                //SendNotificationMessage(TradeType.Payment, orderModel.Id, orderModel.OrderId, string.Empty, "error");
                _log.Error("Payment error, exception : " + exception.Message);
            }
        }
Пример #27
0
        public void Refund(string message)
        {
            var orderModel = JsonConvert.DeserializeObject <MallPaymentOrder>(message);

            var userWalletDac      = new UserWalletDAC();
            var walletStatementDac = new UserWalletStatementDAC();
            var gatewayOrderDac    = new GatewayOrderDAC();
            var mallDac            = new MallPaymentOrderDAC();
            var refundDac          = new GatewayRefundOrderDAC();

            var gatewayOrder = gatewayOrderDac.GetByTradeNo(orderModel.TradeNo);

            if (gatewayOrder.Status == GatewayOrderStatus.Pending)
            {
                _log.Error("Order message " + message + " not payment.");
                return;
            }
            if (gatewayOrder.Status == GatewayOrderStatus.Refunded)
            {
                _log.Info("Order message " + message + " has refund.");
                return;
            }

            var fiiiWallet = userWalletDac.GetByCryptoCode(orderModel.UserAccountId, "FIII");

            try
            {
                var id            = Guid.NewGuid();
                var refundTradeNo = NumberGenerator.GenerateUnixOrderNo();
                using (var scope = new TransactionScope())
                {
                    mallDac.UpdateStatus(orderModel.Id, (byte)OrderStatus.Refunded);
                    mallDac.UpdateRefundTradeNo(orderModel.Id, refundTradeNo);

                    gatewayOrderDac.UpdateStatus(gatewayOrder.Id, (byte)OrderStatus.Refunded);

                    userWalletDac.Increase(fiiiWallet.Id, gatewayOrder.CryptoAmount);
                    walletStatementDac.Insert(new UserWalletStatement
                    {
                        WalletId      = fiiiWallet.Id,
                        Action        = UserWalletStatementAction.Refund,
                        Amount        = orderModel.CryptoAmount,
                        Balance       = fiiiWallet.Balance + gatewayOrder.CryptoAmount,
                        FrozenAmount  = 0,
                        FrozenBalance = fiiiWallet.FrozenBalance,
                        Timestamp     = DateTime.UtcNow
                    });

                    refundDac.Insert(new GatewayRefundOrder
                    {
                        Id            = id,
                        OrderId       = gatewayOrder.Id,
                        Remark        = "",
                        Status        = RefundStatus.Completed,
                        Timestamp     = DateTime.UtcNow,
                        RefundTradeNo = refundTradeNo
                    });

                    scope.Complete();
                }

                RabbitMQSender.SendMessage("ShopPaymentRefund", id);
                SendNotificationMessage(TradeType.Refund, orderModel.Id, orderModel.OrderId, refundTradeNo, "success");
            }
            catch (Exception exception)
            {
                _log.Error("Refund error, exception : " + exception.Message);

                //SendNotificationMessage(TradeType.Refund, orderModel.Id, orderModel.OrderId, string.Empty, "error");
            }
        }
Пример #28
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()
            });
        }
Пример #29
0
        public bool Refund(string orderNo)
        {
            var orderDac = new OrderDAC();

            var order = orderDac.GetByOrderNo(orderNo);

            if (order == null)
            {
                throw new CommonException(10000, "Order does not exist!");
            }

            if (order.Status != OrderStatus.Completed)
            {
                throw new CommonException(10001, "Order state exception!");
            }

            if (DateTime.UtcNow.AddDays(-3000) > order.PaymentTime)
            {
                throw new CommonException(10000, "Orders cannot be refundable for more than three days!");
            }

            var merchantWalletDAC = new MerchantWalletDAC();
            var userWalletDAC     = new UserWalletDAC();

            var merchantWallet = merchantWalletDAC.GetByAccountId(order.MerchantAccountId, order.CryptoId);

            if (merchantWallet == null)
            {
                throw new CommonException(10001, "The currency that the merchant does not support!");
            }

            if (merchantWallet.Balance < order.ActualCryptoAmount)
            {
                throw new CommonException(10001, "Not sufficient funds!");
            }

            var userWallet = userWalletDAC.GetByAccountId(order.UserAccountId.Value, order.CryptoId);

            if (userWallet == null)
            {
                throw new CommonException(10001, "A currency that is not supported by the user");
            }

            var merchantAccount = new MerchantAccountDAC().GetById(order.MerchantAccountId);

            var orderWithdrawalFee = new OrderWithdrawalFeeDAC().GetByOrderId(order.Id);

            if (orderWithdrawalFee != null)
            {
                var merchantOrderWithdrawalFeeWallet = merchantWalletDAC.GetByAccountId(order.MerchantAccountId, orderWithdrawalFee.CryptoId);
                using (var scope = new TransactionScope())
                {
                    merchantWalletDAC.Decrease(order.MerchantAccountId, order.CryptoId, order.ActualCryptoAmount);
                    new MerchantWalletStatementDAC().Insert(new MerchantWalletStatement
                    {
                        WalletId  = merchantWallet.Id,
                        Action    = "REFUND",
                        Amount    = -order.ActualCryptoAmount,
                        Balance   = merchantWallet.Balance - order.ActualCryptoAmount,
                        Timestamp = DateTime.UtcNow,
                        Remark    = $"Refund to order({order.OrderNo})"
                    });

                    merchantWalletDAC.Increase(order.MerchantAccountId, orderWithdrawalFee.CryptoId, orderWithdrawalFee.Amount);
                    new MerchantWalletStatementDAC().Insert(new MerchantWalletStatement
                    {
                        WalletId  = merchantOrderWithdrawalFeeWallet.Id,
                        Action    = "REFUND",
                        Amount    = orderWithdrawalFee.Amount,
                        Balance   = merchantWallet.Balance - orderWithdrawalFee.Amount,
                        Timestamp = DateTime.UtcNow,
                        Remark    = $"Refund to order({order.OrderNo})"
                    });

                    userWalletDAC.Increase(order.UserAccountId.Value, order.CryptoId, order.CryptoAmount);
                    new UserWalletStatementDAC().Insert(new UserWalletStatement
                    {
                        WalletId      = userWallet.Id,
                        Action        = "REFUND",
                        Amount        = order.CryptoAmount,
                        Balance       = userWallet.Balance + order.CryptoAmount,
                        FrozenAmount  = 0,
                        FrozenBalance = userWallet.FrozenBalance,
                        Timestamp     = DateTime.UtcNow,
                        Remark        = $"Refund from order({order.OrderNo})"
                    });

                    order.Status    = OrderStatus.Refunded;
                    order.Timestamp = DateTime.UtcNow;
                    orderDac.UpdateStatus(order);

                    new UserTransactionDAC().Insert(new UserTransaction
                    {
                        Id           = Guid.NewGuid(),
                        AccountId    = order.UserAccountId.Value,
                        CryptoId     = userWallet.CryptoId,
                        CryptoCode   = userWallet.CryptoCode,
                        Type         = UserTransactionType.Refund,
                        DetailId     = order.Id.ToString(),
                        Status       = (byte)order.Status,
                        Timestamp    = DateTime.UtcNow,
                        Amount       = order.CryptoAmount,
                        OrderNo      = order.OrderNo,
                        MerchantName = merchantAccount?.MerchantName
                    });

                    new RefundDAC().Insert(new Refund
                    {
                        OrderId   = order.Id,
                        Status    = RefundStatus.Completed,
                        Timestamp = DateTime.UtcNow
                    });

                    scope.Complete();
                }
            }
            else
            {
                using (var scope = new TransactionScope())
                {
                    merchantWalletDAC.Decrease(order.MerchantAccountId, order.CryptoId, order.ActualCryptoAmount);
                    new MerchantWalletStatementDAC().Insert(new MerchantWalletStatement
                    {
                        WalletId  = merchantWallet.Id,
                        Action    = "REFUND",
                        Amount    = -order.ActualCryptoAmount,
                        Balance   = merchantWallet.Balance - order.ActualCryptoAmount,
                        Timestamp = DateTime.UtcNow,
                        Remark    = $"Refund to order({order.OrderNo})"
                    });

                    userWalletDAC.Increase(order.UserAccountId.Value, order.CryptoId, order.CryptoAmount);
                    new UserWalletStatementDAC().Insert(new UserWalletStatement
                    {
                        WalletId      = userWallet.Id,
                        Action        = "REFUND",
                        Amount        = order.CryptoAmount,
                        Balance       = userWallet.Balance + order.CryptoAmount,
                        FrozenAmount  = 0,
                        FrozenBalance = userWallet.FrozenBalance,
                        Timestamp     = DateTime.UtcNow,
                        Remark        = $"Refund from order({order.OrderNo})"
                    });

                    order.Status = OrderStatus.Refunded;
                    //order.Timestamp = DateTime.UtcNow;
                    orderDac.UpdateStatus(order);

                    new UserTransactionDAC().Insert(new UserTransaction
                    {
                        Id           = Guid.NewGuid(),
                        AccountId    = order.UserAccountId.Value,
                        CryptoId     = userWallet.CryptoId,
                        CryptoCode   = userWallet.CryptoCode,
                        Type         = UserTransactionType.Refund,
                        DetailId     = order.Id.ToString(),
                        Status       = (byte)order.Status,
                        Timestamp    = DateTime.UtcNow,
                        Amount       = order.CryptoAmount,
                        OrderNo      = order.OrderNo,
                        MerchantName = merchantAccount?.MerchantName
                    });

                    new RefundDAC().Insert(new Refund
                    {
                        OrderId   = order.Id,
                        Status    = RefundStatus.Completed,
                        Timestamp = DateTime.UtcNow
                    });

                    scope.Complete();
                }
            }
            return(true);
        }
Пример #30
0
        /// <summary>
        /// 插入记录
        /// </summary>
        /// <param name="inviteCode">邀请码</param>
        /// <param name="accoundId">被邀请人id</param>
        /// /// <param name="type">1:fiiipay 2:fiiipos</param>
        public void InsertRecord(InviteRecordIM im)
        {
            //判断是fiiipos还是fiiipay

            //1 插入数据 invite profit两个表 邀请双方都支持插入数据 钱包 流水进行更新
            // 判断当前邀请人数到达五十 进行推送。。。。。。。。。。。。

            //2 插入数据 invite
            if (!(im.Type == (int)SystemPlatform.FiiiPay || im.Type == (int)SystemPlatform.FiiiPOS))
            {
                throw new ArgumentException("只支持fiiipay和fiiipos邀请");
            }
            var userAccountDAC    = new UserAccountDAC();
            var account           = userAccountDAC.GetByInvitationCode(im.InvitationCode);
            var settingCollection = new MasterSettingDAC().SelectByGroup("InviteReward");
            var cryptoCurrencty   = new CryptocurrencyDAC().GetByCode("FIII");
            var cryptoId          = cryptoCurrencty.Id;

            if (im.Type == (int)SystemPlatform.FiiiPay)
            {
                var iDAC        = new InviteRecordDAC();
                var pfDAC       = new ProfitDetailDAC();
                var uwComponent = new UserWalletComponent();

                var uwDAC  = new UserWalletDAC();
                var uwsDAC = new UserWalletStatementDAC();
                var utDAC  = new UserTransactionDAC();

                var inviteMoney  = decimal.Parse(settingCollection.Where(item => item.Name == "Invite_Reward_Amount").Select(item => item.Value).FirstOrDefault());
                var rewardMoney  = decimal.Parse(settingCollection.Where(item => item.Name == "Over_People_Count_Reward_Amount").Select(item => item.Value).FirstOrDefault());
                var maxCount     = decimal.Parse(settingCollection.Where(item => item.Name == "Max_Reward_Amount").Select(item => item.Value).FirstOrDefault());
                var orderNo1     = CreateOrderno();
                var orderNo2     = CreateOrderno();
                var inviteWallet = uwComponent.GetUserWallet(account.Id, cryptoId);
                if (inviteWallet == null)
                {
                    inviteWallet = uwComponent.GenerateWallet(account.Id, cryptoId);
                }

                var beInvitedWallet = uwComponent.GetUserWallet(im.BeInvitedAccountId, cryptoId);
                if (beInvitedWallet == null)
                {
                    beInvitedWallet = uwComponent.GenerateWallet(im.BeInvitedAccountId, cryptoId);
                }

                int     inviteId;
                long    profitId1    = 0; //邀请人奖励ID
                long    profitId2    = 0; //被邀请人奖励ID
                long    exProfitId1  = 0; //邀请人额外奖励ID
                decimal totalReward  = pfDAC.GetTotalReward(account);
                int     invitedCount = pfDAC.GetInvitedCount(account);

                using (var scope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, new TimeSpan(0, 0, 1, 30)))
                {
                    //插入数据到inviterecord表中
                    inviteId = iDAC.Insert(new InviteRecord()
                    {
                        Type = (InviteType)im.Type, AccountId = im.BeInvitedAccountId, Timestamp = DateTime.UtcNow, InviterCode = im.InvitationCode, InviterAccountId = account.Id
                    });

                    if (totalReward < maxCount)
                    {
                        profitId1 = pfDAC.Insert(new ProfitDetail()
                        {
                            InvitationId = inviteId,
                            CryptoAmount = inviteMoney,
                            AccountId    = account.Id,
                            Status       = InviteStatusType.IssuedFrozen,
                            Type         = ProfitType.InvitePiiiPay,
                            OrderNo      = orderNo1,
                            Timestamp    = DateTime.UtcNow,
                            CryptoId     = cryptoId
                        });

                        utDAC.Insert(new UserTransaction
                        {
                            Id         = Guid.NewGuid(),
                            AccountId  = account.Id,
                            CryptoId   = cryptoCurrencty.Id,
                            CryptoCode = cryptoCurrencty.Code,
                            Type       = UserTransactionType.Profit,
                            DetailId   = profitId1.ToString(),
                            Status     = (byte)InviteStatusType.IssuedFrozen,
                            Timestamp  = DateTime.UtcNow,
                            Amount     = inviteMoney,
                            OrderNo    = orderNo1
                        });

                        uwDAC.IncreaseFrozen(inviteWallet.Id, inviteMoney);

                        uwsDAC.Insert(new UserWalletStatement
                        {
                            WalletId      = inviteWallet.Id,
                            Action        = UserWalletStatementAction.Invite,
                            Amount        = 0,
                            Balance       = inviteWallet.Balance,
                            FrozenAmount  = inviteMoney,
                            FrozenBalance = inviteWallet.FrozenBalance + inviteMoney,
                            Timestamp     = DateTime.UtcNow
                        });

                        // 每当满50人时则可以奖励 采用了插入操作 所以只要满足为49个就可以了
                        if ((invitedCount + 1) % 50 == 0)
                        {
                            var pd50 = new ProfitDetail()
                            {
                                InvitationId = inviteId,
                                CryptoAmount = rewardMoney,
                                AccountId    = account.Id,
                                Status       = InviteStatusType.IssuedFrozen,
                                Type         = ProfitType.Reward,
                                OrderNo      = CreateOrderno(),
                                Timestamp    = DateTime.UtcNow,
                                CryptoId     = cryptoId
                            };
                            exProfitId1 = pfDAC.Insert(pd50);

                            utDAC.Insert(new UserTransaction
                            {
                                Id         = Guid.NewGuid(),
                                AccountId  = account.Id,
                                CryptoId   = cryptoCurrencty.Id,
                                CryptoCode = cryptoCurrencty.Code,
                                Type       = UserTransactionType.Profit,
                                DetailId   = exProfitId1.ToString(),
                                Status     = (byte)InviteStatusType.IssuedFrozen,
                                Timestamp  = DateTime.UtcNow,
                                Amount     = rewardMoney,
                                OrderNo    = pd50.OrderNo
                            });

                            uwDAC.IncreaseFrozen(inviteWallet.Id, rewardMoney);

                            uwsDAC.Insert(new UserWalletStatement
                            {
                                WalletId      = inviteWallet.Id,
                                Action        = UserWalletStatementAction.Invite,
                                Amount        = 0,
                                Balance       = inviteWallet.Balance,
                                FrozenAmount  = rewardMoney,
                                FrozenBalance = inviteWallet.FrozenBalance + inviteMoney + rewardMoney,
                                Timestamp     = DateTime.UtcNow
                            });
                        }
                        profitId2 = pfDAC.Insert(new ProfitDetail()
                        {
                            InvitationId = inviteId,
                            CryptoAmount = inviteMoney,
                            AccountId    = im.BeInvitedAccountId,
                            Type         = ProfitType.BeInvited,
                            Status       = InviteStatusType.IssuedActive,
                            OrderNo      = orderNo2,
                            Timestamp    = DateTime.UtcNow,
                            CryptoId     = cryptoId
                        });
                        utDAC.Insert(new UserTransaction
                        {
                            Id         = Guid.NewGuid(),
                            AccountId  = im.BeInvitedAccountId,
                            CryptoId   = cryptoCurrencty.Id,
                            CryptoCode = cryptoCurrencty.Code,
                            Type       = UserTransactionType.Profit,
                            DetailId   = profitId2.ToString(),
                            Status     = (byte)InviteStatusType.IssuedActive,
                            Timestamp  = DateTime.UtcNow,
                            Amount     = inviteMoney,
                            OrderNo    = orderNo2
                        });
                        uwDAC.Increase(beInvitedWallet.Id, inviteMoney);
                        uwsDAC.Insert(new UserWalletStatement
                        {
                            WalletId      = beInvitedWallet.Id,
                            Action        = UserWalletStatementAction.BeInvite,
                            Amount        = inviteMoney,
                            Balance       = beInvitedWallet.Balance + inviteMoney,
                            FrozenAmount  = 0,
                            FrozenBalance = beInvitedWallet.FrozenBalance,
                            Timestamp     = DateTime.UtcNow
                        });
                    }
                    scope.Complete();
                }

                if (!(im.Type == (int)SystemPlatform.FiiiPay || im.Type == (int)SystemPlatform.FiiiPOS))
                {
                    throw new ArgumentException("只支持fiiipay和fiiipos邀请");
                }

                if (im.Type == (int)SystemPlatform.FiiiPay)
                {
                    UserMSMQ.PubUserInviteSuccessed(profitId2, 0);
                }
                //else if (im.Type == SystemPlatform.FiiiPOS)
                //    MerchantMSMQ.PubUserInviteSuccessed(profitId2, 0);
            }
            //else
            //{
            //    var iDAC = new InviteRecordDAC();
            //    iDAC.Insert(new InviteRecord() { Type = im.Type, AccountId = im.BeInvitedAccountId, Timestamp = DateTime.UtcNow, InviterCode = im.InvitationCode, InviterAccountId = account.Id });
            //}
        }