<?php
// +----------------------------------------------------------------------
// | Quotes [未来可期]
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | Author: 微站网 www.btwcms.com 作者QQ：1617643
// +----------------------------------------------------------------------
// | Date: 2020年2月5日
// +----------------------------------------------------------------------
include 'header.php';

$list = $DB->query("SELECT * FROM `wcms_user` WHERE `api_key` is not null")->fetchAll();
?>
<!-- Page Content-->
<div class="page-content">
    <div class="container-fluid">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">
                <div class="page-title-box">
                    <div class="float-right">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="javascript:void(0);">系统模块</a></li>
                            <li class="breadcrumb-item active">分站设置</li>
                        </ol>
                    </div>
                    <h4 class="page-title">系统模块</h4>
                </div><!--end page-title-box-->
            </div><!--end col-->
        </div>
        <!-- end page title end breadcrumb -->
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <h4 class="mt-0 header-title">分站设置</h4>
                        <p class="text-muted mb-3">levelSet.
                        </p>
                        <form>
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="form-group row">
                                        <label class="col-sm-2 col-form-label text-left">是否开启分站</label>
                                        <div class="col-sm-10">
                                            <select name="level_status" class="custom-select">
												<option value="1"<?php if ($conf['level_status'] == 1) { ?> selected<?php } ?>>
                                                        开启
                                                    </option>
                                                    <option value="0"<?php if ($conf['level_status'] == 0) { ?> selected<?php } ?>>
                                                        关闭
                                                    </option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label for="example-text-input"
                                               class="col-sm-2 col-form-label text-left">分站价格</label>
                                        <div class="col-sm-10">
                                            <input class="form-control" type="text" name="level_price"
                                                   value="<?php echo $conf['level_price'] ?>">
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label for="example-email-input"
                                               class="col-sm-2 col-form-label text-left">分站源码包下载链接</label>
                                        <div class="col-sm-10">
                                            <input class="form-control" type="text" name="level_pack"
                                                   value="<?php echo $conf['level_pack'] ?>">
                                        </div>
                                    </div>
                                </div>
                            </div><!--end card-body-->
                            <div class="row">
                                <div class="col-sm-10 ml-auto">
                                    <button type="button" class="btn btn-primary" onclick="levelSet()">保存数据</button>
                                </div>
                            </div>
                        </form>
					</div><!--end card body-->
                </div><!--end card-->
            </div><!--end col-->
        </div><!--end row-->
		
		<div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">

                        <h4 class="mt-0 header-title">分站用户</h4>
                        <p class="text-muted mb-4 font-13">
                            开通API分站用户
                        </p>
                        <table id="datatable" class="table table-bordered dt-responsive nowrap"
                               style="border-collapse: collapse; border-spacing: 0; width: 100%;">
                            <thead>
                            <tr>
                               <th>用户编号</th>
							   <th>用户名</th>
							   <th>用户邮箱</th>
							   <th>余额</th>
							   <th>注册时间</th>
							   <th>分站密钥</th>
                            </tr>
                            </thead>
                            <tbody>
							<?php foreach($list as $res){?>
                            <tr>
                                <td><?php echo $res['uid']?></td>
                                <td><?php echo $res['username']?></td>
								<td><?php echo $res['email']?></td>
								<td><?php echo $res['money']?></td>
								<td><?php echo $res['regtime']?></td>
								<td><?php echo $res['api_key']?></td>
                            </tr>
                            
							<?php }?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div> <!-- end col -->
        </div> <!-- end row -->

        </div><!--end row-->

    </div><!-- container -->

    <?php
    require_once 'footer.php';
    ?>
    <script>
        function levelSet() {
            var ii = layer.msg('数据处理中···', { icon: 16, shade: 0.01, time: 15000 });
            $.ajax({
                url: 'level.ajax.php?act=levelSet',
                type: 'POST',
                dataType: 'json',
                data: {
                    level_status: $("select[name='level_status']").val(),
                    level_price: $("input[name='level_price']").val(),
                    level_pack: $("input[name='level_pack']").val()
                },
                success: function (data) {
                    layer.close(ii);
                    if (data.code == 1) {
                        layer.msg(data.msg, { icon: 1, time: 2000, shade: 0.4 }, function () {
                            //
                        });
                    } else {
                        layer.msg(data.msg, { icon: 2, time: 2000, shade: 0.4 });
                    }
                },
                error:function () {
                    layer.alert("网络连接错误");
                }
            })

        }
    </script>
