diff --git a/app/Caches/ImGroupActiveUserList.php b/app/Caches/ImGroupActiveUserList.php index 82c24f68..ce7a3aef 100644 --- a/app/Caches/ImGroupActiveUserList.php +++ b/app/Caches/ImGroupActiveUserList.php @@ -2,7 +2,7 @@ namespace App\Caches; -use App\Models\ImGroupMessage as ImGroupMessageModel; +use App\Models\ImMessage as ImMessageModel; use App\Models\User as UserModel; use App\Repos\User as UserRepo; use Phalcon\Mvc\Model\Resultset; @@ -58,11 +58,12 @@ class ImGroupActiveUserList extends Cache $startTime = strtotime("-{$days} days"); $endTime = time(); - $rows = ImGroupMessageModel::query() + $rows = ImMessageModel::query() ->columns(['sender_id', 'total_count' => 'count(sender_id)']) ->groupBy('sender_id') ->orderBy('total_count DESC') - ->where('group_id = :group_id:', ['group_id' => $groupId]) + ->where('receiver_id = :group_id:', ['group_id' => $groupId]) + ->andWhere('receiver_type = :type:', ['type' => ImMessageModel::TYPE_GROUP]) ->betweenWhere('create_time', $startTime, $endTime) ->limit($limit) ->execute(); diff --git a/app/Console/Tasks/SyncCourseIndexTask.php b/app/Console/Tasks/SyncCourseIndexTask.php index ecb9f9e3..8911734d 100644 --- a/app/Console/Tasks/SyncCourseIndexTask.php +++ b/app/Console/Tasks/SyncCourseIndexTask.php @@ -34,7 +34,7 @@ class SyncCourseIndexTask extends Task { $key = $this->getSyncKey(); - $courseIds = $this->redis->sRandMember($key, 100); + $courseIds = $this->redis->sRandMember($key, 1000); if (!$courseIds) return; diff --git a/app/Console/Tasks/SyncGroupIndexTask.php b/app/Console/Tasks/SyncGroupIndexTask.php new file mode 100644 index 00000000..ebb81e2f --- /dev/null +++ b/app/Console/Tasks/SyncGroupIndexTask.php @@ -0,0 +1,80 @@ +cache = $this->getDI()->get('cache'); + + $this->redis = $this->cache->getRedis(); + + $this->rebuild(); + } + + protected function rebuild() + { + $key = $this->getSyncKey(); + + $groupIds = $this->redis->sRandMember($key, 1000); + + if (!$groupIds) return; + + $groupRepo = new GroupRepo(); + + $groups = $groupRepo->findByIds($groupIds); + + if ($groups->count() == 0) { + return; + } + + $document = new GroupDocument(); + + $handler = new GroupSearcher(); + + $index = $handler->getXS()->getIndex(); + + $index->openBuffer(); + + foreach ($groups as $group) { + + $doc = $document->setDocument($group); + + if ($group->published == 1) { + $index->update($doc); + } else { + $index->del($group->id); + } + } + + $index->closeBuffer(); + + $this->redis->sRem($key, ...$groupIds); + } + + protected function getSyncKey() + { + $syncer = new GroupIndexSyncer(); + + return $syncer->getSyncKey(); + } + +} diff --git a/app/Console/Tasks/SyncUserIndexTask.php b/app/Console/Tasks/SyncUserIndexTask.php new file mode 100644 index 00000000..bd7c8aea --- /dev/null +++ b/app/Console/Tasks/SyncUserIndexTask.php @@ -0,0 +1,80 @@ +cache = $this->getDI()->get('cache'); + + $this->redis = $this->cache->getRedis(); + + $this->rebuild(); + } + + protected function rebuild() + { + $key = $this->getSyncKey(); + + $userIds = $this->redis->sRandMember($key, 1000); + + if (!$userIds) return; + + $userRepo = new UserRepo(); + + $users = $userRepo->findByIds($userIds); + + if ($users->count() == 0) { + return; + } + + $document = new UserDocument(); + + $handler = new UserSearcher(); + + $index = $handler->getXS()->getIndex(); + + $index->openBuffer(); + + foreach ($users as $user) { + + $doc = $document->setDocument($user); + + if ($user->deleted == 0) { + $index->update($doc); + } else { + $index->del($user->id); + } + } + + $index->closeBuffer(); + + $this->redis->sRem($key, ...$userIds); + } + + protected function getSyncKey() + { + $syncer = new UserIndexSyncer(); + + return $syncer->getSyncKey(); + } + +} diff --git a/app/Http/Admin/Views/setting/site.volt b/app/Http/Admin/Views/setting/site.volt index 7259ad83..c1c231e6 100644 --- a/app/Http/Admin/Views/setting/site.volt +++ b/app/Http/Admin/Views/setting/site.volt @@ -2,10 +2,27 @@ {% block content %} + {% set closed_tips_display = site.status == 'normal' ? 'style="display:none;"' : '' %} +
站点配置
+
+ +
+ + +
+
+
+
+ +
+ +
+
+
@@ -79,4 +96,29 @@
+{% endblock %} + + +{% block inline_js %} + + + {% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Controllers/Controller.php b/app/Http/Web/Controllers/Controller.php index c436cbdf..917020de 100644 --- a/app/Http/Web/Controllers/Controller.php +++ b/app/Http/Web/Controllers/Controller.php @@ -45,6 +45,10 @@ class Controller extends \Phalcon\Mvc\Controller public function beforeExecuteRoute(Dispatcher $dispatcher) { + $this->site = $this->getSiteSettings(); + + $this->checkSiteStatus(); + if ($this->isNotSafeRequest()) { $this->checkHttpReferer(); $this->checkCsrfToken(); @@ -57,16 +61,15 @@ class Controller extends \Phalcon\Mvc\Controller public function initialize() { - $this->navs = $this->getNavs(); $this->seo = $this->getSeo(); - $this->site = $this->getSiteSettings(); + $this->navs = $this->getNavs(); $this->appInfo = $this->getAppInfo(); $this->authUser = $this->getAuthUser(); $this->seo->setTitle($this->site['title']); - $this->view->setVar('seo', $this->seo); $this->view->setVar('site', $this->site); + $this->view->setVar('seo', $this->seo); $this->view->setVar('navs', $this->navs); $this->view->setVar('app_info', $this->appInfo); $this->view->setVar('auth_user', $this->authUser); @@ -114,4 +117,15 @@ class Controller extends \Phalcon\Mvc\Controller return $config->websocket->url; } + protected function checkSiteStatus() + { + if ($this->site['status'] == 'closed') { + $this->dispatcher->forward([ + 'controller' => 'error', + 'action' => 'shutdown', + 'params' => ['message' => $this->site['closed_tips']], + ]); + } + } + } diff --git a/app/Http/Web/Controllers/ErrorController.php b/app/Http/Web/Controllers/ErrorController.php index e4969051..ee32bdf3 100644 --- a/app/Http/Web/Controllers/ErrorController.php +++ b/app/Http/Web/Controllers/ErrorController.php @@ -67,4 +67,16 @@ class ErrorController extends \Phalcon\Mvc\Controller $this->response->setStatusCode(503); } + /** + * @Get("/shutdown", name="web.error.shutdown") + */ + public function shutdownAction() + { + $message = $this->dispatcher->getParam('message'); + + $this->response->setStatusCode(503); + + $this->view->setVar('message', $message); + } + } diff --git a/app/Http/Web/Controllers/ImController.php b/app/Http/Web/Controllers/ImController.php index 64885519..953d2287 100644 --- a/app/Http/Web/Controllers/ImController.php +++ b/app/Http/Web/Controllers/ImController.php @@ -14,14 +14,6 @@ class ImController extends LayerController use ResponseTrait; - /** - * @Get("/", name="web.im.index") - */ - public function indexAction() - { - - } - /** * @Get("/init", name="web.im.init") */ diff --git a/app/Http/Web/Controllers/IndexController.php b/app/Http/Web/Controllers/IndexController.php index 5bf1ef35..c24043ef 100644 --- a/app/Http/Web/Controllers/IndexController.php +++ b/app/Http/Web/Controllers/IndexController.php @@ -32,4 +32,11 @@ class IndexController extends Controller } + protected function getSocketUrl() + { + $config = $this->getDI()->get('config'); + + return $config->websocket->url; + } + } diff --git a/app/Http/Web/Controllers/SearchController.php b/app/Http/Web/Controllers/SearchController.php index 6891a2b4..13f7dd0a 100644 --- a/app/Http/Web/Controllers/SearchController.php +++ b/app/Http/Web/Controllers/SearchController.php @@ -42,6 +42,14 @@ class SearchController extends Controller $this->view->setVar('pager', $pager); } + /** + * @Get("/form", name="web.search.form") + */ + public function formAction() + { + + } + /** * @param string $type * @return CourseSearchService|GroupSearchService|UserSearchService diff --git a/app/Http/Web/Services/Live.php b/app/Http/Web/Services/Live.php index 51981116..810252d6 100644 --- a/app/Http/Web/Services/Live.php +++ b/app/Http/Web/Services/Live.php @@ -34,7 +34,7 @@ class Live extends Service public function getStats($id) { - $chapter = $this->checkChapterCache($id); + $chapter = $this->checkChapter($id); Gateway::$registerAddress = $this->getRegisterAddress(); @@ -55,7 +55,7 @@ class Live extends Service { $clientId = $this->request->getPost('client_id'); - $chapter = $this->checkChapterCache($id); + $chapter = $this->checkChapter($id); $user = $this->getCurrentUser(); diff --git a/app/Http/Web/Views/error/show400.volt b/app/Http/Web/Views/error/show400.volt index c0dee182..b7dc4c3c 100644 --- a/app/Http/Web/Views/error/show400.volt +++ b/app/Http/Web/Views/error/show400.volt @@ -1,10 +1,10 @@ {% extends 'templates/error.volt' %} {% block content %} +
-
{{ flashSession.output() }}

4 @@ -14,4 +14,5 @@

+ {% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/error/show401.volt b/app/Http/Web/Views/error/show401.volt index b43c266d..cd322fbf 100644 --- a/app/Http/Web/Views/error/show401.volt +++ b/app/Http/Web/Views/error/show401.volt @@ -1,6 +1,7 @@ {% extends 'templates/error.volt' %} {% block content %} +
@@ -13,4 +14,5 @@
+ {% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/error/show403.volt b/app/Http/Web/Views/error/show403.volt index 913cb840..6a1dbbd3 100644 --- a/app/Http/Web/Views/error/show403.volt +++ b/app/Http/Web/Views/error/show403.volt @@ -1,6 +1,7 @@ {% extends 'templates/error.volt' %} {% block content %} +
@@ -13,4 +14,5 @@
+ {% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/error/show404.volt b/app/Http/Web/Views/error/show404.volt index aa1f5c55..b815f72a 100644 --- a/app/Http/Web/Views/error/show404.volt +++ b/app/Http/Web/Views/error/show404.volt @@ -1,6 +1,7 @@ {% extends 'templates/error.volt' %} {% block content %} +
@@ -13,4 +14,5 @@
+ {% endblock %} diff --git a/app/Http/Web/Views/error/show500.volt b/app/Http/Web/Views/error/show500.volt index 3a0fe52e..68580147 100644 --- a/app/Http/Web/Views/error/show500.volt +++ b/app/Http/Web/Views/error/show500.volt @@ -1,6 +1,7 @@ {% extends 'templates/error.volt' %} {% block content %} +
@@ -13,4 +14,5 @@
+ {% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/error/show503.volt b/app/Http/Web/Views/error/show503.volt index 6f77ba49..b3452e80 100644 --- a/app/Http/Web/Views/error/show503.volt +++ b/app/Http/Web/Views/error/show503.volt @@ -1,6 +1,7 @@ {% extends 'templates/error.volt' %} {% block content %} +
@@ -13,4 +14,5 @@
+ {% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/error/shutdown.volt b/app/Http/Web/Views/error/shutdown.volt new file mode 100644 index 00000000..0f2e95fd --- /dev/null +++ b/app/Http/Web/Views/error/shutdown.volt @@ -0,0 +1,17 @@ +{% extends 'templates/error.volt' %} + +{% block content %} +
+
+ +
{{ message }}
+
+

+ 5 + 0 + 3 +

+
+
+
+{% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/partials/header.volt b/app/Http/Web/Views/partials/header.volt index 47a0ef05..64f05d51 100644 --- a/app/Http/Web/Views/partials/header.volt +++ b/app/Http/Web/Views/partials/header.volt @@ -17,16 +17,17 @@ -{% set query = request.get('query',['trim','striptags'],'') %} -{% set type = request.get('type',['trim','string'],'course') %} +{% set s_type = request.get('type',['trim','string'],'course') %} +{% set s_query = request.get('query',['trim','striptags'],'') %} +{% set s_url = url({'for':'web.search.index'}) %}