| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?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) {
- $msg = 'token错误';
- 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',
- 'servicelog_id',
- ];
- // 关联信息.
- $serviceLogJoin['groups b'] = 'a.group_id = b.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 (empty($start) === false && empty($end) === false) {
- $startTime = strtotime($start);
- $endTime = strtotime($end);
- }
- if (empty($userName) === false) {
- $serviceLogWhere['user_name'] = $userName;
- }
- $serviceLogWhere['start_time'] = [
- 'between',
- [
- $startTime,
- $endTime,
- ],
- ];
- $offset = (($currentPage - 1) * $pageSize);
- // 获取用户信息.
- $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) {
- $serviceLog[$k]->evaluate_name = $va->evaluate_name;
- }
- }
- }
- $result['total'] = $countServiceLog;
- $result['countPage'] = (ceil(($result['total']) / $pageSize));
- $result['currentPage'] = $currentPage;
- $result['list'] = $serviceLog;
- $result['pageSize'] = $pageSize;
- return json(['code' => 1, 'data' => $result, '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) {
- $msg = 'token错误';
- 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' => 1, 'data' => $result, 'msg' => '成功']);
- } catch (\Exception $e) {
- return json(['code' => $code, 'data' => [], 'msg' => $msg]);
- }//end try
- }//end historyInfo()
- /**
- * 获取用户会话历史详细
- *
- * @access public
- * @return array JsonString
- */
- public function userHistory()
- {
- // 验证token.
- $tokenStatus = $this->verifyToken();
- $code = -2;
- $msg = '错误';
- if ($tokenStatus === false) {
- $msg = 'token错误';
- 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' => 1, 'data' => $result, 'msg' => '成功']);
- } catch (\Exception $e) {
- return json(['code' => $code, 'data' => [], 'msg' => $msg]);
- }//end try
- }//end userHistory()
- }
|