示例#1
0
<?php

require_once "../../../include/config.php";
require_once $basedir . "/admin/include/functions.php";
include $basedir . '/admin/include/isadmin.php';
$datatables = '';
$gamemenu = '';
$settingsmenu = 'active';
$coin_packages = getCoinPackages();
?>

<!DOCTYPE html>
<html>
	<head>
		<?php 
include $basedir . '/admin/include/header.php';
?>
	</head>

	<body class="skin-blue">
	<!-- header logo: style can be found in header.less -->
	<header class="header">
		<?php 
include $basedir . '/admin/include/header_menu.php';
?>
	</header><!-- ./header -->
	
	<div class="wrapper row-offcanvas row-offcanvas-left">

		<!-- Left side column. -->
		<aside class="left-side sidebar-offcanvas">                
function winLoseRatio($user_id, $from, $to, $coin_deals)
{
    global $config, $lang;
    // add 23 hours and 59 minutes
    $to = $to + 60 * 60 * 24 - 1;
    $data = array();
    $user_bets = array();
    $all_games = array();
    $coin_packages = getCoinPackages();
    $bets = getAllUserBets($user_id);
    // assign cd_id to the key
    foreach ($bets as $b) {
        $user_bets[$b['cd_id']] = $b;
    }
    $file = $config['basedir'] . '/temp/all_games.txt';
    $games = json_decode(file_get_contents($file), true);
    foreach ($games as $g) {
        $all_games[$g['g_id']] = $g;
    }
    if ($coin_deals) {
        //{label: "Win Game", value: 0},
        $data = array('won' => 0, 'wonpie' => 0, 'lose' => 0, 'losepie' => 0, 'cancelled' => 0, 'cancelpie' => 0, 'total' => 0);
        foreach ($coin_deals as $cd) {
            $tx_date = $cd['cd_tx_date'];
            $coins = $cd['cd_amount'];
            $cd_id = $cd['cd_id'];
            $cd_type = $cd['cd_type'];
            if (isset($user_bets[$cd_id])) {
                $bet = $user_bets[$cd_id];
                $game = $all_games[$bet['g_id']];
                $is_closed = $game['g_isClosed'];
            } else {
                $game = isset($all_games[$cd['g_id']]) ? $all_games[$cd['g_id']] : array();
                if ($game) {
                    $is_closed = $game['g_isClosed'];
                    $is_cancelled = $game['g_isCancelled'];
                } else {
                    $is_closed = 0;
                    $is_cancelled = 0;
                }
            }
            if ($tx_date >= $from and $tx_date <= $to) {
                if ($cd_type == 'bet') {
                    if ($is_closed) {
                        if ($bet['ub_iswinner'] == 0) {
                            $data['lose'] += $coins;
                            $data['total'] += $coins;
                        }
                    } elseif ($is_cancelled) {
                        $data['cancelled'] += $coins;
                        $data['total'] += $coins;
                    }
                } elseif ($cd_type == 'bet winning') {
                    $data['won'] += $coins;
                    $data['total'] += $coins;
                }
            }
        }
        // foreach
    }
    // if $coin_deals
    if ($data['total']) {
        $data['wonpie'] = $data['won'] ? number_format($data['won'] / $data['total'] * 100) : 0;
        $data['losepie'] = $data['lose'] ? number_format($data['lose'] / $data['total'] * 100) : 0;
        $data['cancelpie'] = $data['cancelled'] ? number_format($data['cancelled'] / $data['total'] * 100) : 0;
    } else {
        $data['wonpie'] = 0;
        $data['losepie'] = 0;
        $data['cancelpie'] = 0;
    }
    //{label: "Win Game", value: 0},
    $ret = array();
    $i = 0;
    if ($data['wonpie']) {
        $ret[$i]['label'] = $lang[411];
        // Win Game
        $ret[$i]['value'] = $data['wonpie'];
        $i++;
    }
    if ($data['losepie']) {
        $ret[$i]['label'] = $lang[412];
        // Lose Game
        $ret[$i]['value'] = $data['losepie'];
        $i++;
    }
    if ($data['cancelpie']) {
        $ret[$i]['label'] = $lang[62];
        // cancelled
        $ret[$i]['value'] = $data['cancelpie'];
    }
    return array('data' => $data, 'pie' => $ret);
}