History.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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('get.currentPage', '1');
  46. $pageSize = input('get.pageSize', '10');
  47. $offset = (($currentPage - 1) * $pageSize);
  48. // 获取用户信息.
  49. $serviceLog = model('ServiceLog')->selectServiceLog(
  50. $serviceLogField,
  51. $offset,
  52. $pageSize,
  53. $serviceLogWhere,
  54. $serviceLogJoin
  55. );
  56. $countServiceLog = model('ServiceLog')->countServiceLog($serviceLogWhere);
  57. $evaluate = model('Evaluate')->getEvaluate();
  58. foreach ($serviceLog as $k => $v) {
  59. foreach ($evaluate as $va) {
  60. if ($v->evaluate_id === $va->evaluate_id) {
  61. $serviceLog[$k]->evaluate_name = $va->evaluate_name;
  62. }
  63. }
  64. }
  65. $result['total'] = $countServiceLog;
  66. $result['countPage'] = (ceil(($result['total']) / $pageSize));
  67. $result['currentPage'] = $currentPage;
  68. $result['list'] = $serviceLog;
  69. $result['pageSize'] = $pageSize;
  70. return json(['code' => 200, 'data' => $result, 'msg' => '成功']);
  71. } catch (\Exception $e) {
  72. return json(['code' => $code, 'data' => [], 'msg' => $msg]);
  73. }//end try
  74. }//end historyList()
  75. /**
  76. * 获取会话历史详细
  77. *
  78. * @access public
  79. * @return array JsonString
  80. */
  81. public function historyInfo()
  82. {
  83. // 验证token.
  84. $tokenStatus = $this->verifyToken();
  85. $code = -2;
  86. $msg = '错误';
  87. if ($tokenStatus === false) {
  88. return json(['code' => $code, 'data' => [], 'msg' => $msg]);
  89. }
  90. try {
  91. // 获取用户信息.
  92. $servicelogId = input('get.servicelog_id');
  93. $chatLogField = ['*'];
  94. // 关联信息.
  95. $chatLogWhere['servicelog_id'] = $servicelogId;
  96. // 分页.
  97. $currentPage = input('get.currentPage', '1');
  98. $pageSize = input('get.pageSize', '10');
  99. $offset = (($currentPage - 1) * $pageSize);
  100. // 获取用户信息.
  101. $chatLog = model('ChatLog')->selectChatLog($chatLogField, $offset, $pageSize, $chatLogWhere);
  102. $countChatLog = model('ChatLog')->countChatLog($chatLogWhere);
  103. $result['total'] = $countChatLog;
  104. $result['countPage'] = (ceil(($result['total']) / $pageSize));
  105. $result['currentPage'] = $currentPage;
  106. $result['list'] = $chatLog;
  107. $result['pageSize'] = $pageSize;
  108. return json(['code' => 200, 'data' => $result, 'msg' => '成功']);
  109. } catch (\Exception $e) {
  110. return json(['code' => $code, 'data' => [], 'msg' => $msg]);
  111. }//end try
  112. }//end historyInfo()
  113. /**
  114. * 获取用户会话历史详细
  115. *
  116. * @access public
  117. * @return array JsonString
  118. */
  119. public function userHistory()
  120. {
  121. // 验证token.
  122. $tokenStatus = $this->verifyToken();
  123. $code = -2;
  124. $msg = '错误';
  125. if ($tokenStatus === false) {
  126. return json(['code' => $code, 'data' => [], 'msg' => $msg]);
  127. }
  128. try {
  129. // 获取用户ID.
  130. $accountId = input('get.account_id');
  131. $chatLogField = ['*'];
  132. // 关联信息.
  133. $chatLogWhere['from_id'] = $accountId;
  134. $chatLogWhereOr['to_id'] = $accountId;
  135. // 分页.
  136. $currentPage = input('get.currentPage', '1');
  137. $pageSize = input('get.pageSize', '10');
  138. $offset = (($currentPage - 1) * $pageSize);
  139. // 获取用户信息.
  140. $chatLog = model('ChatLog')->userChatLog(
  141. $chatLogField,
  142. $chatLogWhere,
  143. $chatLogWhereOr,
  144. $offset,
  145. $pageSize
  146. );
  147. $countChatLog = model('ChatLog')->userChatLogCount($chatLogWhere, $chatLogWhereOr);
  148. $result['total'] = $countChatLog;
  149. $result['countPage'] = (ceil(($result['total']) / $pageSize));
  150. $result['currentPage'] = $currentPage;
  151. $result['list'] = $chatLog;
  152. $result['pageSize'] = $pageSize;
  153. return json(['code' => 200, 'data' => $result, 'msg' => '成功']);
  154. } catch (\Exception $e) {
  155. return json(['code' => $code, 'data' => [], 'msg' => $msg]);
  156. }//end try
  157. }//end userHistory()
  158. }