-
+
+
+
+
+ {{ partial('setting/im_basic') }}
+
+
+ {{ partial('setting/im_cs') }}
+
+
+ {{ partial('setting/im_robot') }}
-
-
-
-
-
+
{% endblock %}
\ No newline at end of file
diff --git a/app/Http/Admin/Views/setting/im_basic.volt b/app/Http/Admin/Views/setting/im_basic.volt
new file mode 100644
index 00000000..cfb5cc4d
--- /dev/null
+++ b/app/Http/Admin/Views/setting/im_basic.volt
@@ -0,0 +1,15 @@
+
\ No newline at end of file
diff --git a/app/Http/Admin/Views/setting/im_cs.volt b/app/Http/Admin/Views/setting/im_cs.volt
new file mode 100644
index 00000000..6290ea09
--- /dev/null
+++ b/app/Http/Admin/Views/setting/im_cs.volt
@@ -0,0 +1,34 @@
+
\ No newline at end of file
diff --git a/app/Http/Admin/Views/setting/im_robot.volt b/app/Http/Admin/Views/setting/im_robot.volt
new file mode 100644
index 00000000..3625709c
--- /dev/null
+++ b/app/Http/Admin/Views/setting/im_robot.volt
@@ -0,0 +1,34 @@
+
\ No newline at end of file
diff --git a/app/Http/Web/Controllers/Controller.php b/app/Http/Web/Controllers/Controller.php
index 62babec3..e9580a7d 100644
--- a/app/Http/Web/Controllers/Controller.php
+++ b/app/Http/Web/Controllers/Controller.php
@@ -35,6 +35,11 @@ class Controller extends \Phalcon\Mvc\Controller
*/
protected $siteInfo;
+ /**
+ * @var array
+ */
+ protected $imInfo;
+
/**
* @var UserModel
*/
@@ -63,17 +68,18 @@ class Controller extends \Phalcon\Mvc\Controller
{
$this->seo = $this->getSeo();
$this->navs = $this->getNavs();
- $this->appInfo = $this->getAppInfo();
$this->authUser = $this->getAuthUser();
+ $this->appInfo = $this->getAppInfo();
+ $this->imInfo = $this->getImInfo();
$this->seo->setTitle($this->siteInfo['title']);
$this->view->setVar('seo', $this->seo);
$this->view->setVar('navs', $this->navs);
+ $this->view->setVar('auth_user', $this->authUser);
$this->view->setVar('app_info', $this->appInfo);
$this->view->setVar('site_info', $this->siteInfo);
- $this->view->setVar('auth_user', $this->authUser);
- $this->view->setVar('socket_url', $this->getSocketUrl());
+ $this->view->setVar('im_info', $this->imInfo);
}
protected function getAuthUser()
@@ -95,14 +101,14 @@ class Controller extends \Phalcon\Mvc\Controller
{
$cache = new NavCache();
- return $cache->get() ?: [];
+ return $cache->get();
}
protected function getSiteInfo()
{
$cache = new SettingCache();
- return $cache->get('site') ?: [];
+ return $cache->get('site');
}
protected function getAppInfo()
@@ -110,11 +116,24 @@ class Controller extends \Phalcon\Mvc\Controller
return new AppInfo();
}
- protected function getSocketUrl()
+ protected function getImInfo()
{
- $config = $this->getDI()->get('config');
+ $cache = new SettingCache();
- return $config->websocket->url;
+ $im = $cache->get('im');
+
+ return [
+ 'title' => $im['title'],
+ 'cs' => [
+ 'enabled' => $im['cs_enabled'],
+ ],
+ 'robot' => [
+ 'enabled' => $im['robot_enabled'],
+ ],
+ 'websocket' => [
+ 'url' => $this->config->websocket->url,
+ ],
+ ];
}
protected function checkSiteStatus()
diff --git a/app/Http/Web/Controllers/ImController.php b/app/Http/Web/Controllers/ImController.php
index 5abe6a35..bee55ab0 100644
--- a/app/Http/Web/Controllers/ImController.php
+++ b/app/Http/Web/Controllers/ImController.php
@@ -14,12 +14,21 @@ class ImController extends Controller
use ResponseTrait;
+ public function initialize()
+ {
+ parent::initialize();
+
+ if ($this->authUser->id == 0) {
+ return $this->response->redirect(['for' => 'web.account.login']);
+ }
+ }
+
/**
* @Get("/", name="web.im.index")
*/
public function indexAction()
{
-
+ $this->seo->prependTitle('微聊');
}
/**
@@ -27,9 +36,13 @@ class ImController extends Controller
*/
public function csAction()
{
- /**
- * @todo 在线客服
- */
+ $this->seo->prependTitle('在线客服');
+
+ $service = new ImService();
+
+ $csUser = $service->getCsUser();
+
+ $this->view->setVar('cs_user', $csUser);
}
/**
@@ -37,9 +50,13 @@ class ImController extends Controller
*/
public function robotAction()
{
- /**
- * @todo 聊天机器人
- */
+ $this->seo->prependTitle('智能聊天');
+
+ $service = new ImService();
+
+ $csUser = $service->getRobotUser();
+
+ $this->view->setVar('cs_user', $csUser);
}
/**
@@ -49,7 +66,7 @@ class ImController extends Controller
{
$service = new ImService();
- $data = $service->init();
+ $data = $service->getInitInfo();
return $this->jsonSuccess(['data' => $data]);
}
@@ -178,13 +195,25 @@ class ImController extends Controller
}
/**
- * @Post("/msg/send", name="web.im.send_msg")
+ * @Post("/msg/chat/send", name="web.im.send_chat_msg")
*/
- public function sendMessageAction()
+ public function sendChatMessageAction()
{
$service = new ImService();
- $service->sendMessage();
+ $service->sendChatMessage();
+
+ return $this->jsonSuccess();
+ }
+
+ /**
+ * @Post("/msg/cs/send", name="web.im.send_cs_msg")
+ */
+ public function sendCsMessageAction()
+ {
+ $service = new ImService();
+
+ $service->sendCsMessage();
return $this->jsonSuccess();
}
diff --git a/app/Http/Web/Services/Im.php b/app/Http/Web/Services/Im.php
index cb962bfd..a905ec94 100644
--- a/app/Http/Web/Services/Im.php
+++ b/app/Http/Web/Services/Im.php
@@ -2,19 +2,11 @@
namespace App\Http\Web\Services;
-use App\Builders\ImMessageList as ImMessageListBuilder;
-use App\Library\Paginator\Query as PagerQuery;
-use App\Models\ImMessage as ImMessageModel;
+use App\Caches\Setting as SettingCache;
use App\Models\ImUser as ImUserModel;
-use App\Repos\ImFriendUser as ImFriendUserRepo;
use App\Repos\ImGroup as ImGroupRepo;
-use App\Repos\ImMessage as ImMessageRepo;
-use App\Repos\ImNotice as ImNoticeRepo;
use App\Repos\ImUser as ImUserRepo;
-use App\Validators\ImFriendUser as ImFriendUserValidator;
use App\Validators\ImGroup as ImGroupValidator;
-use App\Validators\ImGroupUser as ImGroupUserValidator;
-use App\Validators\ImMessage as ImMessageValidator;
use App\Validators\ImUser as ImUserValidator;
use GatewayClient\Gateway;
@@ -23,8 +15,64 @@ class Im extends Service
use ImFriendTrait;
use ImGroupTrait;
+ use ImMessageTrait;
+ use ImNoticeTrait;
- public function init()
+ public function getRobotUser()
+ {
+ $imUser = new ImUserModel();
+
+ $imUser->id = -10000;
+ $imUser->name = '聊天机器人';
+ $imUser->avatar = kg_ci_avatar_img_url(null);
+
+ return $imUser;
+ }
+
+ public function getCsUser()
+ {
+ $userIds = [];
+ $onlineUserIds = [];
+
+ $cache = new SettingCache();
+
+ $imInfo = $cache->get('im');
+
+ Gateway::$registerAddress = $this->getRegisterAddress();
+
+ if (!empty($imInfo['cs_user1_id'])) {
+ $userIds[] = $imInfo['cs_user1_id'];
+ if (Gateway::isUidOnline($imInfo['cs_user1_id'])) {
+ $onlineUserIds[] = $imInfo['cs_user1_id'];
+ }
+ }
+
+ if (!empty($imInfo['cs_user2_id'])) {
+ $userIds[] = $imInfo['cs_user2_id'];
+ if (Gateway::isUidOnline($imInfo['cs_user2_id'])) {
+ $onlineUserIds[] = $imInfo['cs_user2_id'];
+ }
+ }
+
+ if (!empty($imInfo['cs_user3_id'])) {
+ $userIds[] = $imInfo['cs_user3_id'];
+ if (Gateway::isUidOnline($imInfo['cs_user3_id'])) {
+ $onlineUserIds[] = $imInfo['cs_user3_id'];
+ }
+ }
+
+ if (count($onlineUserIds) > 0) {
+ $key = array_rand($onlineUserIds);
+ $userId = $onlineUserIds[$key];
+ } else {
+ $key = array_rand($userIds);
+ $userId = $userIds[$key];
+ }
+
+ return $this->getImUser($userId);
+ }
+
+ public function getInitInfo()
{
$loginUser = $this->getLoginUser();
@@ -81,125 +129,6 @@ class Im extends Service
return $result;
}
- public function pullUnreadFriendMessages()
- {
- $user = $this->getLoginUser();
-
- $id = $this->request->getQuery('id');
-
- $validator = new ImUserValidator();
-
- $friend = $validator->checkUser($id);
-
- $userRepo = new ImUserRepo();
-
- $messages = $userRepo->findUnreadFriendMessages($friend->id, $user->id);
-
- if ($messages->count() == 0) {
- return;
- }
-
- Gateway::$registerAddress = $this->getRegisterAddress();
-
- foreach ($messages as $message) {
-
- $message->update(['viewed' => 1]);
-
- $content = kg_json_encode([
- 'type' => 'show_chat_msg',
- 'message' => [
- 'username' => $friend->name,
- 'avatar' => $friend->avatar,
- 'id' => $friend->id,
- 'fromid' => $friend->id,
- 'content' => $message->content,
- 'timestamp' => 1000 * $message->create_time,
- 'type' => 'friend',
- 'mine' => false,
- ],
- ]);
-
- Gateway::sendToUid($user->id, $content);
- }
-
- $repo = new ImFriendUserRepo();
-
- $friendUser = $repo->findFriendUser($user->id, $friend->id);
-
- $friendUser->update(['msg_count' => 0]);
- }
-
- public function countUnreadNotices()
- {
- $user = $this->getLoginUser();
-
- $userRepo = new ImUserRepo();
-
- return $userRepo->countUnreadNotices($user->id);
- }
-
- public function getNotices()
- {
- $user = $this->getLoginUser();
-
- $pagerQuery = new PagerQuery();
-
- $params = $pagerQuery->getParams();
-
- $params['receiver_id'] = $user->id;
-
- $sort = $pagerQuery->getSort();
- $page = $pagerQuery->getPage();
- $limit = $pagerQuery->getLimit();
-
- $noticeRepo = new ImNoticeRepo();
-
- return $noticeRepo->paginate($params, $sort, $page, $limit);
- }
-
- public function getChatMessages()
- {
- $user = $this->getLoginUser();
-
- $pagerQuery = new PagerQuery();
-
- $params = $pagerQuery->getParams();
-
- $validator = new ImMessageValidator();
-
- $validator->checkType($params['type']);
-
- $sort = $pagerQuery->getSort();
- $page = $pagerQuery->getPage();
- $limit = $pagerQuery->getLimit();
-
- if ($params['type'] == ImMessageModel::TYPE_FRIEND) {
-
- $chatId = ImMessageModel::getChatId($user->id, $params['id']);
-
- $where = ['chat_id' => $chatId];
-
- $messageRepo = new ImMessageRepo();
-
- $pager = $messageRepo->paginate($where, $sort, $page, $limit);
-
- return $this->handleChatMessagePager($pager);
-
- } elseif ($params['type'] == ImMessageModel::TYPE_GROUP) {
-
- $where = [
- 'receiver_type' => $params['type'],
- 'receiver_id' => $params['id'],
- ];
-
- $messageRepo = new ImMessageRepo();
-
- $pager = $messageRepo->paginate($where, $sort, $page, $limit);
-
- return $this->handleChatMessagePager($pager);
- }
- }
-
public function getFriendStatus()
{
$id = $this->request->getQuery('id');
@@ -245,115 +174,6 @@ class Im extends Service
$this->pushOnlineTips($user);
}
- public function sendMessage()
- {
- $user = $this->getLoginUser();
-
- $from = $this->request->getPost('from');
- $to = $this->request->getPost('to');
-
- $validator = new ImMessageValidator();
-
- $from['content'] = $validator->checkContent($from['content']);
-
- $message = [
- 'username' => $from['username'],
- 'avatar' => $from['avatar'],
- 'content' => $from['content'],
- 'fromid' => $from['id'],
- 'id' => $from['id'],
- 'type' => $to['type'],
- 'timestamp' => 1000 * time(),
- 'mine' => false,
- ];
-
- if ($to['type'] == 'group') {
- $message['id'] = $to['id'];
- }
-
- $content = json_encode([
- 'type' => 'show_chat_msg',
- 'message' => $message,
- ]);
-
- Gateway::$registerAddress = $this->getRegisterAddress();
-
- if ($to['type'] == ImMessageModel::TYPE_FRIEND) {
-
- $validator = new ImFriendUserValidator();
-
- $relation = $validator->checkFriendUser($to['id'], $user->id);
-
- $online = Gateway::isUidOnline($to['id']);
-
- $messageModel = new ImMessageModel();
-
- $messageModel->create([
- 'sender_id' => $from['id'],
- 'receiver_id' => $to['id'],
- 'chat_type' => $to['type'],
- 'content' => $from['content'],
- 'viewed' => $online ? 1 : 0,
- ]);
-
- if ($online) {
- Gateway::sendToUid($to['id'], $content);
- } else {
- $this->incrFriendUserMsgCount($relation);
- }
-
- } elseif ($to['type'] == ImMessageModel::TYPE_GROUP) {
-
- $validator = new ImGroupValidator();
-
- $group = $validator->checkGroup($to['id']);
-
- $validator = new ImGroupUserValidator();
-
- $validator->checkGroupUser($group->id, $user->id);
-
- $messageModel = new ImMessageModel();
-
- $messageModel->create([
- 'sender_id' => $from['id'],
- 'receiver_id' => $to['id'],
- 'chat_type' => $to['type'],
- 'content' => $from['content'],
- ]);
-
- $this->incrGroupMessageCount($group);
-
- $excludeClientId = null;
-
- /**
- * 不推送自己在群组中发的消息
- */
- if ($user->id == $from['id']) {
- $excludeClientId = Gateway::getClientIdByUid($user->id);
- }
-
- $groupName = $this->getGroupName($to['id']);
-
- Gateway::sendToGroup($groupName, $content, $excludeClientId);
- }
- }
-
- public function readNotices()
- {
- $user = $this->getLoginUser();
-
- $userRepo = new ImUserRepo();
-
- $messages = $userRepo->findUnreadNotices($user->id);
-
- if ($messages->count() > 0) {
- foreach ($messages as $message) {
- $message->viewed = 1;
- $message->update();
- }
- }
- }
-
public function updateStatus()
{
$loginUser = $this->getLoginUser();
@@ -543,35 +363,6 @@ class Im extends Service
return $result;
}
- protected function handleChatMessagePager($pager)
- {
- if ($pager->total_items == 0) {
- return $pager;
- }
-
- $messages = $pager->items->toArray();
-
- $builder = new ImMessageListBuilder();
-
- $senders = $builder->getSenders($messages);
-
- $items = [];
-
- foreach ($messages as $message) {
- $sender = $senders[$message['sender_id']] ?? new \stdClass();
- $items[] = [
- 'id' => $message['id'],
- 'content' => $message['content'],
- 'timestamp' => $message['create_time'] * 1000,
- 'user' => $sender,
- ];
- }
-
- $pager->items = $items;
-
- return $pager;
- }
-
protected function getImUser($id)
{
$repo = new ImUserRepo();
diff --git a/app/Http/Web/Services/ImMessageTrait.php b/app/Http/Web/Services/ImMessageTrait.php
new file mode 100644
index 00000000..0ba858c5
--- /dev/null
+++ b/app/Http/Web/Services/ImMessageTrait.php
@@ -0,0 +1,331 @@
+getLoginUser();
+
+ $id = $this->request->getQuery('id');
+
+ $validator = new ImUserValidator();
+
+ $friend = $validator->checkUser($id);
+
+ $userRepo = new ImUserRepo();
+
+ $messages = $userRepo->findUnreadFriendMessages($friend->id, $user->id);
+
+ if ($messages->count() == 0) {
+ return;
+ }
+
+ Gateway::$registerAddress = $this->getRegisterAddress();
+
+ foreach ($messages as $message) {
+
+ $message->update(['viewed' => 1]);
+
+ $content = kg_json_encode([
+ 'type' => 'show_chat_msg',
+ 'message' => [
+ 'username' => $friend->name,
+ 'avatar' => $friend->avatar,
+ 'id' => $friend->id,
+ 'fromid' => $friend->id,
+ 'content' => $message->content,
+ 'timestamp' => 1000 * $message->create_time,
+ 'type' => 'friend',
+ 'mine' => false,
+ ],
+ ]);
+
+ Gateway::sendToUid($user->id, $content);
+ }
+
+ $repo = new ImFriendUserRepo();
+
+ $friendUser = $repo->findFriendUser($user->id, $friend->id);
+
+ $friendUser->update(['msg_count' => 0]);
+ }
+
+ public function getChatMessages()
+ {
+ $user = $this->getLoginUser();
+
+ $pagerQuery = new PagerQuery();
+
+ $params = $pagerQuery->getParams();
+
+ $validator = new ImMessageValidator();
+
+ $validator->checkType($params['type']);
+
+ $sort = $pagerQuery->getSort();
+ $page = $pagerQuery->getPage();
+ $limit = $pagerQuery->getLimit();
+
+ if ($params['type'] == ImMessageModel::TYPE_FRIEND) {
+
+ $chatId = ImMessageModel::getChatId($user->id, $params['id']);
+
+ $where = ['chat_id' => $chatId];
+
+ $messageRepo = new ImMessageRepo();
+
+ $pager = $messageRepo->paginate($where, $sort, $page, $limit);
+
+ return $this->handleChatMessagePager($pager);
+
+ } elseif ($params['type'] == ImMessageModel::TYPE_GROUP) {
+
+ $where = [
+ 'receiver_type' => $params['type'],
+ 'receiver_id' => $params['id'],
+ ];
+
+ $messageRepo = new ImMessageRepo();
+
+ $pager = $messageRepo->paginate($where, $sort, $page, $limit);
+
+ return $this->handleChatMessagePager($pager);
+ }
+ }
+
+ public function sendChatMessage()
+ {
+ $user = $this->getLoginUser();
+
+ $from = $this->request->getPost('from');
+ $to = $this->request->getPost('to');
+
+ $validator = new ImMessageValidator();
+
+ $from['content'] = $validator->checkContent($from['content']);
+
+ $message = [
+ 'username' => $from['username'],
+ 'avatar' => $from['avatar'],
+ 'content' => $from['content'],
+ 'fromid' => $from['id'],
+ 'id' => $from['id'],
+ 'type' => $to['type'],
+ 'timestamp' => 1000 * time(),
+ 'mine' => false,
+ ];
+
+ if ($to['type'] == 'group') {
+ $message['id'] = $to['id'];
+ }
+
+ $content = kg_json_encode([
+ 'type' => 'show_chat_msg',
+ 'message' => $message,
+ ]);
+
+ Gateway::$registerAddress = $this->getRegisterAddress();
+
+ if ($to['type'] == ImMessageModel::TYPE_FRIEND) {
+
+ $validator = new ImFriendUserValidator();
+
+ $relation = $validator->checkFriendUser($to['id'], $user->id);
+
+ $online = Gateway::isUidOnline($to['id']);
+
+ $messageModel = new ImMessageModel();
+
+ $messageModel->create([
+ 'sender_id' => $from['id'],
+ 'receiver_id' => $to['id'],
+ 'receiver_type' => $to['type'],
+ 'content' => $from['content'],
+ 'viewed' => $online ? 1 : 0,
+ ]);
+
+ if ($online) {
+ Gateway::sendToUid($to['id'], $content);
+ } else {
+ $this->incrFriendUserMsgCount($relation);
+ }
+
+ } elseif ($to['type'] == ImMessageModel::TYPE_GROUP) {
+
+ $validator = new ImGroupValidator();
+
+ $group = $validator->checkGroup($to['id']);
+
+ $validator = new ImGroupUserValidator();
+
+ $validator->checkGroupUser($group->id, $user->id);
+
+ $messageModel = new ImMessageModel();
+
+ $messageModel->create([
+ 'sender_id' => $from['id'],
+ 'receiver_id' => $to['id'],
+ 'receiver_type' => $to['type'],
+ 'content' => $from['content'],
+ ]);
+
+ $this->incrGroupMessageCount($group);
+
+ $excludeClientId = null;
+
+ /**
+ * 不推送自己在群组中发的消息
+ */
+ if ($user->id == $from['id']) {
+ $excludeClientId = Gateway::getClientIdByUid($user->id);
+ }
+
+ $groupName = $this->getGroupName($to['id']);
+
+ Gateway::sendToGroup($groupName, $content, $excludeClientId);
+ }
+ }
+
+ public function sendCsMessage()
+ {
+ $from = $this->request->getPost('from');
+ $to = $this->request->getPost('to');
+
+ $validator = new ImMessageValidator();
+
+ $from['content'] = $validator->checkContent($from['content']);
+
+ if ($to['id'] > 0) {
+ $this->sendCsUserMessage($from, $to);
+ } else {
+ $this->sendCsRobotMessage($from, $to);
+ }
+ }
+
+ protected function handleChatMessagePager($pager)
+ {
+ if ($pager->total_items == 0) {
+ return $pager;
+ }
+
+ $messages = $pager->items->toArray();
+
+ $builder = new ImMessageListBuilder();
+
+ $senders = $builder->getSenders($messages);
+
+ $items = [];
+
+ foreach ($messages as $message) {
+ $sender = $senders[$message['sender_id']] ?? new \stdClass();
+ $items[] = [
+ 'id' => $message['id'],
+ 'content' => $message['content'],
+ 'timestamp' => $message['create_time'] * 1000,
+ 'user' => $sender,
+ ];
+ }
+
+ $pager->items = $items;
+
+ return $pager;
+ }
+
+ /**
+ * 向客服发送消息,建立临时好友关系
+ *
+ * @param array $from
+ * @param array $to
+ */
+ protected function sendCsUserMessage($from, $to)
+ {
+ $message = [
+ 'username' => $from['username'],
+ 'avatar' => $from['avatar'],
+ 'content' => $from['content'],
+ 'fromid' => $from['id'],
+ 'id' => $from['id'],
+ 'type' => $to['type'],
+ 'timestamp' => 1000 * time(),
+ 'mine' => false,
+ ];
+
+ $content = kg_json_encode([
+ 'type' => 'show_cs_msg',
+ 'message' => $message,
+ ]);
+
+ Gateway::$registerAddress = $this->getRegisterAddress();
+
+ $online = Gateway::isUidOnline($to['id']);
+
+ $messageModel = new ImMessageModel();
+
+ $messageModel->create([
+ 'sender_id' => $from['id'],
+ 'receiver_id' => $to['id'],
+ 'receiver_type' => $to['type'],
+ 'content' => $from['content'],
+ 'viewed' => $online ? 1 : 0,
+ ]);
+
+ if ($online) {
+ Gateway::sendToUid($to['id'], $content);
+ }
+ }
+
+ /**
+ * 向机器人发送消息,机器人自动应答
+ *
+ * @param array $from
+ * @param array $to
+ */
+ protected function sendCsRobotMessage($from, $to)
+ {
+ /**
+ * @todo 从腾讯平台获取应答内容
+ */
+ $content = '不知道你在说什么...';
+
+ $message = [
+ 'username' => $to['name'],
+ 'avatar' => $to['avatar'],
+ 'content' => $content,
+ 'fromid' => $to['id'],
+ 'id' => $to['id'],
+ 'type' => $to['type'],
+ 'timestamp' => 1000 * time(),
+ 'mine' => false,
+ ];
+
+ $content = kg_json_encode([
+ 'type' => 'show_cs_msg',
+ 'message' => $message,
+ ]);
+
+ Gateway::$registerAddress = $this->getRegisterAddress();
+
+ Gateway::sendToUid($from['id'], $content);
+ }
+
+}
\ No newline at end of file
diff --git a/app/Http/Web/Services/ImNoticeTrait.php b/app/Http/Web/Services/ImNoticeTrait.php
new file mode 100644
index 00000000..9039786f
--- /dev/null
+++ b/app/Http/Web/Services/ImNoticeTrait.php
@@ -0,0 +1,56 @@
+getLoginUser();
+
+ $userRepo = new ImUserRepo();
+
+ return $userRepo->countUnreadNotices($user->id);
+ }
+
+ public function getNotices()
+ {
+ $user = $this->getLoginUser();
+
+ $pagerQuery = new PagerQuery();
+
+ $params = $pagerQuery->getParams();
+
+ $params['receiver_id'] = $user->id;
+
+ $sort = $pagerQuery->getSort();
+ $page = $pagerQuery->getPage();
+ $limit = $pagerQuery->getLimit();
+
+ $noticeRepo = new ImNoticeRepo();
+
+ return $noticeRepo->paginate($params, $sort, $page, $limit);
+ }
+
+ public function readNotices()
+ {
+ $user = $this->getLoginUser();
+
+ $userRepo = new ImUserRepo();
+
+ $messages = $userRepo->findUnreadNotices($user->id);
+
+ if ($messages->count() > 0) {
+ foreach ($messages as $message) {
+ $message->viewed = 1;
+ $message->update();
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/app/Http/Web/Views/im/cs.volt b/app/Http/Web/Views/im/cs.volt
new file mode 100644
index 00000000..3ddcbfe9
--- /dev/null
+++ b/app/Http/Web/Views/im/cs.volt
@@ -0,0 +1,25 @@
+{% extends 'templates/main.volt' %}
+
+{% block content %}
+
+
+
+
+
+
+
+
+
+
+{% endblock %}
+
+{% block include_js %}
+
+ {{ js_include('web/js/im.cs.js') }}
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/Http/Web/Views/im/robot.volt b/app/Http/Web/Views/im/robot.volt
new file mode 100644
index 00000000..5d2b79ba
--- /dev/null
+++ b/app/Http/Web/Views/im/robot.volt
@@ -0,0 +1,25 @@
+{% extends 'templates/main.volt' %}
+
+{% block content %}
+
+
+
+
+
+
+
+
+
+
+{% endblock %}
+
+{% block include_js %}
+
+ {{ js_include('web/js/im.cs.js') }}
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/Http/Web/Views/partials/js_global_vars.volt b/app/Http/Web/Views/partials/js_global_vars.volt
index 593718df..f4a37f0d 100644
--- a/app/Http/Web/Views/partials/js_global_vars.volt
+++ b/app/Http/Web/Views/partials/js_global_vars.volt
@@ -1,19 +1,23 @@