vali hace 6 años
padre
commit
060f585534

+ 116 - 0
application/admin/controller/Kfnotice.php

@@ -0,0 +1,116 @@
+<?php
+/**
+ * User: nickbai
+ * Date: 2017/10/23 13:33
+ * Email: 1902822973@qq.com
+ */
+namespace app\admin\controller;
+
+use app\admin\model\Servicenotice as ServicenoticeModel;
+use app\admin\model\Users as Usersmodel;
+
+class Kfnotice extends Base
+{
+    // 管理员列表
+    public function index()
+    {
+
+        if(request()->isAjax()){
+
+            $param = input('param.');
+
+            $limit = $param['pageSize'];
+            $offset = ($param['pageNumber'] - 1) * $limit;
+
+            $where = [];
+            if (!empty($param['searchText'])) {
+                $where['atext'] = ['like', '%' . $param['searchText'] . '%'];
+            }
+
+            $model = new ServicenoticeModel();
+            $result = $model->where($where)->limit($offset, $limit)->order('id','desc')->select();
+
+            foreach($result as $key=>$vo){
+                $vo->readtime = empty($vo->readtime) ? '' : date('Y-m-d H:i:s', $vo->readtime);
+                $vo->uid = $vo->kfuser->user_name;
+                $result[$key] = array_merge($vo->toArray(),['operate'=>$this->makeBtn($vo->id)]) ;
+            }
+            $return['total'] = db('servicenotice')->where($where)->count();  //总数据
+            $return['rows'] = $result;
+
+            return json($return);
+
+        }
+
+        return $this->fetch();
+    }
+
+    // 添加管理员
+    public function add()
+    {
+        if(request()->isPost()){
+
+            $atext = input('post.atext');
+
+            if (empty($atext)){
+                return json(['code' => -1, 'data' => '', 'msg' => '内容不能为空']);
+            }
+
+            $Users = (new Usersmodel())->where(['status'=>1])->select();
+            if (!$Users){
+                return json(['code' => -2, 'data' => '', 'msg' => '没有可用客服']);
+            }
+
+            $datas = [] ;
+            foreach ($Users as $val){
+                $arr = [
+                    'uid'=>$val->id,
+                    'atext'=>$atext
+                ];
+                $datas[] = $arr;
+            }
+
+            try{
+                db('servicenotice')->insertAll($datas);
+            }catch(\Exception $e){
+                return json(['code' => -2, 'data' => '', 'msg' => $e->getMessage()]);
+            }
+            return json(['code' => 1, 'data' => '', 'msg' => '添加公告成功']);
+        }
+
+        $this->assign([
+            'status' => config('kf_status')
+        ]);
+
+        return $this->fetch();
+    }
+
+
+    // 删除管理员
+    public function del()
+    {
+        if(request()->isAjax()){
+            $id = input('param.id/d');
+            //return $id;
+
+            try{
+                db('servicenotice')->where('id', $id)->delete();
+            }catch(\Exception $e){
+                return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]);
+            }
+
+            return json(['code' => 1, 'data' => '', 'msg' => '删除成功']);
+        }
+    }
+
+
+
+    // 生成按钮
+    private function makeBtn($id)
+    {
+        $operate = '<a href="javascript:adminDel(' . $id . ')"><button type="button" class="btn btn-danger btn-sm">';
+        $operate .= '<i class="fa fa-trash-o"></i> 删除</button></a> ';
+
+        return $operate;
+    }
+}

+ 14 - 0
application/admin/model/Servicenotice.php

@@ -0,0 +1,14 @@
+<?php
+namespace app\admin\model;
+
+use think\Model;
+
+
+class Servicenotice extends Model
+{
+    public function kfuser()
+    {
+        return $this->belongsTo('Users','uid','id');
+    }
+
+}

+ 12 - 0
application/admin/model/Users.php

