<?php
error_reporting(0);
include("../../conn.php");
include("../../common.php");
session_start();
if (!isset($_SESSION['username'])) {
    echo "<script>alert('管理身份已失效请重新登录!')</script><script>top.location.href='../index.php'</script>";
    exit;
}
$username = ubo($_SESSION['username']);
$uid = ubo($_GET["uid"]);
$dailiid = ubo($_GET["dailiid"]);
$btime = ubo($_GET["btime"]);
$sql1 = mysql_query("SELECT * FROM zhucema WHERE  user='$username'");
$row = mysql_fetch_array($sql1);
if ($row[zdsl] != "1") {
    echo "<script>location.href='../index.php'</script>";
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="gb2312">
    <title>玩家列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="css/layui.css" media="all">
    <link rel="stylesheet" href="css/peizhi.css">
    <script src='newui/js/jquery.min.js' type="text/javascript"></script>
    <script src="newui/layui/layui.js"></script>
    <script src='newui/js/myc.js' type="text/javascript"></script>
    <script src="newui/js/bootstrap.min.js"></script>
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-body">
        <!--tab标签-->
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">玩家列表</li>
                <?php
                $sql1 = " WHERE 1=1 and recommend in (select ma from zhucema WHERE zd ='" . $username . "' ) ";
                if ($dailiid) {
                    $sql1 .= " and recommend='$dailiid' ";
                }
                $sql = mysql_query("SELECT count(1) FROM user " . $sql1 . " ");
                $bs = mysql_fetch_array($sql)[0];
                ?>
                <li class="layui">共有玩家 <?php if ($bs == null) { ?>0<?php } else { ?><?php echo $bs ?><?php } ?> 个</li>
            </ul>
            <div class="layui-tab-content">
                <form class="layui-form layui-form-pane" action="" method="get">
                    <div class="layui-inline">

                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">角色名</label> 
                        <div class="layui-input-inline">
                            <input type="text" name="uid" value="<?php if ($uid == null) {
                            } else {
                                echo $uid;
                            } ?>" placeholder="玩家uid" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn">搜索</button>
                    </div>
                </form>
                <hr>
                <div class="layui-tab-item layui-show">
                    <table class="layui-table" lay-even="" lay-skin="row">
                        <thead>
                        <tr>
                            <th align="center">区服</th>
                            <th align="center">角色</th>
                            <th align="center">上级代理</th>
                            <th align="center">绑定代理时间</th>
                            <th align="center">总充值</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                        $Page_size = 18;
                        $sql = "WHERE 1=1 and recommend in (select ma from zhucema WHERE zd ='" . $username . "' )";
                        if ($uid) {
                            $sql .= " and uid='$uid' ";
                        }
                        if ($dailiid) {
                            $sql .= " and recommend='$dailiid' ";
                        }
                        $result = mysql_query("select count(1) from user   " . $sql . "  ");
                        $count =mysql_fetch_array($result)[0];
                        if ($count == 0) {
                            echo '<tr><td colspan=15 align="center">查询不到数据</td></tr>';
                        }
                        $Page_count = ceil($count / $Page_size);
                        $init = 1;
                        $Page_len = 7;
                        $max_p = $Page_count;
                        $Pages = $Page_count;
                        //判断当前页码
                        if (empty($_GET['page']) || $_GET['page'] < 0) {
                            $Page = 1;
                        } else {
                            $Page = $_GET['page'];
                        }
                        $offset = $Page_size * ($Page - 1);
                        $query = mysql_query("select * from  user   " . $sql . " order by id desc  limit $offset, $Page_size");
                        while ($a = mysql_fetch_array($query)) {

                        $sqlc = mysql_query("select sum(rmb) from chongzhi where 1=1 and  uid='" . $a['uid'] . "' and server='".$a[server]."'");
                        $bs1 = mysql_result($sqlc, 0);
                        ?>

                        <tr>
                            <td align="center"><?php echo $a[server] ?> </td>
                            <td align="center"><?php echo $a[uid] ?> </td>
                            <td align="center"><?php echo $a[recommend] ?></td>
                            <td align="center"><?php echo $a[bindtime] ?></td>
                            <td align="center"><?php if ($bs1 == null) { ?>0<?php } else { ?><?php echo $bs1 ?><?php } ?>
                                元
                            </td>
                            <?php
                            }
                            $Page_len = ($Page_len % 2) ? $Page_len : $Pagelen + 1;//页码个数
                            $Pageoffset = ($Page_len - 1) / 2;//页码个数左右偏移量
                            $key .= "<li><a class='number' >当前第 $Page 页/共 $Pages 页</a></li>"; //第几页,共几页
                            if ($Page != 1) {
                                if ($uid) {
                                    $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page=1&uid=$uid\">&laquo;</a></li>"; //首页
                                    $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . ($Page - 1) . "&uid=$uid\">&lt;</a></li>"; //上一页
                                } else {
                                    $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page=1\">&laquo;</a></li>"; //首页
                                    $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . ($Page - 1) . "\">&lt;</a></li>"; //上一页
                                }
                            } else {
                                $key .= "<li><a>&laquo;</a> "; //首页
                                $key .= "<li><a >&lt;</a>"; //上一页
                            }
                            if ($Pages > $Page_len) {
//如果当前页小于等于左偏移 
                                if ($Page <= $Pageoffset) {
                                    $init = 1;
                                    $max_p = $Page_len;
                                } else {//如果当前页大于左偏移
//如果当前页码右偏移超出最大分页数 
                                    if ($Page + $Pageoffset >= $Pages + 1) {
                                        $init = $Pages - $Page_len + 1;
                                    } else {
//左右偏移都存在时的计算 
                                        $init = $Page - $Pageoffset;
                                        $max_p = $Page + $Pageoffset;
                                    }
                                }
                            }
                            for ($i = $init; $i <= $max_p; $i++) {
                                if ($i == $Page) {
                                    $key .= '<li class="active"><span>' . $i . '</span></li>';
                                } else {
                                    if ($uid) {
                                        $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . $i . "&uid=$uid\">" . $i . "</a></li>";
                                    } else {
                                        $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . $i . "\">" . $i . "</a></li>";
                                    }
                                }
                            }
                            if ($Page != $Pages) {
                                if ($uid) {
                                    $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . ($Page + 1) . "&uid=$uid\">&gt;</a></li> ";//下一页
                                    $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page={$Pages}&uid=$uid\">&raquo;</a></li> "; //最后一页
                                } else {
                                    $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . ($Page + 1) . "\">&gt;</a></li> ";//下一页
                                    $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page={$Pages}\">&raquo;</a></li> "; //最后一页
                                }
                            } else {
                                $key .= "<li>&gt;</li>";//下一页
                                $key .= "<li>&raquo;</li>"; //最后一页
                            }
                            $key .= '';
                            ?>
                        </tbody>
                    </table>
                    <ul class="pagination">
                        <?php if ($count == "0") { ?><?php } else { ?><?php echo $key ?><?php } ?>
                    </ul>
</body>
</html>