['int', 'nullable' => true, 'desc' => '最后更新时间'] 'current_group_id' => ['int', 'nullable' => true, 'desc' => '当前群id'], ]; Param::checkParam2($rules, $args); $user_id = User::getUserId(); // $update_time_int = (int) $args['update_time_int']; $where = compact('user_id'); $keyWord = [ '_field' => 'session_id, is_group, read_hash, is_pin, pin_time_int, is_mute, read_num', // '_sortKey' => 'pin_time_int DESC, update_time_int DESC', '_limit' => 500, // 最多加载500个会话 // '_debug' => 1 ]; $objSession = new Session(); // if ($update_time_int) { // // 只加载新更新的 // $keyWord['_where'] = "update_time_int > {$update_time_int}"; // } $currentGroupId = intval($args['current_group_id']); $currentGroupId && $where['is_group'] = 0; // 群拉人列表过滤群session $list = $objSession->objTable->getAll($where, $keyWord); $list = $objSession->fillSession($user_id, $list, $currentGroupId); return $list; } private function _updateState($session_id, $newData) { $user_id = User::getUserId(); $objSession = new Session(); try { // 私聊 if ($session_id != intval($session_id)) { $objSession->checkPersonSession($user_id, $session_id); } else { $objSession->checkGroupSession($user_id, $session_id); } $newData['update_time_int'] = microtime(true) * 1000; $objSession->updateState($session_id, $newData, compact('user_id')); } catch (Exception $ex) { Response::error($ex->getCode(), $ex->getMessage()); } } private function _delete($session_id) { $user_id = User::getUserId(); $objSession = new Session(); try { // 私聊 if ($session_id != intval($session_id)) { $objSession->checkPersonSession($user_id, $session_id); } else { $objSession->checkGroupSession($user_id, $session_id); } $objSession->objTable->delObject(compact('user_id', 'session_id')); } catch (Exception $ex) { // Response::error($ex->getCode(), $ex->getMessage()); } } // /** // * 设置已读 // * @author benzhan // */ // public function actionSetRead($args) { // $rules = [ // 'session_id' => ['string', 'desc' => '会话id'], // 'hash' => ['string', 'desc' => '消息Hash值'], // ]; // Param::checkParam2($rules, $args); // // $this->_updateState($args['session_id'], ['read_hash' => $args['hash']]); // } /** * 静音 * @author benzhan */ public function actionMute($args) { $rules = [ 'session_id' => ['string', 'desc' => '会话id'], ]; Param::checkParam2($rules, $args); $this->_updateState($args['session_id'], ['is_mute' => 1]); } /** * 取消静音 * @author benzhan */ public function actionUnMute($args) { $rules = [ 'session_id' => ['string', 'desc' => '会话id'], ]; Param::checkParam2($rules, $args); $this->_updateState($args['session_id'], ['is_mute' => 0]); } /** * 置顶 * @author benzhan */ public function actionPin($args) { $rules = [ 'session_id' => ['string', 'desc' => '会话id'], ]; Param::checkParam2($rules, $args); $newData = ['is_pin' => 1, 'pin_time_int' => time()]; $this->_updateState($args['session_id'], $newData); return $newData; } /** * 取消置顶 * @author benzhan */ public function actionUnPin($args) { $rules = [ 'session_id' => ['string', 'desc' => '会话id'], ]; Param::checkParam2($rules, $args); $newData = ['is_pin' => 0, 'pin_time_int' => 0]; $this->_updateState($args['session_id'], $newData); return $newData; } /** * 删除会话 * @author benzhan */ public function actionDelete($args) { $rules = [ 'session_id' => ['string', 'desc' => '会话id'], ]; Param::checkParam2($rules, $args); $this->_delete($args['session_id']); } /** * 迷你版未读数量 * @author solu * @param $args * @return array */ public function actionMiniUnRead($args) { $rules = []; Param::checkParam2($rules, $args); $user_id = User::getUserId(); $objSession = new Session(); $list = $objSession->objTable->getAll(['user_id' => $user_id, 'is_group' => 0], [ '_field' => 'session_id, read_num', ]); $objRedis = dwRedis::init(Eos::REDIS_SERV); $toUserIds = []; foreach ($list as $v) { $toUserIds[] = Session::getToUser($user_id, $v['session_id']); } $groupServers = (new GroupInfo())->getGroupServerFromUserIds($toUserIds); $serverIds = array_keys($groupServers); $unreadMap = []; foreach ($list as $v) { $last = Session::getLastMsgNum($v['session_id'], $objRedis); $unread = max($last - $v['read_num'], 0); $toUser = Session::getToUser($user_id, $v['session_id']); if (in_array($toUser, $serverIds)) { $unreadMap[$groupServers[$toUser]] += $unread; } else { $unreadMap[0] += $unread; } } return $unreadMap; } // // /** // * 文件上传 // * @author solu // * @param $args // * @return array // */ // public function actionUploadFile($args) { // $args = array_merge($args, $_FILES); // $rules = [ // 'res' => ['array', 'desc' => '资源文件'], // ]; // Param::checkParam2($rules, $args); // // $url = ''; // try { // $url = (new FileUrl())->getFileUrl($args['res']['tmp_name'], $args['res']['name'], $args['res']['type']); // } catch (Exception $e) { // Response::error($e->getCode(), $e->getMessage()); // } // // return compact('url'); // } }