foreach ($messageData as $v) { $messageFkData[$v['id']] = $v; } $showArr = array(); $tmpLastId = 0; foreach ($data as $k => $v) { $message = $messageFkData[$v['message_id']]['message']; $time = $messageFkData[$v['message_id']]['time']; $session = $messageFkData[$v['message_id']]['session']; $level = $messageFkData[$v['message_id']]['level']; if ($v['send_user'] == 0) { $send_user = '******'; } elseif ($v['send_user'] == -1) { $send_user = '******'; } else { $sql = "SELECT `username` FROM `" . $userDB->getTableName() . "` WHERE `id` = ?"; $user = $userDB->getRow($sql, array($v['send_user'])); $send_user = $user['username']; } if ($lastId != 0) { echo $message = '{"message":"' . $message . '", "session":"' . $session . '", "time":"' . $time . '","level":"' . $level . '","send_user":"******"}'; } $tmpLastId = $v['id']; } $lastId = $tmpLastId; //$message .= pack("h", '00'); $r = stream_socket_sendto($socket, $message, 0, $peer); } sleep(1); } } while ($pkt !== false);
public function sessionList() { $messageDB = new AlarmMessageModelDB(); $userDB = new AlarmUserModelDB(); $listDB = new AlarmListModelDB(); $whereArr = array(); $whereArr[] = $_GET['session']; $_GET['first_id'] = intval($_GET['first_id']); if (!empty($_GET['first_id'])) { $whereStr = " AND `id` < ?"; $whereArr[] = $_GET['first_id']; } $sql = "SELECT * FROM `" . $messageDB->getTableName() . "` WHERE `session` = ?{$whereStr} ORDER BY `id` DESC LIMIT 10"; $data = $messageDB->getData($sql, $whereArr); if (!empty($data[0]['id'])) { $sql = "SELECT * FROM `" . $listDB->getTableName() . "` WHERE `message_id` = ?"; $list = $listDB->getData($sql, array($data[0]['id'])); $userIdArr = array(); foreach ($list as $v) { $userIdArr[] = $v['user_id']; } $sql = "SELECT * FROM `" . $userDB->getTableName() . "` WHERE `id` IN ?"; $userListArr = $listDB->getData($sql, array($userIdArr)); $userList = ''; foreach ($userListArr as $v) { $userList .= $v['username'] . ","; } $userList = rtrim($userList, ","); } $data = Common::arrayOrderBy($data, 'id', 'ASC'); $showArr = array(); foreach ($data as $k => $v) { $showArr[$k]['id'] = $v['id']; if (preg_match_all("/http(s)?:\\/\\/([\\w-]+\\.)+[\\w-]+(\\/[\\w- .\\/?%&=]*)?/", $v['message'], $match)) { $showArr[$k]['link'] = $match[0][0]; } else { $showArr[$k]['link'] = ""; } $showArr[$k]['message'] = preg_replace("/http(s)?:\\/\\/([\\w-]+\\.)+[\\w-]+(\\/[\\w- .\\/?%&=]*)?/", "", $v['message']); $showArr[$k]['time'] = $v['time']; $showArr[$k]['level'] = $v['level']; if ($v['send_user'] == 0) { $showArr[$k]['send_user'] = '******'; } elseif ($v['send_user'] == -1) { $showArr[$k]['send_user'] = '******'; } else { $sql = "SELECT `username` FROM `" . $userDB->getTableName() . "` WHERE `id` = ?"; $user = $userDB->getRow($sql, array($v['send_user'])); $showArr[$k]['send_user'] = $user['username']; } } if (empty($showArr)) { $showArr[0] = array("id" => "-1", "message" => "暂无更多消息...", "link" => "", "session" => "", "time" => (string) time(), "levele" => 1, "level" => '1', 'send_user' => 'system'); $userList = ""; } Message::showSucc('succ', $showArr, array('user' => $userList)); }