Jonlin 6 gadi atpakaļ
vecāks
revīzija
d41166ba16

+ 142 - 0
application/admin/controller/Iplimit.php

@@ -0,0 +1,142 @@
+<?php
+namespace app\admin\controller;
+
+class Iplimit extends Base
+{
+    //访问ip管理
+    public function index()
+    {
+        if (request()->isAjax()) {
+            $param  = input('param.');
+            $limit  = $param['pageSize'];
+            $offset = (($param['pageNumber'] - 1) * $limit);
+            $where['object'] = $param['type'];
+            if (strlen($param['searchText'])) {
+                $where['ip'] = ['like', '%' . $param['searchText'] . '%'];
+            }
+
+            $result = db('iplimit')->where($where)->limit($offset, $limit)->select();
+            $admins = db('admins')->select();
+            foreach ($result as $key => $vo) {
+                
+                for($i=0;$i<count($admins);$i++){
+                    if($vo['admin_id'] == $admins[$i]['id']){
+                        $result[$key]['admin'] = $admins[$i]['user_name'];
+                    }
+                }
+
+                // 生成操作按钮.
+                $result[$key]['operate'] = $this->makeBtn($vo['id']);
+            }
+
+            // 总数据.
+            $return['total'] = db('iplimit')->where($where)->count();  //总数据
+            $return['rows'] = $result;
+
+            return json($return);
+
+        }
+
+        return $this->fetch();
+    }
+
+    //访问ip添加
+    public function add(){
+        if(request()->isPost()){
+
+            $param     = input('post.');
+            $findWhere = [
+                'ip' => $param['ip'],
+                'object'  => $param['object'],
+            ];
+
+            $has = db('iplimit')->where($findWhere)->find();
+            if (empty($has) === false) {
+                return json(['code' => -1, 'data' => '', 'msg' => '该ip已经存在']);
+            }
+
+            $param['ctime'] = date('Y-m-d H:i:s',time());
+            $param['utime']  = date('Y-m-d H:i:s',time());
+            $param['admin_id']  = session('user_id');
+
+
+            try {
+                db('iplimit')->insert($param);
+            } catch(\Exception $e) {
+                return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
+            }
+
+            return json(['code' => 1, 'data' => '', 'msg' => '添加访问ip成功']);
+        }
+
+        $this->assign([
+            'status' => config('kf_status')
+        ]);
+
+        return $this->fetch();
+    }
+
+    //访问ip编辑
+    public function edit(){
+        if(request()->isAjax()){
+
+            $param = input('post.');
+
+            // 检测用户修改的管理员是否重复
+            $has = db('iplimit')->where('ip', $param['ip'])->where('id', $param['id'])->find();
+            if(!empty($has)){
+                return json(['code' => -1, 'data' => '', 'msg' => '该访问ip已经存在']);
+            }
+
+            $param['ctime'] = date('Y-m-d H:i:s',time());
+            $param['utime']  = date('Y-m-d H:i:s',time());
+            $param['admin_id']  = session('user_id');
+
+            try{
+                db('iplimit')->where('id', $param['id'])->update($param);
+            }catch(\Exception $e){
+                return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
+            }
+
+            return json(['code' => 1, 'data' => '', 'msg' => '编辑访问ip成功']);
+        }
+
+        $id = input('param.id/d');
+        $info = db('iplimit')->where('id', $id)->find();
+
+        $this->assign([
+            'info' => $info,
+            'status' => config('kf_status')
+        ]);
+        return $this->fetch();
+    }
+
+    //删除
+    public function del(){
+        if(request()->isAjax()){
+            $id = input('param.id/d');
+            // return $id;
+
+            try{
+                db('iplimit')->where('id', $id)->delete();
+            }catch(\Exception $e){
+                return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]);
+            }
+
+            return json(['code' => 1, 'data' => '', 'msg' => '删除ip成功']);
+        }
+    }
+
+    // 生成按钮
+    private function makeBtn($id)
+    {
+        $operate = '<a href="' . url('iplimit/edit', ['id' => $id]) . '">';
+        $operate .= '<button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 编辑</button></a> ';
+
+        $operate .= '<a href="javascript:Del(' . $id . ')"><button type="button" class="btn btn-danger btn-sm">';
+        $operate .= '<i class="fa fa-trash-o"></i> 删除</button></a> ';
+
+        return $operate;
+    }
+
+}

+ 146 - 0
application/admin/view/iplimit/add.html

