vali 6 жил өмнө
parent
commit
55dc1d6e2a

+ 76 - 75
application/service/controller/History.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace app\service\controller;
 
 use think\cache\driver\Redis;
@@ -20,8 +21,8 @@ class History extends Common
     {
         // 验证token.
         $tokenStatus = $this->verifyToken();
-        $code        = -2;
-        $msg         = '错误';
+        $code = -2;
+        $msg = '错误';
         if ($tokenStatus === false) {
             $msg = 'token错误';
             return json(['code' => $code, 'data' => [], 'msg' => $msg]);
@@ -35,9 +36,9 @@ class History extends Common
                 return json(['code' => 1, 'data' => [], 'msg' => $msg]);
             }
 
-            $groups     = model('Groups')->selectGroups();
-            $redis      = new Redis;
-            $kefuInfo   = $redis->handler()->hGetall('KFINFO');
+            $groups = model('Groups')->selectGroups();
+            $redis = new Redis;
+            $kefuInfo = $redis->handler()->hGetall('KFINFO');
             $servicelog = $redis->handler()->hGetall('SERVICELOG');
             // 获取所有用户ID.
             $userIds = [];
@@ -50,13 +51,13 @@ class History extends Common
                 'nick_name',
             ];
             $getAccountsWhere['id'] = ['in', $userIds];
