From 138b9d45cec340c19073e628e120ab833eabd036 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Mon, 28 Aug 2023 15:55:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=B8=B8=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Migrations/V20230817240809.php | 58 +++++++++ app/Http/Admin/Controllers/PageController.php | 2 +- app/Http/Admin/Services/Article.php | 110 +++++++++++------- app/Http/Admin/Services/Chapter.php | 26 ++--- app/Http/Admin/Services/Course.php | 28 +++++ app/Http/Admin/Services/FlashSale.php | 45 ++++--- app/Http/Admin/Services/Help.php | 26 +++-- app/Http/Admin/Services/Package.php | 14 +-- app/Http/Admin/Services/Page.php | 16 +++ app/Http/Admin/Services/PointGift.php | 30 +++-- app/Http/Admin/Services/Question.php | 107 ++++++++++------- app/Http/Admin/Services/Resource.php | 48 ++++---- app/Http/Admin/Services/Slide.php | 10 +- app/Http/Admin/Services/Topic.php | 14 +-- app/Http/Admin/Services/User.php | 23 ++++ app/Http/Admin/Views/topic/edit.volt | 56 +++------ app/Http/Admin/Views/topic/edit_basic.volt | 38 ++++++ app/Http/Admin/Views/topic/edit_course.volt | 15 +++ app/Http/Admin/Views/user/search.volt | 8 +- .../Controllers/UserConsoleController.php | 29 ----- app/Services/Logic/Course/ResourceList.php | 75 ++++++++++++ .../Logic/User/Console/FavoriteList.php | 2 + app/Validators/Account.php | 18 ++- config/errors.php | 1 - db/migrations/20230816234130.php | 37 ++++++ 25 files changed, 596 insertions(+), 240 deletions(-) create mode 100644 app/Console/Migrations/V20230817240809.php create mode 100644 app/Http/Admin/Views/topic/edit_basic.volt create mode 100644 app/Http/Admin/Views/topic/edit_course.volt create mode 100644 app/Services/Logic/Course/ResourceList.php create mode 100644 db/migrations/20230816234130.php diff --git a/app/Console/Migrations/V20230817240809.php b/app/Console/Migrations/V20230817240809.php new file mode 100644 index 00000000..0da4357b --- /dev/null +++ b/app/Console/Migrations/V20230817240809.php @@ -0,0 +1,58 @@ +handleCourseResourceCount(); + } + + protected function handleCourseResourceCount() + { + $courses = CourseModel::find(); + + if ($courses->count() == 0) return; + + foreach ($courses as $course) { + if ($course->resource_count > 0) { + $this->recountCourseResources($course); + } + } + } + + protected function recountCourseResources(CourseModel $course) + { + $courseRepo = new CourseRepo(); + + $lessons = $courseRepo->findLessons($course->id); + + $chapterRepo = new ChapterRepo(); + + $resourceCount = 0; + + if ($lessons->count() > 0) { + foreach ($lessons as $lesson) { + if ($lesson->deleted == 0) { + $resourceCount += $chapterRepo->countResources($lesson->id); + } + } + } + + $course->resource_count = $resourceCount; + + $course->update(); + } + +} \ No newline at end of file diff --git a/app/Http/Admin/Controllers/PageController.php b/app/Http/Admin/Controllers/PageController.php index 5c992574..26a0c82b 100644 --- a/app/Http/Admin/Controllers/PageController.php +++ b/app/Http/Admin/Controllers/PageController.php @@ -59,7 +59,7 @@ class PageController extends Controller */ public function editAction($id) { - $pageService = new PageService; + $pageService = new PageService(); $page = $pageService->getPage($id); diff --git a/app/Http/Admin/Services/Article.php b/app/Http/Admin/Services/Article.php index 368dc2cb..42cc02a1 100644 --- a/app/Http/Admin/Services/Article.php +++ b/app/Http/Admin/Services/Article.php @@ -9,6 +9,7 @@ namespace App\Http\Admin\Services; use App\Builders\ArticleList as ArticleListBuilder; use App\Builders\ReportList as ReportListBuilder; +use App\Caches\Article as ArticleCache; use App\Library\Paginator\Query as PagerQuery; use App\Library\Utils\Word as WordUtil; use App\Models\Article as ArticleModel; @@ -26,6 +27,7 @@ use App\Services\Logic\Article\XmTagList as XmTagListService; use App\Services\Logic\Notice\Internal\ArticleApproved as ArticleApprovedNotice; use App\Services\Logic\Notice\Internal\ArticleRejected as ArticleRejectedNotice; use App\Services\Logic\Point\History\ArticlePost as ArticlePostPointHistory; +use App\Services\Sync\ArticleIndex as ArticleIndexSync; use App\Validators\Article as ArticleValidator; class Article extends Service @@ -140,7 +142,8 @@ class Article extends Service $article->create(); $this->saveDynamicAttrs($article); - + $this->rebuildArticleCache($article); + $this->rebuildArticleIndex($article); $this->recountUserArticles($user); $this->eventsManager->fire('Article:afterCreate', $this, $article); @@ -205,10 +208,11 @@ class Article extends Service $article->update($data); - $this->saveDynamicAttrs($article); - $owner = $this->findUser($article->owner_id); + $this->saveDynamicAttrs($article); + $this->rebuildArticleCache($article); + $this->rebuildArticleIndex($article); $this->recountUserArticles($owner); $this->eventsManager->fire('Article:afterUpdate', $this, $article); @@ -224,10 +228,11 @@ class Article extends Service $article->update(); - $this->saveDynamicAttrs($article); - $owner = $this->findUser($article->owner_id); + $this->saveDynamicAttrs($article); + $this->rebuildArticleCache($article); + $this->rebuildArticleIndex($article); $this->recountUserArticles($owner); $this->eventsManager->fire('Article:afterDelete', $this, $article); @@ -243,10 +248,11 @@ class Article extends Service $article->update(); - $this->saveDynamicAttrs($article); - $owner = $this->findUser($article->owner_id); + $this->saveDynamicAttrs($article); + $this->rebuildArticleCache($article); + $this->rebuildArticleIndex($article); $this->recountUserArticles($owner); $this->eventsManager->fire('Article:afterRestore', $this, $article); @@ -278,6 +284,8 @@ class Article extends Service $owner = $this->findUser($article->owner_id); + $this->rebuildArticleCache($article); + $this->rebuildArticleIndex($article); $this->recountUserArticles($owner); $sender = $this->getLoginUser(); @@ -331,6 +339,12 @@ class Article extends Service } $article->update(); + + $owner = $this->findUser($article->owner_id); + + $this->rebuildArticleCache($article); + $this->rebuildArticleIndex($article); + $this->recountUserArticles($owner); } protected function findOrFail($id) @@ -347,6 +361,54 @@ class Article extends Service return $userRepo->findById($id); } + protected function rebuildArticleCache(ArticleModel $article) + { + $cache = new ArticleCache(); + + $cache->rebuild($article->id); + } + + protected function rebuildArticleIndex(ArticleModel $article) + { + $sync = new ArticleIndexSync(); + + $sync->addItem($article->id); + } + + protected function recountUserArticles(UserModel $user) + { + $userRepo = new UserRepo(); + + $articleCount = $userRepo->countArticles($user->id); + + $user->article_count = $articleCount; + + $user->update(); + } + + protected function handleArticlePostPoint(ArticleModel $article) + { + if ($article->published != ArticleModel::PUBLISH_APPROVED) return; + + $service = new ArticlePostPointHistory(); + + $service->handle($article); + } + + protected function handleArticleApprovedNotice(ArticleModel $article, UserModel $sender) + { + $notice = new ArticleApprovedNotice(); + + $notice->handle($article, $sender); + } + + protected function handleArticleRejectedNotice(ArticleModel $article, UserModel $sender, $reason) + { + $notice = new ArticleRejectedNotice(); + + $notice->handle($article, $sender, $reason); + } + protected function handleArticles($pager) { if ($pager->total_items > 0) { @@ -383,38 +445,4 @@ class Article extends Service return $pager; } - protected function recountUserArticles(UserModel $user) - { - $userRepo = new UserRepo(); - - $articleCount = $userRepo->countArticles($user->id); - - $user->article_count = $articleCount; - - $user->update(); - } - - protected function handleArticlePostPoint(ArticleModel $article) - { - if ($article->published != ArticleModel::PUBLISH_APPROVED) return; - - $service = new ArticlePostPointHistory(); - - $service->handle($article); - } - - protected function handleArticleApprovedNotice(ArticleModel $article, UserModel $sender) - { - $notice = new ArticleApprovedNotice(); - - $notice->handle($article, $sender); - } - - protected function handleArticleRejectedNotice(ArticleModel $article, UserModel $sender, $reason) - { - $notice = new ArticleRejectedNotice(); - - $notice->handle($article, $sender, $reason); - } - } diff --git a/app/Http/Admin/Services/Chapter.php b/app/Http/Admin/Services/Chapter.php index 93c19241..ef5aaa94 100644 --- a/app/Http/Admin/Services/Chapter.php +++ b/app/Http/Admin/Services/Chapter.php @@ -103,8 +103,9 @@ class Chapter extends Service $this->db->commit(); $this->updateChapterStats($chapter); - $this->updateCourseStat($chapter); + $this->rebuildCatalogCache($chapter); + $this->rebuildChapterCache($chapter); return $chapter; @@ -160,10 +161,9 @@ class Chapter extends Service $chapter->update($data); $this->updateChapterStats($chapter); - $this->updateCourseStat($chapter); - $this->rebuildCatalogCache($chapter); + $this->rebuildChapterCache($chapter); return $chapter; } @@ -181,10 +181,9 @@ class Chapter extends Service $chapter->update(); $this->updateChapterStats($chapter); - $this->updateCourseStat($chapter); - $this->rebuildCatalogCache($chapter); + $this->rebuildChapterCache($chapter); return $chapter; } @@ -198,14 +197,20 @@ class Chapter extends Service $chapter->update(); $this->updateChapterStats($chapter); - $this->updateCourseStat($chapter); - $this->rebuildCatalogCache($chapter); + $this->rebuildChapterCache($chapter); return $chapter; } + protected function findOrFail($id) + { + $validator = new ChapterValidator(); + + return $validator->checkChapter($id); + } + protected function updateChapterStats(ChapterModel $chapter) { $chapterRepo = new ChapterRepo(); @@ -254,11 +259,4 @@ class Chapter extends Service $cache->rebuild($chapter->course_id); } - protected function findOrFail($id) - { - $validator = new ChapterValidator(); - - return $validator->checkChapter($id); - } - } diff --git a/app/Http/Admin/Services/Course.php b/app/Http/Admin/Services/Course.php index e3f20997..7a53da9c 100644 --- a/app/Http/Admin/Services/Course.php +++ b/app/Http/Admin/Services/Course.php @@ -8,6 +8,7 @@ namespace App\Http\Admin\Services; use App\Builders\CourseList as CourseListBuilder; +use App\Caches\Course as CourseCache; use App\Caches\CourseCategoryList as CourseCategoryListCache; use App\Caches\CourseRelatedList as CourseRelatedListCache; use App\Caches\CourseTeacherList as CourseTeacherListCache; @@ -24,6 +25,7 @@ use App\Repos\CourseCategory as CourseCategoryRepo; use App\Repos\CourseRelated as CourseRelatedRepo; use App\Repos\CourseUser as CourseUserRepo; use App\Repos\User as UserRepo; +use App\Services\Sync\CourseIndex as CourseIndexSync; use App\Validators\Course as CourseValidator; use App\Validators\CourseOffline as CourseOfflineValidator; @@ -86,6 +88,9 @@ class Course extends Service $this->db->commit(); + $this->rebuildCourseCache($course); + $this->rebuildCourseIndex($course); + return $course; } catch (\Exception $e) { @@ -208,6 +213,9 @@ class Course extends Service $course->update($data); + $this->rebuildCourseCache($course); + $this->rebuildCourseIndex($course); + return $course; } @@ -219,6 +227,9 @@ class Course extends Service $course->update(); + $this->rebuildCourseCache($course); + $this->rebuildCourseIndex($course); + return $course; } @@ -230,6 +241,9 @@ class Course extends Service $course->update(); + $this->rebuildCourseCache($course); + $this->rebuildCourseIndex($course); + return $course; } @@ -562,6 +576,20 @@ class Course extends Service $cache->rebuild($course->id); } + protected function rebuildCourseCache(CourseModel $course) + { + $cache = new CourseCache(); + + $cache->rebuild($course->id); + } + + protected function rebuildCourseIndex(CourseModel $course) + { + $sync = new CourseIndexSync(); + + $sync->addItem($course->id); + } + protected function handleCourses($pager) { if ($pager->total_items > 0) { diff --git a/app/Http/Admin/Services/FlashSale.php b/app/Http/Admin/Services/FlashSale.php index 45c0ad8e..b903a6c6 100644 --- a/app/Http/Admin/Services/FlashSale.php +++ b/app/Http/Admin/Services/FlashSale.php @@ -7,6 +7,7 @@ namespace App\Http\Admin\Services; +use App\Caches\FlashSale as FlashSaleCache; use App\Library\Paginator\Query as PagerQuery; use App\Models\Course as CourseModel; use App\Models\FlashSale as FlashSaleModel; @@ -157,6 +158,8 @@ class FlashSale extends Service break; } + $this->rebuildFlashSaleCache($sale); + return $sale; } @@ -198,7 +201,8 @@ class FlashSale extends Service $sale->update($data); - $this->initFlashSaleQueue($sale->id); + $this->initFlashSaleQueue($sale); + $this->rebuildFlashSaleCache($sale); return $sale; } @@ -211,6 +215,8 @@ class FlashSale extends Service $sale->update(); + $this->rebuildFlashSaleCache($sale); + return $sale; } @@ -222,9 +228,32 @@ class FlashSale extends Service $sale->update(); + $this->rebuildFlashSaleCache($sale); + return $sale; } + protected function findOrFail($id) + { + $validator = new FlashSaleValidator(); + + return $validator->checkFlashSale($id); + } + + protected function initFlashSaleQueue(FlashSaleModel $sale) + { + $queue = new FlashSaleQueue(); + + $queue->init($sale->id); + } + + protected function rebuildFlashSaleCache(FlashSaleModel $sale) + { + $cache = new FlashSaleCache(); + + $cache->rebuild($sale->id); + } + protected function createCourseFlashSale($post) { $validator = new FlashSaleValidator(); @@ -348,18 +377,4 @@ class FlashSale extends Service return $result; } - protected function initFlashSaleQueue($id) - { - $queue = new FlashSaleQueue(); - - $queue->init($id); - } - - protected function findOrFail($id) - { - $validator = new FlashSaleValidator(); - - return $validator->checkFlashSale($id); - } - } diff --git a/app/Http/Admin/Services/Help.php b/app/Http/Admin/Services/Help.php index 1cdbddf1..4fb16999 100644 --- a/app/Http/Admin/Services/Help.php +++ b/app/Http/Admin/Services/Help.php @@ -8,6 +8,7 @@ namespace App\Http\Admin\Services; use App\Builders\HelpList as HelpListBuilder; +use App\Caches\Help as HelpCache; use App\Caches\HelpList as HelpListCache; use App\Models\Category as CategoryModel; use App\Models\Help as HelpModel; @@ -75,6 +76,7 @@ class Help extends Service $help->create($data); + $this->rebuildHelpCache($help); $this->rebuildHelpListCache(); return $help; @@ -117,6 +119,7 @@ class Help extends Service $help->update($data); + $this->rebuildHelpCache($help); $this->rebuildHelpListCache(); return $help; @@ -130,6 +133,7 @@ class Help extends Service $help->update(); + $this->rebuildHelpCache($help); $this->rebuildHelpListCache(); return $help; @@ -143,18 +147,12 @@ class Help extends Service $help->update(); + $this->rebuildHelpCache($help); $this->rebuildHelpListCache(); return $help; } - protected function rebuildHelpListCache() - { - $cache = new HelpListCache(); - - $cache->rebuild(); - } - protected function findOrFail($id) { $validator = new HelpValidator(); @@ -162,6 +160,20 @@ class Help extends Service return $validator->checkHelp($id); } + protected function rebuildHelpCache(HelpModel $help) + { + $cache = new HelpCache(); + + $cache->rebuild($help->id); + } + + protected function rebuildHelpListCache() + { + $cache = new HelpListCache(); + + $cache->rebuild(); + } + /** * @param Resultset $helps * @return array|object diff --git a/app/Http/Admin/Services/Package.php b/app/Http/Admin/Services/Package.php index 4cc1d666..ce8552b0 100644 --- a/app/Http/Admin/Services/Package.php +++ b/app/Http/Admin/Services/Package.php @@ -186,6 +186,13 @@ class Package extends Service return $package; } + protected function findOrFail($id) + { + $validator = new PackageValidator(); + + return $validator->checkPackage($id); + } + protected function saveCourses(PackageModel $package, $courseIds) { $packageRepo = new PackageRepo(); @@ -297,11 +304,4 @@ class Package extends Service $course->update(); } - protected function findOrFail($id) - { - $validator = new PackageValidator(); - - return $validator->checkPackage($id); - } - } diff --git a/app/Http/Admin/Services/Page.php b/app/Http/Admin/Services/Page.php index 3ed047c3..4684f8bb 100644 --- a/app/Http/Admin/Services/Page.php +++ b/app/Http/Admin/Services/Page.php @@ -7,6 +7,7 @@ namespace App\Http\Admin\Services; +use App\Caches\Page as PageCache; use App\Library\Paginator\Query as PagerQuery; use App\Models\Page as PageModel; use App\Repos\Page as PageRepo; @@ -52,6 +53,8 @@ class Page extends Service $page->create($data); + $this->rebuildPageCache($page); + return $page; } @@ -93,6 +96,8 @@ class Page extends Service $page->update($data); + $this->rebuildPageCache($page); + return $page; } @@ -104,6 +109,8 @@ class Page extends Service $page->update(); + $this->rebuildPageCache($page); + return $page; } @@ -115,6 +122,8 @@ class Page extends Service $page->update(); + $this->rebuildPageCache($page); + return $page; } @@ -125,4 +134,11 @@ class Page extends Service return $validator->checkPage($id); } + protected function rebuildPageCache(PageModel $page) + { + $cache = new PageCache(); + + $cache->rebuild($page->id); + } + } diff --git a/app/Http/Admin/Services/PointGift.php b/app/Http/Admin/Services/PointGift.php index 5b929c02..545092c8 100644 --- a/app/Http/Admin/Services/PointGift.php +++ b/app/Http/Admin/Services/PointGift.php @@ -7,6 +7,7 @@ namespace App\Http\Admin\Services; +use App\Caches\PointGift as PointGiftCache; use App\Library\Paginator\Query as PagerQuery; use App\Models\PointGift as PointGiftModel; use App\Repos\Course as CourseRepo; @@ -115,6 +116,8 @@ class PointGift extends Service break; } + $this->rebuildPointGiftCache($gift); + return $gift; } @@ -162,6 +165,8 @@ class PointGift extends Service $gift->update($data); + $this->rebuildPointGiftCache($gift); + return $gift; } @@ -173,6 +178,8 @@ class PointGift extends Service $gift->update(); + $this->rebuildPointGiftCache($gift); + return $gift; } @@ -184,9 +191,25 @@ class PointGift extends Service $gift->update(); + $this->rebuildPointGiftCache($gift); + return $gift; } + protected function findOrFail($id) + { + $validator = new PointGiftValidator(); + + return $validator->checkPointGift($id); + } + + protected function rebuildPointGiftCache(PointGiftModel $gift) + { + $cache = new PointGiftCache(); + + $cache->rebuild($gift->id); + } + protected function createCoursePointGift($post) { $validator = new PointGiftValidator(); @@ -257,11 +280,4 @@ class PointGift extends Service return $gift; } - protected function findOrFail($id) - { - $validator = new PointGiftValidator(); - - return $validator->checkPointGift($id); - } - } diff --git a/app/Http/Admin/Services/Question.php b/app/Http/Admin/Services/Question.php index 44a456ef..ad1450b7 100644 --- a/app/Http/Admin/Services/Question.php +++ b/app/Http/Admin/Services/Question.php @@ -9,6 +9,7 @@ namespace App\Http\Admin\Services; use App\Builders\QuestionList as QuestionListBuilder; use App\Builders\ReportList as ReportListBuilder; +use App\Caches\Question as QuestionCache; use App\Library\Paginator\Query as PagerQuery; use App\Models\Category as CategoryModel; use App\Models\Question as QuestionModel; @@ -25,6 +26,7 @@ use App\Services\Logic\Point\History\QuestionPost as QuestionPostPointHistory; use App\Services\Logic\Question\QuestionDataTrait; use App\Services\Logic\Question\QuestionInfo as QuestionInfoService; use App\Services\Logic\Question\XmTagList as XmTagListService; +use App\Services\Sync\QuestionIndex as QuestionIndexSync; use App\Validators\Question as QuestionValidator; class Question extends Service @@ -134,7 +136,8 @@ class Question extends Service $question->create(); $this->saveDynamicAttrs($question); - + $this->rebuildQuestionCache($question); + $this->rebuildQuestionIndex($question); $this->recountUserQuestions($user); $this->eventsManager->fire('Question:afterCreate', $this, $question); @@ -187,10 +190,11 @@ class Question extends Service $question->update($data); - $this->saveDynamicAttrs($question); - $owner = $this->findUser($question->owner_id); + $this->saveDynamicAttrs($question); + $this->rebuildQuestionCache($question); + $this->rebuildQuestionIndex($question); $this->recountUserQuestions($owner); $this->eventsManager->fire('Question:afterUpdate', $this, $question); @@ -206,10 +210,11 @@ class Question extends Service $question->update(); - $this->saveDynamicAttrs($question); - $owner = $this->findUser($question->owner_id); + $this->saveDynamicAttrs($question); + $this->rebuildQuestionCache($question); + $this->rebuildQuestionIndex($question); $this->recountUserQuestions($owner); $this->eventsManager->fire('Question:afterDelete', $this, $question); @@ -227,6 +232,8 @@ class Question extends Service $owner = $this->findUser($question->owner_id); + $this->rebuildQuestionCache($question); + $this->rebuildQuestionIndex($question); $this->recountUserQuestions($owner); $this->eventsManager->fire('Question:afterRestore', $this, $question); @@ -254,6 +261,8 @@ class Question extends Service $owner = $this->findUser($question->owner_id); + $this->rebuildQuestionCache($question); + $this->rebuildQuestionIndex($question); $this->recountUserQuestions($owner); $sender = $this->getLoginUser(); @@ -307,6 +316,12 @@ class Question extends Service } $question->update(); + + $owner = $this->findUser($question->owner_id); + + $this->rebuildQuestionCache($question); + $this->rebuildQuestionIndex($question); + $this->recountUserQuestions($owner); } protected function findOrFail($id) @@ -323,6 +338,54 @@ class Question extends Service return $userRepo->findById($id); } + protected function rebuildQuestionCache(QuestionModel $question) + { + $cache = new QuestionCache(); + + $cache->rebuild($question->id); + } + + protected function rebuildQuestionIndex(QuestionModel $question) + { + $sync = new QuestionIndexSync(); + + $sync->addItem($question->id); + } + + protected function recountUserQuestions(UserModel $user) + { + $userRepo = new UserRepo(); + + $questionCount = $userRepo->countQuestions($user->id); + + $user->question_count = $questionCount; + + $user->update(); + } + + protected function handleQuestionPostPoint(QuestionModel $question) + { + if ($question->published != QuestionModel::PUBLISH_APPROVED) return; + + $service = new QuestionPostPointHistory(); + + $service->handle($question); + } + + protected function handleQuestionApprovedNotice(QuestionModel $question, UserModel $sender) + { + $notice = new QuestionApprovedNotice(); + + $notice->handle($question, $sender); + } + + protected function handleQuestionRejectedNotice(QuestionModel $question, UserModel $sender, $reason) + { + $notice = new QuestionRejectedNotice(); + + $notice->handle($question, $sender, $reason); + } + protected function handleQuestions($pager) { if ($pager->total_items > 0) { @@ -359,38 +422,4 @@ class Question extends Service return $pager; } - protected function recountUserQuestions(UserModel $user) - { - $userRepo = new UserRepo(); - - $questionCount = $userRepo->countQuestions($user->id); - - $user->question_count = $questionCount; - - $user->update(); - } - - protected function handleQuestionPostPoint(QuestionModel $question) - { - if ($question->published != QuestionModel::PUBLISH_APPROVED) return; - - $service = new QuestionPostPointHistory(); - - $service->handle($question); - } - - protected function handleQuestionApprovedNotice(QuestionModel $question, UserModel $sender) - { - $notice = new QuestionApprovedNotice(); - - $notice->handle($question, $sender); - } - - protected function handleQuestionRejectedNotice(QuestionModel $question, UserModel $sender, $reason) - { - $notice = new QuestionRejectedNotice(); - - $notice->handle($question, $sender, $reason); - } - } diff --git a/app/Http/Admin/Services/Resource.php b/app/Http/Admin/Services/Resource.php index 3303d8fe..793a2154 100644 --- a/app/Http/Admin/Services/Resource.php +++ b/app/Http/Admin/Services/Resource.php @@ -13,8 +13,6 @@ use App\Models\Resource as ResourceModel; use App\Models\Upload as UploadModel; use App\Repos\Chapter as ChapterRepo; use App\Repos\Course as CourseRepo; -use App\Repos\Upload as UploadRepo; -use App\Services\Storage as StorageService; use App\Validators\Chapter as ChapterValidator; use App\Validators\Resource as ResourceValidator; use App\Validators\Upload as UploadValidator; @@ -31,26 +29,16 @@ class Resource extends Service $chapter = $validator->checkChapter($post['chapter_id']); $course = $validator->checkCourse($chapter->course_id); - $uploadRepo = new UploadRepo(); + $upload = new UploadModel(); - $upload = $uploadRepo->findByMd5($post['upload']['md5']); + $upload->type = UploadModel::TYPE_RESOURCE; + $upload->name = $post['upload']['name']; + $upload->size = $post['upload']['size']; + $upload->path = $post['upload']['path']; + $upload->md5 = $post['upload']['md5']; + $upload->mime = $post['upload']['mime']; - /** - * 腾讯COS存储可能不会返回文件md5值 - */ - if (!$upload || empty($post['upload']['md5'])) { - - $upload = new UploadModel(); - - $upload->type = UploadModel::TYPE_RESOURCE; - $upload->name = $post['upload']['name']; - $upload->size = $post['upload']['size']; - $upload->path = $post['upload']['path']; - $upload->md5 = $post['upload']['md5']; - $upload->mime = $post['upload']['mime']; - - $upload->create(); - } + $upload->create(); $resource = new ResourceModel(); @@ -124,7 +112,9 @@ class Resource extends Service $resourceCount = 0; foreach ($lessons as $lesson) { - $resourceCount += $chapterRepo->countResources($lesson->id); + if ($lesson->deleted == 0) { + $resourceCount += $chapterRepo->countResources($lesson->id); + } } $parent->resource_count = $resourceCount; @@ -136,7 +126,21 @@ class Resource extends Service { $courseRepo = new CourseRepo(); - $course->resource_count = $courseRepo->countResources($course->id); + $lessons = $courseRepo->findLessons($course->id); + + $chapterRepo = new ChapterRepo(); + + $resourceCount = 0; + + if ($lessons->count() > 0) { + foreach ($lessons as $lesson) { + if ($lesson->deleted == 0) { + $resourceCount += $chapterRepo->countResources($lesson->id); + } + } + } + + $course->resource_count = $resourceCount; $course->update(); } diff --git a/app/Http/Admin/Services/Slide.php b/app/Http/Admin/Services/Slide.php index 492284e1..a58f4ccd 100644 --- a/app/Http/Admin/Services/Slide.php +++ b/app/Http/Admin/Services/Slide.php @@ -105,7 +105,7 @@ class Slide extends Service $slide = $this->createLinkSlide($post); } - $this->rebuildSlideCache(); + $this->rebuildIndexSlideListCache(); return $slide; } @@ -138,7 +138,7 @@ class Slide extends Service $slide->update($data); - $this->rebuildSlideCache(); + $this->rebuildIndexSlideListCache(); return $slide; } @@ -151,7 +151,7 @@ class Slide extends Service $slide->update(); - $this->rebuildSlideCache(); + $this->rebuildIndexSlideListCache(); return $slide; } @@ -164,7 +164,7 @@ class Slide extends Service $slide->update(); - $this->rebuildSlideCache(); + $this->rebuildIndexSlideListCache(); return $slide; } @@ -236,7 +236,7 @@ class Slide extends Service return $slide; } - protected function rebuildSlideCache() + protected function rebuildIndexSlideListCache() { $cache = new IndexSlideListCache(); diff --git a/app/Http/Admin/Services/Topic.php b/app/Http/Admin/Services/Topic.php index 0c9310b7..0d222cab 100644 --- a/app/Http/Admin/Services/Topic.php +++ b/app/Http/Admin/Services/Topic.php @@ -162,6 +162,13 @@ class Topic extends Service return $topic; } + protected function findOrFail($id) + { + $validator = new TopicValidator(); + + return $validator->checkTopic($id); + } + protected function saveCourses(TopicModel $topic, $courseIds) { $topicRepo = new TopicRepo(); @@ -220,11 +227,4 @@ class Topic extends Service $cache->rebuild($topic->id); } - protected function findOrFail($id) - { - $validator = new TopicValidator(); - - return $validator->checkTopic($id); - } - } diff --git a/app/Http/Admin/Services/User.php b/app/Http/Admin/Services/User.php index 8ed17c4e..7a15e29f 100644 --- a/app/Http/Admin/Services/User.php +++ b/app/Http/Admin/Services/User.php @@ -11,6 +11,7 @@ use App\Builders\UserList as UserListBuilder; use App\Caches\User as UserCache; use App\Library\Paginator\Query as PaginateQuery; use App\Library\Utils\Password as PasswordUtil; +use App\Library\Validators\Common as CommonValidator; use App\Models\Account as AccountModel; use App\Models\User as UserModel; use App\Repos\Account as AccountRepo; @@ -61,6 +62,24 @@ class User extends Service $pageQuery = new PaginateQuery(); $params = $pageQuery->getParams(); + + $accountRepo = new AccountRepo(); + + /** + * 兼容用户编号|手机号码|邮箱地址查询 + */ + if (!empty($params['id'])) { + if (CommonValidator::phone($params['id'])) { + $account = $accountRepo->findByPhone($params['id']); + $params['id'] = $account ? $account->id : -1000; + } elseif (CommonValidator::email($params['id'])) { + $account = $accountRepo->findByEmail($params['id']); + $params['id'] = $account ? $account->id : -1000; + } + } + + $params['deleted'] = $params['deleted'] ?? 0; + $sort = $pageQuery->getSort(); $page = $pageQuery->getPage(); $limit = $pageQuery->getLimit(); @@ -132,6 +151,8 @@ class User extends Service $this->updateAdminUserCount($adminRole); } + $this->rebuildUserCache($user); + } catch (\Exception $e) { $this->db->rollback(); @@ -223,6 +244,8 @@ class User extends Service $this->updateAdminUserCount($user->admin_role); } + $this->rebuildUserCache($user); + return $user; } diff --git a/app/Http/Admin/Views/topic/edit.volt b/app/Http/Admin/Views/topic/edit.volt index f60bab0e..a450e8ee 100644 --- a/app/Http/Admin/Views/topic/edit.volt +++ b/app/Http/Admin/Views/topic/edit.volt @@ -2,46 +2,26 @@ {% block content %} -
-
- 编辑专题 -
-
- -
- + {% set action_url = url({'for':'admin.topic.update','id':topic.id}) %} + +
+ 编辑专题 +
+ +
+
    +
  • 基本信息
  • +
  • 相关课程
  • +
