瀏覽代碼

Merge branch 'master' of http://git.bocai108.com:10180/Ethan/Customer-Service

vali 6 年之前
父節點
當前提交
ab8a584fb6

+ 80 - 0
application/admin/controller/Accounts.php

@@ -0,0 +1,80 @@
+<?php
+/**
+ * User: nickbai
+ * Date: 2017/10/23 13:33
+ * Email: 1902822973@qq.com
+ */
+namespace app\admin\controller;
+
+class Accounts extends Base
+{
+    // 用户列表
+    public function index()
+    {
+        if(request()->isAjax()){
+            $param  = input('param.');
+            $limit  = $param['pageSize'];
+            $offset = (($param['pageNumber'] - 1) * $limit);
+            $where = [];
+            if (empty($param['searchText']) === false) {
+                $where['account_name'] = $param['searchText'];
+            }
+            $result = db('accounts')->where($where)->limit($offset, $limit)->order('add_time', 'desc')->select();
+            foreach($result as $key=>$vo){
+                $result[$key]['add_time'] = date('Y-m-d H:i:s',$result[$key]['add_time']);
+                // 生成操作按钮
+                $result[$key]['operate'] = $this->makeBtn($vo['id']);
+            }
+            $return['total'] = db('accounts')->count();  //总数据
+            $return['rows'] = $result;
+            return json($return);
+        }
+        return $this->fetch();
+    }
+
+    // 重置用户密码为 123456
+    public function resetPwd()
+    {
+        if(request()->isAjax()){
+            $id = input('param.id/d');
+            $password = md5('123456' . config('salt'));
+            try{
+                db('accounts')->where('id', $id)->update(['password' => $password]);
+            }catch(\Exception $e){
+                return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]);
+            }
+            return json(['code' => 1, 'data' => 'accounts/index', 'msg' => '重置密码成功']);
+        }
+    }
+
+    // 删除用户
+    public function delAccount()
+    {
+        if(request()->isAjax()){
+            $id = input('param.id/d');
+            try{
+                db('accounts')->where('id', $id)->delete();
+            }catch(\Exception $e){
+                return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]);
+            }
+            return json(['code' => 1, 'data' => 'accounts/index', 'msg' => '删除客服成功']);
+        }
+    }
+
+    // 生成按钮
+    private function makeBtn($id)
+    {
+//        $operate = '<a href="' . url('Accounts/resetpwd', ['id' => $id]) . '">';
+//        $operate .= '<button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 重置密码</button></a> ';
+
+        $operate = '<a href="javascript:resetPwd(' . $id . ')"><button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 重置密码</button></a>';
+
+        $operate .= '<a style="margin-left:5px;" href="javascript:accountDel(' . $id . ')"><button type="button" class="btn btn-danger btn-sm">';
+        $operate .= '<i class="fa fa-trash-o"></i> 删除</button></a> ';
+
+        //$operate .= '<a href="javascript:;">';
+        //$operate .= '<button type="button" class="btn btn-info btn-sm"><i class="fa fa-institution"></i> 详情</button></a>';
+
+        return $operate;
+    }
+}

+ 2 - 2
application/admin/controller/Messages.php

@@ -16,10 +16,10 @@ class Messages extends Base
 
             $param  = input('param.');
             $limit  = $param['pageSize'];
-            $offset = (($param['pageNumber'] - 1) * $limit);
+            $offset = ($param['pageNumber'] - 1) * $limit;
             $where  = [];
             if (empty($param['searchText']) === false) {
-                $where['user_name'] = $param['searchText'];
+                $where['account_name'] = $param['searchText'];
             }
             $join   = [
                 'accounts b'      => 'a.account_id = b.id',

+ 18 - 3
application/admin/controller/Users.php

@@ -172,6 +172,19 @@ class Users extends Base
         return $this->fetch();
     }
 