-            $getAllAccounts     = model('Accounts')->selectAccounts($getAccountsField, $getAccountsWhere);
+            $getAllAccounts = model('Accounts')->selectAccounts($getAccountsField, $getAccountsWhere);
 
             foreach ($groups as $k => $v) {
-                $data[$k]           = (object) [
-                    'label' => $v['name'].'-组',
+                $data[$k] = (object)[
+                    'label' => $v['name'] . '-组',
                 ];
-                $n                  = 0;
+                $n = 0;
                 $data[$k]->children = [];
                 foreach ($kefuInfo as $va) {
                     $kefuInfoData = json_decode($va, true);
@@ -64,18 +65,18 @@ class History extends Common
                         $KFstatus = $kefuInfoData['status'] == 1 ? '(在线)'
                             : ($kefuInfoData['status'] == 2 ? '(隐身)'
                                 : ($kefuInfoData['status'] == 3 ? '(休息)' : '(未知)'));
-                        $data[$k]->children[$n] = (object) [
-                            'label' => $kefuInfoData['name'].$KFstatus.'-客服',
+                        $data[$k]->children[$n] = (object)[
+                            'label' => $kefuInfoData['name'] . $KFstatus . '-客服',
                         ];
                         $data[$k]->children[$n]->children = [];
                         foreach ($servicelog as $val) {
                             $servicelogData = json_decode($val, true);
-                            if (('KF'.$servicelogData['kf_id']) == $kefuInfoData['id']) {
+                            if (('KF' . $servicelogData['kf_id']) == $kefuInfoData['id']) {
                                 $found_key = array_search($servicelogData['user_id'], array_column($getAllAccounts, 'id'));
                                 $label = $getAllAccounts[$found_key]['nick_name'] ?? $servicelogData['user_name'];
-                                $data[$k]->children[$n]->children[] = (object) [
-                                    'label'         => $label.'-会话',
-                                    'user_id'         => $servicelogData['user_id'],
+                                $data[$k]->children[$n]->children[] = (object)[
+                                    'label' => $label . '-会话',
+                                    'user_id' => $servicelogData['user_id'],
                                     'servicelog_id' => $servicelogData['servicelog_id'],
                                 ];
                             }
@@ -89,7 +90,7 @@ class History extends Common
 
             return json(['code' => 1, 'data' => $data, 'msg' => '成功', 'serverList' => array_keys($servicelog)]);
         } catch (\Exception $e) {
-            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+            return json(['code' => $code, 'data' => $e->getMessage(), 'msg' => $msg]);
         }//end try
 
     }//end allConversation()
@@ -105,8 +106,8 @@ class History extends Common
     {
         // 验证token.
         $tokenStatus = $this->verifyToken();
-        $code        = -2;
-        $msg         = '错误';
+        $code = -2;
+        $msg = '错误';
         if ($tokenStatus === false) {
             $msg = 'token错误';
             return json(['code' => $code, 'data' => [], 'msg' => $msg]);
@@ -114,7 +115,7 @@ class History extends Common
 
         try {
             // 获取用户信息.
-            $getUserInfo     = $this->getUserInfo();
+            $getUserInfo = $this->getUserInfo();
             $serviceLogField = [
                 'user_id',
                 'user_name',
@@ -133,18 +134,18 @@ class History extends Common
             ];
             // 关联信息.
             $serviceLogJoin['groups b'] = 'a.group_id = b.id';
-            $serviceLogWhere['kf_id']   = $getUserInfo->id;
+            $serviceLogWhere['kf_id'] = $getUserInfo->id;
             // 分页.
             $currentPage = input('post.currentPage', '1');
-            $pageSize    = input('post.pageSize', '10');
-            $start       = input('post.start');
-            $end         = input('post.end');
-            $userName    = input('post.user_name');
-            $startTime   = strtotime(date('Y-m-d').'-6 day');
-            $endTime     = strtotime(date('Y-m-d').'+1 day');
-            if (strlen($start) && strlen($end) ) {
+            $pageSize = input('post.pageSize', '10');
+            $start = input('post.start');
+            $end = input('post.end');
+            $userName = input('post.user_name');
+            $startTime = strtotime(date('Y-m-d') . '-6 day');
+            $endTime = strtotime(date('Y-m-d') . '+1 day');
+            if (strlen($start) && strlen($end)) {
                 $startTime = strtotime($start);
-                $endTime   = strtotime($end.'+1 day');
+                $endTime = strtotime($end . '+1 day');
             }
 
             if (strlen($userName)) {
@@ -160,7 +161,7 @@ class History extends Common
             ];
             $offset = (($currentPage - 1) * $pageSize);
             // 获取用户信息.
-            $serviceLog      = model('ServiceLog')->selectServiceLog(
+            $serviceLog = model('ServiceLog')->selectServiceLog(
                 $serviceLogField,
                 $offset,
                 $pageSize,
@@ -168,7 +169,7 @@ class History extends Common
                 $serviceLogJoin
             );
             $countServiceLog = model('ServiceLog')->countServiceLog($serviceLogWhere);
-            $evaluate        = model('Evaluate')->getEvaluate();
+            $evaluate = model('Evaluate')->getEvaluate();
             foreach ($serviceLog as $k => $v) {
                 foreach ($evaluate as $va) {
                     if ($v->evaluate_id == $va->evaluate_id) {
@@ -177,11 +178,11 @@ class History extends Common
                 }
             }
 
-            $result['total']       = $countServiceLog;
-            $result['countPage']   = (ceil(($result['total']) / $pageSize));
+            $result['total'] = $countServiceLog;
+            $result['countPage'] = (ceil(($result['total']) / $pageSize));
             $result['currentPage'] = $currentPage;
-            $result['list']        = $serviceLog;
-            $result['pageSize']    = $pageSize;
+            $result['list'] = $serviceLog;
+            $result['pageSize'] = $pageSize;
 
             return json(['code' => 1, 'data' => $result, 'msg' => '成功']);
         } catch (\Exception $e) {
@@ -201,8 +202,8 @@ class History extends Common
     {
         // 验证token.
         $tokenStatus = $this->verifyToken();
-        $code        = -2;
-        $msg         = '错误';
+        $code = -2;
+        $msg = '错误';
         if ($tokenStatus === false) {
             $msg = 'token错误';
             return json(['code' => $code, 'data' => [], 'msg' => $msg]);
@@ -216,13 +217,13 @@ class History extends Common
             $chatLogWhere['servicelog_id'] = $servicelogId;
             // 分页.
             $currentPage = input('get.currentPage', '1');
-            $pageSize    = input('get.pageSize', '10');
-            $offset      = (($currentPage - 1) * $pageSize);
+            $pageSize = input('get.pageSize', '10');
+            $offset = (($currentPage - 1) * $pageSize);
             // 获取用户信息.
-            $chatLog      = model('ChatLog')->selectChatLog($chatLogField, $offset, $pageSize, $chatLogWhere);
+            $chatLog = model('ChatLog')->selectChatLog($chatLogField, $offset, $pageSize, $chatLogWhere);
             $countChatLog = model('ChatLog')->countChatLog($chatLogWhere);
             // 查询报警信息.
-            $alarmField                    = [
+            $alarmField = [
                 'evaluate_id',
                 'alarm_corresponding',
                 'alarm_cvtOvertime',
@@ -253,31 +254,31 @@ class History extends Common
                 }
             }
 
-            $service_log = db('service_log')->where('servicelog_id',$servicelogId)->find();
+            $service_log = db('service_log')->where('servicelog_id', $servicelogId)->find();
             $account = db('accounts')
                 ->alias('a')
                 ->join('accountslabel b', 'a.label_id = b.id')
                 ->field('a.id,account_name,nick_name,account_email,account_phone,address,remark,name as label')
-                ->where('a.id',$service_log['user_id'])
+                ->where('a.id', $service_log['user_id'])
                 ->find();
             $account['user_ip'] = $service_log['user_ip'];
             $account['system'] = $service_log['system'];
             $account['browse'] = $service_log['browse'];
 
 
-            $result['total']       = $countChatLog;
-            $result['countPage']   = (ceil(($result['total']) / $pageSize));
+            $result['total'] = $countChatLog;
+            $result['countPage'] = (ceil(($result['total']) / $pageSize));
             $result['currentPage'] = $currentPage;
-            $result['list']        = $chatLog;
-            $result['pageSize']    = $pageSize;
-            $result['account']    = $account;
-            $result['alarm']       = [
-                'evaluate_id'      => $alarm['evaluate_id'],
+            $result['list'] = $chatLog;
+            $result['pageSize'] = $pageSize;
+            $result['account'] = $account;
+            $result['alarm'] = [
+                'evaluate_id' => $alarm['evaluate_id'],
                 'verifyReturnTime' => $verifyReturnTime,
-                'cvtOvertime'      => $cvtOvertime,
-                'serverSensitive'  => $alarm['alarm_serverSensitive'] ? 1 : 2,
-                'userSensitive'    => $alarm['alarm_userSensitive'] ? 1 : 2,
-                'respond'          => $alarm['alarm_respond'],
+                'cvtOvertime' => $cvtOvertime,
+                'serverSensitive' => $alarm['alarm_serverSensitive'] ? 1 : 2,
+                'userSensitive' => $alarm['alarm_userSensitive'] ? 1 : 2,
+                'respond' => $alarm['alarm_respond'],
             ];
 
             return json(['code' => 1, 'data' => $result, 'msg' => '成功']);
@@ -298,8 +299,8 @@ class History extends Common
     {
         // 验证token.
         $tokenStatus = $this->verifyToken();
-        $code        = -2;
-        $msg         = '错误';
+        $code = -2;
+        $msg = '错误';
         if ($tokenStatus === false) {
             $msg = 'token错误';
             return json(['code' => $code, 'data' => [], 'msg' => $msg]);
@@ -313,40 +314,40 @@ class History extends Common
             $chatLogWhere['servicelog_id'] = $servicelogId;
             if (strlen(input('get.lastTime'))) {
                 $lastTime = input('get.lastTime');
-                $chatLogWhere['time_line']  = array('gt', $lastTime);
+                $chatLogWhere['time_line'] = array('gt', $lastTime);
             }
             // 分页.
             $currentPage = 1;
-            $pageSize    = 999999;
-            $offset      = (($currentPage - 1) * $pageSize);
-            $chatLog      = model('ChatLog')->selectChatLog($chatLogField, $offset, $pageSize, $chatLogWhere);
+            $pageSize = 999999;
+            $offset = (($currentPage - 1) * $pageSize);
+            $chatLog = model('ChatLog')->selectChatLog($chatLogField, $offset, $pageSize, $chatLogWhere);
 
-            $service_log = db('service_log')->where('servicelog_id',$servicelogId)->find();
+            $service_log = db('service_log')->where('servicelog_id', $servicelogId)->find();
             $account = db('accounts')
                 ->alias('a')
                 ->join('accountslabel b', 'a.label_id = b.id')
                 ->field('a.id,account_name,nick_name,account_email,account_phone,address,remark,name as label')
-                ->where('a.id',$service_log['user_id'])
+                ->where('a.id', $service_log['user_id'])
                 ->find();
             $account['user_ip'] = $service_log['user_ip'];
             $account['system'] = $service_log['system'];
             $account['browse'] = $service_log['browse'];
             // 获取用户信息.
-            $usersField   = [
+            $usersField = [
                 'a.id',
                 'user_name',
                 'user_avatar',
                 'b.name',
             ];
             // 关联信息.
-            $join['groups b']    = 'a.group_id = b.id';
+            $join['groups b'] = 'a.group_id = b.id';
             $usersWhere['a.id'] = $service_log['kf_id'];
             // 获取用户信息.
             $serverInfo = model('users')->findInfo($usersField, $usersWhere, $join);
 
 
-            $result['list']        = $chatLog;
-            $result['account']    = $account;
+            $result['list'] = $chatLog;
+            $result['account'] = $account;
             $result['serverName'] = $serverInfo['user_name'];
             $result['groupName'] = $serverInfo['name'];
 
@@ -368,8 +369,8 @@ class History extends Common
     {
         // 验证token.
         $tokenStatus = $this->verifyToken();
-        $code        = -2;
-        $msg         = '错误';
+        $code = -2;
+        $msg = '错误';
         if ($tokenStatus === false) {
             $msg = 'token错误';
             return json(['code' => $code, 'data' => [], 'msg' => $msg]);
@@ -377,17 +378,17 @@ class History extends Common
 
         try {
             // 获取用户ID.
-            $accountId    = input('get.account_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);
+            $pageSize = input('get.pageSize', '10');
+            $offset = (($currentPage - 1) * $pageSize);
             // 获取用户信息.
-            $chatLog      = model('ChatLog')->userChatLog(
+            $chatLog = model('ChatLog')->userChatLog(
                 $chatLogField,
                 $chatLogWhere,
                 $chatLogWhereOr,
@@ -396,11 +397,11 @@ class History extends Common
             );
             $countChatLog = model('ChatLog')->userChatLogCount($chatLogWhere, $chatLogWhereOr);
 
-            $result['total']       = $countChatLog;
-            $result['countPage']   = (ceil(($result['total']) / $pageSize));
+            $result['total'] = $countChatLog;
+            $result['countPage'] = (ceil(($result['total']) / $pageSize));
             $result['currentPage'] = $currentPage;
-            $result['list']        = $chatLog;
-            $result['pageSize']    = $pageSize;
+            $result['list'] = $chatLog;
+            $result['pageSize'] = $pageSize;
 
             return json(['code' => 1, 'data' => $result, 'msg' => '成功']);
         } catch (\Exception $e) {