|
|
@@ -89,6 +89,12 @@ class Events
|
|
|
self::writeLog(2);
|
|
|
});
|
|
|
|
|
|
+ //每60分钟发一次本组排队数
|
|
|
+ Timer::add(60 * 1, function () {
|
|
|
+ self::lineup();
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -110,29 +116,29 @@ class Events
|
|
|
$whereOr = '1=0';
|
|
|
foreach ($serviceLog as $k => $v) {
|
|
|
if ($k == 0) {
|
|
|
- $whereOr = "`servicelog_id`=".$v['servicelog_id'];
|
|
|
+ $whereOr = "`servicelog_id`=" . $v['servicelog_id'];
|
|
|
} else {
|
|
|
- $whereOr .= " OR `servicelog_id`=".$v['servicelog_id'];
|
|
|
+ $whereOr .= " OR `servicelog_id`=" . $v['servicelog_id'];
|
|
|
}
|
|
|
}
|
|
|
// 查询最后一次会话.
|
|
|
//$chatLog = self::$db->query("SELECT `servicelog_id`,MAX(`time_line`) FROM `ws_chat_log` WHERE ".$whereOr." group by `servicelog_id`");
|
|
|
$chatLog = self::$db->query("
|
|
|
select * from ws_chat_log as a where time_line=(
|
|
|
- select max(b.time_line) from ws_chat_log as b where a.servicelog_id = b.servicelog_id and (".$whereOr.") group by servicelog_id
|
|
|
+ select max(b.time_line) from ws_chat_log as b where a.servicelog_id = b.servicelog_id and (" . $whereOr . ") group by servicelog_id
|
|
|
)
|
|
|
");
|
|
|
- $setOvertime = strtotime('-'.(self::$global->overtime['systemconfig_data']-60).' second');
|
|
|
- $overtime = strtotime('-'.(self::$global->overtime['systemconfig_data']).' second');
|
|
|
- $setUnoperated = strtotime('-'.(self::$global->unoperated['systemconfig_data']-60).' second');
|
|
|
- $unoperated = strtotime('-'.(self::$global->unoperated['systemconfig_data']).' second');
|
|
|
- $noResponse = strtotime('-'.(self::$global->noResponse['systemconfig_data']).' second');
|
|
|
+ $setOvertime = strtotime('-' . (self::$global->overtime['systemconfig_data'] - 60) . ' second');
|
|
|
+ $overtime = strtotime('-' . (self::$global->overtime['systemconfig_data']) . ' second');
|
|
|
+ $setUnoperated = strtotime('-' . (self::$global->unoperated['systemconfig_data'] - 60) . ' second');
|
|
|
+ $unoperated = strtotime('-' . (self::$global->unoperated['systemconfig_data']) . ' second');
|
|
|
+ $noResponse = strtotime('-' . (self::$global->noResponse['systemconfig_data']) . ' second');
|
|
|
foreach ($serviceLog as $k => $v) {//注意该循环时间
|
|
|
if (!strlen(array_search($v['servicelog_id'], array_column($chatLog, 'servicelog_id')))) {
|
|
|
// 如果小于设定时间则关闭会话.
|
|
|
if ($v['start_time'] <= $unoperated) {
|
|
|
self::serverClose($v['client_id']);
|
|
|
- // 如果小于设定时间前一分钟则给出提示.
|
|
|
+ // 如果小于设定时间前一分钟则给出提示.
|
|
|
} elseif ($v['start_time'] <= $setUnoperated) {
|
|
|
$chat_message = [
|
|
|
'message_type' => 'overtime',
|
|
|
@@ -146,12 +152,12 @@ class Events
|
|
|
}
|
|
|
// 循环检测会话时效.
|
|
|
foreach ($chatLog as $k => $v) {
|
|
|
- $toWho = substr($v['to_id'],0,2);
|
|
|
+ $toWho = substr($v['to_id'], 0, 2);
|
|
|
// 如果对话为客服的最后一次对话且时间小于设定时间则结束工单.
|
|
|
if ($toWho != 'KF' && $v['time_line'] <= $overtime) {
|
|
|
$found_key = array_search($v['servicelog_id'], array_column($serviceLog, 'servicelog_id'));
|
|
|
self::serverClose($serviceLog[$found_key]['client_id']);
|
|
|
- // 如果对话为客服的最后一次对话且时间小于设定时间前一分钟则给出提示.
|
|
|
+ // 如果对话为客服的最后一次对话且时间小于设定时间前一分钟则给出提示.
|
|
|
} elseif ($toWho != 'KF' && $v['time_line'] <= $setOvertime) {
|
|
|
$chat_message = [
|
|
|
'message_type' => 'overtime',
|
|
|
@@ -166,6 +172,41 @@ class Events
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 每分钟定时向客服发送一次排队情况
|
|
|
+ */
|
|
|
+
|
|
|
+ public static function lineup()
|
|
|
+ {
|
|
|
+ $userlist = self::$global->userList;
|
|
|
+ $kflist = self::$global->kfList;
|
|
|
+
|
|
|
+ if (empty($userlist) || empty($kflist)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $return = [];
|
|
|
+ foreach ($userlist as $val) {
|
|
|
+ $return[$val['group']] = isset($return[$val['group']]) ? $return[$val['group']] + 1 : 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ $krgroupclientid = [];
|
|
|
+ foreach ($kflist as $gid => $sval) {
|
|
|
+ foreach ($sval as $tval) {
|
|
|
+ $krgroupclientid[$gid][] = $tval['client_id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($return as $fgroup => $fval) {
|
|
|
+ foreach ($krgroupclientid as $sikey => $sival) {
|
|
|
+ if ($fgroup == $sikey) {
|
|
|
+ Gateway::sendToClient($sival, json_encode(['type' => 'lineupCount', $fval], 256));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 当客户端连接时触发
|
|
|
@@ -204,8 +245,8 @@ class Events
|
|
|
Gateway::sendToCurrentClient('{"type":"pong"}');
|
|
|
return;
|
|
|
} else {
|
|
|
- /*echo "onMessage: " . $message . "\r\n";
|
|
|
- print_r([self::$global->kfList, self::$global->userList, self::$global->uidSimpleList, self::$global->userToKf]);*/
|
|
|
+ echo "onMessage: " . $message . "\r\n";
|
|
|
+ print_r([self::$global->kfList, self::$global->userList, self::$global->uidSimpleList, self::$global->userToKf]);
|
|
|
}
|
|
|
|
|
|
$message = json_decode($message, true);
|
|
|
@@ -386,7 +427,7 @@ class Events
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- $tokfidclientid = Gateway::getClientIdByUid($toukfid);
|
|
|
+ $tokfidclientid = Gateway::getClientIdByUid($toukfid);
|
|
|
$tokfidclientid = $tokfidclientid['0'];
|
|
|
$uidclientid = Gateway::getClientIdByUid($uid);
|
|
|
$uidclientid = $uidclientid['0'];
|
|
|
@@ -423,15 +464,17 @@ class Events
|
|
|
|
|
|
|
|
|
/////////取消原有会话,开启新会话
|
|
|
- $histarttimelimit = time() - 3600*24 ;
|
|
|
- $bindval = ['user_id'=>$uid,'kf_id'=>intval(trim($toukfid,'KF')),'histime'=>$histarttimelimit] ;
|
|
|
- $oldlog = self::$db->select('*')->from('ws_service_log')->where('user_id= :user_id and client_id=:client_id and kf_id=:kf_id and status=2 and start_time>=:histime ' )->bindValues($bindval)->row();
|
|
|
- if (!$oldlog){ return false; }
|
|
|
- self::$db->update('ws_service_log')->cols(['status'=>2,'endtime'=>time()])->where('servicelog_id='.$oldlog['servicelog_id'])->query();
|
|
|
+ $histarttimelimit = time() - 3600 * 24;
|
|
|
+ $bindval = ['user_id' => $uid, 'kf_id' => intval(trim($toukfid, 'KF')), 'histime' => $histarttimelimit];
|
|
|
+ $oldlog = self::$db->select('*')->from('ws_service_log')->where('user_id= :user_id and client_id=:client_id and kf_id=:kf_id and status=2 and start_time>=:histime ')->bindValues($bindval)->row();
|
|
|
+ if (!$oldlog) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ self::$db->update('ws_service_log')->cols(['status' => 2, 'endtime' => time()])->where('servicelog_id=' . $oldlog['servicelog_id'])->query();
|
|
|
unset($oldlog['servicelog_id']);
|
|
|
- $oldlog = array_merge($oldlog,['kf_id'=>intval(trim($toukfid,'KF')),'start_time'=>time(),'end_time'=>0,'status'=>1,'evaluate_id'=>0]);
|
|
|
+ $oldlog = array_merge($oldlog, ['kf_id' => intval(trim($toukfid, 'KF')), 'start_time' => time(), 'end_time' => 0, 'status' => 1, 'evaluate_id' => 0]);
|
|
|
$new_id = self::$db->insert('ws_service_log')->cols($oldlog)->query();
|
|
|
- if (!$new_id){
|
|
|
+ if (!$new_id) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -457,9 +500,9 @@ class Events
|
|
|
Gateway::sendToClient($tokfidclientid, json_encode($noticeKf, 256));
|
|
|
unset($noticeKf);
|
|
|
//回转接人,转接成功
|
|
|
- Gateway::sendToCurrentClient(json_encode(['message_type'=>'trunconnect','data'=>['status'=>1],256]));
|
|
|
+ Gateway::sendToCurrentClient(json_encode(['message_type' => 'trunconnect', 'data' => ['status' => 1], 256]));
|
|
|
|
|
|
- return ;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
//客服接入sock,及初始化
|