History.php 6.5 KB

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