+    public function resetPwd(){
+        if(request()->isAjax()){
+            $id = input('param.id/d');
+            $password = md5('123456' . config('salt'));
+            try{
+                db('users')->where('id', $id)->update(['user_pwd' => $password]);
+            }catch(\Exception $e){
+                return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]);
+            }
+            return json(['code' => 1, 'data' => 'accounts/index', 'msg' => '重置密码成功']);
+        }
+    }
+
     // 删除客服
     public function delUser()
     {
@@ -211,10 +224,12 @@ class Users extends Base
     // 生成按钮
     private function makeBtn($id)
     {
-        $operate = '<a href="' . url('users/edituser', ['id' => $id]) . '">';
-        $operate .= '<button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 编辑</button></a> ';
+//        $operate = '<a href="' . url('users/edituser', ['id' => $id]) . '">';
+//        $operate .= '<button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 编辑</button></a> ';
+
+        $operate = '<a href="javascript:resetPwd(' . $id . ')"><button type="button" class="btn btn-primary btn-sm"><i class="fa fa-paste"></i> 重置密码</button></a>';
 
-        $operate .= '<a href="javascript:userDel(' . $id . ')"><button type="button" class="btn btn-danger btn-sm">';
+        $operate .= '<a style="margin-left:5px;" href="javascript:userDel(' . $id . ')"><button type="button" class="btn btn-danger btn-sm">';
         $operate .= '<i class="fa fa-trash-o"></i> 删除</button></a> ';
 
         //$operate .= '<a href="javascript:;">';

+ 2 - 2
application/admin/model/Accountsmessage.php

@@ -38,9 +38,9 @@ class Accountsmessage extends Model
             $result = $result->where($where);
         }
 
-        if (empty($offset) === false && empty($limit) === false) {
+        //if (empty($offset) === false && empty($limit) === false) {
             $result = $result->limit($offset, $limit);
-        }
+        //}
 
         if (empty($order) === false) {
             foreach ($order as $k => $v) {

+ 150 - 0
application/admin/view/accounts/index.html

@@ -0,0 +1,150 @@
+<!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="account_name">用户名称</th>
+                        <th data-field="account_email">用户邮箱</th>
+                        <th data-field="account_phone">用户电话</th>
+                        <th data-field="add_time">注册时间</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('accounts/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 accountDel(id){
+        layer.confirm('确认删除此用户?', {icon: 3, title:'提示'}, function(index){
+            //do something
+            $.getJSON("{:url('accounts/delAccount')}", {'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);
+        })
+
+    }
+
+    function resetPwd(id){
+        layer.confirm('确认重置密码?', {icon: 3, title:'提示'}, function(index){
+            //do something
+            $.getJSON("{:url('accounts/resetPwd')}", {'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>

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

@@ -114,6 +114,19 @@
     </ul>
 </li>
 
+<li class="menu">
+    <a href="#">
+        <i class="fa fa-user"></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('accounts/index')}">用户列表</a>
+        </li>
+    </ul>
+</li>
+
 <li class="menu">
     <a href="#">
         <i class="fa fa-comments-o"></i>

+ 20 - 0
application/admin/view/users/index.html

@@ -129,6 +129,26 @@
         })
 
     }
+
+    function resetPwd(id){
+        layer.confirm('确认重置密码?', {icon: 3, title:'提示'}, function(index){
+            //do something
+            $.getJSON("{:url('users/resetPwd')}", {'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>

+ 2 - 2
application/index/controller/Email.php

@@ -13,7 +13,7 @@ class Email extends Controller
 {
     // 发送邮件
     public function email(){
-        $email=input("post.email");//获取收件人邮箱
+        $email=input("param.email/s");//获取收件人邮箱
         $mail = new PHPMailer();
         $mail->IsSMTP();
         $mail->isHTML(true);
@@ -30,7 +30,7 @@ class Email extends Controller
         session('code', $code, 1800);
         $mail->Subject = '邮箱验证';
         $mail->AddAddress($email);
-        $mail->MsgHTML('邮件内容是 <b>您的验证码是:'.$code.',30分钟内有效</b>,如果非本人操作无需理会!');
+        $mail->MsgHTML('邮箱验证码 <b>您的验证码是:'.$code.'</b>,30分钟内有效,如果非本人操作无需理会!');
 
         $res = $mail->send();
         if($res == true){

+ 10 - 4
application/index/controller/Register.php

@@ -28,6 +28,7 @@ class Register extends Controller
             $userName = input("param.user_name/s");
             $userEmail = input("param.user_email/s");
             $password = input("param.password/s");
+            $phone = input("param.phone/s");
             $emailCode = input("param.code/s");
 
             if(empty($userName)){
@@ -42,22 +43,26 @@ class Register extends Controller
                 return json(['code' => -3, 'data' => '', 'msg' => '密码不能为空']);
             }
 
+            if(empty($phone)){
+                return json(['code' => -4, 'data' => '', 'msg' => '密码不能为空']);
+            }
+
             if(empty($emailCode)){
-                return json(['code' => -4, 'data' => '', 'msg' => '验证码不能为空']);
+                return json(['code' => -5, 'data' => '', 'msg' => '验证码不能为空']);
             }
 
             if($emailCode != session('code')){
-                return json(['code' => -5, 'data' => '', 'msg' => '验证码不正确']);
+                return json(['code' => -6, 'data' => '', 'msg' => '验证码不正确']);
             }
 
             $name = db('accounts')->where('account_name', $userName)->find();
             if(!empty($name)){
-                return json(['code' => -6, 'data' => '', 'msg' => '用户名已存在']);
+                return json(['code' => -7, 'data' => '', 'msg' => '用户名已存在']);
             }
 
             $email = db('accounts')->where('account_email', $userEmail)->find();
             if(!empty($email)){
-                return json(['code' => -7, 'data' => '', 'msg' => '邮箱已存在']);
+                return json(['code' => -8, 'data' => '', 'msg' => '邮箱已存在']);
             }
 
             // 添加用户信息
@@ -65,6 +70,7 @@ class Register extends Controller
                 'account_name' => $userName,
                 'account_email' => $userEmail,
                 'password' => md5($password . config('salt')),
+                'account_phone' => $phone,
                 'status' => 1,
                 'add_time' => time(),
                 'last_login_time' => time()

+ 1 - 1
application/index/controller/User.php

@@ -57,7 +57,7 @@ class User extends Controller
 
         $userInfo = db('accounts')->where('id', $user_id)->find();
 
-        if(md5($password . session('salt')) != $userInfo['password']){
+        if(md5($password . config('salt')) != $userInfo['password']){
             return json(['code' => -3, 'data' => '', 'msg' => '原密码不正确']);
         }
 

+ 87 - 24
application/service/controller/History.php

@@ -40,13 +40,25 @@ class History extends Common
                 'browse',
                 'a.status',
                 'evaluate_id',
+                'servicelog_id',
             ];
             // 关联信息.
             $serviceLogJoin['groups b'] = 'a.group_id = b.id';
             $serviceLogWhere['kf_id']   = $getUserInfo->id;
+            // 分页.
+            $currentPage = input('get.currentPage', '1');
+            $pageSize    = input('get.pageSize', '10');
+            $offset      = (($currentPage - 1) * $pageSize);
             // 获取用户信息.
-            $serviceLog = model('ServiceLog')->selectServiceLog($serviceLogField, $serviceLogWhere, $serviceLogJoin);
-            $evaluate   = model('Evaluate')->getEvaluate();
+            $serviceLog      = model('ServiceLog')->selectServiceLog(
+                $serviceLogField,
+                $offset,
+                $pageSize,
+                $serviceLogWhere,
+                $serviceLogJoin
+            );
+            $countServiceLog = model('ServiceLog')->countServiceLog($serviceLogWhere);
+            $evaluate        = model('Evaluate')->getEvaluate();
             foreach ($serviceLog as $k => $v) {
                 foreach ($evaluate as $va) {
                     if ($v->evaluate_id === $va->evaluate_id) {
@@ -55,8 +67,13 @@ class History extends Common
                 }
             }
 
+            $result['total']       = $countServiceLog;
+            $result['countPage']   = (ceil(($result['total']) / $pageSize));
+            $result['currentPage'] = $currentPage;
+            $result['list']        = $serviceLog;
+            $result['pageSize']    = $pageSize;
 
-            return json(['code' => 200, 'data' => $serviceLog, 'msg' => '成功']);
+            return json(['code' => 200, 'data' => $result, 'msg' => '成功']);
         } catch (\Exception $e) {
             return json(['code' => $code, 'data' => [], 'msg' => $msg]);
         }//end try
@@ -82,35 +99,81 @@ class History extends Common
 
         try {
             // 获取用户信息.
-            $getUserToken = input('get.HTTP_userToken');
-            $getUserInfo     = $this->getUserInfo();
-            $serviceLogField = [
-                'user_id',
-                'user_name',
-                'user_avatar',
-                'user_ip',
-                'start_time',
-                'end_time',
-                'name',
-                'website',
-                'system',
-                'browse',
-                'a.status',
-                'evaluate_id',
-            ];
+            $servicelogId = input('get.servicelog_id');
+            $chatLogField = ['*'];
             // 关联信息.
-            $serviceLogJoin['groups b'] = 'a.group_id = b.id';
-            $serviceLogWhere['kf_id']   = $getUserInfo->id;
+            $chatLogWhere['servicelog_id'] = $servicelogId;
+            // 分页.
+            $currentPage = input('get.currentPage', '1');
+            $pageSize    = input('get.pageSize', '10');
+            $offset      = (($currentPage - 1) * $pageSize);
             // 获取用户信息.
-            $serviceLog = model('ServiceLog')->selectServiceLog($serviceLogField, $serviceLogWhere, $serviceLogJoin);
+            $chatLog      = model('ChatLog')->selectChatLog($chatLogField, $offset, $pageSize, $chatLogWhere);
+            $countChatLog = model('ChatLog')->countChatLog($chatLogWhere);
 
+            $result['total']       = $countChatLog;
+            $result['countPage']   = (ceil(($result['total']) / $pageSize));
+            $result['currentPage'] = $currentPage;
+            $result['list']        = $chatLog;
+            $result['pageSize']    = $pageSize;
 
-            return json(['code' => 200, 'data' => $serviceLog, 'msg' => '成功']);
+            return json(['code' => 200, 'data' => $result, 'msg' => '成功']);
         } catch (\Exception $e) {
             return json(['code' => $code, 'data' => [], 'msg' => $msg]);
         }//end try
 
-    }//end historyList()
+    }//end historyInfo()
+
+
+    /**
+     * 获取用户会话历史详细
+     *
+     * @access public
+     * @return array JsonString
+     */
+    public function userHistory()
+    {
+        // 验证token.
+        $tokenStatus = $this->verifyToken();
+        $code        = -2;
+        $msg         = '错误';
+        if ($tokenStatus === false) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }
+
+        try {
+            // 获取用户ID.
+            $accountId    = input('get.account_id');
+            $chatLogField = ['*'];
+            // 关联信息.
+            $chatLogWhere['from_id'] = $accountId;
+            $chatLogWhereOr['to_id'] = $accountId;
+            // 分页.
+            $currentPage = input('get.currentPage', '1');
+            $pageSize    = input('get.pageSize', '10');
+            $offset      = (($currentPage - 1) * $pageSize);
+            // 获取用户信息.
+            $chatLog      = model('ChatLog')->userChatLog(
+                $chatLogField,
+                $chatLogWhere,
+                $chatLogWhereOr,
+                $offset,
+                $pageSize
+            );
+            $countChatLog = model('ChatLog')->userChatLogCount($chatLogWhere, $chatLogWhereOr);
+
+            $result['total']       = $countChatLog;
+            $result['countPage']   = (ceil(($result['total']) / $pageSize));
+            $result['currentPage'] = $currentPage;
+            $result['list']        = $chatLog;
+            $result['pageSize']    = $pageSize;
+
+            return json(['code' => 200, 'data' => $result, 'msg' => '成功']);
+        } catch (\Exception $e) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }//end try
+
+    }//end userHistory()
 
 
 }

+ 1 - 0
application/service/controller/Index.php

@@ -69,6 +69,7 @@ class Index extends Common
             $wordsField               = [
                 'id',
                 'content',
+                'title',
             ];
             $sysWordsWhere['status']  = 1;
             $sysWordsWhere['user_id'] = 0;

+ 108 - 0
application/service/controller/Services.php

@@ -0,0 +1,108 @@
+<?php
+namespace app\service\controller;
+
+class Services extends Base
+{
+    public function index()
+    {
+        $token = input("param.token/s");
+        $res = model('Services')->checktoken($token);
+        if($res == -1){
+            return $res;
+        }
+        $user_id = $res;
+        //客服信息
+        $service = db('users')->where('id',$user_id )->select();
+        //print_r($service);exit;
+        $this->assign([
+            'service' => $service,
+        ]);
+
+        return $this->fetch();
+    }
+
+    // 客服信息修改
+    public function updateinfo()
+    {
+        if(request()->isPost()){
+
+            $token = input("param.token/s");
+            $res = model('Services')->checktoken($token);
+            if($res == -1){
+                return $res;
+            }
+            $user_id = $res;
+
+            //$user_id = input("param.user_id/s");
+            $user_name = input("param.user_name/s");
+            $user_job_number = input("param.user_job_number/s");
+            $user_email = input("param.user_email/s");
+            $phone = input("param.phone/s");
+            $user_avatar = input("param.user_avatar/s");
+
+            $username = db('users')->where('user_name', $user_name)->where('id', '<>', $user_id)->find();
+            if(!empty($username)){
+                return json(['code' => -1, 'data' => '', 'msg' => '该客服已经存在']);
+            }
+
+            $userjobnumber = db('users')->where('user_job_number', $user_job_number)->where('id', '<>', $user_id)->find();
+            if(!empty($userjobnumber)){
+                return json(['code' => -2, 'data' => '', 'msg' => '该工号已经存在']);
+            }
+
+            $useremail = db('users')->where('user_email', $user_email)->where('id', '<>', $user_id)->find();
+            if(!empty($useremail)){
+                return json(['code' => -3, 'data' => '', 'msg' => '该邮箱已经存在']);
+            }
+
+
+            // 更新客服信息
+            $param = [
+                'user_name' => $user_name,
+                'user_job_number' => $user_job_number,
+                'user_email' => $user_email,
+                'user_avatar' => $user_avatar,
+                'phone' => $phone
+            ];
+            db('users')->where('id', $user_id)->update($param);
+
+            return json(['code' => 1, 'data' => url('service/index'), 'msg' => '修改成功']);
+        }
+    }
+
+    // 客服密码修改
+    public function updatepwd()
+    {
+        if(request()->isPost()){
+
+            $token = input("param.token/s");
+            $res = model('Services')->checktoken($token);
+            if($res == -1){
+                return $res;
+            }
+            $user_id = $res;
+
+            //$user_id = input("param.user_id/s");
+            $password = input("param.password/s");
+            $new_password = input("param.new_password/s");
+
+            $user = db('users')->where('id', $user_id)->find();
+            if(empty($user)){
+                return json(['code' => -1, 'data' => '', 'msg' => '客服不存在']);
+            }else{
+                if($user['user_pwd'] != md5($password . config('salt'))){
+                    return json(['code' => -2, 'data' => '', 'msg' => '原密码不正确']);
+                }
+            }
+
+            // 更新密码
+            $param = [
+                'user_pwd' => md5($new_password . config('salt'))
+            ];
+            db('users')->where('id', $user_id)->update($param);
+
+            return json(['code' => 1, 'data' => url('service/index'), 'msg' => '密码修改成功']);
+        }
+    }
+
+}

+ 153 - 0
application/service/controller/Words.php

@@ -0,0 +1,153 @@
+<?php
+namespace app\service\controller;
+
+/**
+ * 个人快捷语类
+ */
+class Words extends Common
+{
+
+
+    /**
+     * 获取用户快捷语
+     *
+     * @access public
+     * @return array JsonString
+     */
+    public function userWords()
+    {
+        // 验证token.
+        $tokenStatus = $this->verifyToken();
+        $code        = -2;
+        $msg         = '错误';
+        if ($tokenStatus === false) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }
+
+        try {
+            // 获取用户信息.
+            $getUserInfo = $this->getUserInfo();
+            // 获取字段.
+            $wordsField = [
+                'id',
+                'content',
+                'title',
+            ];
+            // 条件.
+            $userWordsWhere['user_id'] = $getUserInfo->id;
+            // 查询用户私有快捷语.
+            $userWords = model('words')->selectWords($wordsField, $userWordsWhere);
+
+            return json(['code' => 200, 'data' => $userWords, 'msg' => '成功']);
+        } catch (\Exception $e) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }//end try
+
+    }//end userWords()
+
+
+    /**
+     * 快捷语修改
+     *
+     * @access public
+     * @return array JsonString
+     */
+    public function updateWords()
+    {
+        // 验证token.
+        $tokenStatus = $this->verifyToken();
+        $code        = -2;
+        $msg         = '错误';
+        if ($tokenStatus === false) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }
+
+        try {
+            // 获取用户信息.
+            $getUserInfo    = $this->getUserInfo();
+            $userWordsWhere = [
+                'user_id' => $getUserInfo->id,
+                'id'      => input('post.id'),
+            ];
+            $content        = input('post.content');
+            $status         = input('post.status');
+            $title          = input('post.title');
+            // 更新内容.
+            if (empty($content) === false) {
+                $userWordsData['content'] = input('post.content');
+            }
+
+            if (empty($status) === false) {
+                $userWordsData['status'] = input('post.status');
+            }
+
+            if (empty($title) === false) {
+                $userWordsData['title'] = input('post.title');
+            }
+
+            // 更新.
+            if (isset($userWordsData) === true) {
+                $updateWordsResult = model('Words')->updateWords($userWordsWhere, $userWordsData);
+                if (empty($updateWordsResult) === false) {
+                    $result = true;
+                }
+            }
+
+            // 参数返回.
+            if (isset($result) === true) {
+                return json(['code' => 200, 'data' => [], 'msg' => '成功']);
+            } else {
+                return json(['code' => 1, 'data' => [], 'msg' => 1]);
+            }
+        } catch (\Exception $e) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }//end try
+
+    }//end updateWords()
+
+
+    /**
+     * 获取会话历史详细
+     *
+     * @access public
+     * @return array JsonString
+     */
+    public function historyInfo()
+    {
+        // 验证token.
+        $tokenStatus = $this->verifyToken();
+        $code        = -2;
+        $msg         = '错误';
+        if ($tokenStatus === false) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }
+
+        try {
+            // 获取用户信息.
+            $servicelogId = input('get.servicelog_id');
+            $chatLogField = ['*'];
+            // 关联信息.
+            $chatLogWhere['servicelog_id'] = $servicelogId;
+            // 分页.
+            $currentPage = input('get.currentPage', '1');
+            $pageSize    = input('get.pageSize', '10');
+            $offset      = (($currentPage - 1) * $pageSize);
+            // 获取用户信息.
+            $chatLog      = model('ChatLog')->selectChatLog($chatLogField, $offset, $pageSize, $chatLogWhere);
+            $countChatLog = model('ChatLog')->countChatLog($chatLogWhere);
+
+            $result['total']       = $countChatLog;
+            $result['countPage']   = (ceil(($result['total']) / $pageSize));
+            $result['currentPage'] = $currentPage;
+            $result['list']        = $chatLog;
+            $result['pageSize']    = $pageSize;
+
+            return json(['code' => 200, 'data' => $result, 'msg' => '成功']);
+        } catch (\Exception $e) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }//end try
+
+    }//end historyInfo()
+
+
+}

+ 99 - 0
application/service/model/ChatLog.php

@@ -0,0 +1,99 @@
+<?php
+namespace app\service\model;
+
+use think\Model;
+
+/**
+ * 会话记录模型
+ */
+class ChatLog extends Model
+{
+
+
+    /**
+     * 数据筛选
+     *
+     * @access public
+     * @param  mixed $field  字段.
+     * @param  mixed $offset 分页开始.
+     * @param  mixed $limit  分页大小.
+     * @param  mixed $where   条件.
+     * @return array 返回类型
+     */
+    public function selectChatLog($field, $offset, $limit, $where=[])
+    {
+        $result = $this->field($field);
+
+        if (empty($where) === false) {
+            $result = $result->where($where);
+        }
+
+        $result = $result->limit($offset, $limit)->order('time_line', 'desc')->select();
+        return $result;
+
+    }//end selectChatLog()
+
+
+    /**
+     * 数据总数
+     *
+     * @access public
+     * @param mixed $where 条件
+     * @return array 返回类型
+     */
+    public function countChatLog($where=[])
+    {
+        $result = $this;
+
+        if (empty($where) === false) {
+            $result = $result->where($where);
+        }
+
+        $result = $result->count();
+        return $result;
+
+    }//end countChatLog()
+
+
+    /**
+     * 用户数据筛选
+     *
+     * @access public
+     * @param mixed $field 字段
+     * @param mixed $offset 分页开始
+     * @param mixed $limit 分页大小
+     * @param mixed $where 条件
+     * @param mixed $whereOr 条件
+     * @return array 返回类型
+     */
+    public function userChatLog($field, $where, $whereOr, $offset, $limit)
+    {
+        $result = $this
+            ->field($field)
+            ->where($where)
+            ->whereOr($whereOr)
+            ->limit($offset, $limit)
+            ->order('time_line', 'desc')
+            ->select();
+        return $result;
+
+    }//end userChatLog()
+
+
+    /**
+     * 用户数据总数
+     *
+     * @access public
+     * @param  mixed $where   条件.
+     * @param  mixed $whereOr 条件.
+     * @return array 返回类型
+     */
+    public function userChatLogCount($where, $whereOr)
+    {
+        $result = $this->where($where)->whereOr($whereOr)->count();
+        return $result;
+
+    }//end userChatLogCount()
+
+
+}

+ 25 - 2
application/service/model/ServiceLog.php

@@ -17,9 +17,11 @@ class ServiceLog extends Model
      * @param mixed $field 字段
      * @param mixed $where 条件
      * @param mixed $join 关联
+     * @param mixed $offset 分页开始
+     * @param mixed $limit 分页大小
      * @return array 返回类型
      */
-    public function selectServiceLog($field, $where=[], $join=[])
+    public function selectServiceLog($field, $offset, $limit, $where=[], $join=[])
     {
         $result = $this->field($field);
         if (empty($join) === false) {
@@ -33,10 +35,31 @@ class ServiceLog extends Model
             $result = $result->where($where);
         }
 
-        $result = $result->select();
+        $result = $result->limit($offset, $limit)->order('start_time', 'desc')->select();
         return $result;
 
     }//end selectServiceLog()
 
 
+    /**
+     * 数据总数
+     *
+     * @access public
+     * @param mixed $where 条件
+     * @return array 返回类型
+     */
+    public function countServiceLog($where=[])
+    {
+        $result = $this;
+
+        if (empty($where) === false) {
+            $result = $result->where($where);
+        }
+
+        $result = $result->count();
+        return $result;
+
+    }//end countServiceLog()
+
+
 }

+ 24 - 0
application/service/model/Services.php

@@ -0,0 +1,24 @@
+<?php
+namespace app\service\model;
+
+use think\Model;
+
+class Services extends Model
+{
+    //检测token
+    function checktoken($token){
+        $user = db('users')->where('token', $token)->find();
+        if(!empty($user)){
+            $time = time()-$user['expire_time'];
+            if($time<3600){
+                db('users')->where('id', $user['id'])->update(['expire_time' => time()]);
+                $user_id = explode('/',base64_decode($token))['2'];
+                return $user_id;
+            }else{
+                return -1;
+            }
+        }
+        return -1;
+    }
+
+}

+ 17 - 0
application/service/model/Words.php

@@ -31,4 +31,21 @@ class Words extends Model
     }//end selectWords()
 
 
+    /**
+     * 数据修改
+     *
+     * @access public
+     * @param mixed $data 数据
+     * @param mixed $where 条件
+     * @return array 返回类型
+     */
+    public function updateWords($where, $data)
+    {
+        $result = $this->where($where)->update($data);
+
+        return $result;
+
+    }//end updateWords()
+
+
 }