mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-21 11:18:10 +08:00
369 lines
7.8 KiB
PHP
369 lines
7.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Web\Controllers;
|
|
|
|
use App\Http\Web\Services\Im as ImService;
|
|
use App\Traits\Response as ResponseTrait;
|
|
use Phalcon\Mvc\View;
|
|
|
|
/**
|
|
* @RoutePrefix("/im")
|
|
*/
|
|
class ImController extends LayerController
|
|
{
|
|
|
|
use ResponseTrait;
|
|
|
|
/**
|
|
* @Get("/init", name="web.im.init")
|
|
*/
|
|
public function initAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$data = $service->init();
|
|
|
|
return $this->jsonSuccess(['data' => $data]);
|
|
}
|
|
|
|
/**
|
|
* @Get("/group/users", name="web.im.group_users")
|
|
*/
|
|
public function groupUsersAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$list = $service->getGroupUsers();
|
|
|
|
return $this->jsonSuccess(['data' => ['list' => $list]]);
|
|
}
|
|
|
|
/**
|
|
* @Get("/msgbox", name="web.im.msgbox")
|
|
*/
|
|
public function msgboxAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$pager = $service->getSystemMessages();
|
|
|
|
$this->view->pick('im/msgbox');
|
|
$this->view->setVar('pager', $pager);
|
|
}
|
|
|
|
/**
|
|
* @Get("/chatlog", name="web.im.chatlog")
|
|
*/
|
|
public function chatlogAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$pager = $service->getChatMessages();
|
|
|
|
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
|
|
$this->view->pick('im/chatlog');
|
|
$this->view->setVar('pager', $pager);
|
|
}
|
|
|
|
/**
|
|
* @Get("/msg/friend/unread", name="web.im.unread_friend_msg")
|
|
*/
|
|
public function unreadFriendMessagesAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->pullUnreadFriendMessages();
|
|
|
|
return $this->jsonSuccess();
|
|
}
|
|
|
|
/**
|
|
* @Get("/msg/sys/unread", name="web.im.unread_sys_msg")
|
|
*/
|
|
public function unreadSystemMessagesAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$count = $service->countUnreadSystemMessages();
|
|
|
|
return $this->jsonSuccess(['count' => $count]);
|
|
}
|
|
|
|
/**
|
|
* @Get("/msg/sys", name="web.im.sys_msg")
|
|
*/
|
|
public function systemMessagesAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$pager = $service->getSystemMessages();
|
|
|
|
$pager->items = kg_array_object($pager->items);
|
|
|
|
$this->view->pick('im/sys_messages');
|
|
$this->view->setVar('pager', $pager);
|
|
}
|
|
|
|
/**
|
|
* @Post("/msg/sys/read", name="web.im.read_sys_msg")
|
|
*/
|
|
public function readSystemMessagesAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->readSystemMessages();
|
|
|
|
return $this->jsonSuccess();
|
|
}
|
|
|
|
/**
|
|
* @Get("/friend/status", name="web.im.friend_status")
|
|
*/
|
|
public function friendStatusAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$status = $service->getFriendStatus();
|
|
|
|
return $this->jsonSuccess(['status' => $status]);
|
|
}
|
|
|
|
/**
|
|
* @Get("/chat/history", name="web.im.chat_history")
|
|
*/
|
|
public function chatHistoryAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$pager = $service->getChatMessages();
|
|
|
|
return $this->jsonPaginate($pager);
|
|
}
|
|
|
|
/**
|
|
* @Get("/find", name="web.im.find")
|
|
*/
|
|
public function findAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$userPager = $service->getNewUsers();
|
|
$groupPager = $service->getNewGroups();
|
|
|
|
$userPager->items = kg_array_object($userPager->items);
|
|
$groupPager->items = kg_array_object($groupPager->items);
|
|
|
|
$this->view->setVar('user_pager', $userPager);
|
|
$this->view->setVar('group_pager', $groupPager);
|
|
}
|
|
|
|
/**
|
|
* @Get("/search", name="web.im.search")
|
|
*/
|
|
public function searchAction()
|
|
{
|
|
$type = $this->request->getQuery('type');
|
|
$query = $this->request->getQuery('query');
|
|
$target = $this->request->getQuery('target');
|
|
|
|
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
|
|
|
|
$service = new ImService();
|
|
|
|
if ($type == 'user') {
|
|
$this->view->pick('im/find_users');
|
|
$target = $target ?: 'tab-users';
|
|
$pager = $service->searchUsers($query);
|
|
} else {
|
|
$this->view->pick('im/find_groups');
|
|
$target = $target ?: 'tab-groups';
|
|
$pager = $service->searchGroups($query);
|
|
}
|
|
|
|
$pager->items = kg_array_object($pager->items);
|
|
$pager->target = $target;
|
|
|
|
$this->view->setVar('pager', $pager);
|
|
}
|
|
|
|
/**
|
|
* @Post("/user/bind", name="web.im.bind_user")
|
|
*/
|
|
public function bindUserAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->bindUser();
|
|
|
|
return $this->jsonSuccess();
|
|
}
|
|
|
|
/**
|
|
* @Post("/msg/send", name="web.im.send_msg")
|
|
*/
|
|
public function sendMessageAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->sendMessage();
|
|
|
|
return $this->jsonSuccess();
|
|
}
|
|
|
|
/**
|
|
* @Post("/img/upload", name="web.im.upload_img")
|
|
*/
|
|
public function uploadImageAction()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @Post("/file/upload", name="web.im.upload_file")
|
|
*/
|
|
public function uploadFileAction()
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* @Post("/status/update", name="web.im.update_status")
|
|
*/
|
|
public function updateStatusAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->updateStatus();
|
|
|
|
return $this->jsonSuccess();
|
|
}
|
|
|
|
/**
|
|
* @Post("/sign/update", name="web.web.im.update_sign")
|
|
*/
|
|
public function updateSignatureAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->updateSignature();
|
|
|
|
return $this->jsonSuccess();
|
|
}
|
|
|
|
/**
|
|
* @Post("/skin/update", name="web.web.im.update_skin")
|
|
*/
|
|
public function updateSKinAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->updateSkin();
|
|
|
|
return $this->jsonSuccess();
|
|
}
|
|
|
|
/**
|
|
* @Post("/friend/apply", name="web.im.apply_friend")
|
|
*/
|
|
public function applyFriendAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->applyFriend();
|
|
|
|
$content = ['msg' => '发送申请成功,请等待对方通过'];
|
|
|
|
return $this->jsonSuccess($content);
|
|
}
|
|
|
|
/**
|
|
* @Post("/friend/accept", name="web.im.accept_friend")
|
|
*/
|
|
public function acceptFriendAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->acceptFriend();
|
|
|
|
return $this->jsonSuccess();
|
|
}
|
|
|
|
/**
|
|
* @Post("/friend/refuse", name="web.im.refuse_friend")
|
|
*/
|
|
public function refuseFriendAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->refuseFriend();
|
|
|
|
return $this->jsonSuccess();
|
|
}
|
|
|
|
/**
|
|
* @Post("/group/apply", name="web.im.apply_group")
|
|
*/
|
|
public function applyGroupAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->applyGroup();
|
|
|
|
$content = ['msg' => '发送申请成功,请等待管理员通过'];
|
|
|
|
return $this->jsonSuccess($content);
|
|
}
|
|
|
|
/**
|
|
* @Post("/group/accept", name="web.web.im.accept_group")
|
|
*/
|
|
public function acceptGroupAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->acceptGroup();
|
|
|
|
return $this->jsonSuccess();
|
|
}
|
|
|
|
/**
|
|
* @Post("/group/refuse", name="web.web.im.refuse_group")
|
|
*/
|
|
public function refuseGroupAction()
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->refuseGroup();
|
|
|
|
return $this->jsonSuccess();
|
|
}
|
|
|
|
/**
|
|
* @Post("/friend/{id:[0-9]+}/quit", name="web.im.quit_friend")
|
|
*/
|
|
public function quitFriendAction($id)
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->quitFriend($id);
|
|
|
|
$content = ['msg' => '解除好友成功'];
|
|
|
|
return $this->jsonSuccess($content);
|
|
}
|
|
|
|
/**
|
|
* @Post("/group/{id:[0-9]+}/quit", name="web.im.quit_group")
|
|
*/
|
|
public function quitGroupAction($id)
|
|
{
|
|
$service = new ImService();
|
|
|
|
$service->quitGroup($id);
|
|
|
|
$content = ['msg' => '退出群组成功'];
|
|
|
|
return $this->jsonSuccess($content);
|
|
}
|
|
|
|
}
|