Ver código fonte

'历史会话'

Ethan 6 anos atrás
pai
commit
6a85b99c52

+ 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;

+ 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()
+
+
 }

+ 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()
+
+
 }