@@ -0,0 +1,146 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>添加访问IP</title>
+    <link rel="shortcut icon" href="favicon.ico">
+    <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
+    <link href="__CSS__/font-awesome.min.css?v=4.4.0" rel="stylesheet">
+    <link href="__CSS__/animate.min.css" rel="stylesheet">
+    <link href="__JS__/layui/css/layui.css" rel="stylesheet">
+    <link href="__CSS__/style.min.css?v=4.1.0" rel="stylesheet">
+</head>
+<body class="gray-bg">
+<div class="wrapper wrapper-content animated fadeInRight">
+    <div class="row">
+        <div class="col-sm-8">
+            <div class="ibox float-e-margins">
+                <div class="ibox-title">
+                    <h5>添加访问IP</h5>
+                </div>
+                <div class="ibox-content">
+                    <form class="form-horizontal m-t layui-form" id="commentForm" method="post" action="{:url('iplimit/add')}">
+
+                        <input style="display: none" id="type" name="object" value=""/>
+                        <div class="form-group">
+                            <label class="col-sm-3 control-label">IP/IP范围:</label>
+                            <div class="input-group col-sm-4">
+                                <input class="form-control" name="ip" required="" aria-required="true" style="width: 400px;height: 38px;resize:none">
+                            </div>
+                        </div>
+                        <!--<div class="form-group">
+                            <label class="col-sm-3 control-label">选择对象:</label>
+                            <input type="hidden" id="sensitivewords_for" name="sensitivewords_for"/>
+                            <div class="input-group col-sm-4 layui-form">
+                                <select lay-verify="required" lay-filter="group">
+                                    <option value="">请选择对象</option>
+                                    <option value="1">用户</option>
+                                    <option value="2">客服</option>
+                                </select>
+                            </div>
+                        </div>-->
+                        <div class="form-group">
+                            <div class="col-sm-4 col-sm-offset-6">
+                                <button class="btn btn-primary" type="submit">提交</button>
+                            </div>
+                        </div>
+                    </form>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>
+<script src="__JS__/jquery.min.js?v=2.1.4"></script>
+<script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
+<script src="__JS__/content.min.js?v=1.0.0"></script>
+<script src="__JS__/plugins/validate/jquery.validate.min.js"></script>
+<script src="__JS__/plugins/validate/messages_zh.min.js"></script>
+<script src="__JS__/plugins/layer/layer.min.js"></script>
+<script src="__JS__/layui/layui.js"></script>
+<script src="__JS__/jquery.form.js"></script>
+<script type="text/javascript">
+    const myHost = "http://" + window.location.host;
+    const type = getQueryVariable('type');
+    $('#type').val(type);
+
+    layui.use(['form', 'upload'], function(){
+        var form = layui.form;
+
+        form.on('select(group)', function(value){
+            $("#object").val(value.value);
+        });
+
+        // form.on('select(robotgroups)', function(value){
+        //     $("#robotgroups_id").val(value.value);
+        // });
+    });
+    function getQueryVariable(variable)
+    {
+      var query = window.location.search.substring(1);
+      var vars = query.split("&");
+      for (var i=0;i<vars.length;i++) {
+        var pair = vars[i].split("=");
+        if(pair[0] == variable){return pair[1];}
+      }
+      return(false);
+    }
+    layui.use(['form', 'upload'], function(){
+        var form = layui.form;
+    });
+
+    var index = '';
+    function showStart(){
+        index = layer.load(0, {shade: false});
+        return true;
+    }
+
+    function showSuccess(res){
+
+        layer.ready(function(){
+            layer.close(index);
+            if(1 == res.code){
+               layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
+                   window.location.href = myHost + '/admin/iplimit/index';
+               });
+            }else if(111 == res.code){
+                window.location.reload();
+            }else{
+                layer.msg(res.msg, {anim: 6});
+            }
+        });
+    }
+
+    $(document).ready(function(){
+        // 添加管理员
+        var options = {
+            beforeSubmit:showStart,
+            success:showSuccess
+        };
+
+        $('#commentForm').submit(function(){
+            $(this).ajaxSubmit(options);
+            return false;
+        });
+    });
+
+    // 表单验证
+    $.validator.setDefaults({
+        highlight: function(e) {
+            $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
+        },
+        success: function(e) {
+            e.closest(".form-group").removeClass("has-error").addClass("has-success")
+        },
+        errorElement: "span",
+        errorPlacement: function(e, r) {
+            e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
+        },
+        errorClass: "help-block m-b-none",
+        validClass: "help-block m-b-none"
+    });
+
+</script>
+</body>
+</html>

+ 122 - 0
application/admin/view/iplimit/edit.html

