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)); }
$listDB = new AlarmListModelDB(); $messageDB = new AlarmMessageModelDB(); $userDB = new AlarmUserModelDB(); $lastId = 0; while (1) { //$message = pack("h", '01'); $userId = 1; $sql = "SELECT * FROM `" . $listDB->getTableName() . "` WHERE `user_id` = ? AND `id` > ? ORDER BY `id` ASC LIMIT 10"; $data = $listDB->getData($sql, array($userId, $lastId)); if (!empty($data)) { $messageIds = array(); foreach ($data as $key => $val) { $messageIds[$val['message_id']] = $val['message_id']; } $sql = "SELECT * FROM `" . $messageDB->getTableName() . "` WHERE `id` IN ?"; $messageData = $messageDB->getData($sql, array($messageIds)); $messageFkData = array(); 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 = '******';