Sfoglia il codice sorgente

'客服模块会话、列表'

Ethan 6 anni fa
parent
commit
9683b4fe21

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

@@ -4,7 +4,7 @@ namespace app\index\controller;
 use think\Controller;
 
 /**
- * 分组
+ * 公共
  */
 class Common extends Controller
 {

+ 1 - 0
application/index/controller/Evaluate.php

@@ -16,6 +16,7 @@ class Evaluate extends Common
      */
     public function index()
     {
+        // 验证token.
         $tokenStatus = $this->verifyApiToken();
         $code        = -2;
         $msg         = '错误';

+ 1 - 0
application/index/controller/Groups.php

@@ -17,6 +17,7 @@ class Groups extends Common
      */
     public function index()
     {
+        // 验证token.
         $tokenStatus = $this->verifyApiToken();
         $code        = -2;
         $msg         = '错误';

+ 2 - 0
application/index/controller/Robot.php

@@ -16,6 +16,7 @@ class Robot extends Common
      */
     public function index()
     {
+        // 验证token.
         $tokenStatus = $this->verifyApiToken();
         $code        = -2;
         $msg         = '错误';
@@ -56,6 +57,7 @@ class Robot extends Common
      */
     public function getRobotGroups()
     {
+        // 验证token.
         $tokenStatus = $this->verifyApiToken();
         $code        = -2;
         $msg         = '错误';

+ 3 - 3
application/index/controller/Upload.php

@@ -30,7 +30,7 @@ class Upload extends Controller
         $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
         if($info){
             $src =  '/uploads' . '/' . date('Ymd') . '/' . $info->getFilename();
-            return json(['code' => 0, 'data' => ['src' => $src ], 'msg' => '']);
+            return json(['code' => 200, 'data' => ['src' => $src ], 'msg' => '']);
         }else{
             // 上传失败获取错误信息
             return json(['code' => -1, 'data' => '', 'msg' => $file->getError()]);
@@ -61,10 +61,10 @@ class Upload extends Controller
         $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
         if($info){
             $src =  '/uploads' . '/' . date('Ymd') . '/' . $info->getFilename();
-            return json(['code' => 0, 'data' => ['src' => $src ], 'msg' => $fileInfo['name']]);
+            return json(['code' => 200, 'data' => ['src' => $src ], 'msg' => $fileInfo['name']]);
         }else{
             // 上传失败获取错误信息
             return json(['code' => -1, 'data' => '', 'msg' => $file->getError()]);
         }
     }
-}
+}

+ 62 - 0
application/service/controller/Common.php

@@ -0,0 +1,62 @@
+<?php
+namespace app\service\controller;
+
+/**
+ * 公共类
+ */
+class Common extends Base
+{
+
+
+    /**
+     * 验证token
+     *
+     * @access public
+     * @return string
+     */
+    protected function verifyToken()
+    {
+        $request      = \think\Request::instance();
+        $getApiToken  = input('server.HTTP_apiToken');
+        $getUserToken = input('server.HTTP_userToken');
+        $action       = $request->action();
+        $controller   = $request->controller();
+        $module       = $request->module();
+        $apiToken     = md5(strtoupper($action.'Customer-Service'.$controller.strtotime(date('Y-m-d')).$module));
+        // 验证服务器token.
+        if ($getApiToken === $apiToken && empty($getUserToken) === false) {
+            $usersField          = ['id'];
+            $usersWhere['token'] = $getUserToken;
+            // 验证用户token.
+            $users = model('users')->findUsers($usersField, $usersWhere);
+            if (empty($users) === false) {
+                return true;
+            } else {
+                return false;
+            }
+        } else {
+            return false;
+        }
+
+    }//end verifyToken()
+
+
+    /**
+     * 获取用户信息
+     *
+     * @access public
+     * @return string
+     */
+    protected function getUserInfo()
+    {
+        $getUserToken        = input('server.HTTP_userToken');
+        $usersField          = ['*'];
+        $usersWhere['token'] = $getUserToken;
+        // 获取用户信息.
+        $usersInfo = model('users')->findUsers($usersField, $usersWhere);
+        return $usersInfo;
+
+    }//end getUserInfo()
+
+
+}

+ 116 - 0
application/service/controller/History.php

@@ -0,0 +1,116 @@
+<?php
+namespace app\service\controller;
+
+/**
+ * 客服系统会话历史类
+ */
+class History extends Common
+{
+
+
+    /**
+     * 获取会话历史
+     *
+     * @access public
+     * @return array JsonString
+     */
+    public function historyList()
+    {
+        // 验证token.
+        $tokenStatus = $this->verifyToken();
+        $code        = -2;
+        $msg         = '错误';
+        if ($tokenStatus === false) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }
+
+        try {
+            // 获取用户信息.
+            $getUserInfo     = $this->getUserInfo();
+            $serviceLogField = [
+                'user_id',
+                'user_name',
+                'user_avatar',
+                'user_ip',
+                'start_time',
+                'end_time',
+                'name',
+                'website',
+                'system',
+                'browse',
+                'a.status',
+                'evaluate_id',
+            ];
+            // 关联信息.
+            $serviceLogJoin['groups b'] = 'a.group_id = b.id';
+            $serviceLogWhere['kf_id']   = $getUserInfo->id;
+            // 获取用户信息.
+            $serviceLog = model('ServiceLog')->selectServiceLog($serviceLogField, $serviceLogWhere, $serviceLogJoin);
+            $evaluate   = model('Evaluate')->getEvaluate();
+            foreach ($serviceLog as $k => $v) {
+                foreach ($evaluate as $va) {
+                    if ($v->evaluate_id === $va->evaluate_id) {
+                        $serviceLog[$k]->evaluate_name = $va->evaluate_name;
+                    }
+                }
+            }
+
+
+            return json(['code' => 200, 'data' => $serviceLog, 'msg' => '成功']);
+        } catch (\Exception $e) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }//end try
+
+    }//end historyList()
+
+
+    /**
+     * 获取会话历史详细
+     *
+     * @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 {
+            // 获取用户信息.
+            $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',
+            ];
+            // 关联信息.
+            $serviceLogJoin['groups b'] = 'a.group_id = b.id';
+            $serviceLogWhere['kf_id']   = $getUserInfo->id;
+            // 获取用户信息.
+            $serviceLog = model('ServiceLog')->selectServiceLog($serviceLogField, $serviceLogWhere, $serviceLogJoin);
+
+
+            return json(['code' => 200, 'data' => $serviceLog, 'msg' => '成功']);
+        } catch (\Exception $e) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }//end try
+
+    }//end historyList()
+
+
+}

+ 97 - 4
application/service/controller/Index.php

@@ -1,8 +1,96 @@
 <?php
 namespace app\service\controller;
 
-class Index extends Base
+/**
+ * 客服系统首页类
+ */
+class Index extends Common
 {
+
+
+    /**
+     * 获取用户详情
+     *
+     * @access public
+     * @return array JsonString
+     */
+    public function userInfo()
+    {
+        // 验证token.
+        $tokenStatus = $this->verifyToken();
+        $code        = -2;
+        $msg         = '错误';
+        if ($tokenStatus === false) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }
+
+        try {
+            $getUserToken = input('server.HTTP_userToken');
+            $usersField   = [
+                'a.id',
+                'user_name',
+                'user_avatar',
+                'b.name',
+            ];
+            // 关联信息.
+            $join['groups b']    = 'a.group_id = b.id';
+            $usersWhere['token'] = $getUserToken;
+            // 获取用户信息.
+            $usersInfo = model('users')->findInfo($usersField, $usersWhere, $join);
+
+            return json(['code' => 200, 'data' => $usersInfo, 'msg' => '成功']);
+        } catch (\Exception $e) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }//end try
+
+    }//end userInfo()
+
+
+    /**
+     * 获取用户快捷语
+     *
+     * @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',
+            ];
+            $sysWordsWhere['status']  = 1;
+            $sysWordsWhere['user_id'] = 0;
+            // 查询系统快捷语.
+            $sysWords = model('words')->selectWords($wordsField, $sysWordsWhere);
+            // 查询用户私有快捷语条件.
+            $userWordsWhere['user_id'] = $getUserInfo->id;
+            // 查询用户私有快捷语.
+            $userWords = model('words')->selectWords($wordsField, $userWordsWhere);
+            $result    = [
+                'sysWords'  => $sysWords,
+                'userWords' => $userWords,
+            ];
+
+            return json(['code' => 200, 'data' => $result, 'msg' => '成功']);
+        } catch (\Exception $e) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }//end try
+
+    }//end userWords()
+
+
     public function index()
     {
         // 客服信息
@@ -18,6 +106,7 @@ class Index extends Base
         return $this->fetch();
     }
 
+
     // 获取服务用户列表
     // 此方法是为了防止客服工作期间错误的刷新工作台,导致服务人员消失的问题
     public function getUserList()
@@ -25,9 +114,13 @@ class Index extends Base
         if(request()->isAjax()){
 
             // 此处只查询过去 三个小时 内的未服务完的用户
-            $userList = db('service_log')->field('user_id id,user_name name,user_avatar avatar,user_ip ip')
-                ->where('kf_id', cookie('l_user_id'))
-                ->where('start_time', '>', time() - 3600 * 3)->where('end_time', 0)->select();
+            $userList = db('service_log')
+                ->where(function ($query) {
+                    $query = $query->where('status', 1);
+                    $query = $query->whereOr('status', 3);
+                    return $query;
+                })
+                ->select();
 
             return json(['code' => 1, 'data' => $userList, 'msg' => 'ok']);
         }

+ 27 - 0
application/service/model/Evaluate.php

@@ -0,0 +1,27 @@
+<?php
+namespace app\service\model;
+
+use think\Model;
+
+/**
+ * 评价模型
+ */
+class Evaluate extends Model
+{
+
+
+    /**
+     * 查询评价
+     *
+     * @access public
+     * @return array 返回类型
+     */
+    public function getEvaluate()
+    {
+        $result = $this->select();
+        return $result;
+
+    }//end getEvaluate()
+
+
+}

+ 42 - 0
application/service/model/ServiceLog.php

@@ -0,0 +1,42 @@
+<?php
+namespace app\service\model;
+
+use think\Model;
+
+/**
+ * 工单模型
+ */
+class ServiceLog extends Model
+{
+
+
+    /**
+     * 数据筛选
+     *
+     * @access public
+     * @param mixed $field 字段
+     * @param mixed $where 条件
+     * @param mixed $join 关联
+     * @return array 返回类型
+     */
+    public function selectServiceLog($field, $where=[], $join=[])
+    {
+        $result = $this->field($field);
+        if (empty($join) === false) {
+            $result = $result->alias('a');
+            foreach ($join as $k => $v) {
+                $result = $result->join($k, $v);
+            }
+        }
+
+        if (empty($where) === false) {
+            $result = $result->where($where);
+        }
+
+        $result = $result->select();
+        return $result;
+
+    }//end selectServiceLog()
+
+
+}

+ 63 - 0
application/service/model/Users.php

@@ -0,0 +1,63 @@
+<?php
+namespace app\service\model;
+
+use think\Model;
+
+/**
+ * 用户模型
+ */
+class Users extends Model
+{
+
+
+    /**
+     * 单个数据筛选
+     *
+     * @access public
+     * @param mixed $field 字段
+     * @param mixed $where 条件
+     * @return array 返回类型
+     */
+    public function findUsers($field, $where=[])
+    {
+        $result = $this->field($field);
+        if (empty($where) === false) {
+            $result = $result->where($where);
+        }
+
+        $result = $result->find();
+        return $result;
+
+    }//end findUsers()
+
+
+    /**
+     * 单个数据筛选
+     *
+     * @access public
+     * @param mixed $field 字段
+     * @param mixed $where 条件
+     * @param mixed $join 关联
+     * @return array 返回类型
+     */
+    public function findInfo($field, $where=[], $join=[])
+    {
+        $result = $this->field($field);
+        if (empty($join) === false) {
+            $result = $result->alias('a');
+            foreach ($join as $k => $v) {
+                $result = $result->join($k, $v);
+            }
+        }
+
+        if (empty($where) === false) {
+            $result = $result->where($where);
+        }
+
+        $result = $result->find();
+        return $result;
+
+    }//end findUsers()
+
+
+}

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

@@ -0,0 +1,34 @@
+<?php
+namespace app\service\model;
+
+use think\Model;
+
+/**
+ * 快捷语模型
+ */
+class Words extends Model
+{
+
+
+    /**
+     * 数据筛选
+     *
+     * @access public
+     * @param mixed $field 字段
+     * @param mixed $where 条件
+     * @return array 返回类型
+     */
+    public function selectWords($field, $where=[])
+    {
+        $result = $this->field($field);
+        if (empty($where) === false) {
+            $result = $result->where($where);
+        }
+
+        $result = $result->select();
+        return $result;
+
+    }//end selectWords()
+
+
+}

+ 1 - 1
public/static/service/js/whisper.js

@@ -300,7 +300,7 @@ function sendMessage(sendMsg) {
     wordBottom();
 }
 
-// 发送消息
+// 关闭工单
 function cc() {
 
     var uid = $("#active-user").attr('data-id');

BIN
public/uploads/20190628/83e4b1e2b23dc4ef9d7d8f2b5bccf5b2.png


BIN
public/uploads/20190628/f2707910919b6e6574aa5bd3f14008f9.png


+ 17 - 20
vendor/GatewayWorker_windows/Applications/whisper/Events.php

@@ -98,7 +98,22 @@ class Events
      */
     public static function onConnect($client_id)
     {
+        // 检测是否开启自动应答
+        $sayHello = self::$db->query('select `word`,`status` from `ws_reply` where `id` = 1');
+        if(!empty($sayHello) && 1 == $sayHello['0']['status']){
 
+            $hello = [
+                'message_type' => 'helloMessage',
+                'data' => [
+                    'name' => '智能助手',
+                    'time' => date('H:i'),
+                    'content' => htmlspecialchars($sayHello['0']['word'])
+                ]
+            ];
+            Gateway::sendToClient($client_id, json_encode($hello));
+            unset($hello);
+        }
+        unset($sayHello);
     }
 
     /**
@@ -248,7 +263,7 @@ class Events
                 unset($reLink);
 
                 // 记录该客服与该会员的服务结束
-                self::$db->query("update `ws_service_log` set `end_time` = " . time() . " where `client_id`= '" . $userClient . "'");
+                self::$db->query("update `ws_service_log` set `end_time` = " . time() . " , `status` = '2' where `client_id`= '" . $userClient . "'");
 
                 // 从当前客服的服务表中删除这个会员
                 $old = $kfList = self::$global->kfList;
@@ -372,6 +387,7 @@ class Events
                     'time' => date('H:i'),
                 ]
             ];
+            self::$db->query("update `ws_service_log` set `status` = '3' where `client_id`= '" . $client_id . "'");
             Gateway::sendToClient($client['0'], json_encode($chat_message));
         }
     }
@@ -646,25 +662,6 @@ class Events
             Gateway::sendToClient($client_id, json_encode($noticeUser));
             unset($noticeUser);
 
-            // 检测是否开启自动应答
-            $sayHello = self::$db->query('select `word`,`status` from `ws_reply` where `id` = 1');
-            if(!empty($sayHello) && 1 == $sayHello['0']['status']){
-
-                $hello = [
-                    'message_type' => 'helloMessage',
-                    'data' => [
-                        'name' => $res['data']['1'],
-                        'avatar' => '',
-                        'id' => $res['data']['0'],
-                        'time' => date('H:i'),
-                        'content' => htmlspecialchars($sayHello['0']['word'])
-                    ]
-                ];
-                Gateway::sendToClient($client_id, json_encode($hello));
-                unset($hello);
-            }
-            unset($sayHello);
-
             // 通知客服端绑定会员的信息
             $noticeKf = [
                 'message_type' => 'connect',