KfjkLogic.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/7/6
  6. * Time: 16:59
  7. */
  8. namespace App\common;
  9. use app\admin\model\Kfonline;
  10. use app\admin\model\Users;
  11. use think\Db;
  12. /**
  13. * [
  14. * 用户名:
  15. * 会话量:今日客服累计的的会话量 hyl
  16. * 接待量:当前客服正在接待的会话数 jdl
  17. * 平均会话时长:今日客服的平均会话时长,即访客进入到会话结束时时间间隔的平均值 pjhusc
  18. * 参评率:今日客服的累计参评率,即参加评价的数量和接入会话数量的比值 cpl
  19. * 满意度率:今日客服的累计满意度率,即满意的数量和评价会话数量的比值 mydl
  20. * 平均响应时长:今日客服的平均响应时长,即访客访问和客服回复时间间隔的平均值。 pjxysc
  21. * 今日休息时长:今日客服的休息时长的累计值 jrxxsc
  22. * ]
  23. */
  24. class KfjkLogic
  25. {
  26. public function getAllData($kfuidarray)
  27. {
  28. if (empty($kfuidarray)) {
  29. return false;
  30. }
  31. $todayall = $this->getTodayServiceData($kfuidarray);
  32. if (!$todayall) {
  33. return false;
  34. }
  35. $kfuidarray_index = kftoKey($kfuidarray, 1);
  36. $uids = $kfuidarray;
  37. $hyl = $this->hyl($kfuidarray, $todayall);
  38. $jdl = $this->jdl($kfuidarray, $todayall);
  39. $pjhysc = $this->pjhusc($kfuidarray, $todayall);
  40. $cpl = $this->cpl($kfuidarray, $todayall);
  41. foreach ($kfuidarray_index as $uid => $val) {
  42. $kfuidarray_index[$uid]['uid'] = $uids[$uid];
  43. $kfuidarray_index[$uid]['hhl'] = $hyl[$uid];
  44. $kfuidarray_index[$uid]['jdl'] = $jdl[$uid];
  45. $kfuidarray_index[$uid]['pjhysc'] = $pjhysc[$uid];
  46. $kfuidarray_index[$uid]['cpl'] = $cpl[$uid];
  47. }
  48. $last = [];
  49. foreach ($kfuidarray_index as $val) {
  50. $last[] = $val;
  51. }
  52. return $last;
  53. }
  54. //按条件获取用户数组 组ID, 在线状态 0为全部
  55. public function getValiKF($groupid, $onlinestatus)
  56. {
  57. $groupusers = (new Users)->getByGroup($groupid);
  58. $groupuserArray = [];
  59. if ($groupusers) {
  60. foreach ($groupusers as $val) {
  61. $groupuserArray[$val['id']] = $val['id'];
  62. }
  63. }
  64. $statusArr = (new Kfonline())->getOnlineAll($onlinestatus);
  65. $return = array_intersect($groupuserArray, $statusArr);
  66. return $return;
  67. }
  68. //会话量 统计
  69. public function hyl($uidArray, $alllogs)
  70. {
  71. $rets = kftoKey($uidArray);
  72. foreach ($rets as $uid => $aaaa) {
  73. foreach ($alllogs as $log) {
  74. if ($uid == $log['kf_id'] && $log['status'] == 2) {
  75. $rets[$uid]++;
  76. }
  77. }
  78. }
  79. return $rets;
  80. }
  81. //接待量 统计
  82. public function jdl($uidArray, $alllogs)
  83. {
  84. $rets = kftoKey($uidArray);
  85. foreach ($rets as $uid => $aaa) {
  86. foreach ($alllogs as $log) {
  87. if ($uid == $log['kf_id']) {
  88. $rets[$uid]++;
  89. }
  90. }
  91. }
  92. return $rets;
  93. }
  94. //平均会话时长 统计
  95. public function pjhusc($uidArray, $alllogs)
  96. {
  97. $rets = kftoKey($uidArray, 1);
  98. foreach ($rets as $uid => $aaa) {
  99. foreach ($alllogs as $log) {
  100. //if ($uid == $log['kf_id'] && $log['status'] == 2) {
  101. if ($uid == $log['kf_id']) {
  102. (!isset($rets[$uid]['count'])) ? ($rets[$uid]['count'] = 1) : $rets[$uid]['count']++;
  103. (!isset($rets[$uid]['times'])) ? ($rets[$uid]['times'] = 0) : ($log['end_time'] - $log['start_time']);
  104. }
  105. }
  106. }
  107. $return = [];
  108. foreach ($rets as $uid => $val) {
  109. if (isset($rets[$uid]['count'])) {
  110. $return[$uid] = $rets[$uid]['times'] / $rets[$uid]['count'];
  111. } else {
  112. $return[$uid] = 0;
  113. }
  114. }
  115. return $return;
  116. }
  117. //参评率
  118. public function cpl($uidArray, $alllogs)
  119. {
  120. $rets = kftoKey($uidArray, 1);
  121. foreach ($rets as $uid => $aaa) {
  122. foreach ($alllogs as $log) {
  123. if ($uid == $log['kf_id']) {
  124. !(isset($rets[$uid]['count'])) ? 1 : $rets[$uid]['count']++;
  125. isset($rets[$uid]['pl']) ? ($rets[$uid]['pl'] = ($log['evaluate_id'] > 0 ? 1 : 0)) : 0;
  126. }
  127. }
  128. }
  129. $return = [];
  130. foreach ($rets as $uid => $val) {
  131. if (isset($rets[$uid]['count'])) {
  132. $return[$uid] = $return[$uid]['pl'] / $return[$uid]['cocountunt'];
  133. } else {
  134. $return[$uid] = 0;
  135. }
  136. }
  137. return $return;
  138. }
  139. public function mydl($kfuid)
  140. {
  141. }
  142. public function pjxysc($kfuid)
  143. {
  144. }
  145. public function jrxxsc($kfuid)
  146. {
  147. }
  148. public function getTodayServiceData($kfuidArray = [])
  149. {
  150. $today_begin = strtotime(date("Y-m-d"));
  151. $today_end = $today_begin + 86400;
  152. $filds = "group_id,kf_id,user_id,status,start_time,intime,end_time,evaluate_id";
  153. if ($kfuidArray) {
  154. $ret = Db::name('service_log')->field($filds)->where(['start_time' => ['>=', $today_begin], 'kf_id' => ['IN', $kfuidArray]])->where(['start_time' => ['<', $today_end]])->select();
  155. } else {
  156. $ret = Db::name('service_log')->field($filds)->where(['start_time' => ['>=', $today_begin]])->where(['start_time' => ['<', $today_end]])->select();
  157. }
  158. return $ret;
  159. }
  160. }