From 190117146feabfa49cf2091c4b54d88c0f1af379 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Wed, 2 Aug 2023 17:18:25 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BC=98=E5=8C=96tag=E8=A1=A8migration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrations/20210720153027.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrations/20210720153027.php b/db/migrations/20210720153027.php index 35e793be..fc3fd960 100644 --- a/db/migrations/20210720153027.php +++ b/db/migrations/20210720153027.php @@ -141,7 +141,7 @@ final class V20210720153027 extends AbstractMigration if (!$table->hasColumn('scopes')) { $table->addColumn('scopes', 'string', [ 'null' => false, - 'default' => '', + 'default' => 'all', 'limit' => 100, 'collation' => 'utf8mb4_general_ci', 'encoding' => 'utf8mb4', From 85ba7911ac5a2c8cfa713ce61e830a751e695a6b Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Wed, 2 Aug 2023 17:59:47 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BC=98=E5=8C=96cleanDemoDataTask?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Tasks/CleanDemoDataTask.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Console/Tasks/CleanDemoDataTask.php b/app/Console/Tasks/CleanDemoDataTask.php index b6de241d..24cba3df 100644 --- a/app/Console/Tasks/CleanDemoDataTask.php +++ b/app/Console/Tasks/CleanDemoDataTask.php @@ -38,7 +38,7 @@ class CleanDemoDataTask extends Task echo '------ start truncate tables ------' . PHP_EOL; $excludeTables = [ - 'kg_area', 'kg_migration', 'kg_nav', 'kg_page', + 'kg_area', 'kg_migration', 'kg_migration_task', 'kg_nav', 'kg_page', 'kg_reward', 'kg_role', 'kg_setting', 'kg_vip', ]; From f284a8ef920c71c83bad3979f623feed5cf7dc92 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Thu, 3 Aug 2023 16:55:55 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=8F=90=E4=BA=A4=E6=8C=89=E9=92=AE=E4=B8=8D?= =?UTF-8?q?=E5=8F=AF=E7=94=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Home/Views/verify/captcha.volt | 8 ++++---- public/static/home/js/captcha.verify.email.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Http/Home/Views/verify/captcha.volt b/app/Http/Home/Views/verify/captcha.volt index 171e875e..a5704aa2 100644 --- a/app/Http/Home/Views/verify/captcha.volt +++ b/app/Http/Home/Views/verify/captcha.volt @@ -68,10 +68,10 @@ parent.layui.$('#cv-phone-submit-btn').removeAttr('disabled').removeClass('layui-btn-disabled'); parent.layui.$('#cv-phone-captcha-ticket').val(ticket); parent.layui.$('#cv-phone-captcha-rand').val(rand); - } else if (verify.type === 'mail') { - parent.layui.$('#cv-mail-submit-btn').removeAttr('disabled').removeClass('layui-btn-disabled'); - parent.layui.$('#cv-mail-captcha-ticket').val(ticket); - parent.layui.$('#cv-mail-captcha-rand').val(rand); + } else if (verify.type === 'email') { + parent.layui.$('#cv-email-submit-btn').removeAttr('disabled').removeClass('layui-btn-disabled'); + parent.layui.$('#cv-email-captcha-ticket').val(ticket); + parent.layui.$('#cv-email-captcha-rand').val(rand); } else { parent.layui.$('#cv-submit-btn').removeAttr('disabled').removeClass('layui-btn-disabled'); parent.layui.$('#cv-captcha-ticket').val(ticket); diff --git a/public/static/home/js/captcha.verify.email.js b/public/static/home/js/captcha.verify.email.js index 8dd02d81..b1d3d8a1 100644 --- a/public/static/home/js/captcha.verify.email.js +++ b/public/static/home/js/captcha.verify.email.js @@ -8,7 +8,7 @@ layui.use(['jquery', 'layer', 'helper'], function () { var $emit = $('#cv-email-emit-btn'); $emit.on('click', function () { - var url = '/verify/captcha?type=mail&account=' + $account.val(); + var url = '/verify/captcha?type=email&account=' + $account.val(); layer.open({ type: 2, title: '获取验证码', From 65b5190a0509edda86ffc8957cff76542a2b76b2 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Fri, 11 Aug 2023 15:53:41 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=BF=9C=E7=A8=8BCOS=E8=AF=BE=E4=BB=B6=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Admin/Services/Resource.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/Http/Admin/Services/Resource.php b/app/Http/Admin/Services/Resource.php index 692fb173..3303d8fe 100644 --- a/app/Http/Admin/Services/Resource.php +++ b/app/Http/Admin/Services/Resource.php @@ -96,14 +96,6 @@ class Resource extends Service $course = $validator->checkCourse($resource->course_id); $chapter = $validator->checkChapter($resource->chapter_id); - $validator = new UploadValidator(); - - $upload = $validator->checkUpload($resource->upload_id); - - $storageService = new StorageService(); - - $storageService->deleteObject($upload->path); - $resource->delete(); $this->recountChapterResources($chapter); From 138b9d45cec340c19073e628e120ab833eabd036 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Mon, 28 Aug 2023 15:55:40 +0800 Subject: [PATCH 5/6] =?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(); + } + +} From ebd310caa6ef39e488e84cef6953019e6c81e56a Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Thu, 31 Aug 2023 17:18:05 +0800 Subject: [PATCH 6/6] v1.6.6 --- CHANGELOG.md | 10 +++- .../Admin/Controllers/ChapterController.php | 13 ----- .../Admin/Controllers/CourseController.php | 16 ++++++ app/Http/Admin/Services/Chapter.php | 19 ------- app/Http/Admin/Services/Course.php | 18 +++++++ app/Http/Admin/Services/Resource.php | 51 ++----------------- app/Http/Admin/Views/chapter/edit_lesson.volt | 7 --- app/Http/Admin/Views/course/chapters.volt | 3 -- app/Http/Admin/Views/course/edit.volt | 6 +++ .../{chapter => course}/edit_resource.volt | 6 +-- .../Views/{chapter => course}/resources.volt | 5 +- .../Home/Controllers/ChapterController.php | 13 ----- .../Home/Controllers/CourseController.php | 14 +++++ app/Http/Home/Views/chapter/resources.volt | 29 ----------- app/Http/Home/Views/chapter/sticky.volt | 18 ------- app/Http/Home/Views/course/resources.volt | 20 ++++++++ app/Http/Home/Views/course/show.volt | 8 +++ app/Repos/Course.php | 11 ++++ app/Services/Logic/Chapter/ResourceList.php | 39 -------------- app/Services/Logic/Course/ResourceList.php | 28 +--------- ...chapter.resource.js => course.resource.js} | 4 +- public/static/home/js/chapter.show.js | 24 --------- public/static/home/js/course.show.js | 5 ++ 23 files changed, 119 insertions(+), 248 deletions(-) rename app/Http/Admin/Views/{chapter => course}/edit_resource.volt (82%) rename app/Http/Admin/Views/{chapter => course}/resources.volt (84%) delete mode 100644 app/Http/Home/Views/chapter/resources.volt create mode 100644 app/Http/Home/Views/course/resources.volt delete mode 100644 app/Services/Logic/Chapter/ResourceList.php rename public/static/admin/js/{chapter.resource.js => course.resource.js} (97%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2177671d..505a5ed3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,12 @@ -### [v1.6.6](https://gitee.com/koogua/course-tencent-cloud/releases/v1.6.6)(2023-08-15) +### [v1.6.6](https://gitee.com/koogua/course-tencent-cloud/releases/v1.6.6)(2023-08-30) + +- 还原意外删除的AnswerList.php文件 +- 修正邮箱注册提交按钮不可用问题 +- 去除删除远程课件逻辑 +- 增加课程课件资料总览 +- 优化cleanDemoDataTask脚本 +- 优化tag表migration脚本 +- 命名结构等常规优化 ### [v1.6.5](https://gitee.com/koogua/course-tencent-cloud/releases/v1.6.5)(2023-07-15) diff --git a/app/Http/Admin/Controllers/ChapterController.php b/app/Http/Admin/Controllers/ChapterController.php index 16e9a6ef..5da3e57c 100644 --- a/app/Http/Admin/Controllers/ChapterController.php +++ b/app/Http/Admin/Controllers/ChapterController.php @@ -20,19 +20,6 @@ use Phalcon\Mvc\View; class ChapterController extends Controller { - /** - * @Get("/{id:[0-9]+}/resources", name="admin.chapter.resources") - */ - public function resourcesAction($id) - { - $chapterService = new ChapterService(); - - $resources = $chapterService->getResources($id); - - $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); - $this->view->setVar('resources', $resources); - } - /** * @Get("/{id:[0-9]+}/lessons", name="admin.chapter.lessons") */ diff --git a/app/Http/Admin/Controllers/CourseController.php b/app/Http/Admin/Controllers/CourseController.php index aab1a83f..2121110f 100644 --- a/app/Http/Admin/Controllers/CourseController.php +++ b/app/Http/Admin/Controllers/CourseController.php @@ -9,6 +9,7 @@ namespace App\Http\Admin\Controllers; use App\Http\Admin\Services\Course as CourseService; use App\Models\Category as CategoryModel; +use Phalcon\Mvc\View; /** * @RoutePrefix("/admin/course") @@ -100,6 +101,7 @@ class CourseController extends Controller { $courseService = new CourseService(); + $cos = $courseService->getSettings('cos'); $course = $courseService->getCourse($id); $xmTeachers = $courseService->getXmTeachers($id); $xmCategories = $courseService->getXmCategories($id); @@ -107,6 +109,7 @@ class CourseController extends Controller $studyExpiryOptions = $courseService->getStudyExpiryOptions(); $refundExpiryOptions = $courseService->getRefundExpiryOptions(); + $this->view->setVar('cos', $cos); $this->view->setVar('course', $course); $this->view->setVar('xm_teachers', $xmTeachers); $this->view->setVar('xm_categories', $xmCategories); @@ -177,4 +180,17 @@ class CourseController extends Controller $this->view->setVar('chapters', $chapters); } + /** + * @Get("/{id:[0-9]+}/resources", name="admin.course.resources") + */ + public function resourcesAction($id) + { + $courseService = new CourseService(); + + $resources = $courseService->getResources($id); + + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); + $this->view->setVar('resources', $resources); + } + } diff --git a/app/Http/Admin/Services/Chapter.php b/app/Http/Admin/Services/Chapter.php index ef5aaa94..5b01ce92 100644 --- a/app/Http/Admin/Services/Chapter.php +++ b/app/Http/Admin/Services/Chapter.php @@ -7,37 +7,18 @@ namespace App\Http\Admin\Services; -use App\Builders\ResourceList as ResourceListBuilder; use App\Caches\Chapter as ChapterCache; use App\Caches\CourseChapterList as CatalogCache; use App\Models\Chapter as ChapterModel; use App\Models\Course as CourseModel; use App\Repos\Chapter as ChapterRepo; use App\Repos\Course as CourseRepo; -use App\Repos\Resource as ResourceRepo; use App\Services\CourseStat as CourseStatService; use App\Validators\Chapter as ChapterValidator; class Chapter extends Service { - public function getResources($id) - { - $resourceRepo = new ResourceRepo(); - - $resources = $resourceRepo->findByChapterId($id); - - if ($resources->count() == 0) return []; - - $builder = new ResourceListBuilder(); - - $items = $resources->toArray(); - - $items = $builder->handleUploads($items); - - return $builder->objects($items); - } - public function getLessons($parentId) { $deleted = $this->request->getQuery('deleted', 'int', 0); diff --git a/app/Http/Admin/Services/Course.php b/app/Http/Admin/Services/Course.php index 7a53da9c..7e8bd99f 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\Builders\ResourceList as ResourceListBuilder; use App\Caches\Course as CourseCache; use App\Caches\CourseCategoryList as CourseCategoryListCache; use App\Caches\CourseRelatedList as CourseRelatedListCache; @@ -404,6 +405,23 @@ class Course extends Service ]); } + public function getResources($id) + { + $courseRepo = new CourseRepo(); + + $resources = $courseRepo->findResources($id); + + if ($resources->count() == 0) return []; + + $builder = new ResourceListBuilder(); + + $items = $resources->toArray(); + + $items = $builder->handleUploads($items); + + return $builder->objects($items); + } + protected function findOrFail($id) { $validator = new CourseValidator(); diff --git a/app/Http/Admin/Services/Resource.php b/app/Http/Admin/Services/Resource.php index 793a2154..439d4931 100644 --- a/app/Http/Admin/Services/Resource.php +++ b/app/Http/Admin/Services/Resource.php @@ -7,13 +7,10 @@ namespace App\Http\Admin\Services; -use App\Models\Chapter as ChapterModel; use App\Models\Course as CourseModel; 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\Validators\Chapter as ChapterValidator; use App\Validators\Resource as ResourceValidator; use App\Validators\Upload as UploadValidator; @@ -24,10 +21,9 @@ class Resource extends Service { $post = $this->request->getPost(); - $validator = new ChapterValidator(); + $validator = new ResourceValidator(); - $chapter = $validator->checkChapter($post['chapter_id']); - $course = $validator->checkCourse($chapter->course_id); + $course = $validator->checkCourse($post['course_id']); $upload = new UploadModel(); @@ -43,12 +39,10 @@ class Resource extends Service $resource = new ResourceModel(); $resource->course_id = $course->id; - $resource->chapter_id = $chapter->id; $resource->upload_id = $upload->id; $resource->create(); - $this->recountChapterResources($chapter); $this->recountCourseResources($course); return $upload; @@ -82,11 +76,9 @@ class Resource extends Service $validator = new ResourceValidator(); $course = $validator->checkCourse($resource->course_id); - $chapter = $validator->checkChapter($resource->chapter_id); $resource->delete(); - $this->recountChapterResources($chapter); $this->recountCourseResources($course); } @@ -97,48 +89,11 @@ class Resource extends Service return $validator->checkResource($id); } - protected function recountChapterResources(ChapterModel $chapter) - { - $chapterRepo = new ChapterRepo(); - - $chapter->resource_count = $chapterRepo->countResources($chapter->id); - - $chapter->update(); - - $parent = $chapterRepo->findById($chapter->parent_id); - - $lessons = $chapterRepo->findLessons($parent->id); - - $resourceCount = 0; - - foreach ($lessons as $lesson) { - if ($lesson->deleted == 0) { - $resourceCount += $chapterRepo->countResources($lesson->id); - } - } - - $parent->resource_count = $resourceCount; - - $parent->update(); - } - 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); - } - } - } + $resourceCount = $courseRepo->countResources($course->id); $course->resource_count = $resourceCount; diff --git a/app/Http/Admin/Views/chapter/edit_lesson.volt b/app/Http/Admin/Views/chapter/edit_lesson.volt index 6a2902b6..90b926bf 100644 --- a/app/Http/Admin/Views/chapter/edit_lesson.volt +++ b/app/Http/Admin/Views/chapter/edit_lesson.volt @@ -22,7 +22,6 @@
  • 基本信息
  • {{ content_title(course.model) }}
  • -
  • 课件资料
@@ -39,9 +38,6 @@ {{ partial('chapter/edit_lesson_offline') }} {% endif %}
-
- {{ partial('chapter/edit_resource') }} -
@@ -65,9 +61,6 @@ {% endif %} - {{ js_include('lib/cos-js-sdk-v5.min.js') }} - {{ js_include('admin/js/chapter.resource.js') }} - {% endblock %} {% block inline_js %} diff --git a/app/Http/Admin/Views/course/chapters.volt b/app/Http/Admin/Views/course/chapters.volt index 5db9943b..0fe08f17 100644 --- a/app/Http/Admin/Views/course/chapters.volt +++ b/app/Http/Admin/Views/course/chapters.volt @@ -29,7 +29,6 @@ - @@ -37,7 +36,6 @@ 编号 名称 课时 - 课件 学员 点赞 评论 @@ -59,7 +57,6 @@ {{ item.lesson_count }} - {{ item.resource_count }} {{ item.user_count }} {{ item.like_count }} {{ item.comment_count }} diff --git a/app/Http/Admin/Views/course/edit.volt b/app/Http/Admin/Views/course/edit.volt index 9d92e9d8..4ecce804 100644 --- a/app/Http/Admin/Views/course/edit.volt +++ b/app/Http/Admin/Views/course/edit.volt @@ -14,6 +14,7 @@ {% endif %}
  • 课程介绍
  • 营销设置
  • +
  • 课件资料
  • 相关课程
  • @@ -31,6 +32,9 @@
    {{ partial('course/edit_sale') }}
    +
    + {{ partial('course/edit_resource') }} +
    {{ partial('course/edit_related') }}
    @@ -42,10 +46,12 @@ {% block include_js %} {{ js_include('lib/xm-select.js') }} + {{ js_include('lib/cos-js-sdk-v5.min.js') }} {{ js_include('lib/kindeditor/kindeditor.min.js') }} {{ js_include('lib/kindeditor/lang/zh-CN.js') }} {{ js_include('admin/js/content.editor.js') }} {{ js_include('admin/js/cover.upload.js') }} + {{ js_include('admin/js/course.resource.js') }} {% endblock %} diff --git a/app/Http/Admin/Views/chapter/edit_resource.volt b/app/Http/Admin/Views/course/edit_resource.volt similarity index 82% rename from app/Http/Admin/Views/chapter/edit_resource.volt rename to app/Http/Admin/Views/course/edit_resource.volt index e2c860c9..5c13e51a 100644 --- a/app/Http/Admin/Views/chapter/edit_resource.volt +++ b/app/Http/Admin/Views/course/edit_resource.volt @@ -1,4 +1,4 @@ -{% set res_list_url = url({'for':'admin.chapter.resources','id':chapter.id}) %} +{% set res_list_url = url({'for':'admin.course.resources','id':course.id}) %}
    资料列表 @@ -17,7 +17,7 @@
    -
    +
    @@ -26,7 +26,7 @@
    - +
    diff --git a/app/Http/Admin/Views/chapter/resources.volt b/app/Http/Admin/Views/course/resources.volt similarity index 84% rename from app/Http/Admin/Views/chapter/resources.volt rename to app/Http/Admin/Views/course/resources.volt index 4bfc0552..1b882762 100644 --- a/app/Http/Admin/Views/chapter/resources.volt +++ b/app/Http/Admin/Views/course/resources.volt @@ -1,4 +1,5 @@ -{% if resources %} +{% if resources|length > 0 %} +
    @@ -16,7 +17,7 @@ diff --git a/app/Http/Home/Controllers/ChapterController.php b/app/Http/Home/Controllers/ChapterController.php index 9d6b8021..1119a909 100644 --- a/app/Http/Home/Controllers/ChapterController.php +++ b/app/Http/Home/Controllers/ChapterController.php @@ -13,7 +13,6 @@ use App\Models\Course as CourseModel; use App\Services\Logic\Chapter\ChapterInfo as ChapterInfoService; use App\Services\Logic\Chapter\ChapterLike as ChapterLikeService; use App\Services\Logic\Chapter\Learning as ChapterLearningService; -use App\Services\Logic\Chapter\ResourceList as ChapterResourceListService; use App\Services\Logic\Course\BasicInfo as CourseInfoService; use App\Services\Logic\Course\ChapterList as CourseChapterListService; @@ -23,18 +22,6 @@ use App\Services\Logic\Course\ChapterList as CourseChapterListService; class ChapterController extends Controller { - /** - * @Get("/{id:[0-9]+}/resources", name="home.chapter.resources") - */ - public function resourcesAction($id) - { - $service = new ChapterResourceListService(); - - $items = $service->handle($id); - - $this->view->setVar('items', $items); - } - /** * @Get("/{id:[0-9]+}", name="home.chapter.show") */ diff --git a/app/Http/Home/Controllers/CourseController.php b/app/Http/Home/Controllers/CourseController.php index 9e82fc2f..6047b3e9 100644 --- a/app/Http/Home/Controllers/CourseController.php +++ b/app/Http/Home/Controllers/CourseController.php @@ -17,6 +17,7 @@ use App\Services\Logic\Course\CourseList as CourseListService; use App\Services\Logic\Course\PackageList as CoursePackageListService; use App\Services\Logic\Course\RecommendedList as CourseRecommendedListService; use App\Services\Logic\Course\RelatedList as CourseRelatedListService; +use App\Services\Logic\Course\ResourceList as CourseResourceListService; use App\Services\Logic\Course\ReviewList as CourseReviewListService; use App\Services\Logic\Course\TopicList as CourseTopicListService; use App\Services\Logic\Reward\OptionList as RewardOptionList; @@ -160,6 +161,19 @@ class CourseController extends Controller $this->view->setVar('pager', $pager); } + /** + * @Get("/{id:[0-9]+}/resources", name="home.course.resources") + */ + public function resourcesAction($id) + { + $service = new CourseResourceListService(); + + $items = $service->handle($id); + + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); + $this->view->setVar('items', $items); + } + /** * @Get("/{id:[0-9]+}/recommended", name="home.course.recommended") */ diff --git a/app/Http/Home/Views/chapter/resources.volt b/app/Http/Home/Views/chapter/resources.volt deleted file mode 100644 index 67c32c57..00000000 --- a/app/Http/Home/Views/chapter/resources.volt +++ /dev/null @@ -1,29 +0,0 @@ -{% extends 'templates/layer.volt' %} - -{% block content %} - -
    名称{{ item.upload.size|human_size }} {{ date('Y-m-d H:i:s',item.create_time) }} - 删除 + 删除 下载
    - - - - - - {% for item in items %} - - - - - - {% endfor %} -
    名称大小操作
    {{ item.name }}{{ item.size|human_size }}下载
    - -{% endblock %} - -{% block inline_js %} - - - -{% endblock %} \ No newline at end of file diff --git a/app/Http/Home/Views/chapter/sticky.volt b/app/Http/Home/Views/chapter/sticky.volt index cc4c20b3..85244ea1 100644 --- a/app/Http/Home/Views/chapter/sticky.volt +++ b/app/Http/Home/Views/chapter/sticky.volt @@ -1,5 +1,3 @@ -{% set download_url = url({'for':'home.chapter.resources','id':chapter.id}) %} -{% set consult_url = url({'for':'home.consult.add'},{'chapter_id':chapter.id}) %} {% set like_url = url({'for':'home.chapter.like','id':chapter.id}) %} {% set like_title = chapter.me.liked == 1 ? '取消点赞' : '点赞支持' %} {% set like_class = chapter.me.liked == 1 ? 'active' : '' %} @@ -23,20 +21,4 @@
    {{ chapter.comment_count }}
    - {% if chapter.resource_count > 0 %} -
    -
    - -
    -
    资料
    -
    - {% endif %} - {% if course.market_price > 0 %} -
    -
    - -
    -
    咨询
    -
    - {% endif %}
    \ No newline at end of file diff --git a/app/Http/Home/Views/course/resources.volt b/app/Http/Home/Views/course/resources.volt new file mode 100644 index 00000000..a500b8bb --- /dev/null +++ b/app/Http/Home/Views/course/resources.volt @@ -0,0 +1,20 @@ +{% if items|length > 0 %} + + + + + + + {% for item in items %} + + + + {% if item.me.owned == 1 and auth_user.id > 0 %} + + {% else %} + + {% endif %} + + {% endfor %} +
    名称大小操作
    {{ item.name }}{{ item.size|human_size }}下载下载
    +{% endif %} \ No newline at end of file diff --git a/app/Http/Home/Views/course/show.volt b/app/Http/Home/Views/course/show.volt index b3a60cca..b03dcb0d 100644 --- a/app/Http/Home/Views/course/show.volt +++ b/app/Http/Home/Views/course/show.volt @@ -28,6 +28,7 @@ {% set show_tab_packages = course.package_count > 0 %} {% set show_tab_consults = course.consult_count > 0 %} {% set show_tab_reviews = course.review_count > 0 %} + {% set show_tab_resources = course.resource_count > 0 %}
    @@ -44,6 +45,9 @@ {% if show_tab_reviews %}
  • 评价{{ course.review_count }}
  • {% endif %} + {% if show_tab_resources %} +
  • 课件{{ course.resource_count }}
  • + {% endif %}
    @@ -64,6 +68,10 @@ {% set reviews_url = url({'for':'home.course.reviews','id':course.id}) %}
    {% endif %} + {% if show_tab_resources %} + {% set resources_url = url({'for':'home.course.resources','id':course.id}) %} +
    + {% endif %}
    diff --git a/app/Repos/Course.php b/app/Repos/Course.php index 538aad47..40000ae0 100644 --- a/app/Repos/Course.php +++ b/app/Repos/Course.php @@ -305,6 +305,17 @@ class Course extends Repository ->execute(); } + /** + * @param int $courseId + * @return ResultsetInterface|Resultset|ResourceModel[] + */ + public function findResources($courseId) + { + return ResourceModel::query() + ->where('course_id = :course_id:', ['course_id' => $courseId]) + ->execute(); + } + /** * @param int $courseId * @param int $userId diff --git a/app/Services/Logic/Chapter/ResourceList.php b/app/Services/Logic/Chapter/ResourceList.php deleted file mode 100644 index ed21327a..00000000 --- a/app/Services/Logic/Chapter/ResourceList.php +++ /dev/null @@ -1,39 +0,0 @@ -checkChapter($id); - - $resourceRepo = new ResourceRepo(); - - $resources = $resourceRepo->findByChapterId($chapter->id); - - if ($resources->count() == 0) { - return []; - } - - $builder = new ResourceListBuilder(); - - $relations = $resources->toArray(); - - return $builder->getUploads($relations); - } - -} diff --git a/app/Services/Logic/Course/ResourceList.php b/app/Services/Logic/Course/ResourceList.php index 9a712384..abead04c 100644 --- a/app/Services/Logic/Course/ResourceList.php +++ b/app/Services/Logic/Course/ResourceList.php @@ -9,7 +9,6 @@ namespace App\Services\Logic\Course; use App\Builders\ResourceList as ResourceListBuilder; use App\Repos\Course as CourseRepo; -use App\Repos\Resource as ResourceRepo; use App\Services\Logic\CourseTrait; use App\Services\Logic\Service as LogicService; @@ -28,26 +27,7 @@ class ResourceList extends LogicService $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); + $resources = $courseRepo->findResources($course->id); if ($resources->count() == 0) { return []; @@ -57,12 +37,6 @@ class ResourceList extends LogicService $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) { diff --git a/public/static/admin/js/chapter.resource.js b/public/static/admin/js/course.resource.js similarity index 97% rename from public/static/admin/js/chapter.resource.js rename to public/static/admin/js/course.resource.js index e7300692..e8be73e8 100644 --- a/public/static/admin/js/chapter.resource.js +++ b/public/static/admin/js/course.resource.js @@ -8,7 +8,7 @@ layui.use(['jquery', 'element', 'layer'], function () { var $resFile = $('input[name=res_file]'); var $uploadBlock = $('#res-upload-block'); var $progressBlock = $('#res-progress-block'); - var chapterId = $('input[name=chapter_id]').val(); + var courseId = $('input[name=course_id]').val(); var myConfig = { bucket: $('input[name=bucket]').val(), @@ -70,7 +70,7 @@ layui.use(['jquery', 'element', 'layer'], function () { path: keyName, md5: data.ETag ? data.ETag.replace(/"/g, '') : '' }, - chapter_id: chapterId, + course_id: courseId, }, function () { $uploadBlock.removeClass('layui-hide'); $progressBlock.addClass('layui-hide'); diff --git a/public/static/home/js/chapter.show.js b/public/static/home/js/chapter.show.js index 39d33773..d7d76e29 100644 --- a/public/static/home/js/chapter.show.js +++ b/public/static/home/js/chapter.show.js @@ -34,30 +34,6 @@ layui.use(['jquery', 'helper'], function () { }); }); - $('.icon-help').on('click', function () { - var url = $(this).parent().data('url'); - helper.checkLogin(function () { - layer.open({ - type: 2, - title: '课程咨询', - content: [url, 'no'], - area: ['640px', '300px'] - }); - }); - }); - - $('.icon-download').on('click', function () { - var url = $(this).parent().data('url'); - helper.checkLogin(function () { - layer.open({ - type: 2, - title: '资料下载', - content: [url, 'no'], - area: ['640px', '300px'] - }); - }); - }); - $('.icon-reply').on('click', function () { $('html').animate({ scrollTop: $('#comment-anchor').offset().top diff --git a/public/static/home/js/course.show.js b/public/static/home/js/course.show.js index 0abfb5a0..ae7ae753 100644 --- a/public/static/home/js/course.show.js +++ b/public/static/home/js/course.show.js @@ -135,6 +135,11 @@ layui.use(['jquery', 'layer', 'helper'], function () { helper.ajaxLoadHtml($tabReviews.data('url'), $tabReviews.attr('id')); } + if ($('#tab-resources').length > 0) { + var $tabResources = $('#tab-resources'); + helper.ajaxLoadHtml($tabResources.data('url'), $tabResources.attr('id')); + } + if ($('#sidebar-topics').length > 0) { var $sdTopics = $('#sidebar-topics'); helper.ajaxLoadHtml($sdTopics.data('url'), $sdTopics.attr('id'));