<?php
/*
 * @Team : 孜然云
 * @Author : 孜然
 * @Url : zrv7.com
 * @Date : 2021-12-24 23:06
 * @Project : 孜然授权系统
 * @Description : 基于ZR框架开发的授权系统
 * @Qq : 2937978586
 * @Wx : hhr2937978586 
 * @Email : 2937978586@qq.com
 * @Read me : 孜然授权系统，是一款多模板/多用途/多权限的授权系统
 * @Remind : 孜然授权系统受《劳动知识产权》和《计算机软件著作法》的法律保护，使用破解即违法法律
 * @Dbfk : 如果您已经使用了盗版，孜然可以通过上述两法告你，不过我是不会这么做的，如果是传播盗版那么就必定告上法院
 */
require_once 'head.php';
if (isset($_GET['kw'])) {
    $kw = daddslashes($_GET['kw']);
    $sql = " ip like '%" . $kw . "%' or name like '%" . $kw . "%' or type like '%" . $kw . "%' or money like '%" . $kw . "%'";
    $numrows = $DB->count("SELECT count(*) from zrauth_code WHERE{$sql}");
    $con = "包含 <b>" . $kw . "</b> 共有 <b>" . $numrows . "</b> 发信记录";
    $link = "&kw=" . $kw;
} else {
    $sql = " 1";
    $numrows = $DB->count("SELECT count(*) from zrauth_code");
    $con = "共有 <b>" . $numrows . "</b> 条发信记录";
}
$pagesize=100;
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize) {
    $pages++;
}
if (isset($_GET['page'])) {
    $page=intval($_GET['page']);
} else {
    $page=1;
}
$offset=$pagesize*($page - 1);
?>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">发信记录</div>
        <div class="layui-card-body layui-form">
            <!-- 表格工具栏 -->
            <blockquote class="layui-elem-quote"><b><?php echo $conf['name'];?></b> <?php echo $con?></blockquote>
            <form class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" class="layui-input" name="kw" placeholder="请输入IP,名称,方式,金额">
                    </div>
                    <div class="layui-inline">
                        <button type="button" class="layui-btn icon-btn" lay-submit lay-filter="search"><i class="layui-icon layui-icon-search"></i>搜索</button>
                        <a href="javascript:pao()" lay-filter="pao" class="layui-btn layui-btn-danger icon-btn"><i class="layui-icon layui-icon-delete"></i>一键跑路</a>
                        <?php echo (isset($_GET['kw']))?'<a href="list_code.php" class="layui-btn layui-btn">查看全部</a>':'';?>
                    </div>
                </div>
            </form>
            <form name="form1" id="form1">
            <div style="white-space:nowrap;overflow-x: auto;">
                <table class="layui-table layuiadmin-page-table">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>邮箱</th>
                            <th>类型</th>
                            <th>IP</th>
                            <th>状态</th>
                            <th>时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                    $rs=$DB->query("SELECT * FROM zrauth_code WHERE{$sql} order by id desc limit $offset,$pagesize");
                    while($res = $DB->fetch($rs)) {
                        if ($res['type'] == 1) {
                        $type = '<input type="checkbox" name="close" lay-skin="switch" value="' . $res['id'] . '" lay-filter="switchTest" lay-text="已使用|未使用" checked/>';
                        } else if ($res['type'] == 0) {
                        $type = '<input type="checkbox" name="close" lay-skin="switch" value="' . $res['id'] . '" lay-filter="switchTest" lay-text="已使用|未使用"/>';
                        }
                    ?>
                        <tr>
                            <td><?php echo $res['id']?></td>
                            <td><?php echo $res['email']?></td>
                            <td>
                            <span lay-direction="1" lay-bg="#4facfe" class="layui-badge layui-badge-green"><?php echo $res['leixing']?></span>
                            </td>
                            <td><?php echo $res['ip']?></td>
                            <td><?php echo $type?></td>
                            <td><?php echo $res['time']?></td>                            
                            <td>
                            <a class="layui-btn layui-btn-sm layui-btn-danger" href="javascript:del(<?php echo $res['id']?>)" lay-filter="del<?php echo $res['id']?>"><i class="layui-icon layui-icon-delete"></i>删除</a>
                            </td>
                        </tr>
                    <?php } ?>
                    </tbody>
                </table>
            </div>
           </form>
            <?php
            echo '<div class="layui-laypage layui-laypage-default">';
            $prev = $page - 1;
            $next = $page + 1;
            if ($page > 1) {
                echo '<a href="list_code.php?page='.$prev.$link.'" class="layui-laypage-prev" data-page="'.$prev.$link.'">上一页</a>';
            } else {
                echo '<a class="layui-laypage-prev layui-disabled"  lay-tips="<img src=\'../assets/img/logo.png\' style=\'width:24px;height:24px;border-radius: 50%;\'/>&nbsp;&nbsp;没有更多页面了哦" lay-bg="#803ed9" lay-bgImg="linear-gradient(to right,#8510FF,#D025C2,#FF8B2D,#F64E2C)" data-page="'.$prev.$link.'">上一页</a>';
            }
            for ($i=1;$i<$page;$i++) {
                echo '<a href="list_code.php?page='.$i.$link.'" data-page="'.$i .'">'.$i .'</a>';
            }
            echo '<span class="layui-laypage-curr" lay-tips="<img src=\'../assets/img/logo.png\' style=\'width:24px;height:24px;border-radius: 50%;\'/>&nbsp;&nbsp;已是第'.$page.'页" lay-bg="#803ed9" lay-bgImg="linear-gradient(to right,#8510FF,#D025C2,#FF8B2D,#F64E2C)"><em class="layui-laypage-em"></em><em>'.$page.'</em></span>';
            if ($pages >= 10) {
                $s = 10;
            } else {
                $s = $pages;
            }
            for ($i=$page+1;$i<=$s;$i++) {
                echo '<a href="list_code.php?page='.$i.$link.'" data-page="'.$i .'">'.$i .'</a>';
            }
            echo '';
            if ($page < $pages) {
                echo '<a href="list_code.php?page='.$next.$link.'" class="layui-laypage-next" data-page="'.$next.$link.'">下一页</a>';
            } else {
                echo '<a class="layui-laypage-next layui-disabled" lay-tips="<img src=\'../assets/img/logo.png\' style=\'width:24px;height:24px;border-radius: 50%;\'/>&nbsp;&nbsp;没有更多页面了哦" lay-bg="#803ed9" lay-bgImg="linear-gradient(to right,#8510FF,#D025C2,#FF8B2D,#F64E2C)" data-page="'.$last.$link.'">下一页</a>';
            }
            echo '</div>';
            ?>
        </div>
    </div>