+
+
+ {{ partial('topic/edit_basic') }} +
+
+ {{ partial('topic/edit_course') }}
-
- -
- - -
-
- -
-
-
- -
- -
-
-
- -
-
-
-
-
- -
- - -
-
- +
{% endblock %} diff --git a/app/Http/Admin/Views/topic/edit_basic.volt b/app/Http/Admin/Views/topic/edit_basic.volt new file mode 100644 index 00000000..31285bae --- /dev/null +++ b/app/Http/Admin/Views/topic/edit_basic.volt @@ -0,0 +1,38 @@ +
+
+ +
+ +
+
+
+ +
+ + +
+
+ +
+
+
+ +
+ +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
\ No newline at end of file diff --git a/app/Http/Admin/Views/topic/edit_course.volt b/app/Http/Admin/Views/topic/edit_course.volt new file mode 100644 index 00000000..19443fde --- /dev/null +++ b/app/Http/Admin/Views/topic/edit_course.volt @@ -0,0 +1,15 @@ +
+
+ +
+
+
+
+
+ +
+ + +
+
+
\ No newline at end of file diff --git a/app/Http/Admin/Views/user/search.volt b/app/Http/Admin/Views/user/search.volt index 323adbf6..c1e77797 100644 --- a/app/Http/Admin/Views/user/search.volt +++ b/app/Http/Admin/Views/user/search.volt @@ -7,15 +7,15 @@ 搜索用户
- +
- +
- +
- +
diff --git a/app/Http/Home/Controllers/UserConsoleController.php b/app/Http/Home/Controllers/UserConsoleController.php index e12da62c..32e64e71 100644 --- a/app/Http/Home/Controllers/UserConsoleController.php +++ b/app/Http/Home/Controllers/UserConsoleController.php @@ -278,35 +278,6 @@ class UserConsoleController extends Controller $this->view->setVar('pager', $pager); } - /** - * @Get("/friends", name="home.uc.friends") - */ - public function friendsAction() - { - $service = new FriendListService(); - - $pager = $service->handle(); - - $this->view->pick('user/console/friends'); - $this->view->setVar('pager', $pager); - } - - /** - * @Get("/groups", name="home.uc.groups") - */ - public function groupsAction() - { - $scope = $this->request->getQuery('scope', 'string', 'joined'); - - $service = new GroupListService(); - - $pager = $service->handle($scope); - - $this->view->pick('user/console/groups'); - $this->view->setVar('scope', $scope); - $this->view->setVar('pager', $pager); - } - /** * @Get("/notifications", name="home.uc.notifications") */ diff --git a/app/Services/Logic/Course/ResourceList.php b/app/Services/Logic/Course/ResourceList.php new file mode 100644 index 00000000..9a712384 --- /dev/null +++ b/app/Services/Logic/Course/ResourceList.php @@ -0,0 +1,75 @@ +checkCourse($id); + + $user = $this->getCurrentUser(true); + + $this->setCourseUser($course, $user); + + $courseRepo = new CourseRepo(); + + $lessons = $courseRepo->findLessons($course->id); + + if ($lessons->count() == 0) { + return []; + } + + $lessonIds = []; + + /** + * 过滤掉未发布和已删除的课时 + */ + foreach ($lessons as $lesson) { + if ($lesson->published == 1 && $lesson->deleted == 0) { + $lessonIds[] = $lesson->id; + } + } + + $resourceRepo = new ResourceRepo(); + + $resources = $resourceRepo->findByCourseId($course->id); + + if ($resources->count() == 0) { + return []; + } + + $builder = new ResourceListBuilder(); + + $relations = $resources->toArray(); + + foreach ($relations as $key => $relation) { + if (!in_array($relation['chapter_id'], $lessonIds)) { + unset($relations[$key]); + } + } + + $uploads = $builder->getUploads($relations); + + foreach ($uploads as $key => $upload) { + $uploads[$key]['me'] = ['owned' => $this->ownedCourse ? 1 : 0]; + } + + return array_values($uploads); + } + +} diff --git a/app/Services/Logic/User/Console/FavoriteList.php b/app/Services/Logic/User/Console/FavoriteList.php index 3ba07d8e..18e425d6 100644 --- a/app/Services/Logic/User/Console/FavoriteList.php +++ b/app/Services/Logic/User/Console/FavoriteList.php @@ -61,6 +61,8 @@ class FavoriteList extends LogicService return $this->handleQuestions($pager); } + + return null; } protected function handleCourses($pager) diff --git a/app/Validators/Account.php b/app/Validators/Account.php index 004c8045..a70e8878 100644 --- a/app/Validators/Account.php +++ b/app/Validators/Account.php @@ -39,7 +39,7 @@ class Account extends Validator $account = $accountRepo->findById($name); } - if (!$account) { + if (!$account || $account->deleted == 1) { throw new BadRequestException('account.not_found'); } @@ -144,7 +144,13 @@ class Account extends Validator $userRepo = new UserRepo(); - return $userRepo->findById($account->id); + $user = $userRepo->findById($account->id); + + if ($user->deleted == 1) { + throw new BadRequestException('user.not_found'); + } + + return $user; } public function checkUserLogin($name, $password) @@ -161,7 +167,13 @@ class Account extends Validator $userRepo = new UserRepo(); - return $userRepo->findById($account->id); + $user = $userRepo->findById($account->id); + + if ($user->deleted == 1) { + throw new BadRequestException('user.not_found'); + } + + return $user; } public function checkAdminLogin($name, $password) diff --git a/config/errors.php b/config/errors.php index d809b316..ac374977 100644 --- a/config/errors.php +++ b/config/errors.php @@ -65,7 +65,6 @@ $error['account.login_pwd_incorrect'] = '登录密码不正确'; $error['user.not_found'] = '用户不存在'; $error['user.name_taken'] = '用户名被占用'; $error['user.title_too_long'] = '头衔过长(超过30个字符)'; -$error['user.sign_too_long'] = '签名过长(超过50个字符)'; $error['user.about_too_long'] = '简介过长(超过255个字符)'; $error['user.invalid_gender'] = '无效的性别类型'; $error['user.invalid_area'] = '无效的省市地区'; diff --git a/db/migrations/20230816234130.php b/db/migrations/20230816234130.php new file mode 100644 index 00000000..1b18c971 --- /dev/null +++ b/db/migrations/20230816234130.php @@ -0,0 +1,37 @@ +alterReviewLikeTable(); + } + + protected function alterReviewLikeTable() + { + $table = $this->table('kg_review_like'); + + if (!$table->hasColumn('deleted')) { + $table->addColumn('deleted', 'integer', [ + 'null' => false, + 'default' => '0', + 'limit' => MysqlAdapter::INT_REGULAR, + 'signed' => false, + 'comment' => '删除标识', + 'after' => 'user_id', + ]); + } + + $table->save(); + } + +}