<?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']);
$type = "WHERE name='$username'";
$duqu = queryall(admin, $type);
$uid = ubo($_GET["uid"]);
$btime = ubo($_GET["btime"]);
$sql1 = mysql_query("SELECT * FROM zhucema WHERE  user='$username'");
$row = mysql_fetch_array($sql1);
if ($row[zdsl] != "") {
    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"><a href="dingdan.php">补偿列表</a></li>
            </ul>
            <div class="layui-tab-content">
                <form class="layui-form layui-form-pane" action="" method="get">

                    <div class="layui-inline">
                        <a class="layui-btn pub_btn" data-toggle="modal" data-target="#myPublic2">添加补偿</a>
                    </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="请输入玩家角色名" class="layui-input">
                        </div>
                    </div>
                    <SCRIPT language=javascript src="../app/laydate/laydate.js" charset="utf-8"></SCRIPT>
                    <script>
                        !function () {
                            laydate.skin('molv');//切换皮肤，请查看skins下面皮肤库
                            laydate({elem: '#btime'});//绑定元素
                        }();
                    </script>
                    <div class="layui-inline">
                        <button class="layui-btn">搜索</button>
                    </div>
                </form>
                <hr>
                <table class="layui-table" lay-even="" lay-skin="row">
                    <thead>
                    <tr>
                        <th align="center">ID编号</th>
                        <th align="center">用户ID</th>
                        <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 = 17;
                    $sql = "WHERE user='buchang' ";
                    if ($uid) {
                        $sql .= " and   uid='$uid' ";
                    } else {
                        if ($btime) {
                            $sql .= "   and shijian  like '%" . $btime . "%'";
                        }
                    }
                    $result = mysql_query("select count(1) from chongzhi   " . $sql . "");
                    $count =mysql_fetch_array($result)[0];
                    if ($count == 0) {
                        echo '<tr class="color2"><td colspan=10 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 chongzhi " . $sql . " order by id desc   limit $offset, $Page_size");
                    while ($a = mysql_fetch_array($query)) {
                    ?>
                    <tr>
                        <td align="center"><?php echo $a[id] ?></td>
                        <td align="center"><?php echo $a[uid] ?></td>
                        <td align="center"><?php echo $a[jin] ?></td>
                        <td align="center"><?php echo $a[shifoulingqu] ?>区</td>
                        <td align="center"><?php echo date("Y-m-d H:i:s", $a[orderid]); ?></td>
                        <td align="center"><?php echo $a[shijian] ?></td>
                        <td align="center"><?php if ($a[dd] == 1) {
                                echo "成功";
                            } else {
                                echo "失败";
                            } ?></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&btime=$btime\">&laquo;</a></li>"; //首页
                                $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . ($Page - 1) . "&uid=$uid&btime=$btime\">&lt;</a></li>"; //上一页
                            } elseif ($btime) {
                                $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page=1&uid=$uid&btime=$btime\">&laquo;</a></li>"; //首页
                                $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . ($Page - 1) . "&uid=$uid&btime=$btime\">&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&btime=$btime\">" . $i . "</a></li>";
                                } elseif ($btime) {
                                    $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . $i . "&uid=$uid&btime=$btime\">" . $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&btime=$btime\">&gt;</a></li> ";//下一页
                                $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page={$Pages}&uid=$uid&btime=$btime\">&raquo;</a></li> "; //最后一页
                            } elseif ($btime) {
                                $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page=" . ($Page + 1) . "&uid=$uid&btime=$btime\">&gt;</a></li> ";//下一页
                                $key .= "<li><a href=\"" . $_SERVER['PHP_SELF'] . "?page={$Pages}&uid=$uid&btime=$btime\">&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>
            </div>
            <div class="modal fade" id="myPublic2" tabindex="-1" role="dialog" aria-labelledby="myPublicLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                        aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="myModalLabel">玩家补偿【金额比例1:10000】</h4>
                        </div>
                        <div class="modal-body">

                            <div class="form-group">
                                <label class="control-label">玩家账号</label>
                                <input type="text" class="layui-input" id="name" placeholder="输入玩家ID">
                            </div>

                            <div class="form-group">
                                <label class="control-label">区服：1就是一区</label>
                                <input type="text" class="layui-input" id="qu" placeholder="输入区服">
                            </div>


                            <div class="form-group">
                                <label class="control-label">补偿元宝数量</label>
                                <input type="text" class="layui-input" id="money" placeholder="输入数量">
                            </div>

                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                <button type="button" id="pub_btn" class="btn btn-primary">确认</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <script type="text/javascript">
                $('.pub_btn').on('click', function () {
                })
                $(function () {
                    $("#pub_btn").click(function () {
                        var qu = $("#qu").val();
                        var name = $("#name").val();
                        var money = $("#money").val();
                        $.ajax({
                            type: "post",
                            url: "data/buchang.php",
                            dataType: "json",
                            async: true,
                            data: {qu: qu, name: name, money: money},
                            timeout: 10000,
                            success: function (data) {
                                if (data.zt == '1') {
                                    myc.toast({
                                        msg: '添加成功'
                                    });
                                    location.reload();
                                } else {
                                    myc.toast({
                                        msg: data.msg
                                    });
                                }
                            },
                            error: function () {
                            }
                        });
                    });
                })
            </script>
        </div>
    </div>
</div>
</body>
</html>