History.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. namespace app\service\controller;
  3. /**
  4. * 客服系统会话历史类
  5. */
  6. class History extends Common
  7. {
  8. /**
  9. * 获取会话历史
  10. *
  11. * @access public
  12. * @return array JsonString
  13. */
  14. public function historyList()
  15. {
  16. // 验证token.
  17. $tokenStatus = $this->verifyToken();
  18. $code = -2;
  19. $msg = '错误';
  20. if ($tokenStatus === false) {
  21. $msg = 'token错误';
  22. return json(['code' => $code, 'data' => [], 'msg' => $msg]);
  23. }
  24. try {
  25. // 获取用户信息.
  26. $getUserInfo = $this->getUserInfo();
  27. $serviceLogField = [
  28. 'user_id',
  29. 'user_name',
  30. 'user_avatar',
  31. 'user_ip',
  32. 'start_time',
  33. 'end_time',
  34. 'name',
  35. 'website',
  36. 'system',
  37. 'browse',
  38. 'a.status',
  39. 'evaluate_id',
  40. 'servicelog_id',
  41. ];
  42. // 关联信息.
  43. $serviceLogJoin['groups b'] = 'a.group_id = b.id';
  44. $serviceLogWhere['kf_id'] = $getUserInfo->id;
  45. // 分页.
  46. $currentPage = input('post.currentPage', '1');
  47. $pageSize = input('post.pageSize', '10');
  48. $start = input('post.start');
  49. $end = input('post.end');
  50. $userName = input('post.user_name');
  51. $startTime = strtotime(date('Y-m-d').'-6 day');
  52. $endTime = strtotime(date('Y-m-d').'+1 day');
  53. if (empty($start) === false && empty($end) === false) {
  54. $startTime = strtotime($start);
  55. $endTime = strtotime($end);
  56. }
  57. if (empty($userName) === false) {
  58. $serviceLogWhere['user_name'] = $userName;
  59. }
  60. $serviceLogWhere['start_time'] = [
  61. 'between',
  62. [
  63. $startTime,
  64. $endTime,
  65. ],
  66. ];
  67. $offset = (($currentPage - 1) * $pageSize);
  68. // 获取用户信息.
  69. $serviceLog = model('ServiceLog')->selectServiceLog(
  70. $serviceLogField,
  71. $offset,
  72. $pageSize,
  73. $serviceLogWhere,
  74. $serviceLogJoin
  75. );
  76. $countServiceLog = model('ServiceLog')->countServiceLog($serviceLogWhere);
  77. $evaluate = model('Evaluate')->getEvaluate();
  78. foreach ($serviceLog as $k => $v) {
  79. foreach ($evaluate as $va) {
  80. if ($v->evaluate_id === $va->evaluate_id) {
  81. $serviceLog[$k]->evaluate_name = $va->evaluate_name;
  82. }
  83. }
  84. }
  85. $result['total'] = $countServiceLog;
  86. $result['countPage'] = (ceil(($result['total']) / $pageSize));
  87. $result['currentPage'] = $currentPage;
  88. $result['list'] = $serviceLog;
  89. $result['pageSize'] = $pageSize;
  90. return json(['code' => 1, 'data' => $result, 'msg' => '成功']);
  91. } catch (\Exception $e) {
  92. return json(['code' => $code, 'data' => [], 'msg' => $msg]);
  93. }//end try
  94. }//end historyList()
  95. /**
  96. * 获取会话历史详细
  97. *
  98. * @access public
  99. * @return array JsonString
  100. */
  101. public function historyInfo()
  102. {
  103. // 验证token.
  104. $tokenStatus = $this->verifyToken();
  105. $code = -2;
  106. $msg = '错误';
  107. if ($tokenStatus === false) {
  108. $msg = 'token错误';
  109. return json(['code' => $code, 'data' => [], 'msg' => $msg]);
  110. }
  111. try {
  112. // 获取用户信息.
  113. $servicelogId = input('get.servicelog_id');
  114. $chatLogField = ['*'];
  115. // 关联信息.
  116. $chatLogWhere['servicelog_id'] = $servicelogId;
  117. // 分页.
  118. $currentPage = input('get.currentPage', '1');
  119. $pageSize = input('get.pageSize', '10');
  120. $offset = (($currentPage - 1) * $pageSize);
  121. // 获取用户信息.
  122. $chatLog = model('ChatLog')->selectChatLog($chatLogField, $offset, $pageSize, $chatLogWhere);
  123. $countChatLog = model('ChatLog')->countChatLog($chatLogWhere);
  124. $result['total'] = $countChatLog;
  125. $result['countPage'] = (ceil(($result['total']) / $pageSize));
  126. $result['currentPage'] = $currentPage;
  127. $result['list'] = $chatLog;
  128. $result['pageSize'] = $pageSize;
  129. return json(['code' => 1, 'data' => $result, 'msg' => '成功']);
  130. } catch (\Exception $e) {
  131. return json(['code' => $code, 'data' => [], 'msg' => $msg]);
  132. }//end try
  133. }//end historyInfo()
  134. /**
  135. * 获取用户会话历史详细
  136. *
  137. * @access public
  138. * @return array JsonString
  139. */
  140. public function userHistory()
  141. {
  142. // 验证token.
  143. $tokenStatus = $this->verifyToken();
  144. $code = -2;
  145. $msg = '错误';
  146. if ($tokenStatus === false) {
  147. $msg = 'token错误';
  148. return json(['code' => $code, 'data' => [], 'msg' => $msg]);
  149. }
  150. try {
  151. // 获取用户ID.
  152. $accountId = input('get.account_id');
  153. $chatLogField = ['*'];
  154. // 关联信息.
  155. $chatLogWhere['from_id'] = $accountId;
  156. $chatLogWhereOr['to_id'] = $accountId;
  157. // 分页.
  158. $currentPage = input('get.currentPage', '1');
  159. $pageSize = input('get.pageSize', '10');
  160. $offset = (($currentPage - 1) * $pageSize);
  161. // 获取用户信息.
  162. $chatLog = model('ChatLog')->userChatLog(
  163. $chatLogField,
  164. $chatLogWhere,
  165. $chatLogWhereOr,
  166. $offset,
  167. $pageSize
  168. );
  169. $countChatLog = model('ChatLog')->userChatLogCount($chatLogWhere, $chatLogWhereOr);
  170. $result['total'] = $countChatLog;
  171. $result['countPage'] = (ceil(($result['total']) / $pageSize));
  172. $result['currentPage'] = $currentPage;
  173. $result['list'] = $chatLog;
  174. $result['pageSize'] = $pageSize;
  175. return json(['code' => 1, 'data' => $result, 'msg' => '成功']);
  176. } catch (\Exception $e) {
  177. return json(['code' => $code, 'data' => [], 'msg' => $msg]);
  178. }//end try
  179. }//end userHistory()
  180. }