</div>
<script>
layui.use(['form', 'element','jquery', 'tagsInput', 'laydate', 'notice'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        var tagsInput = layui.tagsInput;
        var laydate = layui.laydate;
        var notice = layui.notice;
        form.on('switch(switchTest)', function(data){
            var ii = notice.msg('正在执行中..', {icon: 4, close: true});
             if(this.checked){
          $.ajax({
		type : 'GET',
		url : 'ajax/list_ajax.php?act=code_setorder&id='+data.value+'&active='+1,
		dataType : 'json',
		success : function(d) {
		    notice.destroy();
		    notice.msg('该验证码状态已变成已使用ID:'+data.value, {icon: 1});
		},
		error:function(data){
			layer.msg('服务器错误');
			return false;
		}
	});
    
   }else{
 $.ajax({
		type : 'GET',
		url : 'ajax/list_ajax.php?act=code_setorder&id='+data.value+'&active='+0,
		dataType : 'json',
		success : function(d) {
		    notice.destroy();
		     notice.msg('该验证码状态已变成未使用ID:'+data.value, {icon: 1});
		},
		error:function(data){
			layer.msg('服务器错误');
			return false;
		}
  }); 
}
});   
});
</script>
<script type="text/javascript">
layui.use(['form', 'element','layer','dropdown','jquery', 'admin', 'tagsInput', 'notice'], function () {
    var form = layui.form;
    var $ = layui.jquery;
    var tagsInput = layui.tagsInput;
    var admin = layui.admin;
    var notice = layui.notice;
    form.on('submit(search)', function (data) {
        var kw=$("input[name='kw']").val();
        window.location.href = './list_code.php?kw='+kw;
    });
});
//一键跑路
function pao() {
    layui.use(['form', 'element','layer','dropdown','jquery', 'admin', 'tagsInput', 'notice'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        var tagsInput = layui.tagsInput;
        var admin = layui.admin;
        var notice = layui.notice;
        var confirmobj = parent.layui.admin.confirm('你确实要跑路吗？', {
            icon: 3, btn: ['确定','取消']
        }, function(){
            parent.layer.close(confirmobj);
            admin.btnLoading('[lay-filter="pao"]', ' 跑路中');
            var ii = layer.load(2, {shade:[0.1,'#fff']});
            notice.destroy();
            $.ajax({
                type : 'GET',
                url : 'ajax/list_ajax.php?act=code_pao',
                dataType : 'json',
                success : function(data) {
                    layer.close(ii);
                    admin.btnLoading('[lay-filter="pao"]', false);
                    if (data.code == 0) {
                        notice.msg(data.msg, {animateInside: true, icon: 1});
                        setTimeout(function(){
                            window.location.reload();
                        },1000);
                    } else {
                        notice.msg(data.msg, {animateInside: true, icon: 2});
                    }
                },
                error:function(data){
                    notice.msg('服务器错误', {animateInside: true, icon: 2});
                    return false;
                }
            });
        }, function(){
            parent.layer.close(confirmobj);
        });
    });
}
function del(id) {
    layui.use(['form', 'element','layer','dropdown','jquery', 'admin', 'tagsInput', 'notice'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        var tagsInput = layui.tagsInput;
        var admin = layui.admin;
        var notice = layui.notice;
        var confirmobj = parent.layui.admin.confirm('你确实要删除此发信记录吗？', {
            icon: 3, btn: ['确定','取消']
        }, function(){
            parent.layer.close(confirmobj);
            admin.btnLoading('[lay-filter="del'+id+'"]', '删除中');
            var ii = layer.load(2, {shade:[0.1,'#fff']});
            notice.destroy();
            $.ajax({
                type : 'GET',
                url : 'ajax/list_ajax.php?act=code_list&id='+id,
                dataType : 'json',
                success : function(data) {
                    layer.close(ii);
                    admin.btnLoading('[lay-filter="del'+id+'"]', false);
                    if (data.code == 0) {
                        notice.msg(data.msg, {animateInside: true, icon: 1});
                        setTimeout(function(){
                            window.location.reload();
                        },1000);
                    } else {
                        notice.msg(data.msg, {animateInside: true, icon: 2});
                    }
                },
                error:function(data){
                    notice.msg('服务器错误', {animateInside: true, icon: 2});
                    return false;
                }
            });
        }, function(){
            parent.layer.close(confirmobj);
        });
    });
}
</script>