示例#1
0
        public async Task <IHttpActionResult> GetBalances(Guid playerId)
        {
            VerifyPermission(Permissions.View, Modules.PlayerManager);
            VerifyPermission(Permissions.View, Modules.OfflineDepositRequests);

            var player = await _playerQueries.GetPlayerAsync(playerId);

            var wallet = await _walletQueries.GetPlayerBalance(playerId);

            var offlineDeposits = _paymentQueries.GetOfflineDeposits().Where(x => x.PlayerId == playerId);
            var offlineDepositsWithoutWageringCompleted = await offlineDeposits.Where(x => x.DepositWagering != 0).ToListAsync();

            var playerBetStatistics = await _playerQueries.GetPlayerBetStatistics().FirstOrDefaultAsync(s => s.PlayerId == playerId);

            var offlineTotalWithdrawal = _paymentQueries.GetOfflineWithdraws().Where(x => x.PlayerBankAccount.Player.Id == playerId);

            var playerTransactions = _reportQueries.GetPlayerTransactionRecords(playerId);

            decimal totalWin         = 0;
            decimal totalLoss        = 0;
            decimal totalAdjustments = 0;
            var     approvedDeposits = _paymentQueries.GetDepositsAsQueryable().Where(x => x.PlayerId == playerId && x.Status == "Approved")
                                       .Select(x => new { Amount = x.Amount, Id = x.Id }).ToList();

            if (playerBetStatistics != null)
            {
                totalWin         = playerBetStatistics.TotalWon;
                totalLoss        = playerBetStatistics.TotalLoss;
                totalAdjustments = playerBetStatistics.TotlAdjusted;
            }

            return(Ok(new
            {
                Balance = new
                {
                    Currency = player.CurrencyCode,
                    MainBalance = wallet.Main,
                    BonusBalance = wallet.Bonus,
                    PlayableBalance = wallet.Playable,
                    FreeBalance = wallet.Free,
                    TotalBonus = playerTransactions.Any() ? playerTransactions.Sum(x => x.BonusBalanceAmount) : 0,
                    DepositCount = approvedDeposits.Count,
                    TotalDeposit = approvedDeposits.Count > 0? approvedDeposits.Sum(x => x.Amount) : 0,
                    WithdrawalCount = offlineTotalWithdrawal.Any(s => s.Approved.HasValue) ? offlineTotalWithdrawal.Count(s => s.Approved.HasValue) : 0,
                    TotalWithdrawal = offlineTotalWithdrawal.Any(s => s.Approved.HasValue) ? offlineTotalWithdrawal.Where(s => s.Approved.HasValue).Sum(x => x.Amount) : 0,
                    TotalWin = totalWin,
                    TotalLoss = totalLoss,
                    TotalAdjustments = totalAdjustments,
                    TotalCreditsRefund = "-",
                    TotalCreditsCancellation = "-",
                    TotalChargeback = "-",
                    TotalChargebackReversals = "-",
                    TotalWager = "-",
                    AverageWagering = "-",
                    AverageDeposit = "-",
                    MaxBalance = "-"
                },

                GameBalance = new
                {
                    Product = "-",
                    Balance = "-",
                    BonusBalance = playerTransactions.Any(g => g.GameId.HasValue) ? playerTransactions.Where(g => g.GameId.HasValue).Sum(x => x.BonusBalanceAmount) : 0,
                    BettingBalance = "-",
                    TotalBonus = "-"
                },

                DepositWagering = new
                {
                    TotalWagering = offlineDepositsWithoutWageringCompleted.Any() ? offlineDepositsWithoutWageringCompleted.Select(x => x.Amount).Aggregate((x, y) => x + y) : 0,
                    WageringRequired = offlineDepositsWithoutWageringCompleted.Any() ? offlineDepositsWithoutWageringCompleted.Select(x => x.DepositWagering).Aggregate((x, y) => x + y) : 0,
                }
            }));
        }