From df9d77cad21ba44c4c554412fea8ed3a5bb1f220 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Sun, 26 Feb 2023 19:07:54 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=BC=BA=E5=8C=96=E6=96=87=E7=AB=A0|?= =?UTF-8?q?=E6=8F=90=E9=97=AE|=E8=AF=BE=E7=A8=8B=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=A3=80=E6=9F=A5=202.=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=AD=A6=E4=B9=A0=E6=97=B6=E9=95=BF=E5=90=8C?= =?UTF-8?q?=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 +++- app/Http/Home/Services/QuestionQuery.php | 41 ++++++++++++++++++++++++ app/Library/AppInfo.php | 2 +- app/Services/Sync/Learning.php | 4 --- app/Validators/ArticleQuery.php | 5 ++- app/Validators/CourseQuery.php | 4 +-- app/Validators/QuestionQuery.php | 13 ++++++++ 7 files changed, 64 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d97dff2..d4ba1c77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ -### [v1.6.2](https://gitee.com/koogua/course-tencent-cloud/releases/v1.6.1)(2023-01-12) +### [v1.6.2](https://gitee.com/koogua/course-tencent-cloud/releases/v1.6.3)(2023-03-12) +- 强化文章|提问|课程列表参数检查 +- 优化课程学习时长同步 + +### [v1.6.2](https://gitee.com/koogua/course-tencent-cloud/releases/v1.6.2)(2023-02-12) - 增加ServerMonitor监控指标配置 - 同步更新腾讯云短信内容规则 diff --git a/app/Http/Home/Services/QuestionQuery.php b/app/Http/Home/Services/QuestionQuery.php index 3073830f..d4b99971 100644 --- a/app/Http/Home/Services/QuestionQuery.php +++ b/app/Http/Home/Services/QuestionQuery.php @@ -7,7 +7,9 @@ namespace App\Http\Home\Services; +use App\Models\Category as CategoryModel; use App\Models\Question as QuestionModel; +use App\Services\Category as CategoryService; use App\Validators\QuestionQuery as QuestionQueryValidator; class QuestionQuery extends Service @@ -20,6 +22,40 @@ class QuestionQuery extends Service $this->baseUrl = $this->url->get(['for' => 'home.question.list']); } + public function handleCategories() + { + $params = $this->getParams(); + + if (isset($params['category_id'])) { + unset($params['category_id']); + } + + $defaultItem = [ + 'id' => 'all', + 'name' => '全部', + 'url' => $this->baseUrl . $this->buildParams($params), + ]; + + $result = []; + + $result[] = $defaultItem; + + $categoryService = new CategoryService(); + + $topCategories = $categoryService->getChildCategories(CategoryModel::TYPE_QUESTION, 0); + + foreach ($topCategories as $key => $category) { + $params['category_id'] = $category['id']; + $result[] = [ + 'id' => $category['id'], + 'name' => $category['name'], + 'url' => $this->baseUrl . $this->buildParams($params), + ]; + } + + return $result; + } + public function handleSorts() { $params = $this->getParams(); @@ -48,6 +84,11 @@ class QuestionQuery extends Service $validator = new QuestionQueryValidator(); + if (isset($query['category_id']) && $query['category_id'] != 'all') { + $validator->checkCategory($query['category_id']); + $params['category_id'] = $query['category_id']; + } + if (isset($query['tag_id'])) { $validator->checkTag($query['tag_id']); $params['tag_id'] = $query['tag_id']; diff --git a/app/Library/AppInfo.php b/app/Library/AppInfo.php index 70774c80..bd8308fd 100644 --- a/app/Library/AppInfo.php +++ b/app/Library/AppInfo.php @@ -16,7 +16,7 @@ class AppInfo protected $link = 'https://www.koogua.com'; - protected $version = '1.6.2'; + protected $version = '1.6.3'; public function __get($name) { diff --git a/app/Services/Sync/Learning.php b/app/Services/Sync/Learning.php index 9c1461bd..868e004a 100644 --- a/app/Services/Sync/Learning.php +++ b/app/Services/Sync/Learning.php @@ -59,10 +59,6 @@ class Learning extends AppService $key = $this->getSyncKey(); $redis->sAdd($key, $learning->request_id); - - if ($redis->sCard($key) == 1) { - $redis->expire($key, $this->lifetime); - } } public function getItemKey($id) diff --git a/app/Validators/ArticleQuery.php b/app/Validators/ArticleQuery.php index 54b812a5..578cc48c 100644 --- a/app/Validators/ArticleQuery.php +++ b/app/Validators/ArticleQuery.php @@ -7,7 +7,6 @@ namespace App\Validators; -use App\Caches\Category as CategoryCache; use App\Caches\Tag as TagCache; use App\Exceptions\BadRequest as BadRequestException; use App\Models\Article as ArticleModel; @@ -17,9 +16,9 @@ class ArticleQuery extends Validator public function checkCategory($id) { - $categoryCache = new CategoryCache(); + $validator = new Category(); - $category = $categoryCache->get($id); + $category = $validator->checkCategoryCache($id); if (!$category) { throw new BadRequestException('article_query.invalid_category'); diff --git a/app/Validators/CourseQuery.php b/app/Validators/CourseQuery.php index 320acbdf..f3b897e2 100644 --- a/app/Validators/CourseQuery.php +++ b/app/Validators/CourseQuery.php @@ -16,9 +16,9 @@ class CourseQuery extends Validator public function checkTopCategory($id) { - $categoryCache = new CategoryCache(); + $validator = new Category(); - $category = $categoryCache->get($id); + $category = $validator->checkCategoryCache($id); if (!$category) { throw new BadRequestException('course_query.invalid_top_category'); diff --git a/app/Validators/QuestionQuery.php b/app/Validators/QuestionQuery.php index 5c6f2814..83a1dbd0 100644 --- a/app/Validators/QuestionQuery.php +++ b/app/Validators/QuestionQuery.php @@ -14,6 +14,19 @@ use App\Models\Question as QuestionModel; class QuestionQuery extends Validator { + public function checkCategory($id) + { + $validator = new Category(); + + $category = $validator->checkCategoryCache($id); + + if (!$category) { + throw new BadRequestException('question_query.invalid_category'); + } + + return $category->id; + } + public function checkTag($id) { $tagCache = new TagCache();