diff --git a/.gitignore b/.gitignore index 924960c7..c1e37b3e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ /config/xs.course.ini /config/xs.article.ini /config/xs.question.ini -/config/xs.group.ini /config/xs.user.ini /config/alipay/*.crt /config/wxpay/*.pem diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ebb7d15..1a422486 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +### [v1.5.6](https://gitee.com/koogua/course-tencent-cloud/releases/v1.5.6)(2022-08-08) + +- 增加应用内命令行migrations +- 移除群组和微聊模块 +- kindeditor替换vditor - markdown转html + ### [v1.5.5](https://gitee.com/koogua/course-tencent-cloud/releases/v1.5.5)(2022-07-27) - 修正获分类查询条件 diff --git a/app/Builders/ImFriendUserList.php b/app/Builders/ImFriendUserList.php deleted file mode 100644 index 644dc2ec..00000000 --- a/app/Builders/ImFriendUserList.php +++ /dev/null @@ -1,51 +0,0 @@ -getFriends($relations); - - foreach ($relations as $key => $value) { - $relations[$key]['friend'] = $users[$value['friend_id']] ?? new \stdClass(); - } - - return $relations; - } - - public function getFriends(array $relations) - { - $ids = kg_array_column($relations, 'friend_id'); - - $userRepo = new UserRepo(); - - $columns = [ - 'id', 'name', 'avatar', 'title', 'about', 'vip', - 'gender', 'area', 'active_time', - ]; - - $users = $userRepo->findByIds($ids, $columns); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; - } - -} diff --git a/app/Builders/ImGroupList.php b/app/Builders/ImGroupList.php deleted file mode 100644 index 6b021c59..00000000 --- a/app/Builders/ImGroupList.php +++ /dev/null @@ -1,86 +0,0 @@ - $group) { - $groups[$key]['avatar'] = $baseUrl . $group['avatar']; - } - - return $groups; - } - - public function handleCourses(array $groups) - { - $courses = $this->getCourses($groups); - - foreach ($groups as $key => $group) { - $groups[$key]['course'] = $courses[$group['course_id']] ?? new \stdClass(); - } - - return $groups; - } - - public function handleUsers(array $groups) - { - $users = $this->getUsers($groups); - - foreach ($groups as $key => $group) { - $groups[$key]['owner'] = $users[$group['owner_id']] ?? new \stdClass(); - } - - return $groups; - } - - public function getCourses(array $groups) - { - $ids = kg_array_column($groups, 'course_id'); - - $courseRepo = new CourseRepo(); - - $courses = $courseRepo->findByIds($ids, ['id', 'title']); - - $result = []; - - foreach ($courses->toArray() as $course) { - $result[$course['id']] = $course; - } - - return $result; - } - - public function getUsers(array $groups) - { - $ids = kg_array_column($groups, 'owner_id'); - - $userRepo = new UserRepo(); - - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; - } - -} diff --git a/app/Builders/ImGroupUserList.php b/app/Builders/ImGroupUserList.php deleted file mode 100644 index 3827a619..00000000 --- a/app/Builders/ImGroupUserList.php +++ /dev/null @@ -1,105 +0,0 @@ -getGroups($relations); - - foreach ($relations as $key => $value) { - $relations[$key]['group'] = $groups[$value['group_id']] ?? new \stdClass(); - } - - return $relations; - } - - public function handleUsers(array $relations) - { - $users = $this->getUsers($relations); - - foreach ($relations as $key => $value) { - $relations[$key]['user'] = $users[$value['user_id']] ?? new \stdClass(); - } - - return $relations; - } - - public function getUsers(array $relations) - { - $ids = kg_array_column($relations, 'user_id'); - - $userRepo = new UserRepo(); - - $columns = ['id', 'name', 'avatar', 'title', 'about', 'vip', 'gender', 'area']; - - $users = $userRepo->findByIds($ids, $columns); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; - } - - public function getGroups(array $relations) - { - $ids = kg_array_column($relations, 'group_id'); - - $groupRepo = new ImGroupRepo(); - - $columns = ['id', 'type', 'name', 'avatar', 'about', 'owner_id', 'user_count', 'msg_count']; - - $groups = $groupRepo->findByIds($ids, $columns); - - $users = $this->getGroupOwners($groups->toArray()); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($groups->toArray() as $group) { - $group['avatar'] = $baseUrl . $group['avatar']; - $group['owner'] = $users[$group['owner_id']] ?? new \stdClass(); - unset($group['owner_id']); - $result[$group['id']] = $group; - } - - return $result; - } - - protected function getGroupOwners(array $groups) - { - $ids = kg_array_column($groups, 'owner_id'); - - $userRepo = new UserRepo(); - - $users = $userRepo->findByIds($ids, ['id', 'name']); - - $result = []; - - if ($users->count() > 0) { - foreach ($users->toArray() as $user) { - $result[$user['id']] = $user; - } - } - - return $result; - } - -} diff --git a/app/Builders/ImMessageList.php b/app/Builders/ImMessageList.php deleted file mode 100644 index 03fce797..00000000 --- a/app/Builders/ImMessageList.php +++ /dev/null @@ -1,46 +0,0 @@ -getSenders($messages); - - foreach ($messages as $key => $message) { - $messages[$key]['sender'] = $users[$message['sender_id']] ?? new \stdClass(); - } - - return $messages; - } - - public function getSenders(array $messages) - { - $ids = kg_array_column($messages, 'sender_id'); - - $userRepo = new UserRepo(); - - $users = $userRepo->findShallowUserByIds($ids); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; - } - -} diff --git a/app/Caches/ImActiveGroupList.php b/app/Caches/ImActiveGroupList.php deleted file mode 100644 index a91b3a2b..00000000 --- a/app/Caches/ImActiveGroupList.php +++ /dev/null @@ -1,89 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'im_active_group_list'; - } - - public function getContent($id = null) - { - $groups = $this->findGroups(); - - if (empty($groups)) return []; - - $result = []; - - foreach ($groups as $group) { - $result[] = [ - 'id' => $group->id, - 'type' => $group->type, - 'name' => $group->name, - 'avatar' => $group->avatar, - 'about' => $group->about, - 'user_count' => $group->user_count, - 'msg_count' => $group->msg_count, - ]; - } - - return $result; - } - - /** - * @param int $days - * @param int $limit - * @return ResultsetInterface|Resultset|UserModel[] - */ - protected function findGroups($days = 7, $limit = 12) - { - $result = []; - - $startTime = strtotime("-{$days} days"); - $endTime = time(); - - $rows = ImMessageModel::query() - ->columns(['receiver_id', 'total_count' => 'count(receiver_id)']) - ->groupBy('receiver_id') - ->orderBy('total_count DESC') - ->where('receiver_type = :type:', ['type' => ImMessageModel::TYPE_GROUP]) - ->betweenWhere('create_time', $startTime, $endTime) - ->andWhere('deleted = 0') - ->limit($limit) - ->execute(); - - if ($rows->count() > 0) { - - $ids = kg_array_column($rows->toArray(), 'receiver_id'); - - $groupRepo = new ImGroupRepo(); - - $result = $groupRepo->findByIds($ids); - } - - return $result; - } - -} diff --git a/app/Caches/ImActiveUserList.php b/app/Caches/ImActiveUserList.php deleted file mode 100644 index fde85a40..00000000 --- a/app/Caches/ImActiveUserList.php +++ /dev/null @@ -1,85 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'im_active_user_list'; - } - - public function getContent($id = null) - { - $users = $this->findUsers($id); - - if (empty($users)) return []; - - $result = []; - - foreach ($users as $user) { - $result[] = [ - 'id' => $user->id, - 'name' => $user->name, - 'avatar' => $user->avatar, - 'title' => $user->title, - 'about' => $user->about, - 'vip' => $user->vip, - ]; - } - - return $result; - } - - /** - * @param int $days - * @param int $limit - * @return ResultsetInterface|Resultset|UserModel[] - */ - protected function findUsers($days = 7, $limit = 12) - { - $result = []; - - $startTime = strtotime("-{$days} days"); - $endTime = time(); - - $rows = ImMessageModel::query() - ->columns(['sender_id', 'total_count' => 'count(sender_id)']) - ->groupBy('sender_id') - ->orderBy('total_count DESC') - ->betweenWhere('create_time', $startTime, $endTime) - ->limit($limit) - ->execute(); - - if ($rows->count() > 0) { - - $ids = kg_array_column($rows->toArray(), 'sender_id'); - - $userRepo = new UserRepo(); - - $result = $userRepo->findByIds($ids); - } - - return $result; - } - -} diff --git a/app/Caches/ImGroup.php b/app/Caches/ImGroup.php deleted file mode 100644 index ccd639c1..00000000 --- a/app/Caches/ImGroup.php +++ /dev/null @@ -1,36 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return "im_group:{$id}"; - } - - public function getContent($id = null) - { - $groupRepo = new ImGroupRepo(); - - $group = $groupRepo->findById($id); - - return $group ?: null; - } - -} diff --git a/app/Caches/ImGroupActiveUserList.php b/app/Caches/ImGroupActiveUserList.php deleted file mode 100644 index fef5169e..00000000 --- a/app/Caches/ImGroupActiveUserList.php +++ /dev/null @@ -1,88 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return "im_group_active_user_list:{$id}"; - } - - public function getContent($id = null) - { - $users = $this->findUsers($id); - - if (empty($users)) return []; - - $result = []; - - foreach ($users as $user) { - $result[] = [ - 'id' => $user->id, - 'name' => $user->name, - 'avatar' => $user->avatar, - 'title' => $user->title, - 'about' => $user->about, - 'vip' => $user->vip, - ]; - } - - return $result; - } - - /** - * @param int $groupId - * @param int $days - * @param int $limit - * @return ResultsetInterface|Resultset|UserModel[] - */ - protected function findUsers($groupId, $days = 7, $limit = 5) - { - $result = []; - - $startTime = strtotime("-{$days} days"); - $endTime = time(); - - $rows = ImMessageModel::query() - ->columns(['sender_id', 'total_count' => 'count(sender_id)']) - ->groupBy('sender_id') - ->orderBy('total_count DESC') - ->where('receiver_id = :group_id:', ['group_id' => $groupId]) - ->andWhere('receiver_type = :type:', ['type' => ImMessageModel::TYPE_GROUP]) - ->betweenWhere('create_time', $startTime, $endTime) - ->limit($limit) - ->execute(); - - if ($rows->count() > 0) { - - $ids = kg_array_column($rows->toArray(), 'sender_id'); - - $userRepo = new UserRepo(); - - $result = $userRepo->findByIds($ids); - } - - return $result; - } - -} diff --git a/app/Caches/ImNewGroupList.php b/app/Caches/ImNewGroupList.php deleted file mode 100644 index b76e0495..00000000 --- a/app/Caches/ImNewGroupList.php +++ /dev/null @@ -1,79 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'im_new_group_list'; - } - - public function getContent($id = null) - { - $limit = 12; - - $groups = $this->findGroups($limit); - - if ($groups->count() == 0) { - return []; - } - - return $this->handleContent($groups); - } - - /** - * @param ImGroupModel[] $groups - * @return array - */ - protected function handleContent($groups) - { - $result = []; - - foreach ($groups as $group) { - $result[] = [ - 'id' => $group->id, - 'type' => $group->type, - 'name' => $group->name, - 'avatar' => $group->avatar, - 'about' => $group->about, - 'user_count' => $group->user_count, - 'msg_count' => $group->msg_count, - ]; - } - - return $result; - } - - /** - * @param int $limit - * @return ResultsetInterface|Resultset|ImGroupModel[] - */ - public function findGroups($limit = 12) - { - return ImGroupModel::query() - ->where('published = 1') - ->andWhere('deleted = 0') - ->orderBy('id DESC') - ->limit($limit) - ->execute(); - } - -} diff --git a/app/Caches/ImNewUserList.php b/app/Caches/ImNewUserList.php deleted file mode 100644 index 85e9936e..00000000 --- a/app/Caches/ImNewUserList.php +++ /dev/null @@ -1,77 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'im_new_user_list'; - } - - public function getContent($id = null) - { - $limit = 12; - - $users = $this->findUsers($limit); - - if ($users->count() == 0) { - return []; - } - - return $this->handleContent($users); - } - - /** - * @param UserModel[] $users - * @return array - */ - protected function handleContent($users) - { - $result = []; - - foreach ($users as $user) { - $result[] = [ - 'id' => $user->id, - 'name' => $user->name, - 'avatar' => $user->avatar, - 'title' => $user->title, - 'about' => $user->about, - 'vip' => $user->vip, - ]; - } - - return $result; - } - - /** - * @param int $limit - * @return ResultsetInterface|Resultset|UserModel[] - */ - public function findUsers($limit = 12) - { - return UserModel::query() - ->where('deleted = 0') - ->orderBy('id DESC') - ->limit($limit) - ->execute(); - } - -} diff --git a/app/Caches/MaxImGroupId.php b/app/Caches/MaxImGroupId.php deleted file mode 100644 index c34bffa9..00000000 --- a/app/Caches/MaxImGroupId.php +++ /dev/null @@ -1,34 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'max_im_group_id'; - } - - public function getContent($id = null) - { - $group = ImGroupModel::findFirst(['order' => 'id DESC']); - - return $group->id ?? 0; - } - -} diff --git a/app/Caches/SiteGlobalStat.php b/app/Caches/SiteGlobalStat.php index 2e93c8a4..2d0e3d95 100644 --- a/app/Caches/SiteGlobalStat.php +++ b/app/Caches/SiteGlobalStat.php @@ -12,7 +12,6 @@ use App\Repos\Article as ArticleRepo; use App\Repos\Comment as CommentRepo; use App\Repos\Consult as ConsultRepo; use App\Repos\Course as CourseRepo; -use App\Repos\ImGroup as GroupRepo; use App\Repos\Package as PackageRepo; use App\Repos\Question as QuestionRepo; use App\Repos\Review as ReviewRepo; @@ -42,7 +41,6 @@ class SiteGlobalStat extends Cache $answerRepo = new AnswerRepo(); $commentRepo = new CommentRepo(); $consultRepo = new ConsultRepo(); - $groupRepo = new GroupRepo(); $packageRepo = new PackageRepo(); $reviewRepo = new ReviewRepo(); $topicRepo = new TopicRepo(); @@ -55,7 +53,6 @@ class SiteGlobalStat extends Cache 'answer_count' => $answerRepo->countAnswers(), 'comment_count' => $commentRepo->countComments(), 'consult_count' => $consultRepo->countConsults(), - 'group_count' => $groupRepo->countGroups(), 'vip_count' => $userRepo->countVipUsers(), 'package_count' => $packageRepo->countPackages(), 'review_count' => $reviewRepo->countReviews(), diff --git a/app/Console/Migrations/Migration.php b/app/Console/Migrations/Migration.php new file mode 100644 index 00000000..98d848d0 --- /dev/null +++ b/app/Console/Migrations/Migration.php @@ -0,0 +1,13 @@ +initMarkdownConverter(); + $this->courseMarkdownToHtml(); + $this->articleMarkdownToHtml(); + $this->questionMarkdownToHtml(); + $this->answerMarkdownToHtml(); + $this->pageMarkdownToHtml(); + $this->helpMarkdownToHtml(); + $this->pointGiftMarkdownToHtml(); + } + + protected function initMarkdownConverter() + { + $this->markdownConverter = new GithubFlavoredMarkdownConverter([ + 'html_input' => 'escape', + 'allow_unsafe_links' => false, + ]); + } + + protected function articleMarkdownToHtml() + { + /** + * @var $articles Resultset|ArticleModel[] + */ + $articles = ArticleModel::query()->execute(); + + if ($articles->count() == 0) return; + + foreach ($articles as $article) { + $content = $this->markdownConverter->convertToHtml($article->content); + $article->content = $content; + $article->update(); + } + } + + protected function courseMarkdownToHtml() + { + /** + * @var $courses Resultset|CourseModel[] + */ + $courses = CourseModel::query()->execute(); + + if ($courses->count() == 0) return; + + foreach ($courses as $course) { + $details = $this->markdownConverter->convertToHtml($course->details); + $course->details = $details; + $course->update(); + } + } + + protected function questionMarkdownToHtml() + { + /** + * @var $questions Resultset|QuestionModel[] + */ + $questions = QuestionModel::query()->execute(); + + if ($questions->count() == 0) return; + + foreach ($questions as $question) { + $content = $this->markdownConverter->convertToHtml($question->content); + $question->content = $content; + $question->update(); + } + } + + protected function answerMarkdownToHtml() + { + /** + * @var $answers Resultset|AnswerModel[] + */ + $answers = AnswerModel::query()->execute(); + + if ($answers->count() == 0) return; + + foreach ($answers as $answer) { + $content = $this->markdownConverter->convertToHtml($answer->content); + $answer->content = $content; + $answer->update(); + } + } + + protected function pageMarkdownToHtml() + { + /** + * @var $pages Resultset|PageModel[] + */ + $pages = PageModel::query()->execute(); + + if ($pages->count() == 0) return; + + foreach ($pages as $page) { + $content = $this->markdownConverter->convertToHtml($page->content); + $page->content = $content; + $page->update(); + } + } + + protected function helpMarkdownToHtml() + { + /** + * @var $helps Resultset|HelpModel[] + */ + $helps = HelpModel::query()->execute(); + + if ($helps->count() == 0) return; + + foreach ($helps as $help) { + $content = $this->markdownConverter->convertToHtml($help->content); + $help->content = $content; + $help->update(); + } + } + + protected function pointGiftMarkdownToHtml() + { + /** + * @var $gifts Resultset|PointGiftModel[] + */ + $gifts = PointGiftModel::query() + ->where('type = :type:', ['type' => PointGiftModel::TYPE_GOODS]) + ->execute(); + + if ($gifts->count() == 0) return; + + foreach ($gifts as $gift) { + $details = $this->markdownConverter->convertToHtml($gift->details); + $gift->details = $details; + $gift->update(); + } + } + +} \ No newline at end of file diff --git a/app/Console/Tasks/GroupIndexTask.php b/app/Console/Tasks/GroupIndexTask.php deleted file mode 100644 index cad23dbf..00000000 --- a/app/Console/Tasks/GroupIndexTask.php +++ /dev/null @@ -1,131 +0,0 @@ -searchGroups($query); - - var_export($result); - } - - /** - * 清空索引 - * - * @command: php console.php group_index clean - */ - public function cleanAction() - { - $this->cleanGroupIndex(); - } - - /** - * 重建索引 - * - * @command: php console.php group_index rebuild - */ - public function rebuildAction() - { - $this->rebuildGroupIndex(); - } - - /** - * 清空索引 - */ - protected function cleanGroupIndex() - { - $handler = new GroupSearcher(); - - $index = $handler->getXS()->getIndex(); - - echo '------ start clean group index ------' . PHP_EOL; - - $index->clean(); - - echo '------ end clean group index ------' . PHP_EOL; - } - - /** - * 重建索引 - */ - protected function rebuildGroupIndex() - { - $groups = $this->findGroups(); - - if ($groups->count() == 0) return; - - $handler = new GroupSearcher(); - - $documenter = new GroupDocument(); - - $index = $handler->getXS()->getIndex(); - - echo '------ start rebuild group index ------' . PHP_EOL; - - $index->beginRebuild(); - - foreach ($groups as $group) { - $document = $documenter->setDocument($group); - $index->add($document); - } - - $index->endRebuild(); - - echo '------ end rebuild group index ------' . PHP_EOL; - } - - /** - * 搜索课程 - * - * @param string $query - * @return array - * @throws \XSException - */ - protected function searchGroups($query) - { - $handler = new GroupSearcher(); - - return $handler->search($query); - } - - /** - * 查找课程 - * - * @return ResultsetInterface|Resultset|GroupModel[] - */ - protected function findGroups() - { - return GroupModel::query() - ->where('published = 1') - ->andWhere('deleted = 0') - ->execute(); - } - -} diff --git a/app/Console/Tasks/RefundTask.php b/app/Console/Tasks/RefundTask.php index 34fdd257..4ad651df 100644 --- a/app/Console/Tasks/RefundTask.php +++ b/app/Console/Tasks/RefundTask.php @@ -11,9 +11,7 @@ use App\Models\Order as OrderModel; use App\Models\Refund as RefundModel; use App\Models\Task as TaskModel; use App\Models\Trade as TradeModel; -use App\Repos\Course as CourseRepo; use App\Repos\CourseUser as CourseUserRepo; -use App\Repos\ImGroupUser as ImGroupUserRepo; use App\Repos\Order as OrderRepo; use App\Repos\Refund as RefundRepo; use App\Repos\Trade as TradeRepo; @@ -178,18 +176,6 @@ class RefundTask extends Task throw new \RuntimeException('Delete Course User Failed'); } } - - $courseRepo = new CourseRepo(); - $group = $courseRepo->findImGroup($order->item_id); - - $groupUserRepo = new ImGroupUserRepo(); - $groupUser = $groupUserRepo->findGroupUser($group->id, $order->owner_id); - - if ($groupUser) { - if ($groupUser->delete() === false) { - throw new \RuntimeException('Delete Group User Failed'); - } - } } /** @@ -200,8 +186,6 @@ class RefundTask extends Task protected function handlePackageOrderRefund(OrderModel $order) { $courseUserRepo = new CourseUserRepo(); - $groupUserRepo = new ImGroupUserRepo(); - $courseRepo = new CourseRepo(); $itemInfo = $order->item_info; @@ -215,15 +199,6 @@ class RefundTask extends Task throw new \RuntimeException('Delete Course User Failed'); } } - - $group = $courseRepo->findImGroup($course['id']); - $groupUser = $groupUserRepo->findGroupUser($group->id, $order->owner_id); - - if ($groupUser) { - if ($groupUser->delete() === false) { - throw new \RuntimeException('Delete Group User Failed'); - } - } } } diff --git a/app/Console/Tasks/SitemapTask.php b/app/Console/Tasks/SitemapTask.php index 8d7767e2..68ad4e29 100644 --- a/app/Console/Tasks/SitemapTask.php +++ b/app/Console/Tasks/SitemapTask.php @@ -11,7 +11,6 @@ use App\Library\Sitemap; use App\Models\Article as ArticleModel; use App\Models\Course as CourseModel; use App\Models\Help as HelpModel; -use App\Models\ImGroup as ImGroupModel; use App\Models\Page as PageModel; use App\Models\Question as QuestionModel; use App\Models\Topic as TopicModel; @@ -46,7 +45,6 @@ class SitemapTask extends Task $this->addQuestions(); $this->addTeachers(); $this->addTopics(); - $this->addImGroups(); $this->addHelps(); $this->addPages(); $this->addOthers(); @@ -155,21 +153,6 @@ class SitemapTask extends Task } } - protected function addImGroups() - { - /** - * @var Resultset|ImGroupModel[] $groups - */ - $groups = ImGroupModel::query()->where('published = 1')->execute(); - - if ($groups->count() == 0) return; - - foreach ($groups as $group) { - $loc = sprintf('%s/im/group/%s', $this->siteUrl, $group->id); - $this->sitemap->addItem($loc, 0.6); - } - } - protected function addPages() { /** @@ -203,7 +186,6 @@ class SitemapTask extends Task protected function addOthers() { $this->sitemap->addItem("{$this->siteUrl}/course/list", 0.6); - $this->sitemap->addItem("{$this->siteUrl}/im/group/list", 0.6); $this->sitemap->addItem("{$this->siteUrl}/teacher/list", 0.6); $this->sitemap->addItem("{$this->siteUrl}/vip", 0.6); $this->sitemap->addItem("{$this->siteUrl}/help", 0.6); diff --git a/app/Console/Tasks/SyncGroupIndexTask.php b/app/Console/Tasks/SyncGroupIndexTask.php deleted file mode 100644 index 7c2054be..00000000 --- a/app/Console/Tasks/SyncGroupIndexTask.php +++ /dev/null @@ -1,65 +0,0 @@ -getRedis(); - - $key = $this->getSyncKey(); - - $groupIds = $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(); - - $redis->sRem($key, ...$groupIds); - } - - protected function getSyncKey() - { - $sync = new GroupIndexSync(); - - return $sync->getSyncKey(); - } - -} diff --git a/app/Console/Tasks/UpgradeTask.php b/app/Console/Tasks/UpgradeTask.php index 47533f97..42a581ef 100644 --- a/app/Console/Tasks/UpgradeTask.php +++ b/app/Console/Tasks/UpgradeTask.php @@ -7,16 +7,20 @@ namespace App\Console\Tasks; +use App\Caches\AppInfo as AppInfoCache; use App\Caches\NavTreeList as NavTreeListCache; use App\Caches\Setting as SettingCache; -use App\Caches\AppInfo as AppInfoCache; +use App\Models\MigrationTask as MigrationTaskModel; use App\Models\Setting as SettingModel; +use Phalcon\Mvc\Model\Resultset; +use Phalcon\Mvc\Model\ResultsetInterface; class UpgradeTask extends Task { public function mainAction() { + $this->migrateAction(); $this->resetAppInfoAction(); $this->resetSettingAction(); $this->resetAnnotationAction(); @@ -25,6 +29,51 @@ class UpgradeTask extends Task $this->resetNavAction(); } + /** + * 执行迁移 + * + * @command: php console.php upgrade migrate + */ + public function migrateAction() + { + $tasks = $this->findMigrationTasks(); + + $versionList = []; + + if ($tasks->count() > 0) { + $versionList = kg_array_column($tasks->toArray(), 'version'); + } + + $files = scandir(app_path('Console/Migrations')); + + foreach ($files as $file) { + + if (preg_match('/^V[0-9]+\.php$/', $file)) { + + $version = substr($file, 0, -4); + + if (!in_array($version, $versionList)) { + + $startTime = time(); + + $className = "\App\Console\Migrations\\{$version}"; + $obj = new $className(); + $obj->run(); + + $endTime = time(); + + $task = new MigrationTaskModel(); + $task->version = $version; + $task->start_time = $startTime; + $task->end_time = $endTime; + $task->create(); + + echo "------ console migration {$version} ok ------" . PHP_EOL; + } + } + } + } + /** * 重置应用信息 * @@ -144,6 +193,14 @@ class UpgradeTask extends Task echo '------ end reset navigation ------' . PHP_EOL; } + /** + * @return ResultsetInterface|Resultset|MigrationTaskModel[] + */ + protected function findMigrationTasks() + { + return MigrationTaskModel::query()->execute(); + } + protected function handlePhKeys($keys) { return array_map(function ($key) { diff --git a/app/Http/Admin/Controllers/ImGroupController.php b/app/Http/Admin/Controllers/ImGroupController.php deleted file mode 100644 index e22e0086..00000000 --- a/app/Http/Admin/Controllers/ImGroupController.php +++ /dev/null @@ -1,155 +0,0 @@ -getGroup($id); - $pager = $service->getGroupUsers($id); - - $this->view->setVar('group', $group); - $this->view->setVar('pager', $pager); - } - - /** - * @Get("/list", name="admin.im_group.list") - */ - public function listAction() - { - $groupService = new ImGroupService(); - - $pager = $groupService->getGroups(); - - $this->view->setVar('pager', $pager); - } - - /** - * @Get("/search", name="admin.im_group.search") - */ - public function searchAction() - { - $groupService = new ImGroupService(); - - $types = $groupService->getGroupTypes(); - - $this->view->setVar('types', $types); - } - - /** - * @Get("/add", name="admin.im_group.add") - */ - public function addAction() - { - - } - - /** - * @Get("/{id:[0-9]+}/edit", name="admin.im_group.edit") - */ - public function editAction($id) - { - $groupService = new ImGroupService(); - - $group = $groupService->getGroup($id); - - $this->view->setVar('group', $group); - } - - /** - * @Post("/create", name="admin.im_group.create") - */ - public function createAction() - { - $groupService = new ImGroupService(); - - $group = $groupService->createGroup(); - - $location = $this->url->get([ - 'for' => 'admin.im_group.edit', - 'id' => $group->id, - ]); - - $content = [ - 'location' => $location, - 'msg' => '创建群组成功', - ]; - - return $this->jsonSuccess($content); - } - - /** - * @Post("/{id:[0-9]+}/update", name="admin.im_group.update") - */ - public function updateAction($id) - { - $groupService = new ImGroupService(); - - $groupService->updateGroup($id); - - $location = $this->url->get(['for' => 'admin.im_group.list']); - - $content = [ - 'location' => $location, - 'msg' => '更新群组成功', - ]; - - return $this->jsonSuccess($content); - } - - /** - * @Post("/{id:[0-9]+}/delete", name="admin.im_group.delete") - */ - public function deleteAction($id) - { - $groupService = new ImGroupService(); - - $groupService->deleteGroup($id); - - $location = $this->request->getHTTPReferer(); - - $content = [ - 'location' => $location, - 'msg' => '删除群组成功', - ]; - - return $this->jsonSuccess($content); - } - - /** - * @Post("/{id:[0-9]+}/restore", name="admin.im_group.restore") - */ - public function restoreAction($id) - { - $groupService = new ImGroupService(); - - $groupService->restoreGroup($id); - - $location = $this->request->getHTTPReferer(); - - $content = [ - 'location' => $location, - 'msg' => '还原群组成功', - ]; - - return $this->jsonSuccess($content); - } - -} diff --git a/app/Http/Admin/Controllers/ImGroupUserController.php b/app/Http/Admin/Controllers/ImGroupUserController.php deleted file mode 100644 index 3cb648d4..00000000 --- a/app/Http/Admin/Controllers/ImGroupUserController.php +++ /dev/null @@ -1,37 +0,0 @@ -deleteGroupUser(); - - $location = $this->request->getHTTPReferer(); - - $content = [ - 'location' => $location, - 'msg' => '删除成员成功', - ]; - - return $this->jsonSuccess($content); - } - -} diff --git a/app/Http/Admin/Controllers/SettingController.php b/app/Http/Admin/Controllers/SettingController.php index 90e144c7..03489cc3 100644 --- a/app/Http/Admin/Controllers/SettingController.php +++ b/app/Http/Admin/Controllers/SettingController.php @@ -301,33 +301,6 @@ class SettingController extends Controller } } - /** - * @Route("/im", name="admin.setting.im") - */ - public function imAction() - { - $settingService = new SettingService(); - - if ($this->request->isPost()) { - - $section = $this->request->getPost('section', 'string'); - - $data = $this->request->getPost(); - - $settingService->updateSettings($section, $data); - - return $this->jsonSuccess(['msg' => '更新配置成功']); - - } else { - - $main = $settingService->getSettings('im.main'); - $cs = $settingService->getSettings('im.cs'); - - $this->view->setVar('main', $main); - $this->view->setVar('cs', $cs); - } - } - /** * @Route("/oauth", name="admin.setting.oauth") */ diff --git a/app/Http/Admin/Services/AuthNode.php b/app/Http/Admin/Services/AuthNode.php index 274c3b5f..6df40868 100644 --- a/app/Http/Admin/Services/AuthNode.php +++ b/app/Http/Admin/Services/AuthNode.php @@ -1111,55 +1111,6 @@ class AuthNode extends Service ] ], ], - [ - 'id' => '4-3', - 'title' => '群组管理', - 'type' => 'menu', - 'children' => [ - [ - 'id' => '4-3-1', - 'title' => '群组列表', - 'type' => 'menu', - 'route' => 'admin.im_group.list', - ], - [ - 'id' => '4-3-2', - 'title' => '搜索群组', - 'type' => 'menu', - 'route' => 'admin.im_group.search', - ], - [ - 'id' => '4-3-3', - 'title' => '添加群组', - 'type' => 'menu', - 'route' => 'admin.im_group.add', - ], - [ - 'id' => '4-3-4', - 'title' => '编辑群组', - 'type' => 'button', - 'route' => 'admin.im_group.edit', - ], - [ - 'id' => '4-3-5', - 'title' => '删除群组', - 'type' => 'button', - 'route' => 'admin.im_group.delete', - ], - [ - 'id' => '4-3-6', - 'title' => '群员列表', - 'type' => 'button', - 'route' => 'admin.im_group.users', - ], - [ - 'id' => '4-3-7', - 'title' => '删除群员', - 'type' => 'button', - 'route' => 'admin.im_group_user.delete', - ], - ], - ], [ 'id' => '4-4', 'title' => '操作记录', @@ -1293,12 +1244,6 @@ class AuthNode extends Service 'title' => '其它配置', 'type' => 'menu', 'children' => [ - [ - 'id' => '5-4-1', - 'title' => '即时通讯', - 'type' => 'menu', - 'route' => 'admin.setting.im', - ], [ 'id' => '5-4-2', 'title' => '微信公众号', diff --git a/app/Http/Admin/Services/Course.php b/app/Http/Admin/Services/Course.php index e76d595e..cdd951f9 100644 --- a/app/Http/Admin/Services/Course.php +++ b/app/Http/Admin/Services/Course.php @@ -18,14 +18,12 @@ use App\Models\Course as CourseModel; use App\Models\CourseCategory as CourseCategoryModel; use App\Models\CourseRelated as CourseRelatedModel; use App\Models\CourseUser as CourseUserModel; -use App\Models\ImGroupUser as ImGroupUserModel; use App\Repos\Category as CategoryRepo; use App\Repos\Chapter as ChapterRepo; use App\Repos\Course as CourseRepo; use App\Repos\CourseCategory as CourseCategoryRepo; use App\Repos\CourseRelated as CourseRelatedRepo; use App\Repos\CourseUser as CourseUserRepo; -use App\Repos\ImGroup as ImGroupRepo; use App\Repos\User as UserRepo; use App\Services\Sync\CourseIndex as CourseIndexSync; use App\Validators\Course as CourseValidator; @@ -212,38 +210,28 @@ class Course extends Service $course->update($data); - $this->updateImGroup($course); - return $course; } public function deleteCourse($id) { $course = $this->findOrFail($id); + $course->deleted = 1; + $course->update(); - $groupRepo = new ImGroupRepo(); - - $group = $groupRepo->findByCourseId($course->id); - $group->deleted = 1; - $group->update(); - return $course; } public function restoreCourse($id) { $course = $this->findOrFail($id); + $course->deleted = 0; + $course->update(); - $groupRepo = new ImGroupRepo(); - - $group = $groupRepo->findByCourseId($course->id); - $group->deleted = 0; - $group->update(); - return $course; } @@ -590,36 +578,6 @@ class Course extends Service $cache->rebuild($course->id); } - protected function updateImGroup(CourseModel $course) - { - $groupRepo = new ImGroupRepo(); - - $group = $groupRepo->findByCourseId($course->id); - - $data = []; - - if ($course->title != $group->name) { - $data['name'] = $course->title; - } - - if ($course->published != $group->published) { - $data['published'] = $course->published; - } - - if ($course->teacher_id > 0 && $group->owner_id == 0) { - - $groupUser = new ImGroupUserModel(); - $groupUser->group_id = $group->id; - $groupUser->user_id = $course->teacher_id; - $groupUser->create(); - - $data['owner_id'] = $course->teacher_id; - $data['user_count'] = $group->user_count + 1; - } - - $group->update($data); - } - protected function handleCourses($pager) { if ($pager->total_items > 0) { diff --git a/app/Http/Admin/Services/ImGroup.php b/app/Http/Admin/Services/ImGroup.php deleted file mode 100644 index 3a9764ca..00000000 --- a/app/Http/Admin/Services/ImGroup.php +++ /dev/null @@ -1,226 +0,0 @@ -getParams(); - - $params['deleted'] = $params['deleted'] ?? 0; - - $sort = $pagerQuery->getSort(); - $page = $pagerQuery->getPage(); - $limit = $pagerQuery->getLimit(); - - $groupRepo = new ImGroupRepo(); - - $pager = $groupRepo->paginate($params, $sort, $page, $limit); - - return $this->handleGroups($pager); - } - - public function getGroup($id) - { - return $this->findOrFail($id); - } - - public function createGroup() - { - $post = $this->request->getPost(); - - $validator = new ImGroupValidator(); - - $data = []; - - $data['name'] = $validator->checkName($post['name']); - $data['about'] = $validator->checkAbout($post['about']); - $data['type'] = $validator->checkType($post['type']); - - $group = new ImGroupModel(); - - $group->create($data); - - return $group; - } - - public function updateGroup($id) - { - $group = $this->findOrFail($id); - - $post = $this->request->getPost(); - - $validator = new ImGroupValidator(); - - $data = []; - - if (isset($post['name'])) { - $data['name'] = $validator->checkName($post['name']); - } - - if (isset($post['about'])) { - $data['about'] = $validator->checkAbout($post['about']); - } - - if (isset($post['avatar'])) { - $data['avatar'] = $validator->checkAvatar($post['avatar']); - } - - if (isset($post['published'])) { - $data['published'] = $validator->checkPublishStatus($post['published']); - } - - if (isset($post['owner_id'])) { - $validator = new ImGroupUserValidator(); - $user = $validator->checkUser($post['owner_id']); - $data['owner_id'] = $user->id; - $this->handleGroupOwner($group, $user); - } - - $group->update($data); - - return $group; - } - - public function deleteGroup($id) - { - $group = $this->findOrFail($id); - - $group->deleted = 1; - - $group->update(); - - return $group; - } - - public function restoreGroup($id) - { - $group = $this->findOrFail($id); - - $group->deleted = 0; - - $group->update(); - - return $group; - } - - public function getGroupUsers($id) - { - $pagerQuery = new PagerQuery(); - - $params = $pagerQuery->getParams(); - - $params['group_id'] = $id; - - $sort = $pagerQuery->getSort(); - $page = $pagerQuery->getPage(); - $limit = $pagerQuery->getLimit(); - - $groupUserRepo = new ImGroupUserRepo(); - - $pager = $groupUserRepo->paginate($params, $sort, $page, $limit); - - return $this->handleGroupUsers($pager); - } - - protected function handleGroupUsers($pager) - { - if ($pager->total_items == 0) { - return $pager; - } - - $builder = new ImGroupUserListBuilder(); - - $stepA = $pager->items->toArray(); - $stepB = $builder->handleUsers($stepA); - - $pager->items = $stepB; - - return $pager; - } - - protected function handleGroupOwner(ImGroupModel $group, ImUserModel $user) - { - $repo = new ImGroupUserRepo(); - - $groupUser = $repo->findGroupUser($group->id, $user->id); - - if ($groupUser) return; - - $groupUser = new ImGroupUserModel(); - - $groupUser->group_id = $group->id; - $groupUser->user_id = $user->id; - - $groupUser->create(); - - $this->incrGroupUserCount($group); - - $this->incrUserGroupCount($user); - } - - protected function incrGroupUserCount(ImGroupModel $group) - { - $group->user_count += 1; - - $group->update(); - } - - protected function incrUserGroupCount(ImUserModel $user) - { - $user->group_count += 1; - - $user->update(); - } - - protected function handleGroups($pager) - { - if ($pager->total_items > 0) { - - $builder = new ImGroupListBuilder(); - - $items = $pager->items->toArray(); - - $pipeA = $builder->handleGroups($items); - $pipeB = $builder->handleUsers($pipeA); - $pipeC = $builder->objects($pipeB); - - $pager->items = $pipeC; - } - - return $pager; - } - - protected function findOrFail($id) - { - $validator = new ImGroupValidator(); - - return $validator->checkGroup($id); - } - -} diff --git a/app/Http/Admin/Services/ImGroupUser.php b/app/Http/Admin/Services/ImGroupUser.php deleted file mode 100644 index c1e79ac5..00000000 --- a/app/Http/Admin/Services/ImGroupUser.php +++ /dev/null @@ -1,60 +0,0 @@ -request->getQuery('group_id', 'int', 0); - $userId = $this->request->getQuery('user_id', 'int', 0); - - $validator = new ImGroupUserValidator(); - - $group = $validator->checkGroup($groupId); - $user = $validator->checkUser($userId); - - $validator->checkIfAllowDelete($groupId, $userId); - - $groupUser = $this->findOrFail($groupId, $userId); - - $groupUser->delete(); - - $this->decrGroupUserCount($group); - $this->decrUserGroupCount($user); - } - - protected function decrGroupUserCount(ImGroupModel $group) - { - if ($group->user_count > 0) { - $group->user_count -= 1; - $group->update(); - } - } - - protected function decrUserGroupCount(ImUserModel $user) - { - if ($user->group_count > 0) { - $user->group_count -= 1; - $user->update(); - } - } - - protected function findOrFail($groupId, $userId) - { - $validator = new ImGroupUserValidator(); - - return $validator->checkGroupUser($groupId, $userId); - } - -} diff --git a/app/Http/Admin/Services/Student.php b/app/Http/Admin/Services/Student.php index a89fcc4c..d583d320 100644 --- a/app/Http/Admin/Services/Student.php +++ b/app/Http/Admin/Services/Student.php @@ -10,13 +10,9 @@ namespace App\Http\Admin\Services; use App\Builders\CourseUserList as CourseUserListBuilder; use App\Builders\LearningList as LearningListBuilder; use App\Library\Paginator\Query as PagerQuery; -use App\Models\Course as CourseModel; use App\Models\CourseUser as CourseUserModel; -use App\Models\ImGroupUser as ImGroupUserModel; -use App\Models\User as UserModel; use App\Repos\Course as CourseRepo; use App\Repos\CourseUser as CourseUserRepo; -use App\Repos\ImGroupUser as ImGroupUserRepo; use App\Repos\Learning as LearningRepo; use App\Repos\User as UserRepo; use App\Validators\CourseUser as CourseUserValidator; @@ -159,8 +155,6 @@ class Student extends Service $user->course_count += 1; $user->update(); - $this->handleImGroupUser($course, $user); - return $courseUser; } @@ -183,35 +177,6 @@ class Student extends Service return $relation; } - protected function handleImGroupUser(CourseModel $course, UserModel $user) - { - $courseRepo = new CourseRepo(); - - $imGroup = $courseRepo->findImGroup($course->id); - - $userRepo = new UserRepo(); - - $imUser = $userRepo->findImUser($user->id); - - $imGroupUserRepo = new ImGroupUserRepo(); - - $imGroupUser = $imGroupUserRepo->findGroupUser($imGroup->id, $user->id); - - if ($imGroupUser) return; - - $imGroupUser = new ImGroupUserModel(); - - $imGroupUser->group_id = $imGroup->id; - $imGroupUser->user_id = $imUser->id; - $imGroupUser->create(); - - $imUser->group_count += 1; - $imUser->update(); - - $imGroup->user_count += 1; - $imGroup->update(); - } - protected function findOrFail($id) { $validator = new CourseUserValidator(); diff --git a/app/Http/Admin/Views/answer/add.volt b/app/Http/Admin/Views/answer/add.volt index a079013f..c75f39bb 100644 --- a/app/Http/Admin/Views/answer/add.volt +++ b/app/Http/Admin/Views/answer/add.volt @@ -13,8 +13,7 @@