@@ -0,0 +1,122 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>编辑访问ip</title>
+    <link rel="shortcut icon" href="favicon.ico">
+    <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
+    <link href="__CSS__/font-awesome.min.css?v=4.4.0" rel="stylesheet">
+    <link href="__CSS__/animate.min.css" rel="stylesheet">
+    <link href="__JS__/layui/css/layui.css" rel="stylesheet">
+    <link href="__CSS__/style.min.css?v=4.1.0" rel="stylesheet">
+</head>
+<body class="gray-bg">
+<div class="wrapper wrapper-content animated fadeInRight">
+    <div class="row">
+        <div class="col-sm-8">
+            <div class="ibox float-e-margins">
+                <div class="ibox-title">
+                    <h5>编辑访问ip</h5>
+                </div>
+                <div class="ibox-content">
+                    <form class="form-horizontal m-t layui-form" id="commentForm" method="post" action="{:url('iplimit/edit')}">
+                        <input type="hidden" name="id" value="{$info['id']}"/>
+                        <div class="form-group">
+                            <label class="col-sm-3 control-label">访问ip:</label>
+                            <div class="input-group col-sm-4">
+                                <input class="form-control" name="ip" required="" aria-required="true" value="{$info['ip']}">
+                            </div>
+                        </div>
+                        <div class="form-group">
+                            <div class="col-sm-4 col-sm-offset-6">
+                                <button class="btn btn-primary" type="submit">提交</button>
+                            </div>
+                        </div>
+                    </form>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>
+<script src="__JS__/jquery.min.js?v=2.1.4"></script>
+<script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
+<script src="__JS__/content.min.js?v=1.0.0"></script>
+<script src="__JS__/plugins/validate/jquery.validate.min.js"></script>
+<script src="__JS__/plugins/validate/messages_zh.min.js"></script>
+<script src="__JS__/plugins/layer/layer.min.js"></script>
+<script src="__JS__/layui/layui.js"></script>
+<script src="__JS__/jquery.form.js"></script>
+<script type="text/javascript">
+    const myHost = "http://" + window.location.host;
+
+    layui.use(['form', 'upload'], function(){
+        var form = layui.form;
+    });
+
+    var index = '';
+    function showStart(){
+        index = layer.load(0, {shade: false});
+        return true;
+    }
+
+    function showSuccess(res){
+
+        layer.ready(function(){
+            layer.close(index);
+            if(1 == res.code){
+                layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
+                    window.location.href = myHost + '/admin/iplimit/index';
+                });
+            }else if(111 == res.code){
+                window.location.reload();
+            }else{
+                layer.msg(res.msg, {anim: 6});
+            }
+        });
+    }
+
+    $(document).ready(function(){
+        // 添加管理员
+        var options = {
+            beforeSubmit:showStart,
+            success:showSuccess
+        };
+
+        $('#commentForm').submit(function(){
+            $(this).ajaxSubmit(options);
+            return false;
+        });
+    });
+
+    // 表单验证
+    $.validator.setDefaults({
+        highlight: function(e) {
+            $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
+        },
+        success: function(e) {
+            e.closest(".form-group").removeClass("has-error").addClass("has-success")
+        },
+        errorElement: "span",
+        errorPlacement: function(e, r) {
+            e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
+        },
+        errorClass: "help-block m-b-none",
+        validClass: "help-block m-b-none"
+    });
+
+    layui.use(['form', 'upload'], function(){
+        var form = layui.form;
+
+        form.on('select(group)', function(value){
+            $("#object").val(value.value);
+        });
+
+        // form.on('select(robotgroups)', function(value){
+        //     $("#robotgroups_id").val(value.value);
+        // });
+    });
+</script>
+</body>
+</html>

+ 176 - 0
application/admin/view/iplimit/index.html

