From 5617a5f1c1362228f5491759835a79d147224fe5 Mon Sep 17 00:00:00 2001 From: koogua Date: Sun, 26 Sep 2021 12:25:38 +0800 Subject: [PATCH] v1.4.5 beta4 --- CHANGELOG.md | 2 + app/Caches/IndexArticleList.php | 2 +- app/Caches/IndexFlashSaleList.php | 36 ++++++++++ app/Caches/IndexQuestionList.php | 2 +- app/Caches/IndexTeacherList.php | 68 ++++++++++++++++++ app/Caches/SaleTrend.php | 70 ------------------- app/Caches/SiteGlobalStat.php | 6 ++ .../Admin/Views/index/main_global_stat.volt | 4 +- app/Http/Api/Controllers/IndexController.php | 26 +++++++ app/Validators/UserLimit.php | 2 +- 10 files changed, 143 insertions(+), 75 deletions(-) create mode 100644 app/Caches/IndexFlashSaleList.php create mode 100644 app/Caches/IndexTeacherList.php delete mode 100644 app/Caches/SaleTrend.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 9914dcf3..3fe34773 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ ### [v1.4.5](https://gitee.com/koogua/course-tencent-cloud/releases/v1.4.5)(2021-09-27) - 修正点击内容分享到微信会额外出现公众号二维码的问题 +- 修正后台首页提问和回答的数量统计 - 调整登录限制(邮箱|手机)为注册限制 - 调整订单发货为每一分钟执行一次 +- 增加首页推荐教师接口 - 增加微信公众号支付处理 - 增加取消订单功能 - 优化计划任务 diff --git a/app/Caches/IndexArticleList.php b/app/Caches/IndexArticleList.php index 0348b0a4..0f03cc0f 100644 --- a/app/Caches/IndexArticleList.php +++ b/app/Caches/IndexArticleList.php @@ -14,7 +14,7 @@ use App\Services\Logic\Article\ArticleList as ArticleListService; class IndexArticleList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 15 * 60; public function getLifetime() { diff --git a/app/Caches/IndexFlashSaleList.php b/app/Caches/IndexFlashSaleList.php new file mode 100644 index 00000000..587da335 --- /dev/null +++ b/app/Caches/IndexFlashSaleList.php @@ -0,0 +1,36 @@ +handle(); + + return $sales[0]['items'] ?? []; + } + +} diff --git a/app/Caches/IndexQuestionList.php b/app/Caches/IndexQuestionList.php index db028c91..9c301b1a 100644 --- a/app/Caches/IndexQuestionList.php +++ b/app/Caches/IndexQuestionList.php @@ -14,7 +14,7 @@ use App\Services\Logic\Question\QuestionList as QuestionListService; class IndexQuestionList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 15 * 60; public function getLifetime() { diff --git a/app/Caches/IndexTeacherList.php b/app/Caches/IndexTeacherList.php new file mode 100644 index 00000000..2decb09d --- /dev/null +++ b/app/Caches/IndexTeacherList.php @@ -0,0 +1,68 @@ +lifetime; + } + + public function getKey($id = null) + { + return 'index_teacher_list'; + } + + public function getContent($id = null) + { + $teachers = $this->findTeachers(); + + if ($teachers->count() == 0) return []; + + $result = []; + + $baseUrl = kg_cos_url(); + + foreach ($teachers->toArray() as $teacher) { + + $teacher['avatar'] = $baseUrl . $teacher['avatar']; + + $result[] = [ + 'id' => $teacher['id'], + 'name' => $teacher['name'], + 'title' => $teacher['title'], + 'avatar' => $teacher['avatar'], + 'about' => $teacher['about'], + ]; + } + + return $result; + } + + /** + * @param int $limit + * @return ResultsetInterface|Resultset|UserModel[] + */ + protected function findTeachers($limit = 8) + { + return UserModel::query() + ->where('edu_role = :edu_role:', ['edu_role' => UserModel::EDU_ROLE_TEACHER]) + ->orderBy('RAND()') + ->limit($limit) + ->execute(); + } + +} diff --git a/app/Caches/SaleTrend.php b/app/Caches/SaleTrend.php deleted file mode 100644 index c5c7454d..00000000 --- a/app/Caches/SaleTrend.php +++ /dev/null @@ -1,70 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'sale_trend'; - } - - public function getContent($id = null) - { - - } - - /** - * @param OrderModel[] $sales - * @param int $days - * @return array - */ - protected function handleSales($sales, $days = 7) - { - $result = []; - - foreach (array_reverse(range(1, $days)) as $num) { - $date = date('Y-m-d', strtotime("-{$num} days")); - $result[$date] = 0; - } - - foreach ($sales as $sale) { - $date = date('Y-m-d', $sale->create_time); - $result[$date] += $sale->amount; - } - - return $result; - } - - /** - * @param int $days - * @return ResultsetInterface|Resultset|OrderModel[] - */ - protected function findSales($days = 7) - { - $time = strtotime("-{$days} days"); - - return OrderModel::query() - ->where('status = :status:', ['status' => OrderModel::STATUS_FINISHED]) - ->andWhere('create_time > :time:', ['time' => $time]) - ->execute(); - } - -} diff --git a/app/Caches/SiteGlobalStat.php b/app/Caches/SiteGlobalStat.php index 99cb45d3..2e93c8a4 100644 --- a/app/Caches/SiteGlobalStat.php +++ b/app/Caches/SiteGlobalStat.php @@ -7,12 +7,14 @@ namespace App\Caches; +use App\Repos\Answer as AnswerRepo; use App\Repos\Article as ArticleRepo; use App\Repos\Comment as CommentRepo; use App\Repos\Consult as ConsultRepo; use App\Repos\Course as CourseRepo; use App\Repos\ImGroup as GroupRepo; use App\Repos\Package as PackageRepo; +use App\Repos\Question as QuestionRepo; use App\Repos\Review as ReviewRepo; use App\Repos\Topic as TopicRepo; use App\Repos\User as UserRepo; @@ -36,6 +38,8 @@ class SiteGlobalStat extends Cache { $courseRepo = new CourseRepo(); $articleRepo = new ArticleRepo(); + $questionRepo = new QuestionRepo(); + $answerRepo = new AnswerRepo(); $commentRepo = new CommentRepo(); $consultRepo = new ConsultRepo(); $groupRepo = new GroupRepo(); @@ -47,6 +51,8 @@ class SiteGlobalStat extends Cache return [ 'course_count' => $courseRepo->countCourses(), 'article_count' => $articleRepo->countArticles(), + 'question_count' => $questionRepo->countQuestions(), + 'answer_count' => $answerRepo->countAnswers(), 'comment_count' => $commentRepo->countComments(), 'consult_count' => $consultRepo->countConsults(), 'group_count' => $groupRepo->countGroups(), diff --git a/app/Http/Admin/Views/index/main_global_stat.volt b/app/Http/Admin/Views/index/main_global_stat.volt index f4198c5a..1e9738d2 100644 --- a/app/Http/Admin/Views/index/main_global_stat.volt +++ b/app/Http/Admin/Views/index/main_global_stat.volt @@ -59,13 +59,13 @@
提问数
-
0
+
{{ global_stat.question_count }}
回答数
-
0
+
{{ global_stat.answer_count }}
diff --git a/app/Http/Api/Controllers/IndexController.php b/app/Http/Api/Controllers/IndexController.php index eb9557d9..d6efa30c 100644 --- a/app/Http/Api/Controllers/IndexController.php +++ b/app/Http/Api/Controllers/IndexController.php @@ -8,6 +8,7 @@ namespace App\Http\Api\Controllers; use App\Caches\IndexArticleList; +use App\Caches\IndexFlashSaleList; use App\Caches\IndexLiveList; use App\Caches\IndexQuestionList; use App\Caches\IndexSimpleFeaturedCourseList; @@ -15,6 +16,7 @@ use App\Caches\IndexSimpleFreeCourseList; use App\Caches\IndexSimpleNewCourseList; use App\Caches\IndexSimpleVipCourseList; use App\Caches\IndexSlideList; +use App\Caches\IndexTeacherList; /** * @RoutePrefix("/api/index") @@ -70,6 +72,30 @@ class IndexController extends Controller return $this->jsonSuccess(['lives' => $lives]); } + /** + * @Get("/teachers", name="api.index.teachers") + */ + public function teachersAction() + { + $cache = new IndexTeacherList(); + + $teachers = $cache->get(); + + return $this->jsonSuccess(['teachers' => $teachers]); + } + + /** + * @Get("/flash/sales", name="api.index.flash_sales") + */ + public function flashSalesAction() + { + $cache = new IndexFlashSaleList(); + + $sales = $cache->get(); + + return $this->jsonSuccess(['sales' => $sales]); + } + /** * @Get("/courses/featured", name="api.index.featured_courses") */ diff --git a/app/Validators/UserLimit.php b/app/Validators/UserLimit.php index 854b7294..95fbcc9e 100644 --- a/app/Validators/UserLimit.php +++ b/app/Validators/UserLimit.php @@ -111,7 +111,7 @@ class UserLimit extends Validator { $count = $this->counter->hGet($user->id, 'order_count'); - if ($count > 10) { + if ($count > 50) { throw new BadRequestException('user_limit.reach_daily_order_limit'); } }