|
|
@@ -41,8 +41,8 @@ class Events
|
|
|
public static function onWorkerStart($worker)
|
|
|
{
|
|
|
if (empty(self::$db)) {
|
|
|
- //self::$db = new \Workerman\MySQL\Connection('192.168.2.168', '3306', 'vali', '123456', 'customer_service');
|
|
|
- self::$db = new \Workerman\MySQL\Connection('192.168.2.200', '3306', 'vali', '1234', 'customer_service');
|
|
|
+ self::$db = new \Workerman\MySQL\Connection('192.168.2.168', '3306', 'vali', '123456', 'customer_service');
|
|
|
+ //self::$db = new \Workerman\MySQL\Connection('192.168.2.200', '3306', 'vali', '1234', 'customer_service');
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -102,7 +102,7 @@ class Events
|
|
|
//初始化.....
|
|
|
self::upsystemconfig();
|
|
|
//每5分钟更新一次系统配置文件
|
|
|
- Timer::add(60 * 10, function () {
|
|
|
+ Timer::add(60 * 3, function () {
|
|
|
self::upsystemconfig();
|
|
|
});
|
|
|
|
|
|
@@ -118,6 +118,8 @@ class Events
|
|
|
self::systemMonitoring($adminList);
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ self::resetServiceLog();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -206,8 +208,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, $_SESSION['remotip'] . '.' . $_SESSION['remotport']]);
|
|
|
+ self::DebugOut($message, "OnMessage");
|
|
|
+ self::DebugOut([self::$global->kfList, self::$global->userList, self::$global->uidSimpleList, self::$global->userToKf, $_SESSION['remotip'] . ':' . $_SESSION['remotport']], 'Msg mem: ');
|
|
|
}
|
|
|
$message = json_decode($message, true);
|
|
|
if (isset($message['type'])) {
|
|
|
@@ -470,7 +472,6 @@ class Events
|
|
|
$kfs = self::$global->kfList;
|
|
|
$groupnamemap = self::$global->groupmap;
|
|
|
|
|
|
-
|
|
|
if (!$kfs || empty($groupnamemap)) {
|
|
|
return $return;
|
|
|
}
|
|
|
@@ -479,7 +480,7 @@ class Events
|
|
|
|
|
|
foreach ($kfs as $gruop => $users) {
|
|
|
foreach ($users as $uid => $uinfo) {
|
|
|
- if ($uid != $nowkfid && $fromgrouupid == $gruop && $uinfo['status'] == 1) {
|
|
|
+ if ($uid != $nowkfid && $uinfo['status'] == 1) {
|
|
|
$ret[] = ['groupid' => $gruop, 'groupname' => $groupnamemap[$gruop], 'kfuid' => $uid, 'kfname' => $uinfo['name'], 'kfjobname' => $uinfo['job_name']];
|
|
|
}
|
|
|
}
|
|
|
@@ -494,16 +495,19 @@ class Events
|
|
|
{
|
|
|
$message = $smessage['data'];
|
|
|
|
|
|
- $groupid = isset($message['group']) ? intval($message['group']) : 0;
|
|
|
+ $groupid = isset($message['fromgroup']) ? intval($message['fromgroup']) : 0;
|
|
|
+ $groupidto = isset($message['togroup']) ? intval($message['togroup']) : 0;
|
|
|
$toukfid = isset($message['toukfuid']) ? $message['toukfuid'] : 0;
|
|
|
$fromkfuid = isset($message['fromkfuid']) ? $message['fromkfuid'] : 0;
|
|
|
$uid = isset($message['uid']) ? $message['uid'] : 0;
|
|
|
$word = isset($message['word']) ? $message['word'] : '';
|
|
|
|
|
|
- if (empty($groupid) || empty($toukfid) || empty($fromkfuid) || empty($uid) || empty($word) || ($toukfid == $fromkfuid)) {
|
|
|
+ if (empty($groupid) || empty($groupidto) || empty($toukfid) || empty($fromkfuid) || empty($uid) || ($toukfid == $fromkfuid)) {
|
|
|
+ self::DebugOut('changeOtherhKeFu exit1...');
|
|
|
return false;
|
|
|
}
|
|
|
if (!Gateway::isUidOnline($toukfid) || !Gateway::isUidOnline($uid)) {
|
|
|
+ self::DebugOut('changeOtherhKeFu exit2...');
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -516,10 +520,12 @@ class Events
|
|
|
$kfList = $kfList_new = self::$global->kfList;
|
|
|
$userToKf = $userToKf_new = self::$global->userToKf;
|
|
|
|
|
|
- if (!isset($kfList[$groupid]) || !isset($kfList[$groupid][$toukfid]) || !isset($kfList[$groupid][$fromkfuid])) {
|
|
|
+ if (!isset($kfList[$groupidto]) || !isset($kfList[$groupidto][$toukfid]) || !isset($kfList[$groupidto][$fromkfuid])) {
|
|
|
+ self::DebugOut('changeOtherhKeFu exit3...');
|
|
|
return false;
|
|
|
}
|
|
|
- if ($kfList[$groupid][$toukfid]['status'] != 1) {
|
|
|
+ if ($kfList[$groupidto][$toukfid]['status'] != 1) {
|
|
|
+ self::DebugOut('changeOtherhKeFu exit4...');
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -533,12 +539,14 @@ class Events
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ }
|
|
|
+ foreach ($kfList[$groupidto] as $key => $val) {
|
|
|
if ($key == $toukfid) {
|
|
|
- $kfList_new[$groupid][$toukfid]['task']++;
|
|
|
- array_push($kfList_new[$groupid][$key]['user_info'], $uidclientid);
|
|
|
+ $kfList_new[$groupidto][$toukfid]['task']++;
|
|
|
+ array_push($kfList_new[$groupidto][$key]['user_info'], $uidclientid);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
do {
|
|
|
} while (!self::$global->cas('kfList', $kfList, $kfList_new));
|
|
|
|
|
|
@@ -550,9 +558,12 @@ class Events
|
|
|
|
|
|
/////////取消原有会话,开启新会话
|
|
|
$histarttimelimit = time() - 3600 * 24;
|
|
|
- $bindval = ['user_id' => $uid, 'client_id' => $uidclientid, 'kf_id' => intval(trim($fromkfuid, '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();
|
|
|
+ //$bindval = ['user_id' => $uid, 'client_id' => $uidclientid, 'kf_id' => intval(trim($fromkfuid, 'KF')), 'histime' => $histarttimelimit];
|
|
|
+ $bindval = ['user_id' => $uid, 'kf_id' => intval(trim($fromkfuid, 'KF')), 'histime' => $histarttimelimit];
|
|
|
+ echo '$bindval ' . print_r($bindval, true), "\n";
|
|
|
+ $oldlog = self::$db->select('*')->from('ws_service_log')->where('user_id= :user_id and kf_id=:kf_id and status!=2 and start_time>=:histime ')->bindValues($bindval)->orderByDESC(['servicelog_id'])->row();
|
|
|
if (!$oldlog) {
|
|
|
+ self::DebugOut('changeOtherhKeFu exit5...');
|
|
|
return false;
|
|
|
}
|
|
|
self::$db->update('ws_service_log')->cols(['status' => 2, 'end_time' => time()])->where('servicelog_id=' . $oldlog['servicelog_id'])->query();
|
|
|
@@ -573,6 +584,7 @@ class Events
|
|
|
$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) {
|
|
|
+ self::DebugOut('changeOtherhKeFu exit6...');
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -594,7 +606,7 @@ class Events
|
|
|
$noticeKf = [
|
|
|
'message_type' => 'connect',
|
|
|
'data' => [
|
|
|
- 'user_info' => $uid,
|
|
|
+ 'user_info' => self::getClientIndo($uid),
|
|
|
'conversationId' => $new_id,
|
|
|
]
|
|
|
];
|
|
|
@@ -607,9 +619,18 @@ class Events
|
|
|
//回转接人,转接成功
|
|
|
Gateway::sendToCurrentClient(json_encode(['message_type' => 'trunconnect', 'data' => ['status' => 1]], 256));
|
|
|
|
|
|
+ self::DebugOut('changekf 转换成功!');
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ //获取某个用户全部信息
|
|
|
+ public static function getClientIndo($id)
|
|
|
+ {
|
|
|
+ $ret = self::$db->from('ws_accounts')->select("*")->where(['id' => $id])->row();
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
+
|
|
|
//客服接入sock,及初始化
|
|
|
public static function Kfinit($client_id, $message)
|
|
|
{
|
|
|
@@ -808,7 +829,7 @@ class Events
|
|
|
$isKefuoff = isset($_SESSION['iskefu']) ? $_SESSION['iskefu'] : 0;
|
|
|
$uid = isset($_SESSION['uid']) ? $_SESSION['uid'] : false;
|
|
|
|
|
|
- //echo "下线:uid: $uid - cid: $client_id - iskf: $isKefuoff \n";
|
|
|
+ echo "下线:uid: $uid - cid: $client_id - iskf: $isKefuoff \n";
|
|
|
|
|
|
$adminList = self::$global->adminList ?? [];
|
|
|
$key = array_search($client_id, $adminList);
|
|
|
@@ -1937,7 +1958,7 @@ class Events
|
|
|
$serviceLog[$k]['allCount'] = $allCount;
|
|
|
}
|
|
|
|
|
|
- print_r([$serviceLog, $csdTime, $verifyReturnTime]);
|
|
|
+ self::DebugOut([$serviceLog, $csdTime, $verifyReturnTime], 'systemMonitoring');
|
|
|
|
|
|
// 查询对话时效设置.
|
|
|
foreach ($adminList as $v) {
|
|
|
@@ -1977,6 +1998,20 @@ class Events
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public static function resetServiceLog()
|
|
|
+ {
|
|
|
+ $t = time() - 24 * 3600;
|
|
|
+ self::$db->query("update ws_service_log set status=2 where start_time>=$t and status!=2");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function onWorkerStop($businessWorker)
|
|
|
+ {
|
|
|
+ if ($businessWorker->worker_id == 1) {
|
|
|
+ self::resetServiceLog();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//用户下线通知
|
|
|
private static function userCloseNotice($client_id, $cuid, $group)
|
|
|
{
|
|
|
@@ -1990,5 +2025,18 @@ class Events
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private static function DebugOut($msg, $title = '', $type = 'info')
|
|
|
+ {
|
|
|
+ $config = self::$global->systemconfig;
|
|
|
+ if (!isset($config['isdebug']) || empty($config['isdebug']['systemconfig_data'])) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!is_string($msg)) {
|
|
|
+ $msg = json_encode([$msg], 256);
|
|
|
+ }
|
|
|
+ $msg = date("Y-m-d H:i:s") . ' - ' . $type . ' - ' . $title . ' - ' . $msg . "\n";
|
|
|
+ echo $msg;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|