@@ -132,25 +115,11 @@
var form = layui.form;
var laydate = layui.laydate;
- laydate.render({
- elem: 'input[name=vip_expiry_time]',
- type: 'datetime'
- });
-
laydate.render({
elem: 'input[name=lock_expiry_time]',
type: 'datetime'
});
- form.on('radio(vip)', function (data) {
- var block = $('#vip-expiry-block');
- if (data.value === '1') {
- block.show();
- } else {
- block.hide();
- }
- });
-
form.on('radio(locked)', function (data) {
var block = $('#lock-expiry-block');
if (data.value === '1') {
diff --git a/app/Http/Admin/Views/user/list.volt b/app/Http/Admin/Views/user/list.volt
index 2d862e55..2e64d83c 100644
--- a/app/Http/Admin/Views/user/list.volt
+++ b/app/Http/Admin/Views/user/list.volt
@@ -4,9 +4,9 @@
{%- macro gender_info(value) %}
{% if value == 1 %}
-
男
+
男
{% elseif value == 2 %}
-
女
+
女
{% elseif value == 3 %}
密
{% endif %}
diff --git a/app/Http/Web/Controllers/ImController.php b/app/Http/Web/Controllers/ImController.php
index 5ae21432..a4e71501 100644
--- a/app/Http/Web/Controllers/ImController.php
+++ b/app/Http/Web/Controllers/ImController.php
@@ -29,6 +29,18 @@ class ImController extends Controller
public function indexAction()
{
$this->seo->prependTitle('微聊');
+
+ $service = new ImService();
+
+ $activeGroups = $service->getActiveGroups();
+ $activeUsers = $service->getActiveUsers();
+ $newGroups = $service->getNewGroups();
+ $newUsers = $service->getNewUsers();
+
+ $this->view->setVar('active_users', $activeUsers);
+ $this->view->setVar('active_groups', $activeGroups);
+ $this->view->setVar('new_groups', $newGroups);
+ $this->view->setVar('new_users', $newUsers);
}
/**
@@ -74,7 +86,7 @@ class ImController extends Controller
{
$service = new ImService();
- $pager = $service->getSystemMessages();
+ $pager = $service->getNotices();
$this->view->pick('im/msgbox');
$this->view->setVar('pager', $pager);
diff --git a/app/Http/Web/Controllers/ImGroupController.php b/app/Http/Web/Controllers/ImGroupController.php
index d123f706..5dddebf7 100644
--- a/app/Http/Web/Controllers/ImGroupController.php
+++ b/app/Http/Web/Controllers/ImGroupController.php
@@ -46,6 +46,8 @@ class ImGroupController extends Controller
$group = $service->getGroup($id);
+ $this->seo->prependTitle([$group['name'], '群组']);
+
$this->view->pick('im/group/show');
$this->view->setVar('group', $group);
}
diff --git a/app/Http/Web/Services/Im.php b/app/Http/Web/Services/Im.php
index 6dc3940d..bd9e9320 100644
--- a/app/Http/Web/Services/Im.php
+++ b/app/Http/Web/Services/Im.php
@@ -2,7 +2,6 @@
namespace App\Http\Web\Services;
-use App\Caches\Setting as SettingCache;
use App\Models\ImUser as ImUserModel;
use App\Repos\ImGroup as ImGroupRepo;
use App\Repos\ImUser as ImUserRepo;
@@ -13,55 +12,13 @@ use GatewayClient\Gateway;
class Im extends Service
{
+ use ImCsTrait;
use ImFriendTrait;
use ImGroupTrait;
use ImMessageTrait;
use ImNoticeTrait;
use ImStatTrait;
- public function getCsUser()
- {
- $csUserIds = [];
- $onlineUserIds = [];
-
- $cache = new SettingCache();
-
- $imInfo = $cache->get('im');
-
- Gateway::$registerAddress = $this->getRegisterAddress();
-
- if (!empty($imInfo['cs_user1_id'])) {
- $csUserIds[] = $imInfo['cs_user1_id'];
- if (Gateway::isUidOnline($imInfo['cs_user1_id'])) {
- $onlineUserIds[] = $imInfo['cs_user1_id'];
- }
- }
-
- if (!empty($imInfo['cs_user2_id'])) {
- $csUserIds[] = $imInfo['cs_user2_id'];
- if (Gateway::isUidOnline($imInfo['cs_user2_id'])) {
- $onlineUserIds[] = $imInfo['cs_user2_id'];
- }
- }
-
- if (!empty($imInfo['cs_user3_id'])) {
- $csUserIds[] = $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($csUserIds);
- $userId = $csUserIds[$key];
- }
-
- return $this->getImUser($userId);
- }
-
public function getInitInfo()
{
$loginUser = $this->getLoginUser();
@@ -295,26 +252,29 @@ class Im extends Service
$users = $userRepo->findByIds($ids);
- $mappings = [];
+ $baseUrl = kg_ci_base_url();
+
+ $mapping = [];
/**
* 用户可以设置状态为 ['online', 'hide']
* 列表在线状态识别为 ['online', 'offline']
*/
- foreach ($users as $user) {
- $status = in_array($user->status, ['online', 'offline']) ? $user->status : 'offline';
- $mappings[$user->id] = [
- 'id' => $user->id,
- 'username' => $user->name,
- 'avatar' => $user->avatar,
- 'sign' => $user->sign,
+ foreach ($users->toArray() as $user) {
+ $status = in_array($user['status'], ['online', 'offline']) ? $user['status'] : 'offline';
+ $user['avatar'] = $baseUrl . $user['avatar'];
+ $mapping[$user['id']] = [
+ 'id' => $user['id'],
+ 'username' => $user['name'],
+ 'avatar' => $user['avatar'],
+ 'sign' => $user['sign'],
'status' => $status,
];
}
foreach ($items as $key => $item) {
foreach ($friendUsers as $friendUser) {
- $friend = $mappings[$friendUser->friend_id];
+ $friend = $mapping[$friendUser->friend_id];
if ($item['id'] == $friendUser->group_id) {
$friend['msg_count'] = $friendUser->msg_count;
$items[$key]['list'][] = $friend;
@@ -331,23 +291,34 @@ class Im extends Service
{
$userRepo = new ImUserRepo();
- $groups = $userRepo->findGroups($user->id);
+ $groupUsers = $userRepo->findGroupUsers($user->id);
- if ($groups->count() == 0) {
+ if ($groupUsers->count() == 0) {
return [];
}
+ $groupRepo = new ImGroupRepo();
+
+ $ids = kg_array_column($groupUsers->toArray(), 'group_id');
+
+ $groups = $groupRepo->findByIds($ids);
+
$baseUrl = kg_ci_base_url();
+ $mapping = [];
+
+ foreach ($groups->toArray() as $group) {
+ $mapping[$group['id']] = [
+ 'id' => $group['id'],
+ 'groupname' => $group['name'],
+ 'avatar' => $baseUrl . $group['avatar'],
+ ];
+ }
+
$result = [];
- foreach ($groups->toArray() as $group) {
- $group['avatar'] = $baseUrl . $group['avatar'];
- $result[] = [
- 'id' => $group['id'],
- 'groupname' => $group['name'],
- 'avatar' => $group['avatar'],
- ];
+ foreach ($groupUsers as $groupUser) {
+ $result[] = $mapping[$groupUser->group_id];
}
return $result;
diff --git a/app/Http/Web/Services/ImCsTrait.php b/app/Http/Web/Services/ImCsTrait.php
new file mode 100644
index 00000000..4dcfe926
--- /dev/null
+++ b/app/Http/Web/Services/ImCsTrait.php
@@ -0,0 +1,54 @@
+get('im');
+
+ Gateway::$registerAddress = $this->getRegisterAddress();
+
+ if (!empty($imInfo['cs_user1_id'])) {
+ $csUserIds[] = $imInfo['cs_user1_id'];
+ if (Gateway::isUidOnline($imInfo['cs_user1_id'])) {
+ $onlineUserIds[] = $imInfo['cs_user1_id'];
+ }
+ }
+
+ if (!empty($imInfo['cs_user2_id'])) {
+ $csUserIds[] = $imInfo['cs_user2_id'];
+ if (Gateway::isUidOnline($imInfo['cs_user2_id'])) {
+ $onlineUserIds[] = $imInfo['cs_user2_id'];
+ }
+ }
+
+ if (!empty($imInfo['cs_user3_id'])) {
+ $csUserIds[] = $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($csUserIds);
+ $userId = $csUserIds[$key];
+ }
+
+ return $this->getImUser($userId);
+ }
+
+}
\ No newline at end of file
diff --git a/app/Http/Web/Services/ImMessageTrait.php b/app/Http/Web/Services/ImMessageTrait.php
index 8a91e42d..864a6e2e 100644
--- a/app/Http/Web/Services/ImMessageTrait.php
+++ b/app/Http/Web/Services/ImMessageTrait.php
@@ -6,6 +6,7 @@ use App\Builders\ImMessageList as ImMessageListBuilder;
use App\Library\Paginator\Query as PagerQuery;
use App\Models\ImFriendUser as ImFriendUserModel;
use App\Models\ImGroup as ImGroupModel;
+use App\Models\ImGroupUser as ImGroupUserModel;
use App\Models\ImMessage as ImMessageModel;
use App\Repos\ImFriendUser as ImFriendUserRepo;
use App\Repos\ImMessage as ImMessageRepo;
@@ -24,52 +25,6 @@ use GatewayClient\Gateway;
Trait ImMessageTrait
{
- public function pullUnreadFriendMessages($id)
- {
- $user = $this->getLoginUser();
-
- $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();
@@ -86,7 +41,7 @@ Trait ImMessageTrait
$page = $pagerQuery->getPage();
$limit = $pagerQuery->getLimit();
- if ($params['type'] == ImMessageModel::TYPE_FRIEND) {
+ if ($params['type'] == 'friend') {
$chatId = ImMessageModel::getChatId($user->id, $params['id']);
@@ -98,7 +53,7 @@ Trait ImMessageTrait
return $this->handleChatMessagePager($pager);
- } elseif ($params['type'] == ImMessageModel::TYPE_GROUP) {
+ } elseif ($params['type'] == 'group') {
$where = [
'receiver_type' => $params['type'],
@@ -161,6 +116,8 @@ Trait ImMessageTrait
'viewed' => $online ? 1 : 0,
]);
+ $this->updateFriendUserChatTime($relation);
+
if ($online) {
Gateway::sendToUid($to['id'], $content);
} else {
@@ -177,7 +134,7 @@ Trait ImMessageTrait
$validator = new ImGroupUserValidator();
- $validator->checkGroupUser($group->id, $user->id);
+ $relation = $validator->checkGroupUser($group->id, $user->id);
$messageModel = new ImMessageModel();
@@ -188,6 +145,8 @@ Trait ImMessageTrait
'content' => $from['content'],
]);
+ $this->updateGroupUserChatTime($relation);
+
$this->incrGroupMsgCount($group);
$excludeClientId = null;
@@ -254,6 +213,52 @@ Trait ImMessageTrait
$this->sendChatMessage($from, $to);
}
+ public function pullUnreadFriendMessages($id)
+ {
+ $user = $this->getLoginUser();
+
+ $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]);
+ }
+
protected function handleChatMessagePager($pager)
{
if ($pager->total_items == 0) {
@@ -283,6 +288,34 @@ Trait ImMessageTrait
return $pager;
}
+ protected function updateFriendUserChatTime(ImFriendUserModel $hisFriendUser)
+ {
+ /**
+ * 用于联系人排序,近期有联系的排上面
+ */
+ if (time() - $hisFriendUser->update_time > 15 * 60) {
+
+ $hisFriendUser->update(['update_time' => time()]);
+
+ $repo = new ImFriendUserRepo();
+
+ $myFriendUser = $repo->findFriendUser($hisFriendUser->friend_id, $hisFriendUser->user_id);
+
+ $myFriendUser->update(['update_time' => time()]);
+ }
+ }
+
+ protected function updateGroupUserChatTime(ImGroupUserModel $groupUser)
+ {
+ /**
+ * 用于联系人排序,近期有联系的排上面
+ */
+ if (time() - $groupUser->update_time > 15 * 60) {
+ $groupUser->update_time = time();
+ $groupUser->update();
+ }
+ }
+
protected function incrFriendUserMsgCount(ImFriendUserModel $friendUser)
{
$friendUser->msg_count += 1;
diff --git a/app/Http/Web/Services/ImStatTrait.php b/app/Http/Web/Services/ImStatTrait.php
index d0fa379b..1abcfdef 100644
--- a/app/Http/Web/Services/ImStatTrait.php
+++ b/app/Http/Web/Services/ImStatTrait.php
@@ -2,27 +2,40 @@
namespace App\Http\Web\Services;
+use App\Caches\ImActiveGroupList;
+use App\Caches\ImActiveUserList;
+use App\Caches\ImNewGroupList;
+use App\Caches\ImNewUserList;
+
trait ImStatTrait
{
public function getActiveGroups()
{
+ $cache = new ImActiveGroupList();
+ return $cache->get();
}
public function getActiveUsers()
{
+ $cache = new ImActiveUserList();
+ return $cache->get();
}
public function getNewGroups()
{
+ $cache = new ImNewGroupList();
+ return $cache->get();
}
public function getNewUsers()
{
+ $cache = new ImNewUserList();
+ return $cache->get();
}
}
diff --git a/app/Http/Web/Views/account/login.volt b/app/Http/Web/Views/account/login.volt
index b1f24d85..893232cd 100644
--- a/app/Http/Web/Views/account/login.volt
+++ b/app/Http/Web/Views/account/login.volt
@@ -37,4 +37,14 @@
{{ js_include('web/js/captcha.login.js') }}
{{ js_include('web/js/captcha.verify.js') }}
+{% endblock %}
+
+{% block inline_js %}
+
+
+
{% endblock %}
\ No newline at end of file
diff --git a/app/Http/Web/Views/im/group/list.volt b/app/Http/Web/Views/im/group/list.volt
index 80eeabc2..cafa61fb 100644
--- a/app/Http/Web/Views/im/group/list.volt
+++ b/app/Http/Web/Views/im/group/list.volt
@@ -16,5 +16,6 @@
{% block include_js %}
{{ js_include('web/js/im.group.list.js') }}
+ {{ js_include('web/js/im.apply.js') }}
{% endblock %}
\ No newline at end of file
diff --git a/app/Http/Web/Views/im/group/pager.volt b/app/Http/Web/Views/im/group/pager.volt
index f90b7510..e369a51a 100644
--- a/app/Http/Web/Views/im/group/pager.volt
+++ b/app/Http/Web/Views/im/group/pager.volt
@@ -1,40 +1,33 @@
-{%- macro type_info(value) %}
- {% if value == 'course' %}
-
课
- {% elseif value == 'chat' %}
-
聊
- {% elseif value == 'staff' %}
-
工
- {% endif %}
-{%- endmacro %}
+{{ partial('macros/group') }}
-