@@ -0,0 +1,176 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>访客IP设置列表</title>
+    <link rel="shortcut icon" href="favicon.ico">
+    <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
+    <link href="__CSS__/font-awesome.min.css?v=4.4.0" rel="stylesheet">
+    <link href="__CSS__/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
+    <link href="__CSS__/animate.min.css" rel="stylesheet">
+    <link href="__CSS__/style.min.css?v=4.1.0" rel="stylesheet">
+</head>
+<body class="gray-bg">
+<div class="wrapper wrapper-content animated fadeInRight">
+    <!-- Panel Other -->
+    <div class="ibox float-e-margins">
+        <input style="display:none;" type="text" value="2" id="type">
+        <div style="display: flex;">
+            <div class="ibox-title" style="width: 100px; cursor:pointer;" id="current1" onclick="current(2)">
+                <h5>客服</h5>
+            </div>
+            <div class="ibox-title" id="current2" style="width: 100px; cursor:pointer; background: #eee" onclick="current(1)">
+                <h5>用户</h5>
+            </div>
+            <div class="ibox-title" style="width: calc(100% - 200px); background: #eee;">
+            </div>
+        </div>
+        <div class="ibox-content">
+            <a id="add" href="/admin/iplimit/add.html?type=2">
+                <button class="btn btn-primary" type="button" style="margin-top:10px"><strong>新增IP</strong>
+                </button>
+            </a>
+
+            <!--搜索框开始-->
+            <form id='commentForm' role="form" method="post" class="form-inline pull-right">
+                <div class="content clearfix m-b" style="margin-top: 5px;">
+                    <div class="form-group">
+                        <label>IP:</label>
+                        <input type="text" class="form-control" id="content" name="content" value="" placeholder="请输入IP">
+                        <input style="display: none">
+                    </div>
+                    <div class="form-group">
+                        <button class="btn btn-primary" type="button" style="margin-top:5px" id="search"><strong>搜 索</strong>
+                        </button>
+                    </div>
+                </div>
+            </form>
+            <!--搜索框结束-->
+            <div class="example-wrap">
+                <div class="example">
+                    <table id="cusTable">
+                        <thead>
+                        <th data-field="id">ID</th>
+                        <th data-field="ip">IP/IP范围</th>
+                        <th data-field="utime">修改时间</th>
+                        <th data-field="admin">管理员</th>
+                        <th data-field="operate">操作</th>
+                        </thead>
+                    </table>
+                </div>
+            </div>
+
+            <!-- End Example Pagination -->
+        </div>
+    </div>
+</div>
+<!-- End Panel Other -->
+<script src="__JS__/jquery.min.js?v=2.1.4"></script>
+<script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
+<script src="__JS__/content.min.js?v=1.0.0"></script>
+<script src="__JS__/plugins/bootstrap-table/bootstrap-table.min.js"></script>
+<script src="__JS__/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
+<script src="__JS__/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
+<script src="__JS__/plugins/layer/layer.min.js"></script>
+<script type="text/javascript">
+    function current(id) {
+        $("#type").val(id);
+        if (id == 1) {
+            $("#current1").css("background","#eee");
+            $("#current2").css("background","#fff");
+            $("#add").attr('href','/admin/iplimit/add.html?type=1');
+        } else if (id == 2) {
+            $("#current2").css({"background":"#eee"});
+            $("#current1").css({"background":"#fff"});
+            $("#add").attr('href','/admin/iplimit/add.html?type=2');
+        }
+        initTable()
+    }
+    function initTable() {
+        //先销毁表格
+        $('#cusTable').bootstrapTable('destroy');
+        let type = $('#type').val();
+        //初始化表格,动态从服务器加载数据
+        $("#cusTable").bootstrapTable({
+            method: "get",  //使用get请求到服务器获取数据
+            url: "{:url('iplimit/index')}", //获取数据的地址
+            striped: true,  //表格显示条纹
+            pagination: true, //启动分页
+            pageSize: 50,  //每页显示的记录数
+            pageNumber:1, //当前第几页
+            pageList: [20, 50],  //记录数可选列表
+            sidePagination: "server", //表示服务端请求
+            paginationFirstText: "首页",
+            paginationPreText: "上一页",
+            paginationNextText: "下一页",
+            paginationLastText: "尾页",
+            queryParamsType : "undefined",
+            queryParams: function queryParams(params) {   //设置查询参数
+                var param = {
+                    pageNumber: params.pageNumber,
+                    type: type,
+                    pageSize: params.pageSize,
+                    searchText:$('#content').val()
+                };
+                return param;
+            },
+            onLoadSuccess: function(res){  //加载成功时执行
+                if(111 == res.code){
+                    window.location.reload();
+                }
+                layer.msg("加载成功", {time : 1000});
+            },
+            onLoadError: function(){  //加载失败时执行
+                layer.msg("加载数据失败");
+            }
+        });
+    }
+
+    function showSuccess(res){
+
+        layer.ready(function(){
+            layer.close(index);
+            if(1 == res.code){
+                layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
+                    window.location.href = myHost + '/admin/iplimit/index';
+                });
+            }else if(111 == res.code){
+                window.location.reload();
+            }else{
+                layer.msg(res.msg, {anim: 6});
+            }
+        });
+    }
+
+    $(document).ready(function () {
+        //调用函数,初始化表格
+        initTable();
+
+        //当点击查询按钮的时候执行
+        $("#search").bind("click", initTable);
+    });
+
+    function Del(id){
+        layer.confirm('确认删除此ip?', {icon: 3, title:'提示'}, function(index){
+            //do something
+            $.getJSON("{:url('iplimit/del')}", {'id' : id}, function(res){
+                if(1 == res.code){
+                    layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
+                        initTable();
+                    });
+                }else if(111 == res.code){
+                    window.location.reload();
+                }else{
+                    layer.alert(res.msg, {title: '友情提示', icon: 2});
+                }
+            });
+
+            layer.close(index);
+        })
+
+    }
+
+</script>
+</body>
+</html>