123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- /**
- * Class SessionController
- * @author Blackbinbin
- */
- class SessionController extends BaseController {
- protected $ajaxLoginActions = [
- 'list',
- 'personMsg',
- 'sendMsg',
- 'mute',
- 'unMute',
- 'pin',
- 'unPin',
- ];
- public function __construct() {
- parent::__construct(true);
- }
- /**
- * 返回会话列表
- * @author benzhan
- */
- public function actionList($args) {
- $rules = [
- // 'update_time_int' => ['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',
- '_sort' => 'pin_time_int DESC, update_time_int DESC',
- '_limit' => 500, // 最多加载500个会话
- ];
- $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());
- }
- }
- // /**
- // * 设置已读
- // * @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);
- $this->_updateState($args['session_id'], ['is_pin' => 1]);
- }
- /**
- * 取消置顶
- * @author benzhan
- */
- public function actionUnPin($args) {
- $rules = [
- 'session_id' => ['string', 'desc' => '会话id'],
- ];
- Param::checkParam2($rules, $args);
- $this->_updateState($args['session_id'], ['is_pin' => 0]);
- }
- /**
- * 删除会话
- * @author benzhan
- */
- public function actionDelete($args) {
- $rules = [
- 'session_id' => ['string', 'desc' => '会话id'],
- ];
- Param::checkParam2($rules, $args);
- // $this->_updateState($args['session_id'], ['is_delete' => 1]);
- }
- //
- // /**
- // * 文件上传
- // * @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');
- // }
- }
|