@@ -0,0 +1,12 @@
+<?php
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * 分组模型
+ */
+class Users extends Model
+{
+
+}

+ 110 - 0
application/admin/view/kfnotice/add.html

@@ -0,0 +1,110 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>添加公告</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>添加公告</h5>
+                </div>
+                <div class="ibox-content">
+                    <form class="form-horizontal m-t layui-form" id="commentForm" method="post" action="{:url('kfnotice/add')}">
+
+                        <div class="form-group">
+                            <label class="col-sm-3 control-label">内容:</label>
+                            <div class="input-group col-sm-4">
+                                <textarea name="atext" id="atext" required="true" placeholder="请输入内容" class="layui-textarea"></textarea>
+                            </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">
+
+    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 = res.data;
+               });
+            }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>

+ 129 - 0
application/admin/view/kfnotice/index.html

@@ -0,0 +1,129 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>管理员列表</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">
+        <div class="ibox-title">
+            <h5>管理员列表</h5>
+        </div>
+        <div class="ibox-content">
+            <!--搜索框开始-->
+            <form id='commentForm' role="form" method="post" class="form-inline pull-right">
+                <div class="content clearfix m-b">
+                    <div class="form-group">
+                        <label>模糊搜索内容:</label>
+                        <input type="text" class="form-control" id="username" name="user_name">
+                    </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="uid">uid</th>
+                        <th data-field="atext">内容</th>
+                        <th data-field="ctime">发布时间</th>
+                        <th data-field="readtime">读时间</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 initTable() {
+        //先销毁表格
+        $('#cusTable').bootstrapTable('destroy');
+        //初始化表格,动态从服务器加载数据
+        $("#cusTable").bootstrapTable({
+            method: "get",  //使用get请求到服务器获取数据
+            url: "{:url('kfnotice/index')}", //获取数据的地址
+            striped: true,  //表格显示条纹
+            pagination: true, //启动分页
+            pageSize: 10,  //每页显示的记录数
+            pageNumber:1, //当前第几页
+            pageList: [5, 10, 15, 20, 25],  //记录数可选列表
+            sidePagination: "server", //表示服务端请求
+            paginationFirstText: "首页",
+            paginationPreText: "上一页",
+            paginationNextText: "下一页",
+            paginationLastText: "尾页",
+            queryParamsType : "undefined",
+            queryParams: function queryParams(params) {   //设置查询参数
+                var param = {
+                    pageNumber: params.pageNumber,
+                    pageSize: params.pageSize,
+                    searchText:$('#username').val()
+                };
+                return param;
+            },
+            onLoadSuccess: function(res){  //加载成功时执行
+                if(111 == res.code){
+                    window.location.reload();
+                }
+                layer.msg("加载成功", {time : 1000});
+            },
+            onLoadError: function(){  //加载失败时执行
+                layer.msg("加载数据失败");
+            }
+        });
+    }
+
+    $(document).ready(function () {
+        //调用函数,初始化表格
+        initTable();
+
+        //当点击查询按钮的时候执行
+        $("#search").bind("click", initTable);
+    });
+
+    function adminDel(id) {
+        layer.confirm('确认删除记录?', {icon: 3, title: '提示'}, function (index) {
+            //do something
+            $.getJSON("{:url('kfnotice/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>

+ 16 - 0
application/admin/view/menu.html

@@ -153,3 +153,19 @@
     </ul>
 </li>
 
+<li class="menu">
+    <a href="#">
+        <i class="fa fa-comments-o"></i>
+        <span class="nav-label">客服公告</span>
+        <span class="fa arrow"></span>
+    </a>
+    <ul class="nav nav-second-level">
+        <li>
+            <a class="J_menuItem" href="{:url('kfnotice/index')}">公告列表</a>
+        </li>
+        <li>
+            <a class="J_menuItem" href="{:url('kfnotice/add')}">添加公告</a>
+        </li>
+    </ul>
+</li>
+