diff --git a/app/Caches/Article.php b/app/Caches/Article.php index 3bca7d22..18baa434 100644 --- a/app/Caches/Article.php +++ b/app/Caches/Article.php @@ -12,7 +12,7 @@ use App\Repos\Article as ArticleRepo; class Article extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/Chapter.php b/app/Caches/Chapter.php index 5f237013..b2a0fe16 100644 --- a/app/Caches/Chapter.php +++ b/app/Caches/Chapter.php @@ -12,7 +12,7 @@ use App\Repos\Chapter as ChapterRepo; class Chapter extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/Course.php b/app/Caches/Course.php index 872343c0..4479466d 100644 --- a/app/Caches/Course.php +++ b/app/Caches/Course.php @@ -12,7 +12,7 @@ use App\Repos\Course as CourseRepo; class Course extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/CourseCategoryList.php b/app/Caches/CourseCategoryList.php index 0634ffc7..12681a06 100644 --- a/app/Caches/CourseCategoryList.php +++ b/app/Caches/CourseCategoryList.php @@ -13,7 +13,7 @@ use App\Repos\Course as CourseRepo; class CourseCategoryList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/CoursePackageList.php b/app/Caches/CoursePackageList.php index c251e2e9..6c27dd1e 100644 --- a/app/Caches/CoursePackageList.php +++ b/app/Caches/CoursePackageList.php @@ -13,7 +13,7 @@ use App\Repos\Course as CourseRepo; class CoursePackageList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/CourseRecommendedList.php b/app/Caches/CourseRecommendedList.php index fb6c5d17..c810082f 100644 --- a/app/Caches/CourseRecommendedList.php +++ b/app/Caches/CourseRecommendedList.php @@ -14,7 +14,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class CourseRecommendedList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/CourseRelatedList.php b/app/Caches/CourseRelatedList.php index 46274fc1..d8d8f58c 100644 --- a/app/Caches/CourseRelatedList.php +++ b/app/Caches/CourseRelatedList.php @@ -13,7 +13,7 @@ use App\Repos\Course as CourseRepo; class CourseRelatedList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/CourseTeacherList.php b/app/Caches/CourseTeacherList.php index 70314edc..1c676f1a 100644 --- a/app/Caches/CourseTeacherList.php +++ b/app/Caches/CourseTeacherList.php @@ -13,7 +13,7 @@ use App\Repos\Course as CourseRepo; class CourseTeacherList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/CourseTopicList.php b/app/Caches/CourseTopicList.php index 0d9e95aa..580d7d09 100644 --- a/app/Caches/CourseTopicList.php +++ b/app/Caches/CourseTopicList.php @@ -14,7 +14,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class CourseTopicList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/FeaturedArticleList.php b/app/Caches/FeaturedArticleList.php new file mode 100644 index 00000000..bd5fc0f2 --- /dev/null +++ b/app/Caches/FeaturedArticleList.php @@ -0,0 +1,83 @@ +findArticles($limit); + + if ($articles->count() == 0) { + return []; + } + + $result = []; + + foreach ($articles as $article) { + + $userCount = $article->user_count; + + if ($article->fake_user_count > $article->user_count) { + $userCount = $article->fake_user_count; + } + + $result[] = [ + 'id' => $article->id, + 'title' => $article->title, + 'cover' => $article->cover, + 'market_price' => (float)$article->market_price, + 'vip_price' => (float)$article->vip_price, + 'user_count' => $userCount, + 'favorite_count' => $article->favorite_count, + 'comment_count' => $article->comment_count, + 'view_count' => $article->view_count, + 'like_count' => $article->like_count, + ]; + } + + return $result; + } + + /** + * @param int $limit + * @return ResultsetInterface|Resultset|ArticleModel[] + */ + protected function findArticles($limit = 8) + { + return ArticleModel::query() + ->where('featured = 1') + ->andWhere('published = 1') + ->andWhere('deleted = 0') + ->orderBy('id DESC') + ->limit($limit) + ->execute(); + } + +} diff --git a/app/Caches/FeaturedCourseList.php b/app/Caches/FeaturedCourseList.php new file mode 100644 index 00000000..cb2817a8 --- /dev/null +++ b/app/Caches/FeaturedCourseList.php @@ -0,0 +1,85 @@ +findCourses($limit); + + if ($courses->count() == 0) { + return []; + } + + $result = []; + + foreach ($courses as $course) { + + $userCount = $course->user_count; + + if ($course->fake_user_count > $course->user_count) { + $userCount = $course->fake_user_count; + } + + $result[] = [ + 'id' => $course->id, + 'title' => $course->title, + 'cover' => $course->cover, + 'model' => $course->model, + 'level' => $course->level, + 'rating' => round($course->rating, 1), + 'market_price' => (float)$course->market_price, + 'vip_price' => (float)$course->vip_price, + 'user_count' => $userCount, + 'lesson_count' => $course->lesson_count, + 'review_count' => $course->review_count, + 'favorite_count' => $course->favorite_count, + ]; + } + + return $result; + } + + /** + * @param int $limit + * @return ResultsetInterface|Resultset|CourseModel[] + */ + protected function findCourses($limit = 8) + { + return CourseModel::query() + ->where('featured = 1') + ->andWhere('published = 1') + ->andWhere('deleted = 0') + ->orderBy('id DESC') + ->limit($limit) + ->execute(); + } + +} diff --git a/app/Caches/FlashSale.php b/app/Caches/FlashSale.php index 8062e03a..d8b89f43 100644 --- a/app/Caches/FlashSale.php +++ b/app/Caches/FlashSale.php @@ -12,7 +12,7 @@ use App\Repos\FlashSale as FlashSaleRepo; class FlashSale extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/HotQuestionList.php b/app/Caches/HotQuestionList.php index f557a688..64220fd8 100644 --- a/app/Caches/HotQuestionList.php +++ b/app/Caches/HotQuestionList.php @@ -14,7 +14,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class HotQuestionList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexFeaturedCourseList.php b/app/Caches/IndexFeaturedCourseList.php index 54b44f4d..f7d0e6ae 100644 --- a/app/Caches/IndexFeaturedCourseList.php +++ b/app/Caches/IndexFeaturedCourseList.php @@ -19,7 +19,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexFeaturedCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexFlashSaleList.php b/app/Caches/IndexFlashSaleList.php index 587da335..7fd379b6 100644 --- a/app/Caches/IndexFlashSaleList.php +++ b/app/Caches/IndexFlashSaleList.php @@ -12,7 +12,7 @@ use App\Services\Logic\FlashSale\SaleList; class IndexFlashSaleList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexFreeCourseList.php b/app/Caches/IndexFreeCourseList.php index d96847c0..bc20a9dc 100644 --- a/app/Caches/IndexFreeCourseList.php +++ b/app/Caches/IndexFreeCourseList.php @@ -19,7 +19,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexFreeCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexLiveList.php b/app/Caches/IndexLiveList.php index 6d5d0836..734150a1 100644 --- a/app/Caches/IndexLiveList.php +++ b/app/Caches/IndexLiveList.php @@ -18,7 +18,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexLiveList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexNewCourseList.php b/app/Caches/IndexNewCourseList.php index 27d83172..4975cb27 100644 --- a/app/Caches/IndexNewCourseList.php +++ b/app/Caches/IndexNewCourseList.php @@ -19,7 +19,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexNewCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexSimpleFeaturedCourseList.php b/app/Caches/IndexSimpleFeaturedCourseList.php index 1ea87812..b5433216 100644 --- a/app/Caches/IndexSimpleFeaturedCourseList.php +++ b/app/Caches/IndexSimpleFeaturedCourseList.php @@ -17,7 +17,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexSimpleFeaturedCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexSimpleFreeCourseList.php b/app/Caches/IndexSimpleFreeCourseList.php index 065c6066..34a6d4f7 100644 --- a/app/Caches/IndexSimpleFreeCourseList.php +++ b/app/Caches/IndexSimpleFreeCourseList.php @@ -17,7 +17,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexSimpleFreeCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexSimpleNewCourseList.php b/app/Caches/IndexSimpleNewCourseList.php index b6e0b6b9..7dffa5af 100644 --- a/app/Caches/IndexSimpleNewCourseList.php +++ b/app/Caches/IndexSimpleNewCourseList.php @@ -17,7 +17,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexSimpleNewCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexSimpleVipCourseList.php b/app/Caches/IndexSimpleVipCourseList.php index bb073985..6756b39e 100644 --- a/app/Caches/IndexSimpleVipCourseList.php +++ b/app/Caches/IndexSimpleVipCourseList.php @@ -17,7 +17,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexSimpleVipCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/IndexTeacherList.php b/app/Caches/IndexTeacherList.php index df9d2056..0946f126 100644 --- a/app/Caches/IndexTeacherList.php +++ b/app/Caches/IndexTeacherList.php @@ -14,7 +14,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexTeacherList extends Cache { - protected $lifetime = 1 * 3600; + protected $lifetime = 3600; public function getLifetime() { diff --git a/app/Caches/IndexVipCourseList.php b/app/Caches/IndexVipCourseList.php index db09222a..6b268160 100644 --- a/app/Caches/IndexVipCourseList.php +++ b/app/Caches/IndexVipCourseList.php @@ -19,7 +19,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class IndexVipCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/PackageCourseList.php b/app/Caches/PackageCourseList.php index 2843cd71..90de701b 100644 --- a/app/Caches/PackageCourseList.php +++ b/app/Caches/PackageCourseList.php @@ -13,7 +13,7 @@ use App\Repos\Package as PackageRepo; class PackageCourseList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/PointGift.php b/app/Caches/PointGift.php index e9adc52e..07f5afa0 100644 --- a/app/Caches/PointGift.php +++ b/app/Caches/PointGift.php @@ -12,7 +12,7 @@ use App\Repos\PointGift as PointGiftRepo; class PointGift extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/PointHotGiftList.php b/app/Caches/PointHotGiftList.php index 5fe9213a..529c479c 100644 --- a/app/Caches/PointHotGiftList.php +++ b/app/Caches/PointHotGiftList.php @@ -19,7 +19,7 @@ class PointHotGiftList extends Cache * * @var int */ - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; /** * 显示个数 diff --git a/app/Caches/Question.php b/app/Caches/Question.php index f350f6cc..b832fa1f 100644 --- a/app/Caches/Question.php +++ b/app/Caches/Question.php @@ -12,7 +12,7 @@ use App\Repos\Question as QuestionRepo; class Question extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/TaggedArticleList.php b/app/Caches/TaggedArticleList.php index 8113b4f8..d57faf7b 100644 --- a/app/Caches/TaggedArticleList.php +++ b/app/Caches/TaggedArticleList.php @@ -15,7 +15,7 @@ class TaggedArticleList extends Cache protected $limit = 5; - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/TaggedQuestionList.php b/app/Caches/TaggedQuestionList.php index d563dabe..7495823b 100644 --- a/app/Caches/TaggedQuestionList.php +++ b/app/Caches/TaggedQuestionList.php @@ -15,7 +15,7 @@ class TaggedQuestionList extends Cache protected $limit = 5; - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/TopAnswererList.php b/app/Caches/TopAnswererList.php index fe881f5d..37991604 100644 --- a/app/Caches/TopAnswererList.php +++ b/app/Caches/TopAnswererList.php @@ -16,7 +16,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class TopAnswererList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/TopAuthorList.php b/app/Caches/TopAuthorList.php index 48153879..882e4cab 100644 --- a/app/Caches/TopAuthorList.php +++ b/app/Caches/TopAuthorList.php @@ -16,7 +16,7 @@ use Phalcon\Mvc\Model\ResultsetInterface; class TopAuthorList extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/User.php b/app/Caches/User.php index 9e0825d3..9f8ece22 100644 --- a/app/Caches/User.php +++ b/app/Caches/User.php @@ -12,7 +12,7 @@ use App\Repos\User as UserRepo; class User extends Cache { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Caches/UserDailyCounter.php b/app/Caches/UserDailyCounter.php index afda376e..19f59830 100644 --- a/app/Caches/UserDailyCounter.php +++ b/app/Caches/UserDailyCounter.php @@ -10,7 +10,7 @@ namespace App\Caches; class UserDailyCounter extends Counter { - protected $lifetime = 1 * 86400; + protected $lifetime = 86400; public function getLifetime() { diff --git a/app/Http/Home/Controllers/HelpController.php b/app/Http/Home/Controllers/HelpController.php index ff1dfc70..2de44d92 100644 --- a/app/Http/Home/Controllers/HelpController.php +++ b/app/Http/Home/Controllers/HelpController.php @@ -8,7 +8,6 @@ namespace App\Http\Home\Controllers; use App\Http\Home\Services\FullH5Url as FullH5UrlService; -use App\Http\Home\Services\Index as IndexService; use App\Services\Logic\Help\HelpInfo as HelpInfoService; use App\Services\Logic\Help\HelpList as HelpListService; @@ -30,8 +29,6 @@ class HelpController extends Controller return $this->response->redirect($location); } - $featuredCourses = $this->getFeaturedCourses(); - $service = new HelpListService(); $items = $service->handle(); @@ -39,7 +36,6 @@ class HelpController extends Controller $this->seo->prependTitle('帮助'); $this->view->setVar('items', $items); - $this->view->setVar('featured_courses', $featuredCourses); } /** @@ -66,19 +62,9 @@ class HelpController extends Controller $this->notFound(); } - $featuredCourses = $this->getFeaturedCourses(); - $this->seo->prependTitle(['帮助', $help['title']]); $this->view->setVar('help', $help); - $this->view->setVar('featured_courses', $featuredCourses); - } - - protected function getFeaturedCourses() - { - $service = new IndexService(); - - return $service->getSimpleFeaturedCourses(); } } diff --git a/app/Http/Home/Controllers/WidgetController.php b/app/Http/Home/Controllers/WidgetController.php index 1df05810..1d558745 100644 --- a/app/Http/Home/Controllers/WidgetController.php +++ b/app/Http/Home/Controllers/WidgetController.php @@ -7,6 +7,8 @@ namespace App\Http\Home\Controllers; +use App\Caches\FeaturedArticleList as FeaturedArticleListCache; +use App\Caches\FeaturedCourseList as FeaturedCourseListCache; use App\Services\Logic\Article\TopAuthorList as TopAuthorListService; use App\Services\Logic\Question\HotQuestionList as HotQuestionListService; use App\Services\Logic\Question\TopAnswererList as TopAnswererListService; @@ -33,6 +35,34 @@ class WidgetController extends Controller $this->view->setVar('tags', $pager->items); } + /** + * @Get("/featured/courses", name="home.widget.featured_courses") + */ + public function featuredCoursesAction() + { + $cache = new FeaturedCourseListCache(); + + $courses = $cache->get(); + + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); + $this->view->pick('widget/featured_courses'); + $this->view->setVar('courses', $courses); + } + + /** + * @Get("/featured/articles", name="home.widget.featured_articles") + */ + public function featuredArticlesAction() + { + $cache = new FeaturedArticleListCache(); + + $articles = $cache->get(); + + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); + $this->view->pick('widget/featured_articles'); + $this->view->setVar('articles', $articles); + } + /** * @Get("/hot/questions", name="home.widget.hot_questions") */ diff --git a/app/Http/Home/Views/help/index.volt b/app/Http/Home/Views/help/index.volt index 71003dcb..b4078aae 100644 --- a/app/Http/Home/Views/help/index.volt +++ b/app/Http/Home/Views/help/index.volt @@ -2,7 +2,7 @@ {% block content %} - {{ partial('macros/course') }} + {% set courses_url = url({'for':'home.widget.featured_courses'}) %}
{% endblock %} -{% block include_js %} +{% block inline_js %} - {{ js_include('home/js/help.js') }} + {% endblock %} \ No newline at end of file diff --git a/app/Http/Home/Views/help/show.volt b/app/Http/Home/Views/help/show.volt index a816ca07..b243fd1a 100644 --- a/app/Http/Home/Views/help/show.volt +++ b/app/Http/Home/Views/help/show.volt @@ -2,10 +2,7 @@ {% block content %} - {{ partial('macros/course') }} - - {% set share_url = share_url('help',help.id,auth_user.id) %} - {% set qrcode_url = url({'for':'home.qrcode'},{'text':share_url}) %} + {% set courses_url = url({'for':'home.widget.featured_courses'}) %}