1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-28 05:11:39 +08:00

首页可以切换"简洁"和“丰富”

This commit is contained in:
xiaochong0302 2020-09-11 20:00:31 +08:00
parent 8c7453a9ab
commit def5b3605a
15 changed files with 385 additions and 24 deletions

View File

@ -30,7 +30,7 @@ class IndexFreeCourseList extends Cache
{ {
$categoryLimit = 5; $categoryLimit = 5;
$courseLimit = 10; $courseLimit = 8;
$categories = $this->findCategories($categoryLimit); $categories = $this->findCategories($categoryLimit);
@ -100,7 +100,7 @@ class IndexFreeCourseList extends Cache
* @param int $limit * @param int $limit
* @return ResultsetInterface|Resultset|CourseModel[] * @return ResultsetInterface|Resultset|CourseModel[]
*/ */
protected function findCategoryCourses($categoryId, $limit = 10) protected function findCategoryCourses($categoryId, $limit = 8)
{ {
$categoryService = new CategoryService(); $categoryService = new CategoryService();

View File

@ -30,7 +30,7 @@ class IndexNewCourseList extends Cache
{ {
$categoryLimit = 5; $categoryLimit = 5;
$courseLimit = 10; $courseLimit = 8;
$categories = $this->findCategories($categoryLimit); $categories = $this->findCategories($categoryLimit);
@ -100,7 +100,7 @@ class IndexNewCourseList extends Cache
* @param int $limit * @param int $limit
* @return ResultsetInterface|Resultset|CourseModel[] * @return ResultsetInterface|Resultset|CourseModel[]
*/ */
protected function findCategoryCourses($categoryId, $limit = 10) protected function findCategoryCourses($categoryId, $limit = 8)
{ {
$categoryService = new CategoryService(); $categoryService = new CategoryService();

View File

@ -0,0 +1,70 @@
<?php
namespace App\Caches;
use App\Models\Course as CourseModel;
use Phalcon\Mvc\Model\Resultset;
use Phalcon\Mvc\Model\ResultsetInterface;
/**
* 简版免费课程
*/
class IndexSimpleFreeCourseList extends Cache
{
protected $lifetime = 1 * 86400;
public function getLifetime()
{
return $this->lifetime;
}
public function getKey($id = null)
{
return 'index_simple_free_course_list';
}
public function getContent($id = null)
{
$limit = 8;
$courses = $this->findCourses($limit);
if ($courses->count() == 0) {
return [];
}
$result = [];
foreach ($courses as $course) {
$result[] = [
'id' => $course->id,
'title' => $course->title,
'cover' => $course->cover,
'market_price' => $course->market_price,
'vip_price' => $course->vip_price,
'model' => $course->model,
'level' => $course->level,
'user_count' => $course->user_count,
'lesson_count' => $course->lesson_count,
];
}
return $result;
}
/**
* @param int $limit
* @return ResultsetInterface|Resultset|CourseModel[]
*/
protected function findCourses($limit = 8)
{
return CourseModel::query()
->where('published = 1')
->andWhere('market_price = 0')
->orderBy('score DESC')
->limit($limit)
->execute();
}
}

View File

@ -0,0 +1,69 @@
<?php
namespace App\Caches;
use App\Models\Course as CourseModel;
use Phalcon\Mvc\Model\Resultset;
use Phalcon\Mvc\Model\ResultsetInterface;
/**
* 简版新上课程
*/
class IndexSimpleNewCourseList extends Cache
{
protected $lifetime = 1 * 86400;
public function getLifetime()
{
return $this->lifetime;
}
public function getKey($id = null)
{
return 'index_simple_new_course_list';
}
public function getContent($id = null)
{
$limit = 8;
$courses = $this->findCourses($limit);
if ($courses->count() == 0) {
return [];
}
$result = [];
foreach ($courses as $course) {
$result[] = [
'id' => $course->id,
'title' => $course->title,
'cover' => $course->cover,
'market_price' => $course->market_price,
'vip_price' => $course->vip_price,
'model' => $course->model,
'level' => $course->level,
'user_count' => $course->user_count,
'lesson_count' => $course->lesson_count,
];
}
return $result;
}
/**
* @param int $limit
* @return ResultsetInterface|Resultset|CourseModel[]
*/
protected function findCourses($limit = 8)
{
return CourseModel::query()
->where('published = 1')
->orderBy('id DESC')
->limit($limit)
->execute();
}
}

View File

@ -0,0 +1,70 @@
<?php
namespace App\Caches;
use App\Models\Course as CourseModel;
use Phalcon\Mvc\Model\Resultset;
use Phalcon\Mvc\Model\ResultsetInterface;
/**
* 简版会员课程
*/
class IndexSimpleVipCourseList extends Cache
{
protected $lifetime = 1 * 86400;
public function getLifetime()
{
return $this->lifetime;
}
public function getKey($id = null)
{
return 'index_simple_vip_course_list';
}
public function getContent($id = null)
{
$limit = 8;
$courses = $this->findCourses($limit);
if ($courses->count() == 0) {
return [];
}
$result = [];
foreach ($courses as $course) {
$result[] = [
'id' => $course->id,
'title' => $course->title,
'cover' => $course->cover,
'market_price' => $course->market_price,
'vip_price' => $course->vip_price,
'model' => $course->model,
'level' => $course->level,
'user_count' => $course->user_count,
'lesson_count' => $course->lesson_count,
];
}
return $result;
}
/**
* @param int $limit
* @return ResultsetInterface|Resultset|CourseModel[]
*/
protected function findCourses($limit = 8)
{
return CourseModel::query()
->where('published = 1')
->andWhere('vip_price >= 0')
->orderBy('score DESC')
->limit($limit)
->execute();
}
}

View File

@ -30,7 +30,7 @@ class IndexVipCourseList extends Cache
{ {
$categoryLimit = 5; $categoryLimit = 5;
$courseLimit = 10; $courseLimit = 8;
$categories = $this->findCategories($categoryLimit); $categories = $this->findCategories($categoryLimit);
@ -100,7 +100,7 @@ class IndexVipCourseList extends Cache
* @param int $limit * @param int $limit
* @return ResultsetInterface|Resultset|CourseModel[] * @return ResultsetInterface|Resultset|CourseModel[]
*/ */
protected function findCategoryCourses($categoryId, $limit = 10) protected function findCategoryCourses($categoryId, $limit = 8)
{ {
$categoryService = new CategoryService(); $categoryService = new CategoryService();

View File

@ -23,6 +23,13 @@
</div> </div>
</div> </div>
</div> </div>
<div class="layui-form-item">
<label class="layui-form-label">首页版式</label>
<div class="layui-input-block">
<input type="radio" name="index_template" value="simple" title="简洁" {% if site.index_template == 'simple' %}checked{% endif %}>
<input type="radio" name="index_template" value="full" title="丰富" {% if site.index_template == 'full' %}checked{% endif %}>
</div>
</div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">网站名称</label> <label class="layui-form-label">网站名称</label>
<div class="layui-input-block"> <div class="layui-input-block">

View File

@ -15,13 +15,37 @@ class IndexController extends Controller
$this->seo->setKeywords($this->siteInfo['keywords']); $this->seo->setKeywords($this->siteInfo['keywords']);
$this->seo->setDescription($this->siteInfo['description']); $this->seo->setDescription($this->siteInfo['description']);
$indexService = new IndexService(); $template = $this->siteInfo['index_template'] ?? 'full';
$this->view->setVar('lives', $indexService->getLives()); if ($template == 'full') {
$this->view->setVar('carousels', $indexService->getCarousels()); $this->fullIndex();
$this->view->setVar('new_courses', $indexService->getNewCourses()); } else {
$this->view->setVar('free_courses', $indexService->getFreeCourses()); $this->simpleIndex();
$this->view->setVar('vip_courses', $indexService->getVipCourses()); }
}
protected function fullIndex()
{
$service = new IndexService();
$this->view->pick('index/full');
$this->view->setVar('lives', $service->getLives());
$this->view->setVar('carousels', $service->getCarousels());
$this->view->setVar('new_courses', $service->getNewCourses());
$this->view->setVar('free_courses', $service->getFreeCourses());
$this->view->setVar('vip_courses', $service->getVipCourses());
}
protected function simpleIndex()
{
$service = new IndexService();
$this->view->pick('index/simple');
$this->view->setVar('lives', $service->getLives());
$this->view->setVar('carousels', $service->getCarousels());
$this->view->setVar('new_courses', $service->getSimpleNewCourses());
$this->view->setVar('free_courses', $service->getSimpleFreeCourses());
$this->view->setVar('vip_courses', $service->getSimpleVipCourses());
} }
} }

View File

@ -2,11 +2,14 @@
namespace App\Http\Desktop\Services; namespace App\Http\Desktop\Services;
use App\Caches\IndexCarouselList as IndexCarouselListCache; use App\Caches\IndexCarouselList;
use App\Caches\IndexFreeCourseList as IndexFreeCourseListCache; use App\Caches\IndexFreeCourseList;
use App\Caches\IndexLiveList as IndexLiveListCache; use App\Caches\IndexLiveList;
use App\Caches\IndexNewCourseList as IndexNewCourseListCache; use App\Caches\IndexNewCourseList;
use App\Caches\IndexVipCourseList as IndexVipCourseListCache; use App\Caches\IndexSimpleFreeCourseList;
use App\Caches\IndexSimpleNewCourseList;
use App\Caches\IndexSimpleVipCourseList;
use App\Caches\IndexVipCourseList;
use App\Models\Carousel as CarouselModel; use App\Models\Carousel as CarouselModel;
class Index extends Service class Index extends Service
@ -14,7 +17,7 @@ class Index extends Service
public function getCarousels() public function getCarousels()
{ {
$cache = new IndexCarouselListCache(); $cache = new IndexCarouselList();
/** /**
* @var array $carousels * @var array $carousels
@ -53,14 +56,14 @@ class Index extends Service
public function getLives() public function getLives()
{ {
$cache = new IndexLiveListCache(); $cache = new IndexLiveList();
return $cache->get(); return $cache->get();
} }
public function getNewCourses() public function getNewCourses()
{ {
$cache = new IndexNewCourseListCache(); $cache = new IndexNewCourseList();
$courses = $cache->get(); $courses = $cache->get();
@ -69,7 +72,7 @@ class Index extends Service
public function getFreeCourses() public function getFreeCourses()
{ {
$cache = new IndexFreeCourseListCache(); $cache = new IndexFreeCourseList();
$courses = $cache->get(); $courses = $cache->get();
@ -78,13 +81,34 @@ class Index extends Service
public function getVipCourses() public function getVipCourses()
{ {
$cache = new IndexVipCourseListCache(); $cache = new IndexVipCourseList();
$courses = $cache->get(); $courses = $cache->get();
return $this->handleCategoryCourses($courses); return $this->handleCategoryCourses($courses);
} }
public function getSimpleNewCourses()
{
$cache = new IndexSimpleNewCourseList();
return $cache->get();
}
public function getSimpleFreeCourses()
{
$cache = new IndexSimpleFreeCourseList();
return $cache->get();
}
public function getSimpleVipCourses()
{
$cache = new IndexSimpleVipCourseList();
return $cache->get();
}
protected function handleCategoryCourses($items, $limit = 8) protected function handleCategoryCourses($items, $limit = 8)
{ {
if (count($items) == 0) { if (count($items) == 0) {

View File

@ -0,0 +1,60 @@
{% extends 'templates/main.volt' %}
{% block content %}
{{ partial('macros/course') }}
{%- macro show_courses(courses) %}
<div class="index-course-list clearfix">
<div class="layui-row layui-col-space20">
{% for course in courses %}
<div class="layui-col-md3">
{{ course_card(course) }}
</div>
{% endfor %}
</div>
</div>
{%- endmacro %}
<div class="index-wrap index-carousel wrap">
<div class="layui-carousel" id="carousel">
<div class="carousel" carousel-item>
{% for carousel in carousels %}
<div class="item" style="{{ carousel.style }}">
<a href="{{ carousel.url }}">
<img class="carousel" src="{{ carousel.cover }}" alt="{{ carousel.title }}">
</a>
</div>
{% endfor %}
</div>
</div>
</div>
<div class="index-wrap wrap">
<div class="header">新上课程</div>
<div class="content">
{{ show_courses(new_courses) }}
</div>
</div>
<div class="index-wrap wrap">
<div class="header">免费课程</div>
<div class="content">
{{ show_courses(free_courses) }}
</div>
</div>
<div class="index-wrap wrap">
<div class="header">会员课程</div>
<div class="content">
{{ show_courses(vip_courses) }}
</div>
</div>
{% endblock %}
{% block include_js %}
{{ js_include('desktop/js/index.js') }}
{% endblock %}

View File

@ -3,6 +3,8 @@
namespace Bootstrap; namespace Bootstrap;
use App\Library\Logger as AppLogger; use App\Library\Logger as AppLogger;
use Phalcon\Config as PhConfig;
use Phalcon\Logger\Adapter\File as PhLogger;
use Phalcon\Mvc\User\Component; use Phalcon\Mvc\User\Component;
class ConsoleErrorHandler extends Component class ConsoleErrorHandler extends Component
@ -25,17 +27,30 @@ class ConsoleErrorHandler extends Component
*/ */
public function handleException($e) public function handleException($e)
{ {
$content = sprintf('%s(%d): %s', $e->getFile(), $e->getLine(), $e->getMessage()); $config = $this->getConfig();
$logger = $this->getLogger(); $logger = $this->getLogger();
$content = sprintf('%s(%d): %s', $e->getFile(), $e->getLine(), $e->getMessage());
$logger->error($content); $logger->error($content);
if ($this->config->env == ENV_DEV) { if ($config->get('env') == ENV_DEV) {
echo $content; echo $content;
} }
} }
/**
* @return PhConfig
*/
protected function getConfig()
{
return $this->getDI()->get('config');
}
/**
* @return PhLogger
*/
protected function getLogger() protected function getLogger()
{ {
$logger = new AppLogger(); $logger = new AppLogger();

View File

@ -24,6 +24,9 @@ abstract class Kernel
*/ */
protected $loader; protected $loader;
/**
* @var array
*/
protected $configs = []; protected $configs = [];
public function getApp() public function getApp()

View File

@ -230,6 +230,16 @@ final class InsertSettingData extends AbstractMigration
'item_key' => 'enabled', 'item_key' => 'enabled',
'item_value' => '1', 'item_value' => '1',
], ],
[
'section' => 'pay.wxpay',
'item_key' => 'mp_app_id',
'item_value' => '',
],
[
'section' => 'pay.wxpay',
'item_key' => 'mini_app_id',
'item_value' => '',
],
[ [
'section' => 'pay.wxpay', 'section' => 'pay.wxpay',
'item_key' => 'app_id', 'item_key' => 'app_id',
@ -300,6 +310,11 @@ final class InsertSettingData extends AbstractMigration
'item_key' => 'closed_tips', 'item_key' => 'closed_tips',
'item_value' => '站点维护中,请稍后再访问。', 'item_value' => '站点维护中,请稍后再访问。',
], ],
[
'section' => 'site',
'item_key' => 'index_template',
'item_value' => 'simple',
],
[ [
'section' => 'site', 'section' => 'site',
'item_key' => 'copyright', 'item_key' => 'copyright',

View File

@ -202,6 +202,10 @@ body {
line-height: 40px; line-height: 40px;
} }
.index-wrap {
padding-bottom: 15px;
}
.index-wrap .layui-tab { .index-wrap .layui-tab {
margin-bottom: 0; margin-bottom: 0;
} }